OSC: same fix for /select/*
[ardour.git] / libs / surfaces / osc / osc.cc
index 954b7edb643ce1f7a17407f5a2ab768a1e692621..9eee330949f0408e168ba035a8a9de72de55fa8c 100644 (file)
@@ -39,6 +39,7 @@
 #include "ardour/route.h"
 #include "ardour/audio_track.h"
 #include "ardour/midi_track.h"
+#include "ardour/vca.h"
 #include "ardour/monitor_control.h"
 #include "ardour/dB.h"
 #include "ardour/filesystem_paths.h"
@@ -543,6 +544,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/master/mute", "i", master_set_mute);
                REGISTER_CALLBACK (serv, "/master/trimdB", "f", master_set_trim);
                REGISTER_CALLBACK (serv, "/master/pan_stereo_position", "f", master_set_pan_stereo_position);
+               REGISTER_CALLBACK (serv, "/master/select", "f", master_select);
                REGISTER_CALLBACK (serv, "/monitor/gain", "f", monitor_set_gain);
                REGISTER_CALLBACK (serv, "/monitor/fader", "f", monitor_set_fader);
                REGISTER_CALLBACK (serv, "/monitor/db_delta", "f", monitor_delta_gain);
@@ -962,6 +964,10 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
 
                ret = 0;
        } else
+       if (strstr (path, "/strip") && (argc != 1)) {
+               // All of the strip commands below require 1 parameter
+               PBD::warning << "OSC: Wrong number of parameters." << endmsg;
+       } else
        if (!strncmp (path, "/strip/gain/", 12) && strlen (path) > 12) {
                // in dB
                int ssid = atoi (&path[12]);
@@ -1035,6 +1041,10 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
        else if (!strncmp (path, "/strip/select/", 14) && strlen (path) > 14) {
                int ssid = atoi (&path[14]);
                ret = strip_gui_select (ssid, argv[0]->i, msg);
+       } else
+       if (strstr (path, "/select") && (argc != 1)) {
+               // All of the select commands below require 1 parameter
+               PBD::warning << "OSC: Wrong number of parameters." << endmsg;
        }
        else if (!strncmp (path, "/select/send_gain/", 18) && strlen (path) > 18) {
                int ssid = atoi (&path[18]);
@@ -1237,27 +1247,29 @@ OSC::routes_list (lo_message msg)
 
                        lo_message reply = lo_message_new ();
 
-                       if (s->presentation_info().flags() & PresentationInfo::AudioTrack) {
+                       if (boost::dynamic_pointer_cast<AudioTrack>(s)) {
                                lo_message_add_string (reply, "AT");
-                       } else if (s->presentation_info().flags() & PresentationInfo::MidiTrack) {
+                       } else if (boost::dynamic_pointer_cast<MidiTrack>(s)) {
                                lo_message_add_string (reply, "MT");
-                       } else if (s->presentation_info().flags() & PresentationInfo::AudioBus) {
-                               // r->feeds (session->master_out()) may make more sense
-                               if (r->direct_feeds_according_to_reality (session->master_out())) {
-                                       // this is a bus
-                                       lo_message_add_string (reply, "B");
-                               } else {
-                                       // this is an Aux out
-                                       lo_message_add_string (reply, "AX");
-                               }
-                       } else if (s->presentation_info().flags() & PresentationInfo::MidiBus) {
-                               lo_message_add_string (reply, "MB");
-                       } else if (s->presentation_info().flags() & PresentationInfo::VCA) {
+                       } else if (boost::dynamic_pointer_cast<VCA>(s)) {
                                lo_message_add_string (reply, "V");
                        } else if (s->is_master()) {
                                lo_message_add_string (reply, "MA");
                        } else if (s->is_monitor()) {
                                lo_message_add_string (reply, "MO");
+                       } else if (boost::dynamic_pointer_cast<Route>(s) && !boost::dynamic_pointer_cast<Track>(s)) {
+                               if (!(s->presentation_info().flags() & PresentationInfo::MidiBus)) {
+                                       // r->feeds (session->master_out()) may make more sense
+                                       if (r->direct_feeds_according_to_reality (session->master_out())) {
+                                               // this is a bus
+                                               lo_message_add_string (reply, "B");
+                                       } else {
+                                               // this is an Aux out
+                                               lo_message_add_string (reply, "AX");
+                                       }
+                               } else {
+                                       lo_message_add_string (reply, "MB");
+                               }
                        }
 
                        lo_message_add_string (reply, s->name().c_str());
@@ -2484,6 +2496,22 @@ OSC::master_set_mute (uint32_t state)
        return 0;
 }
 
+int
+OSC::master_select (lo_message msg)
+{
+       if (!session) {
+               return -1;
+       }
+       OSCSurface *sur = get_surface(get_address (msg));
+       sur->expand_enable = false;
+       boost::shared_ptr<Stripable> s = session->master_out();
+       if (s) {
+               SetStripableSelection (s);
+       }
+
+       return 0;
+}
+
 int
 OSC::monitor_set_gain (float dB)
 {
@@ -4077,11 +4105,6 @@ OSC::route_plugin_descriptor (int ssid, int piid, lo_message msg) {
        boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
        bool ok = false;
 
-       lo_message reply = lo_message_new();
-       lo_message_add_int32 (reply, ssid);
-       lo_message_add_int32 (reply, piid);
-       lo_message_add_int32(reply, redi->enabled() ? 1 : 0);
-
        for ( uint32_t ppi = 0; ppi < pip->parameter_count(); ppi++) {
 
                uint32_t controlid = pip->nth_parameter(ppi, ok);
@@ -4090,6 +4113,10 @@ OSC::route_plugin_descriptor (int ssid, int piid, lo_message msg) {
                }
                boost::shared_ptr<AutomationControl> c = pi->automation_control(Evoral::Parameter(PluginAutomation, 0, controlid));
 
+               lo_message reply = lo_message_new();
+               lo_message_add_int32 (reply, ssid);
+               lo_message_add_int32 (reply, piid);
+
                lo_message_add_int32 (reply, ppi + 1);
                ParameterDescriptor pd;
                pi->plugin()->get_parameter_descriptor(controlid, pd);
@@ -4102,6 +4129,10 @@ OSC::route_plugin_descriptor (int ssid, int piid, lo_message msg) {
                flags |= pd.logarithmic ? 4 : 0;
                flags |= pd.sr_dependent ? 32 : 0;
                flags |= pd.toggled ? 64 : 0;
+               flags |= pip->parameter_is_input(controlid) ? 0x80 : 0;
+
+               std::string param_desc = pi->plugin()->describe_parameter(Evoral::Parameter(PluginAutomation, 0, controlid));
+               flags |= (param_desc == X_("hidden")) ? 0x100 : 0;
                lo_message_add_int32 (reply, flags);
 
                switch(pd.datatype) {
@@ -4139,27 +4170,34 @@ OSC::route_plugin_descriptor (int ssid, int piid, lo_message msg) {
                                lo_message_add_string(reply, _("UNKNOWN"));
                                break;
                }
-
                lo_message_add_float (reply, pd.lower);
                lo_message_add_float (reply, pd.upper);
                lo_message_add_string (reply, pd.print_fmt.c_str());
                if ( pd.scale_points ) {
                        lo_message_add_int32 (reply, pd.scale_points->size());
                        for ( ARDOUR::ScalePoints::const_iterator i = pd.scale_points->begin(); i != pd.scale_points->end(); ++i) {
-                               lo_message_add_int32 (reply, i->second);
+                               lo_message_add_float (reply, i->second);
                                lo_message_add_string (reply, ((std::string)i->first).c_str());
                        }
-               } else {
+               }
+               else {
                        lo_message_add_int32 (reply, 0);
                }
                if ( c ) {
                        lo_message_add_double (reply, c->get_value());
-               } else {
+               }
+               else {
                        lo_message_add_double (reply, 0);
                }
+
+               lo_send_message (get_address (msg), "/strip/plugin/descriptor", reply);
+               lo_message_free (reply);
        }
 
-       lo_send_message (get_address (msg), "/strip/plugin/descriptor", reply);
+       lo_message reply = lo_message_new ();
+       lo_message_add_int32 (reply, ssid);
+       lo_message_add_int32 (reply, piid);
+       lo_send_message (get_address (msg), "/strip/plugin/descriptor_end", reply);
        lo_message_free (reply);
 
        return 0;
@@ -4990,10 +5028,9 @@ OSC::Sorted
 OSC::get_sorted_stripables(std::bitset<32> types, bool cue)
 {
        Sorted sorted;
-
-       // fetch all stripables
        StripableList stripables;
 
+       // fetch all stripables
        session->get_stripables (stripables);
 
        // Look for stripables that match bit in sur->strip_types
@@ -5002,46 +5039,49 @@ OSC::get_sorted_stripables(std::bitset<32> types, bool cue)
                boost::shared_ptr<Stripable> s = *it;
                if ((!cue) && (!types[9]) && (s->presentation_info().flags() & PresentationInfo::Hidden)) {
                        // do nothing... skip it
+               } else if (types[8] && (s->is_selected())) {
+                       sorted.push_back (s);
+               } else if (types[9] && (s->presentation_info().flags() & PresentationInfo::Hidden)) {
+                       sorted.push_back (s);
+               } else if (s->is_master() || s->is_monitor() || s->is_auditioner()) {
+                       // do nothing for these either (we add them later)
                } else {
-
-                       if (types[0] && (s->presentation_info().flags() & PresentationInfo::AudioTrack)) {
+                       if (types[0] && boost::dynamic_pointer_cast<AudioTrack>(s)) {
+                               sorted.push_back (s);
+                       } else if (types[1] && boost::dynamic_pointer_cast<MidiTrack>(s)) {
+                               sorted.push_back (s);
+                       } else if (types[4] && boost::dynamic_pointer_cast<VCA>(s)) {
                                sorted.push_back (s);
                        } else
-                       if (types[1] && (s->presentation_info().flags() & PresentationInfo::MidiTrack)) {
+#ifdef MIXBUS
+                       if (types[2] && Profile->get_mixbus() && s->mixbus()) {
                                sorted.push_back (s);
                        } else
-                       if ((s->presentation_info().flags() & PresentationInfo::AudioBus)) {
-                               boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s);
-                               // r->feeds (session->master_out()) may make more sense
-                               if (r->direct_feeds_according_to_reality (session->master_out())) {
-                                       // this is a bus
-                                       if (types[2]) {
-                                               sorted.push_back (s);
-                                       }
-                               } else {
-                                       // this is an Aux out
-                                       if (types[7]) {
-                                               sorted.push_back (s);
-                                       }
+                       if (types[7] && boost::dynamic_pointer_cast<Route>(s) && !boost::dynamic_pointer_cast<Track>(s)) {
+                               if (Profile->get_mixbus() && !s->mixbus()) {
+                                       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->is_selected())) {
-                               sorted.push_back (s);
-                       } else if (types[9] && (s->presentation_info().flags() & PresentationInfo::Hidden)) {
-                               sorted.push_back (s);
-                       }
-#ifdef MIXBUS
-                       else if (types[2]) {
-                               if (Profile->get_mixbus()) {
-                                       if (s->mixbus()) {
-                                               sorted.push_back (s);
+                       } else
+#endif
+                       if ((types[2] || types[3] || types[7]) && boost::dynamic_pointer_cast<Route>(s) && !boost::dynamic_pointer_cast<Track>(s)) {
+                               boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(s);
+                               if (!(s->presentation_info().flags() & PresentationInfo::MidiBus)) {
+                                       // note some older sessions will show midibuses as busses
+                                       if (r->direct_feeds_according_to_reality (session->master_out())) {
+                                               // this is a bus
+                                               if (types[2]) {
+                                                       sorted.push_back (s);
+                                               }
+                                       } else {
+                                               // this is an Aux out
+                                               if (types[7]) {
+                                                       sorted.push_back (s);
+                                               }
                                        }
+                               } else if (types[3]) {
+                                               sorted.push_back (s);
                                }
                        }
-#endif
                }
        }
        sort (sorted.begin(), sorted.end(), StripableByPresentationOrder());
@@ -5050,7 +5090,9 @@ OSC::get_sorted_stripables(std::bitset<32> types, bool cue)
                sorted.push_back (session->master_out());
        }
        if (types[6]) {
-               sorted.push_back (session->monitor_out());
+               if (session->monitor_out()) {
+                       sorted.push_back (session->monitor_out());
+               }
        }
        return sorted;
 }
@@ -5062,24 +5104,34 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
 
        if (!strncmp (path, "/cue/aux", 8)) {
                // set our Aux bus
-               ret = cue_set (argv[0]->i, msg);
+               if (argv[0]->f) {
+                       ret = cue_set (argv[0]->f, msg);
+               } else {
+                       ret = 0;
+               }
        }
        else if (!strncmp (path, "/cue/connect", 12)) {
                // Connect to default Aux bus
-               if ((!argc) || argv[0]->i) {
+               if ((!argc) || argv[0]->f) {
                        ret = cue_set (1, msg);
+               } else {
+                       ret = 0;
                }
        }
        else if (!strncmp (path, "/cue/next_aux", 13)) {
                // switch to next Aux bus
-               if ((!argc) || argv[0]->i) {
+               if ((!argc) || argv[0]->f) {
                        ret = cue_next (msg);
+               } else {
+                       ret = 0;
                }
        }
        else if (!strncmp (path, "/cue/previous_aux", 17)) {
                // switch to previous Aux bus
-               if ((!argc) || argv[0]->i) {
+               if ((!argc) || argv[0]->f) {
                        ret = cue_previous (msg);
+               } else {
+                       ret = 0;
                }
        }
        else if (!strncmp (path, "/cue/send/fader/", 16) && strlen (path) > 16) {