OSC: add /strip/hide
[ardour.git] / libs / surfaces / osc / osc.cc
index 181bb4d8067fa448f6f02054af5f8af6ae1f2f86..a026e0283a5a2e16c027d8870fd6026274be2f42 100644 (file)
@@ -576,6 +576,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/select/fader", "f", sel_fader);
                REGISTER_CALLBACK (serv, "/select/db_delta", "f", sel_dB_delta);
                REGISTER_CALLBACK (serv, "/select/trimdB", "f", sel_trim);
+               REGISTER_CALLBACK (serv, "/select/hide", "i", sel_hide);
                REGISTER_CALLBACK (serv, "/select/pan_stereo_position", "f", sel_pan_position);
                REGISTER_CALLBACK (serv, "/select/pan_stereo_width", "f", sel_pan_width);
                REGISTER_CALLBACK (serv, "/select/send_gain", "if", sel_sendgain);
@@ -617,6 +618,7 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/strip/monitor_input", "ii", route_monitor_input);
                REGISTER_CALLBACK (serv, "/strip/monitor_disk", "ii", route_monitor_disk);
                REGISTER_CALLBACK (serv, "/strip/expand", "ii", strip_expand);
+               REGISTER_CALLBACK (serv, "/strip/hide", "ii", strip_hide);
                REGISTER_CALLBACK (serv, "/strip/select", "ii", strip_gui_select);
                REGISTER_CALLBACK (serv, "/strip/polarity", "ii", strip_phase);
                REGISTER_CALLBACK (serv, "/strip/gain", "if", route_set_gain_dB);
@@ -962,6 +964,10 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
                int ssid = atoi (&path[14]);
                ret = strip_expand (ssid, argv[0]->i, msg);
        }
+       else if (!strncmp (path, "/strip/hide/", 12) && strlen (path) > 12) {
+               int ssid = atoi (&path[12]);
+               ret = strip_hide (ssid, argv[0]->i, msg);
+       }
        else if (!strncmp (path, "/strip/select/", 14) && strlen (path) > 14) {
                int ssid = atoi (&path[14]);
                ret = strip_gui_select (ssid, argv[0]->i, msg);
@@ -998,6 +1004,9 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
                int ssid = atoi (&path[17]);
                ret = sel_eq_shape (ssid, argv[0]->f, msg);
        }
+       else if (!strncmp (path, "/marker", 7)) {
+               ret = set_marker (types, argv, argc, msg);
+       }
        else if (!strncmp (path, "/set_surface", 12)) {
                ret = surface_parse (path, types, argv, argc, msg);
        }
