Defer session_loaded until AFTER lo_server_new.
[ardour.git] / libs / surfaces / osc / osc.cc
index 47ef9e13c2ead53bf16cff1460b1d66ca86d7f30..0565e24f609bab1f0be43f75f9a0ea86e2940e1d 100644 (file)
@@ -88,7 +88,6 @@ OSC::OSC (Session& s, uint32_t port)
 {
        _instance = this;
 
-       session_loaded (s);
        session->Exported.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::session_exported, this, _1, _2), this);
 }
 
@@ -227,6 +226,8 @@ OSC::start ()
 
        register_callbacks();
 
+       session_loaded (@session);
+
        // lo_server_thread_add_method(_sthread, NULL, NULL, OSC::_dummy_handler, this);
 
        /* startup the event loop thread */
@@ -359,6 +360,46 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/ardour/toggle_punch_out", "", toggle_punch_out);
                REGISTER_CALLBACK (serv, "/ardour/rec_enable_toggle", "", rec_enable_toggle);
                REGISTER_CALLBACK (serv, "/ardour/toggle_all_rec_enables", "", toggle_all_rec_enables);
+               REGISTER_CALLBACK (serv, "/ardour/all_tracks_rec_in", "f", all_tracks_rec_in);
+               REGISTER_CALLBACK (serv, "/ardour/all_tracks_rec_out", "f", all_tracks_rec_out);
+               REGISTER_CALLBACK (serv, "/ardour/remove_marker", "", remove_marker_at_playhead);
+               REGISTER_CALLBACK (serv, "/ardour/jump_bars", "f", jump_by_bars);
+               REGISTER_CALLBACK (serv, "/ardour/jump_seconds", "f", jump_by_seconds);
+               REGISTER_CALLBACK (serv, "/ardour/mark_in", "", mark_in);
+               REGISTER_CALLBACK (serv, "/ardour/mark_out", "", mark_out);
+               REGISTER_CALLBACK (serv, "/ardour/toggle_click", "", toggle_click);
+               REGISTER_CALLBACK (serv, "/ardour/midi_panic", "", midi_panic);
+               REGISTER_CALLBACK (serv, "/ardour/toggle_roll", "", toggle_roll);
+               REGISTER_CALLBACK (serv, "/ardour/stop_forget", "", stop_forget);
+               REGISTER_CALLBACK (serv, "/ardour/set_punch_range", "", set_punch_range);
+               REGISTER_CALLBACK (serv, "/ardour/set_loop_range", "", set_loop_range);
+               REGISTER_CALLBACK (serv, "/ardour/set_session_range", "", set_session_range);
+               REGISTER_CALLBACK (serv, "/ardour/toggle_monitor_mute", "", toggle_monitor_mute);
+               REGISTER_CALLBACK (serv, "/ardour/toggle_monitor_dim", "", toggle_monitor_dim);
+               REGISTER_CALLBACK (serv, "/ardour/toggle_monitor_mono", "", toggle_monitor_mono);
+               REGISTER_CALLBACK (serv, "/ardour/quick_snapshot_switch", "", quick_snapshot_switch);
+               REGISTER_CALLBACK (serv, "/ardour/quick_snapshot_stay", "", quick_snapshot_stay);
+               REGISTER_CALLBACK (serv, "/ardour/fit_1_track", "", fit_1_track);
+               REGISTER_CALLBACK (serv, "/ardour/fit_2_tracks", "", fit_2_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/fit_4_tracks", "", fit_4_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/fit_8_tracks", "", fit_8_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/fit_16_tracks", "", fit_16_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/fit_32_tracks", "", fit_32_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/fit_all_tracks", "", fit_all_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/zoom_100_ms", "", zoom_100_ms);
+               REGISTER_CALLBACK (serv, "/ardour/zoom_1_sec", "", zoom_1_sec);
+               REGISTER_CALLBACK (serv, "/ardour/zoom_10_sec", "", zoom_10_sec);
+               REGISTER_CALLBACK (serv, "/ardour/zoom_1_min", "", zoom_1_min);
+               REGISTER_CALLBACK (serv, "/ardour/zoom_5_min", "", zoom_5_min);
+               REGISTER_CALLBACK (serv, "/ardour/zoom_10_min", "", zoom_10_min);
+               REGISTER_CALLBACK (serv, "/ardour/zoom_to_session", "", zoom_to_session);
+               REGISTER_CALLBACK (serv, "/ardour/temporal_zoom_in", "f", temporal_zoom_in);
+               REGISTER_CALLBACK (serv, "/ardour/temporal_zoom_out", "f", temporal_zoom_out);
+               REGISTER_CALLBACK (serv, "/ardour/scroll_up_1_track", "f", scroll_up_1_track);
+               REGISTER_CALLBACK (serv, "/ardour/scroll_dn_1_track", "f", scroll_dn_1_track);
+               REGISTER_CALLBACK (serv, "/ardour/scroll_up_1_page", "f", scroll_up_1_page);
+               REGISTER_CALLBACK (serv, "/ardour/scroll_dn_1_page", "f", scroll_dn_1_page);
+
 
                /*
                 * NOTE: these messages are provided for (arguably broken) apps
@@ -387,7 +428,45 @@ OSC::register_callbacks()
                REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_punch_out", "f", toggle_punch_out);
                REGISTER_CALLBACK (serv, "/ardour/pushbutton/rec_enable_toggle", "f", rec_enable_toggle);
                REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_all_rec_enables", "f", toggle_all_rec_enables);
-
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/all_tracks_rec_in", "f", all_tracks_rec_in);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/all_tracks_rec_out", "f", all_tracks_rec_out);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/remove_marker", "f", remove_marker_at_playhead);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/mark_in", "f", mark_in);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/mark_out", "f", mark_out);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_click", "f", toggle_click);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/midi_panic", "f", midi_panic);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_roll", "f", toggle_roll);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/stop_forget", "f", stop_forget);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/set_punch_range", "f", set_punch_range);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/set_loop_range", "f", set_loop_range);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/set_session_range", "f", set_session_range);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_monitor_mute", "f", toggle_monitor_mute);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_monitor_dim", "f", toggle_monitor_dim);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_monitor_mono", "f", toggle_monitor_mono);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/quick_snapshot_switch", "f", quick_snapshot_switch);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/quick_snapshot_stay", "f", quick_snapshot_stay);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/fit_1_track", "f", fit_1_track);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/fit_2_tracks", "f", fit_2_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/fit_4_tracks", "f", fit_4_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/fit_8_tracks", "f", fit_8_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/fit_16_tracks", "f", fit_16_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/fit_32_tracks", "f", fit_32_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/fit_all_tracks", "f", fit_all_tracks);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/zoom_100_ms", "f", zoom_100_ms);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/zoom_1_sec", "f", zoom_1_sec);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/zoom_10_sec", "f", zoom_10_sec);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/zoom_1_min", "f", zoom_1_min);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/zoom_5_min", "f", zoom_5_min);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/zoom_10_min", "f", zoom_10_min);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/zoom_to_session", "f", zoom_to_session);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/temporal_zoom_in", "f", temporal_zoom_in);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/temporal_zoom_out", "f", temporal_zoom_out);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/scroll_up_1_track", "f", scroll_up_1_track);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/scroll_dn_1_track", "f", scroll_dn_1_track);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/scroll_up_1_page", "f", scroll_up_1_page);
+               REGISTER_CALLBACK (serv, "/ardour/pushbutton/scroll_dn_1_page", "f", scroll_dn_1_page);
+
+               /* These commands require the route index in addition to the arg; TouchOSC (et al) can't use these  */ 
                REGISTER_CALLBACK (serv, "/ardour/routes/mute", "ii", route_mute);
                REGISTER_CALLBACK (serv, "/ardour/routes/solo", "ii", route_solo);
                REGISTER_CALLBACK (serv, "/ardour/routes/recenable", "ii", route_recenable);
