+ for (uint32_t n = bank_start; n < (min ((b_size + bank_start), s->nstrips + 1)); ++n) {
+ if (n <= s->strips.size()) {
+ boost::shared_ptr<Stripable> stp = s->strips[n - 1];
+
+ if (stp) {
+ listen_to_route(stp, addr);
+ }
+ }
+ }
+ }
+ // light bankup or bankdown buttons if it is possible to bank in that direction
+ if (s->feedback[4]) {
+ // these two messages could be bundled
+ lo_message reply;
+ reply = lo_message_new ();
+ if ((s->bank > (s->nstrips - s->bank_size)) || (s->nstrips < s->bank_size)) {
+ lo_message_add_int32 (reply, 0);
+ } else {
+ lo_message_add_int32 (reply, 1);
+ }
+ lo_send_message (addr, "/bank_up", reply);
+ lo_message_free (reply);
+ reply = lo_message_new ();
+ if (s->bank > 1) {
+ lo_message_add_int32 (reply, 1);
+ } else {
+ lo_message_add_int32 (reply, 0);
+ }
+ lo_send_message (addr, "/bank_down", reply);
+ lo_message_free (reply);
+ }
+ bank_dirty = false;
+ tick = true;
+ return 0;
+}
+
+int
+OSC::bank_up (lo_message msg)
+{
+ if (!session) {
+ return -1;
+ }
+ OSCSurface *s = get_surface(get_address (msg));
+ set_bank (s->bank + s->bank_size, msg);
+ return 0;
+}
+
+int
+OSC::bank_down (lo_message msg)
+{
+ if (!session) {
+ return -1;
+ }
+ OSCSurface *s = get_surface(get_address (msg));
+ if (s->bank < s->bank_size) {
+ set_bank (1, msg);
+ } else {
+ set_bank (s->bank - s->bank_size, msg);
+ }
+ return 0;
+}
+
+uint32_t
+OSC::get_sid (boost::shared_ptr<ARDOUR::Stripable> strip, lo_address addr)
+{
+ if (!strip) {
+ return 0;
+ }
+
+ OSCSurface *s = get_surface(addr);
+
+ uint32_t b_size;
+ if (!s->bank_size) {
+ // no banking
+ b_size = s->nstrips;
+ } else {
+ b_size = s->bank_size;
+ }
+
+ for (uint32_t n = s->bank; n < (min ((b_size + s->bank), s->nstrips + 1)); ++n) {
+ if (n <= s->strips.size()) {
+ if (strip == s->strips[n-1]) {
+ return n - s->bank + 1;
+ }
+ }
+ }
+ // failsafe... should never get here.
+ return 0;
+}
+
+boost::shared_ptr<ARDOUR::Stripable>
+OSC::get_strip (uint32_t ssid, lo_address addr)
+{
+ OSCSurface *s = get_surface(addr);
+ if (ssid && ((ssid + s->bank - 2) < s->nstrips)) {
+ return s->strips[ssid + s->bank - 2];
+ }
+ // guess it is out of range
+ return boost::shared_ptr<ARDOUR::Stripable>();
+}
+
+void
+OSC::transport_frame (lo_message msg)
+{
+ if (!session) {
+ return;
+ }
+ framepos_t pos = session->transport_frame ();
+
+ lo_message reply = lo_message_new ();
+ lo_message_add_int64 (reply, pos);
+
+ lo_send_message (get_address (msg), "/transport_frame", reply);
+
+ lo_message_free (reply);
+}
+
+void
+OSC::transport_speed (lo_message msg)
+{
+ if (!session) {
+ return;
+ }
+ double ts = session->transport_speed ();
+
+ lo_message reply = lo_message_new ();
+ lo_message_add_double (reply, ts);
+
+ lo_send_message (get_address (msg), "/transport_speed", reply);
+
+ lo_message_free (reply);
+}
+
+void
+OSC::record_enabled (lo_message msg)
+{
+ if (!session) {
+ return;
+ }
+ int re = (int)session->get_record_enabled ();
+
+ lo_message reply = lo_message_new ();
+ lo_message_add_int32 (reply, re);
+
+ lo_send_message (get_address (msg), "/record_enabled", reply);
+
+ lo_message_free (reply);
+}
+
+// master and monitor calls
+int
+OSC::master_set_gain (float dB)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = session->master_out();
+ if (s) {
+ if (dB < -192) {
+ s->gain_control()->set_value (0.0, PBD::Controllable::NoGroup);
+ } else {
+ s->gain_control()->set_value (dB_to_coefficient (dB), PBD::Controllable::NoGroup);
+ }
+ }
+ return 0;
+}
+
+int
+OSC::master_set_fader (float position)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = session->master_out();
+ if (s) {
+ s->gain_control()->set_value (slider_position_to_gain_with_max (position, 2.0), PBD::Controllable::NoGroup);
+ }
+ return 0;
+}
+
+int
+OSC::master_set_trim (float dB)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = session->master_out();
+
+ if (s) {
+ s->trim_control()->set_value (dB_to_coefficient (dB), PBD::Controllable::NoGroup);
+ }
+
+ return 0;
+}
+
+int
+OSC::master_set_pan_stereo_position (float position, lo_message msg)
+{
+ if (!session) return -1;
+
+ float endposition = .5;
+ boost::shared_ptr<Stripable> s = session->master_out();
+
+ if (s) {
+ if (s->pan_azimuth_control()) {
+ s->pan_azimuth_control()->set_value (s->pan_azimuth_control()->interface_to_internal (position), PBD::Controllable::NoGroup);
+ endposition = s->pan_azimuth_control()->internal_to_interface (s->pan_azimuth_control()->get_value ());
+ }
+ }
+ OSCSurface *sur = get_surface(get_address (msg));
+
+ if (sur->feedback[4]) {
+ lo_message reply = lo_message_new ();
+ lo_message_add_float (reply, endposition);
+
+ lo_send_message (get_address (msg), "/master/pan_stereo_position", reply);
+ lo_message_free (reply);
+ }
+
+ return 0;
+}
+
+int
+OSC::master_set_mute (uint32_t state)
+{
+ if (!session) return -1;
+
+ boost::shared_ptr<Stripable> s = session->master_out();
+
+ if (s) {
+ s->mute_control()->set_value (state, PBD::Controllable::NoGroup);
+ }
+
+ return 0;
+}
+
+int
+OSC::monitor_set_gain (float dB)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = session->monitor_out();
+
+ if (s) {
+ if (dB < -192) {
+ s->gain_control()->set_value (0.0, PBD::Controllable::NoGroup);
+ } else {
+ s->gain_control()->set_value (dB_to_coefficient (dB), PBD::Controllable::NoGroup);
+ }
+ }
+ return 0;
+}
+
+int
+OSC::monitor_set_fader (float position)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = session->monitor_out();
+ if (s) {
+ s->gain_control()->set_value (slider_position_to_gain_with_max (position, 2.0), PBD::Controllable::NoGroup);
+ }
+ return 0;
+}
+
+// strip calls
+int
+OSC::route_mute (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if (s->mute_control()) {
+ s->mute_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+
+ return route_send_fail ("mute", ssid, 0, get_address (msg));
+}
+
+int
+OSC::sel_mute (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->mute_control()) {
+ s->mute_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("mute", 0, get_address (msg));
+}
+
+int
+OSC::route_solo (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if (s->solo_control()) {
+ s->solo_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+
+ return route_send_fail ("solo", ssid, 0, get_address (msg));
+}
+
+int
+OSC::route_solo_iso (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if (s->solo_isolate_control()) {
+ s->solo_isolate_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+
+ return route_send_fail ("solo_iso", ssid, 0, get_address (msg));
+}
+
+int
+OSC::route_solo_safe (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, lo_message_get_source (msg));
+
+ if (s) {
+ if (s->solo_safe_control()) {
+ s->solo_safe_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+
+ return route_send_fail ("solo_safe", ssid, 0, get_address (msg));
+}
+
+int
+OSC::sel_solo (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->solo_control()) {
+ s->solo_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("solo", 0, get_address (msg));
+}
+
+int
+OSC::sel_solo_iso (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->solo_isolate_control()) {
+ s->solo_isolate_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("solo_iso", 0, get_address (msg));
+}
+
+int
+OSC::sel_solo_safe (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->solo_safe_control()) {
+ s->solo_safe_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("solo_safe", 0, get_address (msg));
+}
+
+int
+OSC::sel_recenable (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->rec_enable_control()) {
+ s->rec_enable_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("recenable", 0, get_address (msg));
+}
+
+int
+OSC::route_recenable (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if (s->rec_enable_control()) {
+ s->rec_enable_control()->set_value (yn, PBD::Controllable::UseGroup);
+ if (s->rec_enable_control()->get_value()) {
+ return 0;
+ }
+ }
+ }
+ return route_send_fail ("recenable", ssid, 0, get_address (msg));
+}
+
+int
+OSC::sel_recsafe (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->rec_safe_control()) {
+ s->rec_safe_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("record_safe", 0, get_address (msg));
+}
+
+int
+OSC::route_recsafe (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+ if (s) {
+ if (s->rec_safe_control()) {
+ s->rec_safe_control()->set_value (yn, PBD::Controllable::UseGroup);
+ if (s->rec_safe_control()->get_value()) {
+ return 0;
+ }
+ }
+ }
+ return route_send_fail ("record_safe", ssid, 0,get_address (msg));
+}
+
+int
+OSC::route_monitor_input (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (s);
+ if (track) {
+ if (track->monitoring_control()) {
+ track->monitoring_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ }
+
+ return route_send_fail ("monitor_input", ssid, 0, get_address (msg));
+}
+
+int
+OSC::sel_monitor_input (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (s);
+ if (track) {
+ if (track->monitoring_control()) {
+ track->monitoring_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ }
+ return sel_fail ("monitor_input", 0, get_address (msg));
+}
+
+int
+OSC::route_monitor_disk (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (s);
+ if (track) {
+ if (track->monitoring_control()) {
+ track->monitoring_control()->set_value (yn ? 2.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ }
+
+ return route_send_fail ("monitor_disk", ssid, 0, get_address (msg));
+}
+
+int
+OSC::sel_monitor_disk (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (s);
+ if (track) {
+ if (track->monitoring_control()) {
+ track->monitoring_control()->set_value (yn ? 2.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ }
+ return sel_fail ("monitor_disk", 0, get_address (msg));
+}
+
+
+int
+OSC::strip_phase (int ssid, int yn, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if (s->phase_control()) {
+ s->phase_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+
+ return route_send_fail ("polarity", ssid, 0, get_address (msg));
+}
+
+int
+OSC::sel_phase (uint32_t yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->phase_control()) {
+ s->phase_control()->set_value (yn ? 1.0 : 0.0, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("polarity", 0, get_address (msg));
+}
+
+int
+OSC::strip_expand (int ssid, int yn, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ sur->expand_enable = (bool) yn;
+ sur->expand = ssid;
+ boost::shared_ptr<Stripable> s;
+ if (yn) {
+ s = get_strip (ssid, get_address (msg));
+ } else {
+ s = ControlProtocol::first_selected_stripable();
+ }
+
+ return _strip_select (s, get_address (msg));
+}
+
+int
+OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr)
+{
+ if (!session) {
+ return -1;
+ }
+ OSCSurface *sur = get_surface(addr);
+ if (sur->sel_obs) {
+ delete sur->sel_obs;
+ sur->sel_obs = 0;
+ }
+ if (s) {
+ OSCSelectObserver* sel_fb = new OSCSelectObserver (s, addr, sur->gainmode, sur->feedback);
+ s->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
+ sur->sel_obs = sel_fb;
+ } else if (sur->expand_enable) {
+ sur->expand = 0;
+ sur->expand_enable = false;
+ if (_select) {
+ OSCSelectObserver* sel_fb = new OSCSelectObserver (_select, addr, sur->gainmode, sur->feedback);
+ _select->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::recalcbanks, this), this);
+ sur->sel_obs = sel_fb;
+ }
+ } else {
+ route_send_fail ("select", sur->expand, 0 , addr);
+ }
+ //update buttons on surface
+ int b_s = sur->bank_size;
+ if (!b_s) { // bank size 0 means we need to know how many strips there are.
+ b_s = sur->nstrips;
+ }
+ for (int i = 1; i <= b_s; i++) {
+ string path = "expand";
+
+ if ((i == (int) sur->expand) && sur->expand_enable) {
+ lo_message reply = lo_message_new ();
+ if (sur->feedback[2]) {
+ ostringstream os;
+ os << "/strip/" << path << "/" << i;
+ path = os.str();
+ } else {
+ ostringstream os;
+ os << "/strip/" << path;
+ path = os.str();
+ lo_message_add_int32 (reply, i);
+ }
+ lo_message_add_float (reply, (float) 1);
+
+ lo_send_message (addr, path.c_str(), reply);
+ lo_message_free (reply);
+ reply = lo_message_new ();
+ lo_message_add_float (reply, 1.0);
+ lo_send_message (addr, "/select/expand", reply);
+ lo_message_free (reply);
+
+ } else {
+ lo_message reply = lo_message_new ();
+ lo_message_add_int32 (reply, i);
+ lo_message_add_float (reply, 0.0);
+ lo_send_message (addr, "/strip/expand", reply);
+ lo_message_free (reply);
+ }
+ }
+ if (!sur->expand_enable) {
+ lo_message reply = lo_message_new ();
+ lo_message_add_float (reply, 0.0);
+ lo_send_message (addr, "/select/expand", reply);
+ lo_message_free (reply);
+ }
+
+ return 0;
+}
+
+int
+OSC::strip_gui_select (int ssid, int yn, lo_message msg)
+{
+ //ignore button release
+ if (!yn) return 0;
+
+ if (!session) {
+ route_send_fail ("select", ssid, 0, get_address (msg));
+ return -1;
+ }
+ OSCSurface *sur = get_surface(get_address (msg));
+ sur->expand_enable = false;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+ if (s) {
+ SetStripableSelection (s);
+ } else {
+ route_send_fail ("select", ssid, 0, get_address (msg));
+ }
+
+ return 0;
+}
+
+int
+OSC::sel_expand (uint32_t state, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ sur->expand_enable = (bool) state;
+ if (state && sur->expand) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = ControlProtocol::first_selected_stripable();
+ }
+
+ return _strip_select (s, get_address (msg));
+}
+
+int
+OSC::route_set_gain_abs (int ssid, float level, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if (s->gain_control()) {
+ s->gain_control()->set_value (level, PBD::Controllable::NoGroup);
+ } else {
+ return 1;
+ }
+ } else {
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+OSC::route_set_gain_dB (int ssid, float dB, lo_message msg)
+{
+ if (!session) {
+ route_send_fail ("gain", ssid, -193, get_address (msg));
+ return -1;
+ }
+ int ret;
+ if (dB < -192) {
+ ret = route_set_gain_abs (ssid, 0.0, msg);
+ } else {
+ ret = route_set_gain_abs (ssid, dB_to_coefficient (dB), msg);
+ }
+ if (ret != 0) {
+ return route_send_fail ("gain", ssid, -193, get_address (msg));
+ }
+ return 0;
+}
+
+int
+OSC::sel_gain (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ float abs;
+ if (val < -192) {
+ abs = 0;
+ } else {
+ abs = dB_to_coefficient (val);
+ }
+ if (s->gain_control()) {
+ s->gain_control()->set_value (abs, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("gain", -193, get_address (msg));
+}
+
+int
+OSC::route_set_gain_fader (int ssid, float pos, lo_message msg)
+{
+ if (!session) {
+ route_send_fail ("fader", ssid, 0, get_address (msg));
+ return -1;
+ }
+ int ret;
+ ret = route_set_gain_abs (ssid, slider_position_to_gain_with_max (pos, 2.0), msg);
+ if (ret != 0) {
+ return route_send_fail ("fader", ssid, 0, get_address (msg));
+ }
+ return 0;
+}
+
+int
+OSC::sel_fader (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ float abs;
+ abs = slider_position_to_gain_with_max (val, 2.0);
+ if (s->gain_control()) {
+ s->gain_control()->set_value (abs, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("fader", 0, get_address (msg));
+}
+
+int
+OSC::route_set_trim_abs (int ssid, float level, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if (s->trim_control()) {
+ s->trim_control()->set_value (level, PBD::Controllable::NoGroup);
+ return 0;
+ }
+
+ }
+
+ return -1;
+}
+
+int
+OSC::route_set_trim_dB (int ssid, float dB, lo_message msg)
+{
+ int ret;
+ ret = route_set_trim_abs(ssid, dB_to_coefficient (dB), msg);
+ if (ret != 0) {
+ return route_send_fail ("trimdB", ssid, 0, get_address (msg));
+ }
+
+return 0;
+}
+
+int
+OSC::sel_trim (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->trim_control()) {
+ s->trim_control()->set_value (dB_to_coefficient (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("trimdB", 0, get_address (msg));
+}
+
+int
+OSC::sel_pan_position (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if(s->pan_azimuth_control()) {
+ s->pan_azimuth_control()->set_value (s->pan_azimuth_control()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return sel_fail ("pan_stereo_position", s->pan_azimuth_control()->internal_to_interface (s->pan_azimuth_control()->get_value ()), get_address (msg));
+ return 0;
+ }
+ }
+ return sel_fail ("pan_stereo_position", 0.5, get_address (msg));
+}
+
+int
+OSC::sel_pan_width (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->pan_width_control()) {
+ s->pan_width_control()->set_value (s->pan_width_control()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("pan_stereo_width", 1, get_address (msg));
+}
+
+int
+OSC::route_set_pan_stereo_position (int ssid, float pos, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if(s->pan_azimuth_control()) {
+ s->pan_azimuth_control()->set_value (s->pan_azimuth_control()->interface_to_internal (pos), PBD::Controllable::NoGroup);
+ return route_send_fail ("pan_stereo_position", ssid, s->pan_azimuth_control()->internal_to_interface (s->pan_azimuth_control()->get_value ()), get_address (msg));
+ }
+ }
+
+ return route_send_fail ("pan_stereo_position", ssid, 0.5, get_address (msg));
+}
+
+int
+OSC::route_set_pan_stereo_width (int ssid, float pos, lo_message msg)
+{
+ if (!session) return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+ if (s->pan_width_control()) {
+ s->pan_width_control()->set_value (pos, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+
+ return route_send_fail ("pan_stereo_width", ssid, 1, get_address (msg));
+}
+
+int
+OSC::route_set_send_gain_dB (int ssid, int id, float val, lo_message msg)
+{
+ if (!session) {
+ return -1;
+ }
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+ float abs;
+ if (s) {
+ if (id > 0) {
+ --id;
+ }
+#ifdef MIXBUS
+ abs = val;
+#else
+ if (val < -192) {
+ abs = 0;
+ } else {
+ abs = dB_to_coefficient (val);
+ }
+#endif
+ if (s->send_level_controllable (id)) {
+ s->send_level_controllable (id)->set_value (abs, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return 0;
+}
+
+int
+OSC::route_set_send_fader (int ssid, int id, float val, lo_message msg)
+{
+ if (!session) {
+ return -1;
+ }
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+ float abs;
+ if (s) {
+
+ if (id > 0) {
+ --id;
+ }
+
+ if (s->send_level_controllable (id)) {
+#ifdef MIXBUS
+ abs = s->send_level_controllable(id)->interface_to_internal (val);
+#else
+ abs = slider_position_to_gain_with_max (val, 2.0);
+#endif
+ s->send_level_controllable (id)->set_value (abs, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return 0;
+}
+
+int
+OSC::sel_sendgain (int id, float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ float abs;
+ if (s) {
+ if (id > 0) {
+ --id;
+ }
+#ifdef MIXBUS
+ abs = val;
+#else
+ if (val < -192) {
+ abs = 0;
+ } else {
+ abs = dB_to_coefficient (val);
+ }
+#endif
+ if (s->send_level_controllable (id)) {
+ s->send_level_controllable (id)->set_value (abs, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_send_fail ("send_gain", id + 1, -193, get_address (msg));
+}
+
+int
+OSC::sel_sendfader (int id, float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ float abs;
+ if (s) {
+
+ if (id > 0) {
+ --id;
+ }
+
+ if (s->send_level_controllable (id)) {
+#ifdef MIXBUS
+ abs = s->send_level_controllable(id)->interface_to_internal (val);
+#else
+ abs = slider_position_to_gain_with_max (val, 2.0);
+#endif
+ s->send_level_controllable (id)->set_value (abs, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_send_fail ("send_fader", id, 0, get_address (msg));
+}
+
+int
+OSC::route_set_send_enable (int ssid, int sid, float val, lo_message msg)
+{
+ if (!session) {
+ return -1;
+ }
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ if (s) {
+
+ /* revert to zero-based counting */
+
+ if (sid > 0) {
+ --sid;
+ }
+
+ if (s->send_enable_controllable (sid)) {
+ s->send_enable_controllable (sid)->set_value (val, PBD::Controllable::NoGroup);
+ return 0;
+ }
+
+ if (s->send_level_controllable (sid)) {
+ return 0;
+ }
+
+ }
+
+ return -1;
+}
+
+int
+OSC::sel_sendenable (int id, float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (id > 0) {
+ --id;
+ }
+ if (s->send_enable_controllable (id)) {
+ s->send_enable_controllable (id)->set_value (val, PBD::Controllable::NoGroup);
+ return 0;
+ }
+ if (s->send_level_controllable (id)) {
+ return sel_send_fail ("send_enable", id + 1, 1, get_address (msg));
+ }
+ }
+ return sel_send_fail ("send_enable", id + 1, 0, get_address (msg));
+}
+
+int
+OSC::route_plugin_parameter (int ssid, int piid, int par, float val, lo_message msg)
+{
+ if (!session)
+ return -1;
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s);
+
+ if (!r) {
+ PBD::error << "OSC: Invalid Remote Control ID '" << ssid << "'" << endmsg;
+ return -1;
+ }
+
+ boost::shared_ptr<Processor> redi=r->nth_plugin (piid);
+
+ if (!redi) {
+ PBD::error << "OSC: cannot find plugin # " << piid << " for RID '" << ssid << "'" << endmsg;
+ return -1;
+ }
+
+ boost::shared_ptr<PluginInsert> pi;
+
+ if (!(pi = boost::dynamic_pointer_cast<PluginInsert>(redi))) {
+ PBD::error << "OSC: given processor # " << piid << " on RID '" << ssid << "' is not a Plugin." << endmsg;
+ return -1;
+ }
+
+ boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
+ bool ok=false;
+
+ uint32_t controlid = pip->nth_parameter (par,ok);
+
+ if (!ok) {
+ PBD::error << "OSC: Cannot find parameter # " << par << " for plugin # " << piid << " on RID '" << ssid << "'" << endmsg;
+ return -1;
+ }
+
+ if (!pip->parameter_is_input(controlid)) {
+ PBD::error << "OSC: Parameter # " << par << " for plugin # " << piid << " on RID '" << ssid << "' is not a control input" << endmsg;
+ return -1;
+ }
+
+ ParameterDescriptor pd;
+ pi->plugin()->get_parameter_descriptor (controlid,pd);
+
+ if (val >= pd.lower && val <= pd.upper) {
+
+ boost::shared_ptr<AutomationControl> c = pi->automation_control (Evoral::Parameter(PluginAutomation, 0, controlid));
+ // cerr << "parameter:" << redi->describe_parameter(controlid) << " val:" << val << "\n";
+ c->set_value (val, PBD::Controllable::NoGroup);
+ } else {
+ PBD::warning << "OSC: Parameter # " << par << " for plugin # " << piid << " on RID '" << ssid << "' is out of range" << endmsg;
+ PBD::info << "OSC: Valid range min=" << pd.lower << " max=" << pd.upper << endmsg;
+ }
+
+ return 0;
+}
+
+//prints to cerr only
+int
+OSC::route_plugin_parameter_print (int ssid, int piid, int par, lo_message msg)
+{
+ if (!session) {
+ return -1;
+ }
+ boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+ boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s);
+
+ if (!r) {
+ return -1;
+ }
+
+ boost::shared_ptr<Processor> redi=r->nth_processor (piid);
+
+ if (!redi) {
+ return -1;
+ }
+
+ boost::shared_ptr<PluginInsert> pi;
+
+ if (!(pi = boost::dynamic_pointer_cast<PluginInsert>(redi))) {
+ return -1;
+ }
+
+ boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
+ bool ok=false;
+
+ uint32_t controlid = pip->nth_parameter (par,ok);
+
+ if (!ok) {
+ return -1;
+ }
+
+ ParameterDescriptor pd;
+
+ if (pi->plugin()->get_parameter_descriptor (controlid, pd) == 0) {
+ boost::shared_ptr<AutomationControl> c = pi->automation_control (Evoral::Parameter(PluginAutomation, 0, controlid));
+
+ cerr << "parameter: " << redi->describe_parameter(controlid) << "\n";
+ cerr << "current value: " << c->get_value ();
+ cerr << "lower value: " << pd.lower << "\n";
+ cerr << "upper value: " << pd.upper << "\n";
+ }
+
+ return 0;
+}
+
+// select
+
+int
+OSC::sel_pan_elevation (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->pan_elevation_control()) {
+ s->pan_elevation_control()->set_value (s->pan_elevation_control()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("pan_elevation_position", 0, get_address (msg));
+}
+
+int
+OSC::sel_pan_frontback (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->pan_frontback_control()) {
+ s->pan_frontback_control()->set_value (s->pan_frontback_control()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("pan_frontback_position", 0.5, get_address (msg));
+}
+
+int
+OSC::sel_pan_lfe (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->pan_lfe_control()) {
+ s->pan_lfe_control()->set_value (s->pan_lfe_control()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("pan_lfe_control", 0, get_address (msg));
+}
+
+// compressor control
+int
+OSC::sel_comp_enable (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->comp_enable_controllable()) {
+ s->comp_enable_controllable()->set_value (s->comp_enable_controllable()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("comp_enable", 0, get_address (msg));
+}
+
+int
+OSC::sel_comp_threshold (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->comp_threshold_controllable()) {
+ s->comp_threshold_controllable()->set_value (s->comp_threshold_controllable()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("comp_threshold", 0, get_address (msg));
+}
+
+int
+OSC::sel_comp_speed (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->comp_speed_controllable()) {
+ s->comp_speed_controllable()->set_value (s->comp_speed_controllable()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("comp_speed", 0, get_address (msg));
+}
+
+int
+OSC::sel_comp_mode (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->comp_mode_controllable()) {
+ s->comp_mode_controllable()->set_value (s->comp_mode_controllable()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("comp_mode", 0, get_address (msg));
+}
+
+int
+OSC::sel_comp_makeup (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->comp_makeup_controllable()) {
+ s->comp_makeup_controllable()->set_value (s->comp_makeup_controllable()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("comp_makeup", 0, get_address (msg));
+}
+
+// EQ control
+
+int
+OSC::sel_eq_enable (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->eq_enable_controllable()) {
+ s->eq_enable_controllable()->set_value (s->eq_enable_controllable()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("eq_enable", 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_hpf (float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (s->eq_hpf_controllable()) {
+ s->eq_hpf_controllable()->set_value (s->eq_hpf_controllable()->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_fail ("eq_hpf", 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_gain (int id, float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (id > 0) {
+ --id;
+ }
+ if (s->eq_gain_controllable (id)) {
+ s->eq_gain_controllable (id)->set_value (s->eq_gain_controllable(id)->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_send_fail ("eq_gain", id + 1, 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_freq (int id, float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (id > 0) {
+ --id;
+ }
+ if (s->eq_freq_controllable (id)) {
+ s->eq_freq_controllable (id)->set_value (s->eq_freq_controllable(id)->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_send_fail ("eq_freq", id + 1, 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_q (int id, float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (id > 0) {
+ --id;
+ }
+ if (s->eq_q_controllable (id)) {
+ s->eq_q_controllable (id)->set_value (s->eq_q_controllable(id)->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_send_fail ("eq_q", id + 1, 0, get_address (msg));
+}
+
+int
+OSC::sel_eq_shape (int id, float val, lo_message msg)
+{
+ OSCSurface *sur = get_surface(get_address (msg));
+ boost::shared_ptr<Stripable> s;
+ if (sur->expand_enable) {
+ s = get_strip (sur->expand, get_address (msg));
+ } else {
+ s = _select;
+ }
+ if (s) {
+ if (id > 0) {
+ --id;
+ }
+ if (s->eq_shape_controllable (id)) {
+ s->eq_shape_controllable (id)->set_value (s->eq_shape_controllable(id)->interface_to_internal (val), PBD::Controllable::NoGroup);
+ return 0;
+ }
+ }
+ return sel_send_fail ("eq_shape", id + 1, 0, get_address (msg));
+}
+
+void
+OSC::gui_selection_changed ()
+{
+ boost::shared_ptr<Stripable> strip = ControlProtocol::first_selected_stripable();
+
+ if (strip) {
+ _select = strip;
+ for (uint32_t it = 0; it < _surface.size(); ++it) {
+ OSCSurface* sur = &_surface[it];
+ if(!sur->expand_enable) {
+ lo_address addr = lo_address_new_from_url (sur->remote_url.c_str());
+ _strip_select (strip, addr);
+ }
+ }
+ }
+}
+
+// timer callbacks
+bool
+OSC::periodic (void)
+{
+ if (!tick) {
+ Glib::usleep(100); // let flurry of signals subside
+ if (global_init) {
+ for (uint32_t it = 0; it < _surface.size(); it++) {
+ OSCSurface* sur = &_surface[it];
+ lo_address addr = lo_address_new_from_url (sur->remote_url.c_str());
+ global_feedback (sur->feedback, addr, sur->gainmode);
+ }
+ global_init = false;
+ tick = true;
+ }
+ if (bank_dirty) {
+ _recalcbanks ();
+ bank_dirty = false;
+ tick = true;
+ }
+ }
+
+ for (GlobalObservers::iterator x = global_observers.begin(); x != global_observers.end(); x++) {
+
+ OSCGlobalObserver* go;
+
+ if ((go = dynamic_cast<OSCGlobalObserver*>(*x)) != 0) {
+ go->tick();
+ }
+ }
+ for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end(); x++) {
+
+ OSCRouteObserver* ro;
+
+ if ((ro = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
+ ro->tick();
+ }
+ }
+ for (uint32_t it = 0; it < _surface.size(); it++) {
+ OSCSurface* sur = &_surface[it];
+ OSCSelectObserver* so;
+ if ((so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs)) != 0) {
+ so->tick();
+ }
+ }
+ return true;
+}
+
+int
+OSC::route_send_fail (string path, uint32_t ssid, float val, lo_address addr)
+{
+ OSCSurface *sur = get_surface(addr);
+
+ ostringstream os;
+ lo_message reply;
+ if (ssid) {
+ reply = lo_message_new ();
+ if (sur->feedback[2]) {
+ os << "/strip/" << path << "/" << ssid;
+ } else {
+ os << "/strip/" << path;
+ lo_message_add_int32 (reply, ssid);
+ }
+ string str_pth = os.str();
+ lo_message_add_float (reply, (float) val);
+
+ lo_send_message (addr, str_pth.c_str(), reply);
+ lo_message_free (reply);
+ }
+ if ((_select == get_strip (ssid, addr)) || ((sur->expand == ssid) && (sur->expand_enable))) {
+ os.str("");
+ os << "/select/" << path;
+ string sel_pth = os.str();
+ reply = lo_message_new ();
+ lo_message_add_float (reply, (float) val);
+ lo_send_message (addr, sel_pth.c_str(), reply);
+ lo_message_free (reply);
+ }
+
+ return 0;
+}
+
+int
+OSC::sel_fail (string path, float val, lo_address addr)
+{
+ ostringstream os;
+ os.str("");
+ os << "/select/" << path;
+ string sel_pth = os.str();
+ lo_message reply = lo_message_new ();
+ lo_message_add_float (reply, (float) val);
+ lo_send_message (addr, sel_pth.c_str(), reply);
+ lo_message_free (reply);
+
+ return 0;
+}
+
+int
+OSC::sel_send_fail (string path, uint32_t id, float val, lo_address addr)
+{
+ OSCSurface *sur = get_surface(addr);
+
+ ostringstream os;
+ lo_message reply;
+ reply = lo_message_new ();
+ if (sur->feedback[2]) {
+ os << "/select/" << path << "/" << id;
+ } else {
+ os << "/select/" << path;
+ lo_message_add_int32 (reply, id);
+ }
+ string str_pth = os.str();
+ lo_message_add_float (reply, (float) val);
+
+ lo_send_message (addr, str_pth.c_str(), reply);
+ lo_message_free (reply);
+
+ return 0;
+}
+
+XMLNode&
+OSC::get_state ()
+{
+ XMLNode& node (ControlProtocol::get_state());
+ node.add_property("debugmode", (int) _debugmode); // TODO: enum2str
+ node.add_property ("address-only", address_only);
+ node.add_property ("remote-port", remote_port);
+ node.add_property ("banksize", default_banksize);
+ node.add_property ("striptypes", default_strip);
+ node.add_property ("feedback", default_feedback);
+ node.add_property ("gainmode", default_gainmode);
+ if (_surface.size()) {
+ XMLNode* config = new XMLNode (X_("Configurations"));
+ for (uint32_t it = 0; it < _surface.size(); ++it) {
+ OSCSurface* sur = &_surface[it];
+ XMLNode* devnode = new XMLNode (X_("Configuration"));
+ devnode->add_property (X_("url"), sur->remote_url);
+ devnode->add_property (X_("bank-size"), sur->bank_size);
+ devnode->add_property (X_("strip-types"), sur->strip_types.to_ulong());
+ devnode->add_property (X_("feedback"), sur->feedback.to_ulong());
+ devnode->add_property (X_("gainmode"), sur->gainmode);
+ config->add_child_nocopy (*devnode);
+ }
+ node.add_child_nocopy (*config);
+ }
+ return node;
+}
+
+int
+OSC::set_state (const XMLNode& node, int version)
+{
+ if (ControlProtocol::set_state (node, version)) {
+ return -1;
+ }
+ XMLProperty const * p = node.property (X_("debugmode"));
+ if (p) {
+ _debugmode = OSCDebugMode (PBD::atoi(p->value ()));
+ }
+ p = node.property (X_("address-only"));
+ if (p) {
+ address_only = OSCDebugMode (PBD::atoi(p->value ()));
+ }
+ p = node.property (X_("remote-port"));
+ if (p) {
+ remote_port = p->value ();
+ }
+ p = node.property (X_("banksize"));
+ if (p) {
+ default_banksize = OSCDebugMode (PBD::atoi(p->value ()));
+ }
+ p = node.property (X_("striptypes"));
+ if (p) {
+ default_strip = OSCDebugMode (PBD::atoi(p->value ()));
+ }
+ p = node.property (X_("feedback"));
+ if (p) {
+ default_feedback = OSCDebugMode (PBD::atoi(p->value ()));
+ }
+ p = node.property (X_("gainmode"));
+ if (p) {
+ default_gainmode = OSCDebugMode (PBD::atoi(p->value ()));
+ }
+ XMLNode* cnode = node.child (X_("Configurations"));
+
+ if (cnode) {
+ XMLNodeList const& devices = cnode->children();
+ for (XMLNodeList::const_iterator d = devices.begin(); d != devices.end(); ++d) {
+ XMLProperty const * prop = (*d)->property (X_("url"));
+ if (prop) {
+ OSCSurface s;
+ bank_dirty = true;
+ s.remote_url = prop->value();
+ prop = (*d)->property (X_("bank-size"));
+ if (prop) {
+ s.bank_size = atoi (prop->value().c_str());
+ }
+ prop = (*d)->property (X_("strip-types"));
+ if (prop) {
+ s.strip_types = atoi (prop->value().c_str());
+ }
+ prop = (*d)->property (X_("feedback"));
+ if (prop) {
+ s.feedback = atoi (prop->value().c_str());
+ }
+ prop = (*d)->property (X_("gainmode"));
+ if (prop) {
+ s.gainmode = atoi (prop->value().c_str());
+ }
+ s.bank = 1;
+ s.sel_obs = 0;
+ s.expand = 0;
+ s.expand_enable = false;
+ s.strips = get_sorted_stripables(s.strip_types);
+ s.nstrips = s.strips.size();
+ _surface.push_back (s);
+ }
+ }
+ }
+ global_init = true;
+ tick = false;
+
+ return 0;
+}
+
+// predicate for sort call in get_sorted_stripables
+struct StripableByPresentationOrder
+{
+ bool operator () (const boost::shared_ptr<Stripable> & a, const boost::shared_ptr<Stripable> & b) const
+ {
+ return a->presentation_info().order() < b->presentation_info().order();
+ }
+
+ bool operator () (const Stripable & a, const Stripable & b) const
+ {
+ return a.presentation_info().order() < b.presentation_info().order();
+ }
+
+ bool operator () (const Stripable * a, const Stripable * b) const
+ {
+ return a->presentation_info().order() < b->presentation_info().order();
+ }
+};
+
+OSC::Sorted
+OSC::get_sorted_stripables(std::bitset<32> types)
+{
+ Sorted sorted;
+
+ // fetch all stripables
+ StripableList stripables;
+
+ session->get_stripables (stripables);
+
+ // Look for stripables that match bit in sur->strip_types
+ for (StripableList::iterator it = stripables.begin(); it != stripables.end(); ++it) {
+
+ boost::shared_ptr<Stripable> s = *it;
+ if ((!types[9]) && (s->presentation_info().flags() & PresentationInfo::Hidden)) {
+ // do nothing... skip it
+ } else {
+
+ if (types[0] && (s->presentation_info().flags() & PresentationInfo::AudioTrack)) {
+ sorted.push_back (s);
+ } else
+ if (types[1] && (s->presentation_info().flags() & PresentationInfo::MidiTrack)) {
+ sorted.push_back (s);
+ } else
+ if (types[2] && (s->presentation_info().flags() & PresentationInfo::AudioBus)) {
+ sorted.push_back (s);
+ } else
+ if (types[3] && (s->presentation_info().flags() & PresentationInfo::MidiBus)) {
+ sorted.push_back (s);
+ } else
+ if (types[4] && (s->presentation_info().flags() & PresentationInfo::VCA)) {
+ sorted.push_back (s);
+ } else
+ if (types[8] && (s->presentation_info().flags() & PresentationInfo::Selected)) {
+ sorted.push_back (s);
+ } else
+ if (types[9] && (s->presentation_info().flags() & PresentationInfo::Hidden)) {
+ sorted.push_back (s);
+ }
+ }
+ }
+ sort (sorted.begin(), sorted.end(), StripableByPresentationOrder());
+ // Master/Monitor might be anywhere... we put them at the end - Sorry ;)
+ if (types[5]) {
+ sorted.push_back (session->master_out());
+ }
+ if (types[6]) {
+ sorted.push_back (session->monitor_out());
+ }
+ return sorted;
+}