@@ -1261,6 +1270,13 @@ OSC::routes_list (lo_message msg)
 void
 OSC::surface_list (lo_message msg)
 {
+               get_surfaces ();
+}
+
+void
+OSC::get_surfaces ()
+{
+
        /* this function is for debugging and prints lots of
         * information about what surfaces Ardour knows about and their
         * internal parameters. It is best accessed by sending:
@@ -1268,28 +1284,28 @@ OSC::surface_list (lo_message msg)
         * a surface entry.
         */
 
-       cerr << "List of known Surfaces: " << _surface.size() << "\n\n";
+       PBD::info << string_compose ("\nList of known Surfaces (%1):\n", _surface.size());
 
        Glib::Threads::Mutex::Lock lm (surfaces_lock);
        for (uint32_t it = 0; it < _surface.size(); it++) {
                OSCSurface* sur = &_surface[it];
-               cerr << string_compose ("  Surface: %1 URL: %2\n", it, sur->remote_url);
-               cerr << string_compose ("       Number of strips: %1 Bank size: %2 Current Bank %3\n", sur->nstrips, sur->bank_size, sur->bank);
-               cerr << string_compose ("       Use Custom: %1 Custom Strips: %2\n", sur->custom_mode, sur->custom_strips.size ());
+               PBD::info << string_compose ("\n  Surface: %1 - URL: %2\n", it, sur->remote_url);
+               PBD::info << string_compose ("  Number of strips: %1   Bank size: %2   Current Bank %3\n", sur->nstrips, sur->bank_size, sur->bank);
+               PBD::info << string_compose ("  Use Custom: %1   Custom Strips: %2\n", sur->custom_mode, sur->custom_strips.size ());
                bool ug = false;
                if (sur->usegroup == PBD::Controllable::UseGroup) {
                        ug = true;
                }
-               cerr << string_compose ("       Strip Types: %1 Feedback: %2 no_clear: %3 gain mode: %4 use groups? %5\n", \
+               PBD::info << string_compose ("  Strip Types: %1   Feedback: %2   No_clear flag: %3   Gain mode: %4   Use groups flag %5\n", \
                        sur->strip_types.to_ulong(), sur->feedback.to_ulong(), sur->no_clear, sur->gainmode, ug);
-               cerr << string_compose ("       using plugin: %1 of %2 plugins, with %3 params. page size: %4 page: %5\n", \
+               PBD::info << string_compose ("  Using plugin: %1  of  %2 plugins, with %3 params.  Page size: %4  Page: %5\n", \
                        sur->plugin_id, sur->plugins.size(), sur->plug_params.size(), sur->plug_page_size, sur->plug_page);
-               cerr << string_compose ("       send page size: %1 page: %2\n", sur->send_page_size, sur->send_page);
-               cerr << string_compose ("       expanded? %1 track: %2 jogmode: %3\n", sur->expand_enable, sur->expand, sur->jogmode);
-               cerr << string_compose ("       personal monitor? %1, Aux master: %2, number of sends: %3\n", sur->cue, sur->aux, sur->sends.size());
-               cerr << string_compose ("       Linkset: %1 Device Id: %2\n", sur->linkset, sur->linkid);
+               PBD::info << string_compose ("  Send page size: %1  Page: %2\n", sur->send_page_size, sur->send_page);
+               PBD::info << string_compose ("  Expanded flag %1   Track: %2   Jogmode: %3\n", sur->expand_enable, sur->expand, sur->jogmode);
+               PBD::info << string_compose ("  Personal monitor flag %1,   Aux master: %2,   Number of sends: %3\n", sur->cue, sur->aux, sur->sends.size());
+               PBD::info << string_compose ("  Linkset: %1   Device Id: %2\n", sur->linkset, sur->linkid);
        }
-       cerr << "\nList of LinkSets " << link_sets.size() << "\n\n";
+       PBD::info << string_compose ("\nList of LinkSets (%1):\n", link_sets.size());
        std::map<uint32_t, LinkSet>::iterator it;
        for (it = link_sets.begin(); it != link_sets.end(); it++) {
                if (!(*it).first) {
@@ -1300,12 +1316,12 @@ OSC::surface_list (lo_message msg)
                if (set->urls.size()) {
                        devices = set->urls.size() - 1;
                }
-               cerr << string_compose ("  Linkset %1 has %2 devices and sees %3 strips\n", (*it).first, devices, set->strips.size());
-               cerr << string_compose ("       Bank size: %1 Current bank: %2 Strip Types: %3\n", set->banksize, set->bank, set->strip_types.to_ulong());
-               cerr << string_compose ("       auto bank sizing: %1 linkset not ready: %2\n", set->autobank, set->not_ready);
-               cerr << string_compose ("       Use Custom: %1 Custom Strips: %2\n", set->custom_mode, set->custom_strips.size ());
+               PBD::info << string_compose ("\n  Linkset %1 has %2 devices and sees %3 strips\n", (*it).first, devices, set->strips.size());
+               PBD::info << string_compose ("  Bank size: %1   Current bank: %2   Strip Types: %3\n", set->banksize, set->bank, set->strip_types.to_ulong());
+               PBD::info << string_compose ("  Auto bank sizing: %1 Linkset not ready flag: %2\n", set->autobank, set->not_ready);
+               PBD::info << string_compose ("  Use Custom: %1 Number of Custom Strips: %2\n", set->custom_mode, set->custom_strips.size ());
        }
-       cerr << "\n";
+       PBD::info << endmsg;
 }
 
 int
@@ -2047,6 +2063,8 @@ OSC::get_surface (lo_address addr , bool quiet)
 void
 OSC::global_feedback (OSCSurface* sur)
 {
+       OSCGlobalObserver* o = sur->global_obs;
+       delete o;
        if (sur->feedback[4] || sur->feedback[3] || sur->feedback[5] || sur->feedback[6]) {
 
                // create a new Global Observer for this surface
@@ -2808,16 +2826,80 @@ OSC::jog_mode (float mode, lo_message msg)
                default:
                        PBD::warning << "Jog Mode: " << mode << " is not valid." << endmsg;
                        break;
+       }
        lo_message reply = lo_message_new ();
        lo_message_add_int32 (reply, s->jogmode);
        lo_send_message (get_address(msg), "/jog/mode", reply);
        lo_message_free (reply);
 
-       }
        return 0;
 
 }
 
+// two structs to help with going to markers
+struct LocationMarker {
+       LocationMarker (const std::string& l, samplepos_t w)
+               : label (l), when (w) {}
+       std::string label;
+       samplepos_t  when;
+};
+
+struct LocationMarkerSort {
+       bool operator() (const LocationMarker& a, const LocationMarker& b) {
+               return (a.when < b.when);
+       }
+};
+
+int
+OSC::set_marker (const char* types, lo_arg **argv, int argc, lo_message msg)
+{
+       if (argc != 1) {
+               PBD::warning << "Wrong number of parameters, one only." << endmsg;
+               return -1;
+       }
+       const Locations::LocationList& ll (session->locations ()->list ());
+       uint32_t marker = 0;
+
+       switch (types[0]) {
+               case 's':
+                       for (Locations::LocationList::const_iterator l = ll.begin(); l != ll.end(); ++l) {
+                               if ((*l)->is_mark ()) {
+                                       if (strcmp (&argv[0]->s, (*l)->name().c_str()) == 0) {
+                                               session->request_locate ((*l)->start (), false);
+                                               return 0;
+                                       }
+                               }
+                       }
+                       break;
+               case 'i':
+                       marker = (uint32_t) argv[0]->i - 1;
+                       break;
+               case 'f':
+                       marker = (uint32_t) argv[0]->f - 1;
+                       break;
+               default:
+                       return -1;
+                       break;
+       }
+       std::vector<LocationMarker> lm;
+       // get Locations that are marks
+       for (Locations::LocationList::const_iterator l = ll.begin(); l != ll.end(); ++l) {
+               if ((*l)->is_mark ()) {
+                       lm.push_back (LocationMarker((*l)->name(), (*l)->start ()));
+               }
+       }
+       // sort them by position
+       LocationMarkerSort location_marker_sort;
+       std::sort (lm.begin(), lm.end(), location_marker_sort);
+       // go there
+       if (marker < lm.size()) {
+               session->request_locate (lm[marker].when, false);
+               return 0;
+       }
+       // we were unable to deal with things
+       return -1;
+}
+
 int
 OSC::click_level (float position)
 {
@@ -3712,6 +3794,19 @@ OSC::strip_expand (int ssid, int yn, lo_message msg)
        return _strip_select (s, get_address (msg));
 }
 
+int
+OSC::strip_hide (int ssid, int state, lo_message msg)
+{
+       boost::shared_ptr<Stripable> s = get_strip (ssid, get_address (msg));
+
+       if (s) {
+               if (state != s->is_hidden ()) {
+                       s->presentation_info().set_hidden ((bool) state);
+               }
+       }
+       return 0;
+}
+
 int
 OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr)
 {
@@ -3747,7 +3842,7 @@ OSC::_strip_select (boost::shared_ptr<Stripable> s, lo_address addr)
        OSCSelectObserver* so = dynamic_cast<OSCSelectObserver*>(sur->sel_obs);
        if (sur->feedback[13]) {
                if (so != 0) {
-                       so->refresh_strip (s, nsends, true);
+                       so->refresh_strip (s, nsends, sur->gainmode, true);
                } else {
                        OSCSelectObserver* sel_fb = new OSCSelectObserver (*this, sur);
                        sur->sel_obs = sel_fb;
@@ -4047,6 +4142,24 @@ OSC::sel_trim (float val, lo_message msg)
        return float_message("/select/trimdB", 0, get_address (msg));
 }
 
+int
+OSC::sel_hide (uint32_t state, 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 (state != s->is_hidden ()) {
+                       s->presentation_info().set_hidden ((bool) state);
+               }
+       }
+       return 0;
+}
+
 int
 OSC::sel_pan_position (float val, lo_message msg)
 {
@@ -4461,21 +4574,23 @@ OSC::sel_plugin_activate (float state, lo_message msg)
                return -1;
        }
        OSCSurface *sur = get_surface(get_address (msg));
-       boost::shared_ptr<Stripable> s = sur->select;
+       if (sur->plugins.size() > 0) {
+               boost::shared_ptr<Stripable> s = sur->select;
 
-       boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s);
+               boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s);
 
-       if (r) {
-               boost::shared_ptr<Processor> redi=r->nth_plugin (sur->plugins[sur->plugin_id -1]);
-               if (redi) {
-                       boost::shared_ptr<PluginInsert> pi;
-                       if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redi))) {
-                               if(state > 0) {
-                                       pi->activate();
-                               } else {
-                                       pi->deactivate();
+               if (r) {
+                       boost::shared_ptr<Processor> redi=r->nth_plugin (sur->plugins[sur->plugin_id -1]);
+                       if (redi) {
+                               boost::shared_ptr<PluginInsert> pi;
+                               if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redi))) {
+                                       if(state > 0) {
+                                               pi->activate();
+                                       } else {
+                                               pi->deactivate();
+                                       }
+                                       return 0;
                                }
-                               return 0;
                        }
                }
        }