@@ -676,9 +755,37 @@ OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_
                }
 
                ret = 0;
+       } else if (argc == 1 && types[0] == 'f') { // single float -- probably TouchOSC
+               if (!strncmp (path, "/ardour/routes/gainabs/", 23) && strlen (path) > 23) {
+                       int rid = atoi (&path[23]);
+                       // use some power-scale mapping??
+                       route_set_gain_abs (rid, argv[0]->f);
+                       ret = 0;
+               }
+               else if (!strncmp (path, "/ardour/routes/trimabs/", 23) && strlen (path) > 23) {
+                       int rid = atoi (&path[23]);
+                       // normalize 0..1 ?
+                       route_set_trim_abs (rid, argv[0]->f);
+                       ret = 0;
+               }
+               else if (!strncmp (path, "/ardour/routes/mute/", 20) && strlen (path) > 20) {
+                       int rid = atoi (&path[20]);
+                       route_mute (rid, argv[0]->f == 1.0);
+                       ret = 0;
+               }
+               else if (!strncmp (path, "/ardour/routes/solo/", 20) && strlen (path) > 20) {
+                       int rid = atoi (&path[20]);
+                       route_solo (rid, argv[0]->f == 1.0);
+                       ret = 0;
+               }
+               else if (!strncmp (path, "/ardour/routes/recenable/", 25) && strlen (path) > 25) {
+                       int rid = atoi (&path[25]);
+                       route_recenable (rid, argv[0]->f == 1.0);
+                       ret = 0;
+               }
        }
 
