first vaguely working version using PresentationInfo
[ardour.git] / libs / surfaces / control_protocol / control_protocol.cc
index 708373e3bc590239189ec6d19bf8ca59b582f37c..2562edebcbedac9847b97883a5c8f279fa8b061a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2006 Paul Davis 
+    Copyright (C) 2006 Paul Davis
 
     This program is free software; you can redistribute it
     and/or modify it under the terms of the GNU Lesser
 
 */
 
-#include <ardour/session.h>
-#include <ardour/route.h>
-#include <ardour/audio_track.h>
-#include <ardour/meter.h>
-#include <control_protocol/control_protocol.h>
+#include "pbd/error.h"
+
+#include "ardour/gain_control.h"
+#include "ardour/session.h"
+#include "ardour/route.h"
+#include "ardour/audio_track.h"
+#include "ardour/meter.h"
+#include "ardour/amp.h"
+#include "control_protocol/control_protocol.h"
 
 using namespace ARDOUR;
 using namespace std;
-
-sigc::signal<void> ControlProtocol::ZoomToSession;
-sigc::signal<void> ControlProtocol::ZoomOut;
-sigc::signal<void> ControlProtocol::ZoomIn;
-sigc::signal<void> ControlProtocol::Enter;
-sigc::signal<void,float> ControlProtocol::ScrollTimeline;
+using namespace PBD;
+
+Signal0<void>       ControlProtocol::ZoomToSession;
+Signal0<void>       ControlProtocol::ZoomOut;
+Signal0<void>       ControlProtocol::ZoomIn;
+Signal0<void>       ControlProtocol::Enter;
+Signal0<void>       ControlProtocol::Undo;
+Signal0<void>       ControlProtocol::Redo;
+Signal1<void,float> ControlProtocol::ScrollTimeline;
+Signal1<void,uint32_t> ControlProtocol::GotoView;
+Signal0<void> ControlProtocol::CloseDialog;
+PBD::Signal0<void> ControlProtocol::VerticalZoomInAll;
+PBD::Signal0<void> ControlProtocol::VerticalZoomOutAll;
+PBD::Signal0<void> ControlProtocol::VerticalZoomInSelected;
+PBD::Signal0<void> ControlProtocol::VerticalZoomOutSelected;
+PBD::Signal1<void,RouteNotificationListPtr> ControlProtocol::TrackSelectionChanged;
+PBD::Signal1<void,uint64_t> ControlProtocol::AddRouteToSelection;
+PBD::Signal1<void,uint64_t> ControlProtocol::SetRouteSelection;
+PBD::Signal1<void,uint64_t> ControlProtocol::ToggleRouteSelection;
+PBD::Signal1<void,uint64_t> ControlProtocol::RemoveRouteFromSelection;
+PBD::Signal0<void>          ControlProtocol::ClearRouteSelection;
+PBD::Signal0<void>          ControlProtocol::StepTracksDown;
+PBD::Signal0<void>          ControlProtocol::StepTracksUp;
+
+const std::string ControlProtocol::state_node_name ("Protocol");
 
 ControlProtocol::ControlProtocol (Session& s, string str)
-       : BasicUI (s),
-         _name (str)
+       : BasicUI (s)
+       , _name (str)
+       , _active (false)
 {
-       _active = false;
-       session->RouteAdded.connect (mem_fun(*this, &ControlProtocol::add_strip));
 }
 
 ControlProtocol::~ControlProtocol ()
 {
 }
 
-void
-ControlProtocol::add_strip (std::list<boost::shared_ptr<ARDOUR::Route> >)
+int
+ControlProtocol::set_active (bool yn)
 {
-       route_list_changed();
+       _active = yn;
+       return 0;
 }
