13
0

OSC: Paths changed, feedback added, etc.

This commit is contained in:
Len Ovens 2016-05-31 14:09:38 -07:00
parent c69ef7aa37
commit 9ff3c55e34
7 changed files with 1594 additions and 376 deletions

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,8 @@
#define ardour_osc_h
#include <string>
#include <vector>
#include <bitset>
#include <sys/time.h>
#include <pthread.h>
@ -41,6 +43,7 @@
class OSCControllable;
class OSCRouteObserver;
class OSCGlobalObserver;
namespace ARDOUR {
class Session;
@ -92,6 +95,50 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
All
};
// keep a surface's global setup by remote server url
struct OSCSurface {
public:
std::string remote_url; // the url these setting belong to
uint32_t bank; // current bank
uint32_t bank_size; // size of banks for this surface
std::bitset<32> strip_types; // what strip types are a part of this bank
std::bitset<32> feedback; // What is fed back? strips/meters/timecode/bar_beat/global
int gainmode; // what kind of faders do we have Gain db or position 0 to 1023?
uint32_t surface_sel; // which strip within the bank is locally selected
//StripableList strips; //list of stripables for the current bank
};
/*
* Reminder of what strip_types there are
AudioTrack = 0x1,
MidiTrack = 0x2,
AudioBus = 0x4,
MidiBus = 0x8,
VCA = 0x10,
MasterOut = 0x800,
MonitorOut = 0x1000,
Auditioner = 0x2000,
Selected = 0x4000,
Hidden = 0x8000,
*/
/*
* feedback bits:
* [0] - Strips - buttons
* [1] - Strips - variables (pots/faders)
* [2] - Strips - Send SSID as path extension
* [3] - Send heart beat to surface
* [4] - Send feedback for master/global buttons/variables
* [5] - Send Bar and Beat
* [6] - Send Time code
* [7] - Send metering as dB or positional depending on gainmode
* [8] - Send metering as 16 bits (led strip)
* [9] - Send signal present (signal greater than -20dB)
*/
// storage for each surface's settings
typedef std::vector<OSCSurface> Surface;
Surface _surface;
std::string get_server_url ();
void set_debug_mode (OSCDebugMode m) { _debugmode = m; }
OSCDebugMode get_debug_mode () { return _debugmode; }
@ -127,6 +174,10 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
// end "Application Hook" handles
std::string get_unix_server_url ();
OSCSurface * get_surface (lo_address addr);
uint32_t get_sid (uint32_t rid, lo_address addr);
uint32_t get_rid (uint32_t sid, lo_address addr);
void global_feedback (std::bitset<32> feedback, lo_address msg, uint32_t gainmode);
void send_current_value (const char* path, lo_arg** argv, int argc, lo_message msg);
void current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg);
@ -152,6 +203,7 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
} \
int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
OSC_DEBUG; \
if (argc > 0 && !strcmp (types, "f") && argv[0]->f != 1.0) { return 0; } \
name (data); \
return 0; \
}
@ -160,6 +212,8 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
PATH_CALLBACK_MSG(transport_frame);
PATH_CALLBACK_MSG(transport_speed);
PATH_CALLBACK_MSG(record_enabled);
PATH_CALLBACK_MSG(bank_up);
PATH_CALLBACK_MSG(bank_down);
#define PATH_CALLBACK(name) \
static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
@ -244,6 +298,27 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
PATH_CALLBACK1(jump_by_bars,f,);
PATH_CALLBACK1(jump_by_seconds,f,);
PATH_CALLBACK1(master_set_gain,f,);
PATH_CALLBACK1(master_set_fader,i,);
PATH_CALLBACK1(master_set_trim,f,);
PATH_CALLBACK1(master_set_pan_stereo_position,f,);
PATH_CALLBACK1(master_set_mute,i,);
PATH_CALLBACK1(monitor_set_gain,f,);
PATH_CALLBACK1(monitor_set_fader,i,);
#define PATH_CALLBACK1_MSG(name,arg1type) \
static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
} \
int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
OSC_DEBUG; \
if (argc > 0) { \
name (argv[0]->arg1type, data); \
} \
return 0; \
}
PATH_CALLBACK1_MSG(set_surface_feedback,i);
#define PATH_CALLBACK2(name,arg1type,arg2type) \
static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
@ -257,14 +332,26 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
return 0; \
}
#define PATH_CALLBACK2_MSG(name,arg1type,arg2type) \
static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
} \
int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
OSC_DEBUG; \
if (argc > 1) { \
name (argv[0]->arg1type, argv[1]->arg2type, data); \
} \
return 0; \
}
#define PATH_CALLBACK3(name,arg1type,arg2type,arg3type) \
static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
} \
int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *) { \
int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
OSC_DEBUG; \
if (argc > 1) { \
name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type); \
name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type, data); \
} \
return 0; \
}
@ -273,57 +360,87 @@ class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
} \
int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *) { \
int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
OSC_DEBUG; \
if (argc > 1) { \
name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type,argv[3]->arg4type); \
name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type,argv[3]->arg4type, data); \
} \
return 0; \
}
PATH_CALLBACK2(locate,i,i);
PATH_CALLBACK2(loop_location,i,i);
PATH_CALLBACK2(route_mute,i,i);
PATH_CALLBACK2(route_solo,i,i);
PATH_CALLBACK2(route_recenable,i,i);
PATH_CALLBACK2(route_set_gain_abs,i,f);
PATH_CALLBACK2(route_set_gain_dB,i,f);
PATH_CALLBACK2(route_set_gain_fader,i,f);
PATH_CALLBACK2(route_set_trim_abs,i,f);
PATH_CALLBACK2(route_set_trim_dB,i,f);
PATH_CALLBACK2(route_set_pan_stereo_position,i,f);
PATH_CALLBACK2(route_set_pan_stereo_width,i,f);
PATH_CALLBACK3(route_set_send_gain_abs,i,i,f);
PATH_CALLBACK3(route_set_send_gain_dB,i,i,f);
PATH_CALLBACK4(route_plugin_parameter,i,i,i,f);
PATH_CALLBACK3(route_plugin_parameter_print,i,i,i);
PATH_CALLBACK4(set_surface,i,i,i,i);
PATH_CALLBACK2(locate,i,i);
PATH_CALLBACK2(loop_location,i,i);
PATH_CALLBACK2_MSG(route_mute,i,i);
PATH_CALLBACK2_MSG(route_solo,i,i);
PATH_CALLBACK2_MSG(route_recenable,i,i);
PATH_CALLBACK2_MSG(route_recsafe,i,i);
PATH_CALLBACK2_MSG(route_monitor_input,i,i);
PATH_CALLBACK2_MSG(route_monitor_disk,i,i);
PATH_CALLBACK2_MSG(route_set_gain_abs,i,f);
PATH_CALLBACK2_MSG(route_set_gain_dB,i,f);
PATH_CALLBACK2_MSG(route_set_gain_fader,i,f);
PATH_CALLBACK2_MSG(route_set_trim_abs,i,f);
PATH_CALLBACK2_MSG(route_set_trim_dB,i,f);
PATH_CALLBACK2_MSG(route_set_pan_stereo_position,i,f);
PATH_CALLBACK2_MSG(route_set_pan_stereo_width,i,f);
PATH_CALLBACK3(route_set_send_gain_abs,i,i,f);
PATH_CALLBACK3(route_set_send_gain_dB,i,i,f);
PATH_CALLBACK4(route_plugin_parameter,i,i,i,f);
PATH_CALLBACK3(route_plugin_parameter_print,i,i,i);
int route_mute (int rid, int yn);
int route_solo (int rid, int yn);
int route_recenable (int rid, int yn);
int route_set_gain_abs (int rid, float level);
int route_set_gain_dB (int rid, float dB);
int route_set_gain_fader (int rid, float pos);
int route_set_trim_abs (int rid, float level);
int route_set_trim_dB (int rid, float dB);
int route_set_pan_stereo_position (int rid, float left_right_fraction);
int route_set_pan_stereo_width (int rid, float percent);
int route_set_send_gain_abs (int rid, int sid, float val);
int route_set_send_gain_dB (int rid, int sid, float val);
int route_plugin_parameter (int rid, int piid,int par, float val);
int route_plugin_parameter_print (int rid, int piid,int par);
int route_mute (int rid, int yn, lo_message msg);
int route_solo (int rid, int yn, lo_message msg);
int route_recenable (int rid, int yn, lo_message msg);
int route_recsafe (int ssid, int yn, lo_message msg);
int route_monitor_input (int rid, int yn, lo_message msg);
int route_monitor_disk (int rid, int yn, lo_message msg);
int route_set_gain_abs (int rid, float level, lo_message msg);
int route_set_gain_dB (int rid, float dB, lo_message msg);
int route_set_gain_fader (int rid, float pos, lo_message msg);
int route_set_trim_abs (int rid, float level, lo_message msg);
int route_set_trim_dB (int rid, float dB, lo_message msg);
int route_set_pan_stereo_position (int rid, float left_right_fraction, lo_message msg);
int route_set_pan_stereo_width (int rid, float percent, lo_message msg);
int route_set_send_gain_abs (int rid, int sid, float val, lo_message msg);
int route_set_send_gain_dB (int rid, int sid, float val, lo_message msg);
int route_plugin_parameter (int rid, int piid,int par, float val, lo_message msg);
int route_plugin_parameter_print (int rid, int piid,int par, lo_message msg);
void listen_to_route (boost::shared_ptr<ARDOUR::Route>, lo_address);
void end_listen (boost::shared_ptr<ARDOUR::Route>, lo_address);
void drop_route (boost::weak_ptr<ARDOUR::Route>);
//banking functions
int set_bank (uint32_t bank_start, lo_message msg);
int bank_up (lo_message msg);
int bank_down (lo_message msg);
int set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gmode, lo_message msg);
int set_surface_feedback (uint32_t fb, lo_message msg);
int master_set_gain (float dB);
int master_set_fader (uint32_t position);
int master_set_trim (float dB);
int master_set_pan_stereo_position (float position);
int master_set_mute (uint32_t state);
int monitor_set_gain (float dB);
int monitor_set_fader (uint32_t position);
void listen_to_route (boost::shared_ptr<ARDOUR::Stripable>, lo_address);
void end_listen (boost::shared_ptr<ARDOUR::Stripable>, lo_address);
void drop_route (boost::weak_ptr<ARDOUR::Stripable>);
void route_name_changed (const PBD::PropertyChange&, boost::weak_ptr<ARDOUR::Route> r, lo_address addr);
void update_clock ();
bool periodic (void);
sigc::connection periodic_connection;
int route_send_fail (std::string path, uint32_t ssid, lo_message msg);
typedef std::list<OSCRouteObserver*> RouteObservers;
RouteObservers route_observers;
typedef std::list<OSCGlobalObserver*> GlobalObservers;
GlobalObservers global_observers;
void debugmsg (const char *prefix, const char *path, const char* types, lo_arg **argv, int argc);
static OSC* _instance;