-       if ((ret && _debugmode == Unhandled) || _debugmode == All) {
+       if ((ret && _debugmode == Unhandled)) {
                debugmsg (_("Unhandled OSC message"), path, types, argv, argc);
        }
 
@@ -736,7 +843,7 @@ OSC::debugmsg (const char *prefix, const char *path, const char* types, lo_arg *
                                ss << "<SYMBOL>";
                                break;
                        default:
-                               ss << "<??>";
+                               ss << "< ?? >";
                                break;
                }
        }
@@ -941,7 +1048,7 @@ OSC::route_mute (int rid, int yn)
        boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
 
        if (r) {
-               r->set_mute (yn, this);
+               r->set_mute (yn, PBD::Controllable::NoGroup);
        }
 
        return 0;
@@ -957,7 +1064,7 @@ OSC::route_solo (int rid, int yn)
        if (r) {
                boost::shared_ptr<RouteList> rl (new RouteList);
                rl->push_back (r);
-               session->set_solo (rl, yn);
+               session->set_solo (rl, yn, Session::rt_cleanup, PBD::Controllable::NoGroup);
        }
 
        return 0;
@@ -971,7 +1078,7 @@ OSC::route_recenable (int rid, int yn)
        boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
 
        if (r) {
-               r->set_record_enabled (yn, this);
+               r->set_record_enabled (yn, PBD::Controllable::NoGroup);
        }
 
        return 0;
@@ -985,7 +1092,7 @@ OSC::route_set_gain_abs (int rid, float level)
        boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
 
        if (r) {
-               r->set_gain (level, this);
+               r->set_gain (level, PBD::Controllable::NoGroup);
        }
 
        return 0;
@@ -1006,7 +1113,7 @@ OSC::route_set_trim_abs (int rid, float level)
        boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
 
        if (r) {
-               r->set_trim (level, this);
+               r->set_trim (level, PBD::Controllable::NoGroup);
        }
 
        return 0;
@@ -1081,7 +1188,7 @@ OSC::route_set_send_gain_abs (int rid, int sid, float val)
                boost::shared_ptr<Amp> a = s->amp();
 
                if (a) {
-                       a->set_gain (val, this);
+                       a->gain_control()->set_value (val, PBD::Controllable::NoGroup);
                }
        }
        return 0;
@@ -1113,7 +1220,7 @@ OSC::route_set_send_gain_dB (int rid, int sid, float val)
                boost::shared_ptr<Amp> a = s->amp();
 
                if (a) {
-                       a->set_gain (dB_to_coefficient (val), this);
+                       a->gain_control()->set_value (dB_to_coefficient (val), PBD::Controllable::NoGroup);
                }
        }
        return 0;