-       
+
 void
 ControlProtocol::next_track (uint32_t initial_id)
 {
-       uint32_t limit = session->nroutes();
-       boost::shared_ptr<Route> cr = route_table[0];
-       uint32_t id;
-
-       if (cr) {
-               id = cr->remote_control_id ();
-       } else {
-               id = 0;
-       }
-
-       if (id == limit) {
-               id = 0;
-       } else {
-               id++;
-       }
-
-       while (id < limit) {
-               if ((cr = session->route_by_remote_id (id)) != 0) {
-                       break;
-               }
-               id++;
-       }
-
-       if (id == limit) {
-               id = 0;
-               while (id != initial_id) {
-                       if ((cr = session->route_by_remote_id (id)) != 0) {
-                               break;
-                       }
-                       id++;
-               }
-       }
-
-       route_table[0] = cr;
+       // STRIPABLE route_table[0] = _session->get_nth_stripable (++initial_id, RemoteControlID::Route);
 }
 
 void
 ControlProtocol::prev_track (uint32_t initial_id)
 {
-       uint32_t limit = session->nroutes() - 1;
-       boost::shared_ptr<Route> cr = route_table[0];
-       uint32_t id;
-
-       if (cr) {
-               id = cr->remote_control_id ();
-       } else {
-               id = 0;
-       }
-
-       if (id == 0) {
-               id = session->nroutes() - 1;
-       } else {
-               id--;
-       }
-
-       while (id >= 0) {
-               if ((cr = session->route_by_remote_id (id)) != 0) {
-                       break;
-               }
-               id--;
-       }
-
-       if (id < 0) {
-               id = limit;
-               while (id > initial_id) {
-                       if ((cr = session->route_by_remote_id (id)) != 0) {
-                               break;
-                       }
-                       id--;
-               }
+       if (!initial_id) {
+               return;
        }
-
-       route_table[0] = cr;
+       // STRIPABLE route_table[0] = _session->get_nth_stripable (--initial_id, RemoteControlID::Route);
 }
 
-
 void
 ControlProtocol::set_route_table_size (uint32_t size)
 {
@@ -144,7 +103,7 @@ ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR
        if (table_index >= route_table.size()) {
                return;
        }
-       
+
        route_table[table_index] = r;
 
        // XXX SHAREDPTR need to handle r->GoingAway
@@ -153,6 +112,7 @@ ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR
 bool
 ControlProtocol::set_route_table (uint32_t table_index, uint32_t remote_control_id)
 {
+#if 0 // STRIPABLE
        boost::shared_ptr<Route> r = session->route_by_remote_id (remote_control_id);
 
        if (!r) {
@@ -160,7 +120,7 @@ ControlProtocol::set_route_table (uint32_t table_index, uint32_t remote_control_
        }
 
        set_route_table (table_index, r);
-
+#endif
        return true;
 }
 
@@ -176,7 +136,7 @@ ControlProtocol::route_set_rec_enable (uint32_t table_index, bool yn)
        boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
 
        if (at) {
-               at->set_record_enable (yn, this);
+               at->rec_enable_control()->set_value (1.0, Controllable::UseGroup);
        }
 }
 
@@ -192,7 +152,7 @@ ControlProtocol::route_get_rec_enable (uint32_t table_index)
        boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
 
        if (at) {
-               return at->record_enabled ();
+               return at->rec_enable_control()->get_value();
        }
 
        return false;
@@ -212,7 +172,7 @@ ControlProtocol::route_get_gain (uint32_t table_index)
                return 0.0f;
        }
 
-       return r->gain ();
+       return r->gain_control()->get_value();
 }
 
 void
@@ -223,9 +183,9 @@ ControlProtocol::route_set_gain (uint32_t table_index, float gain)
        }
 
        boost::shared_ptr<Route> r = route_table[table_index];
-       
+
        if (r != 0) {
-               r->set_gain (gain, this);
+               r->gain_control()->set_value (gain, Controllable::UseGroup);
        }
 }
 
@@ -242,7 +202,7 @@ ControlProtocol::route_get_effective_gain (uint32_t table_index)
                return 0.0f;
        }
 
-       return r->effective_gain ();
+       return r->amp()->gain_control()->get_value();
 }
 
 
@@ -259,10 +219,9 @@ ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t whic
                return 0.0f;
        }
 
-       return r->peak_meter().peak_power (which_input);
+       return r->peak_meter()->meter_level (which_input, MeterPeak);
 }
 
-
 bool
 ControlProtocol::route_get_muted (uint32_t table_index)
 {
@@ -276,7 +235,7 @@ ControlProtocol::route_get_muted (uint32_t table_index)
                return false;
        }
 
-       return r->muted ();
+       return r->mute_control()->muted ();
 }
 
 void
@@ -289,7 +248,7 @@ ControlProtocol::route_set_muted (uint32_t table_index, bool yn)
        boost::shared_ptr<Route> r = route_table[table_index];
 
        if (r != 0) {
-               r->set_mute (yn, this);
+               r->mute_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup);
        }
 }
 
@@ -320,7 +279,7 @@ ControlProtocol::route_set_soloed (uint32_t table_index, bool yn)
        boost::shared_ptr<Route> r = route_table[table_index];
 
        if (r != 0) {
-               r->set_solo (yn, this);
+               r->solo_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup);
        }
 }
 
@@ -340,3 +299,31 @@ ControlProtocol:: route_get_name (uint32_t table_index)
        return r->name();
 }
 
+list<boost::shared_ptr<Bundle> >
+ControlProtocol::bundles ()
+{
+       return list<boost::shared_ptr<Bundle> > ();
+}
+
+XMLNode&
+ControlProtocol::get_state ()
+{
+       XMLNode* node = new XMLNode (state_node_name);
+
+       node->add_property ("name", _name);
+       node->add_property ("feedback", get_feedback() ? "yes" : "no");
+
+       return *node;
+}
+
+int
+ControlProtocol::set_state (XMLNode const & node, int /* version */)
+{
+       const XMLProperty* prop;
+
+       if ((prop = node.property ("feedback")) != 0) {
+               set_feedback (string_is_affirmative (prop->value()));
+       }
+
+       return 0;
+}