View File

@ -0,0 +1,337 @@
/*
Copyright (C) 2009 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "boost/lambda/lambda.hpp"
#include "ardour/session.h"
#include "ardour/dB.h"
#include "ardour/meter.h"
#include "osc.h"
#include "osc_global_observer.h"
#include "i18n.h"
using namespace std;
using namespace PBD;
using namespace ARDOUR;
using namespace ArdourSurface;
OSCGlobalObserver::OSCGlobalObserver (Session& s, lo_address a, uint32_t gm, std::bitset<32> fb)
: gainmode (gm)
,feedback (fb)
{
addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
session = &s;
_last_frame = -1;
// connect to all the things we want to send feed back from
/*
* Master (todo)
* Pan width
*/
// Master channel first
boost::shared_ptr<Stripable> strip = session->master_out();
boost::shared_ptr<Controllable> mute_controllable = boost::dynamic_pointer_cast<Controllable>(strip->mute_control());
mute_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCGlobalObserver::send_change_message, this, X_("/master/mute"), strip->mute_control()), OSC::instance());
send_change_message ("/master/mute", strip->mute_control());
boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(strip->trim_control());
trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCGlobalObserver::send_trim_message, this, X_("/master/trimdB"), strip->trim_control()), OSC::instance());
send_trim_message ("/master/trimdB", strip->trim_control());
boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(strip->pan_azimuth_control());
pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCGlobalObserver::send_change_message, this, X_("/master/pan_stereo_position"), strip->pan_azimuth_control()), OSC::instance());
send_change_message ("/master/pan_stereo_position", strip->pan_azimuth_control());
boost::shared_ptr<Controllable> gain_controllable = boost::dynamic_pointer_cast<Controllable>(strip->gain_control());
if (gainmode) {
gain_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCGlobalObserver::send_gain_message, this, X_("/master/fader"), strip->gain_control()), OSC::instance());
send_gain_message ("/master/fader", strip->gain_control());
} else {
gain_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCGlobalObserver::send_gain_message, this, X_("/master/gain"), strip->gain_control()), OSC::instance());
send_gain_message ("/master/gain", strip->gain_control());
}
// monitor stuff next
/*
* Monitor (todo)
* Mute
* Dim
* Mono
* Rude Solo
* etc.
*/
strip = session->monitor_out();
// Hmm, it seems the monitor mute is not at route->mute_control()
/*boost::shared_ptr<Controllable> mute_controllable2 = boost::dynamic_pointer_cast<Controllable>(strip->mute_control());
//mute_controllable = boost::dynamic_pointer_cast<Controllable>(r2->mute_control());
mute_controllable2->Changed.connect (monitor_mute_connection, MISSING_INVALIDATOR, bind (&OSCGlobalObserver::send_change_message, this, X_("/monitor/mute"), strip->mute_control()), OSC::instance());
send_change_message ("/monitor/mute", strip->mute_control());
*/
gain_controllable = boost::dynamic_pointer_cast<Controllable>(strip->gain_control());
if (gainmode) {
gain_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCGlobalObserver::send_gain_message, this, X_("/monitor/fader"), strip->gain_control()), OSC::instance());
send_gain_message ("/monitor/fader", strip->gain_control());
} else {
gain_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCGlobalObserver::send_gain_message, this, X_("/monitor/gain"), strip->gain_control()), OSC::instance());
send_gain_message ("/monitor/gain", strip->gain_control());
}
/*
* Transport (todo)
* punchin/out
*/
//Transport feedback
session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_transport_state_changed, this), OSC::instance());
send_transport_state_changed ();
session->TransportLooped.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_transport_state_changed, this), OSC::instance());
session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_record_state_changed, this), OSC::instance());
send_record_state_changed ();
// session feedback
session->StateSaved.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_session_saved, this, _1), OSC::instance());
send_session_saved (session->snap_name());
/*
* Maybe (many) more
*/
}
OSCGlobalObserver::~OSCGlobalObserver ()
{
strip_connections.drop_connections ();
session_connections.drop_connections ();
lo_address_free (addr);
}
void
OSCGlobalObserver::tick ()
{
framepos_t now_frame = session->transport_frame();
if (now_frame != _last_frame) {
if (feedback[6]) { // timecode enabled
Timecode::Time timecode;
session->timecode_time (now_frame, timecode);
// Timecode mode: Hours/Minutes/Seconds/Frames
ostringstream os;
os << setw(2) << setfill('0') << timecode.hours;
os << ':';
os << setw(2) << setfill('0') << timecode.minutes;
os << ':';
os << setw(2) << setfill('0') << timecode.seconds;
os << '.';
os << setw(2) << setfill('0') << timecode.frames;
lo_message msg = lo_message_new ();
lo_message_add_string (msg, os.str().c_str());
lo_send_message (addr, "/timecode", msg);
lo_message_free (msg);
}
if (feedback[5]) { // Bar beat enabled
Timecode::BBT_Time bbt_time;
session->bbt_time (now_frame, bbt_time);
// semantics: BBB/bb/tttt
ostringstream os;
os << setw(3) << setfill('0') << bbt_time.bars;
os << '|';
os << setw(2) << setfill('0') << bbt_time.beats;
os << '|';
os << setw(4) << setfill('0') << bbt_time.ticks;
lo_message msg = lo_message_new ();
lo_message_add_string (msg, os.str().c_str());
lo_send_message (addr, "/bar_beat", msg);
lo_message_free (msg);
}
_last_frame = now_frame;
}
if (feedback[3]) { //heart beat enabled
if (_heartbeat == 10) {
lo_message msg = lo_message_new ();
lo_message_add_float (msg, 1.0);
lo_send_message (addr, "/heartbeat", msg);
lo_message_free (msg);
}
if (!_heartbeat) {
lo_message msg = lo_message_new ();
lo_message_add_float (msg, 0.0);
lo_send_message (addr, "/heartbeat", msg);
lo_message_free (msg);
}
_heartbeat++;
if (_heartbeat > 20) _heartbeat = 0;
}
if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
// the only meter here is master
float now_meter = session->master_out()->peak_meter()->meter_level(0, MeterMCP);
if (now_meter < -193) now_meter = -193;
if (_last_meter != now_meter) {
if (feedback[7] || feedback[8]) {
lo_message msg = lo_message_new ();
if (gainmode && feedback[7]) {
uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
lo_message_add_int32 (msg, lev1023);
lo_send_message (addr, "/master/meter", msg);
} else if ((!gainmode) && feedback[7]) {
lo_message_add_float (msg, now_meter);
lo_send_message (addr, "/master/meter", msg);
} else if (feedback[8]) {
uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
uint32_t ledbits = ~(0xfff<<ledlvl);
lo_message_add_int32 (msg, ledbits);
lo_send_message (addr, "/master/meter", msg);
}
lo_message_free (msg);
}
if (feedback[9]) {
lo_message msg = lo_message_new ();
float signal;
if (now_meter < -40) {
signal = 0;
} else {
signal = 1;
}
lo_message_add_float (msg, signal);
lo_send_message (addr, "/master/signal", msg);
lo_message_free (msg);
}
}
_last_meter = now_meter;
}
}
void
OSCGlobalObserver::send_change_message (string path, boost::shared_ptr<Controllable> controllable)
{
lo_message msg = lo_message_new ();
lo_message_add_float (msg, (float) controllable->get_value());
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
void
OSCGlobalObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
{
lo_message msg = lo_message_new ();
if (gainmode) {
if (controllable->get_value() == 1) {
lo_message_add_int32 (msg, 800);
} else {
lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
}
} else {
if (controllable->get_value() < 1e-15) {
lo_message_add_float (msg, -200);
} else {
lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
}
}
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
void
OSCGlobalObserver::send_trim_message (string path, boost::shared_ptr<Controllable> controllable)
{
lo_message msg = lo_message_new ();
lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
void
OSCGlobalObserver::send_transport_state_changed()
{
lo_message msg = lo_message_new ();
lo_message_add_int32 (msg, session->get_play_loop());
lo_send_message (addr, "/loop_toggle", msg);
lo_message_free (msg);
msg = lo_message_new ();
lo_message_add_int32 (msg, session->transport_speed() == 1.0);
lo_send_message (addr, "/transport_play", msg);
lo_message_free (msg);
msg = lo_message_new ();
lo_message_add_int32 (msg, session->transport_stopped ());
lo_send_message (addr, "/transport_stop", msg);
lo_message_free (msg);
msg = lo_message_new ();
lo_message_add_int32 (msg, session->transport_speed() < 0.0);
lo_send_message (addr, "/rewind", msg);
lo_message_free (msg);
msg = lo_message_new ();
lo_message_add_int32 (msg, session->transport_speed() > 1.0);
lo_send_message (addr, "/ffwd", msg);
lo_message_free (msg);
}
void
OSCGlobalObserver::send_record_state_changed ()
{
lo_message msg = lo_message_new ();
lo_message_add_int32 (msg, (int)session->get_record_enabled ());
lo_send_message (addr, "/rec_enable_toggle", msg);
lo_message_free (msg);
msg = lo_message_new ();
if (session->have_rec_enabled_track ()) {
lo_message_add_int32 (msg, 1);
} else {
lo_message_add_int32 (msg, 0);
}
lo_send_message (addr, "/record_tally", msg);
lo_message_free (msg);
}
void
OSCGlobalObserver::send_session_saved (std::string name)
{
lo_message msg = lo_message_new ();
lo_message_add_string (msg, name.c_str());
lo_send_message (addr, "/session_name", msg);
lo_message_free (msg);
}

View File

@ -0,0 +1,65 @@
/*
Copyright (C) 2009 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __osc_oscglobalobserver_h__
#define __osc_oscglobalobserver_h__
#include <string>
#include <boost/shared_ptr.hpp>
#include <sigc++/sigc++.h>
#include <lo/lo.h>
#include "pbd/controllable.h"
#include "pbd/stateful.h"
#include "ardour/types.h"
class OSCGlobalObserver
{
public:
OSCGlobalObserver (ARDOUR::Session& s, lo_address addr, uint32_t gainmode, std::bitset<32> feedback);
~OSCGlobalObserver ();
lo_address address() const { return addr; };
void tick (void);
private:
PBD::ScopedConnectionList strip_connections;
PBD::ScopedConnectionList session_connections;
lo_address addr;
std::string path;
uint32_t gainmode;
std::bitset<32> feedback;
ARDOUR::Session* session;
framepos_t _last_frame;
uint32_t _heartbeat;
float _last_meter;
void send_change_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
void send_gain_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
void send_trim_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
void send_transport_state_changed(void);
void send_record_state_changed (void);
void send_session_saved (std::string name);
};
#endif /* __osc_oscglobalobserver_h__ */

View File

@ -19,10 +19,11 @@
#include "boost/lambda/lambda.hpp"
#include "ardour/route.h"
#include "ardour/record_enable_control.h"
#include "ardour/audio_track.h"
#include "ardour/midi_track.h"
#include "ardour/session.h"
#include "ardour/track.h"
#include "ardour/monitor_control.h"
#include "ardour/dB.h"
#include "ardour/meter.h"
#include "osc.h"
#include "osc_route_observer.h"
@ -34,41 +35,172 @@ using namespace PBD;
using namespace ARDOUR;
using namespace ArdourSurface;
OSCRouteObserver::OSCRouteObserver (boost::shared_ptr<Route> r, lo_address a)
: _route (r)
OSCRouteObserver::OSCRouteObserver (boost::shared_ptr<Stripable> s, lo_address a, uint32_t ss, uint32_t gm, std::bitset<32> fb)
: _strip (s)
,ssid (ss)
,gainmode (gm)
,feedback (fb)
{
addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
_route->PropertyChanged.connect (name_changed_connection, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::name_changed, this, boost::lambda::_1), OSC::instance());
if (feedback[0]) { // buttons are separate feedback
_strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::name_changed, this, boost::lambda::_1), OSC::instance());
name_changed (ARDOUR::Properties::name);
boost::shared_ptr<AutomationControl> rc = _route->rec_enable_control();
if (rc) {
// XXX BIND ALERT: boost::shared_ptr to record enable control
// bound to functor.
rc->Changed.connect (rec_changed_connection, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/route/rec"), rc), OSC::instance());
_strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/mute"), _strip->mute_control()), OSC::instance());
send_change_message ("/strip/mute", _strip->mute_control());
_strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/solo"), _strip->solo_control()), OSC::instance());
send_change_message ("/strip/solo", _strip->solo_control());
boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
if (track) {
track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_monitor_status, this, track->monitoring_control()), OSC::instance());
send_monitor_status (track->monitoring_control());
}
boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
if (rec_controllable) {
rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/recenable"), _strip->rec_enable_control()), OSC::instance());
send_change_message ("/strip/recenable", _strip->rec_enable_control());
}
boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
if (rec_controllable) {
recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/record_safe"), _strip->rec_safe_control()), OSC::instance());
send_change_message ("/strip/record_safe", _strip->rec_safe_control());
}
}
boost::shared_ptr<Controllable> mute_controllable = boost::dynamic_pointer_cast<Controllable>(_route->mute_control());
mute_controllable->Changed.connect (mute_changed_connection, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/route/mute"), _route->mute_control()), OSC::instance());
if (feedback[1]) { // level controls
if (gainmode) {
_strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_gain_message, this, X_("/strip/fader"), _strip->gain_control()), OSC::instance());
send_gain_message ("/strip/fader", _strip->gain_control());
} else {
_strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_gain_message, this, X_("/strip/gain"), _strip->gain_control()), OSC::instance());
send_gain_message ("/strip/gain", _strip->gain_control());
}
boost::shared_ptr<Controllable> solo_controllable = boost::dynamic_pointer_cast<Controllable>(_route->solo_control());
solo_controllable->Changed.connect (solo_changed_connection, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/route/solo"), _route->solo_control()), OSC::instance());
boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
if (trim_controllable) {
trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_trim_message, this, X_("/strip/trimdB"), _strip->trim_control()), OSC::instance());
send_trim_message ("/strip/trimdB", _strip->trim_control());
}
boost::shared_ptr<Controllable> gain_controllable = boost::dynamic_pointer_cast<Controllable>(_route->gain_control());
gain_controllable->Changed.connect (gain_changed_connection, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/route/gain"), _route->gain_control()), OSC::instance());
boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
if (pan_controllable) {
pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/pan_stereo_position"), _strip->pan_azimuth_control()), OSC::instance());
send_change_message ("/strip/pan_stereo_position", _strip->pan_azimuth_control());
}
}
tick();
}
OSCRouteObserver::~OSCRouteObserver ()
{
name_changed_connection.disconnect();
rec_changed_connection.disconnect();
mute_changed_connection.disconnect();
solo_changed_connection.disconnect();
gain_changed_connection.disconnect();
strip_connections.drop_connections ();
// all strip buttons should be off and faders 0 and etc.
if (feedback[0]) { // buttons are separate feedback
lo_message msg = lo_message_new ();
// name is a string do it first
string path = "/strip/name";
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
lo_message_add_string (msg, " ");
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
clear_strip ("/strip/mute", 0);
clear_strip ("/strip/solo", 0);
clear_strip ("/strip/recenable", 0);
clear_strip ("/strip/record_safe", 0);
clear_strip ("/strip/monitor_input", 0);
clear_strip ("/strip/monitor_disk", 0);
}
if (feedback[1]) { // level controls
if (gainmode) {
clear_strip ("/strip/fader", 0);
} else {
clear_strip ("/strip/gain", -193);
}
clear_strip ("/strip/trimdB", 0);
clear_strip ("/strip/pan_stereo_position", 0.5);
}
if (feedback[9]) {
clear_strip ("/strip/signal", 0);
}
if (feedback[7]) {
if (gainmode) {
clear_strip ("/strip/meter", 0);
} else {
clear_strip ("/strip/meter", -193);
}
}else if (feedback[8]) {
clear_strip ("/strip/meter", 0);
}
lo_address_free (addr);
}
void
OSCRouteObserver::tick ()
{
if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
// the only meter here is master
float now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
if (now_meter < -193) now_meter = -193;
if (_last_meter != now_meter) {
if (feedback[7] || feedback[8]) {
string path = "/strip/meter";
lo_message msg = lo_message_new ();
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
if (gainmode && feedback[7]) {
uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
lo_message_add_int32 (msg, lev1023);
lo_send_message (addr, path.c_str(), msg);
} else if ((!gainmode) && feedback[7]) {
lo_message_add_float (msg, now_meter);
lo_send_message (addr, path.c_str(), msg);
} else if (feedback[8]) {
uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
uint16_t ledbits = ~(0xfff<<ledlvl);
lo_message_add_int32 (msg, ledbits);
lo_send_message (addr, path.c_str(), msg);
}
lo_message_free (msg);
}
if (feedback[9]) {
string path = "/strip/signal";
lo_message msg = lo_message_new ();
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
float signal;
if (now_meter < -40) {
signal = 0;
} else {
signal = 1;
}
lo_message_add_float (msg, signal);
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
}
_last_meter = now_meter;
}
}
void
OSCRouteObserver::name_changed (const PBD::PropertyChange& what_changed)
{
@ -76,17 +208,23 @@ OSCRouteObserver::name_changed (const PBD::PropertyChange& what_changed)
return;
}
if (!_route) {
if (!_strip) {
return;
}
lo_message msg = lo_message_new ();
/* XXX can only use group part of ID at present */
lo_message_add_int32 (msg, _route->presentation_info().group_order());
lo_message_add_string (msg, _route->name().c_str());
// ssid is the strip on the surface this observer refers to
// not part of the internal ordering.
string path = "/strip/name";
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
lo_message_add_string (msg, _strip->name().c_str());
lo_send_message (addr, "/route/name", msg);
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
@ -95,14 +233,129 @@ OSCRouteObserver::send_change_message (string path, boost::shared_ptr<Controllab
{
lo_message msg = lo_message_new ();
/* XXX can only use group part of ID at present */
lo_message_add_int32 (msg, _route->presentation_info().group_order());
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
lo_message_add_float (msg, (float) controllable->get_value());
/* XXX thread issues */
//std::cerr << "ORC: send " << path << " = " << controllable->get_value() << std::endl;
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
void
OSCRouteObserver::send_monitor_status (boost::shared_ptr<Controllable> controllable)
{
int disk, input;
float val = controllable->get_value();
switch ((int) val) {
case 1:
disk = 0;
input = 1;
break;
case 2:
disk = 1;
input = 0;
break;
default:
disk = 0;
input = 0;
}
lo_message msg = lo_message_new ();
string path = "/strip/monitor_input";
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
lo_message_add_int32 (msg, (float) input);
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
msg = lo_message_new ();
path = "/strip/monitor_disk";
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
lo_message_add_int32 (msg, (float) disk);
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
void
OSCRouteObserver::send_trim_message (string path, boost::shared_ptr<Controllable> controllable)
{
lo_message msg = lo_message_new ();
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
void
OSCRouteObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
{
lo_message msg = lo_message_new ();
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
if (gainmode) {
if (controllable->get_value() == 1) {
lo_message_add_int32 (msg, 800);
} else {
lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
}
} else {
if (controllable->get_value() < 1e-15) {
lo_message_add_float (msg, -200);
} else {
lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
}
}
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}
string
OSCRouteObserver::set_path (string path)
{
if (feedback[2]) {
ostringstream os;
os << path << "/" << ssid;
path = os.str();
}
return path;
}
void
OSCRouteObserver::clear_strip (string path, float val)
{
lo_message msg = lo_message_new ();
if (feedback[2]) {
path = set_path (path);
} else {
lo_message_add_int32 (msg, ssid);
}
lo_message_add_float (msg, val);
lo_send_message (addr, path.c_str(), msg);
lo_message_free (msg);
}

View File

@ -21,6 +21,7 @@
#define __osc_oscrouteobserver_h__
#include <string>
#include <bitset>
#include <boost/shared_ptr.hpp>
#include <sigc++/sigc++.h>
#include <lo/lo.h>
@ -33,27 +34,33 @@ class OSCRouteObserver
{
public:
OSCRouteObserver (boost::shared_ptr<ARDOUR::Route>, lo_address addr);
OSCRouteObserver (boost::shared_ptr<ARDOUR::Stripable>, lo_address addr, uint32_t sid, uint32_t gainmode, std::bitset<32> feedback);
~OSCRouteObserver ();
boost::shared_ptr<ARDOUR::Route> route () const { return _route; }
boost::shared_ptr<ARDOUR::Stripable> strip () const { return _strip; }
lo_address address() const { return addr; };
void tick (void);
private:
boost::shared_ptr<ARDOUR::Route> _route;
//boost::shared_ptr<Controllable> _controllable;
boost::shared_ptr<ARDOUR::Stripable> _strip;
PBD::ScopedConnection name_changed_connection;
PBD::ScopedConnection rec_changed_connection;
PBD::ScopedConnection mute_changed_connection;
PBD::ScopedConnection solo_changed_connection;
PBD::ScopedConnection gain_changed_connection;
PBD::ScopedConnectionList strip_connections;
lo_address addr;
std::string path;
uint32_t ssid;
uint32_t gainmode;
std::bitset<32> feedback;
float _last_meter;
void name_changed (const PBD::PropertyChange& what_changed);
void send_change_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
void send_monitor_status (boost::shared_ptr<PBD::Controllable> controllable);
void send_gain_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
void send_trim_message (std::string path, boost::shared_ptr<PBD::Controllable> controllable);
std::string set_path (std::string path);
void clear_strip (std::string path, float val);
};
#endif /* __osc_oscrouteobserver_h__ */

View File

@ -18,6 +18,7 @@ def build(bld):
osc.cc
osc_controllable.cc
osc_route_observer.cc
osc_global_observer.cc
interface.cc
osc_gui.cc
'''