Move MIDI control port ownership into the MIDI Manager, since control port state...
[ardour.git] / libs / surfaces / control_protocol / control_protocol.cc
index bb8ada746f5bf0254667e12ce80a9d552f073b05..62214e6429031da68b35d1ca7b6357911a49bbda 100644 (file)
 
 */
 
-#include <ardour/session.h>
-#include <ardour/route.h>
-#include <ardour/audio_track.h>
+#include "pbd/error.h"
 
-#include <control_protocol/control_protocol.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;
+using namespace PBD;
 
-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;
+Signal0<void>       ControlProtocol::ZoomToSession;
+Signal0<void>       ControlProtocol::ZoomOut;
+Signal0<void>       ControlProtocol::ZoomIn;
+Signal0<void>       ControlProtocol::Enter;
+Signal1<void,float> ControlProtocol::ScrollTimeline;
 
-ControlProtocol::ControlProtocol (Session& s, string str)
+ControlProtocol::ControlProtocol (Session& s, string str, EventLoop* evloop)
        : BasicUI (s),
          _name (str)
 {
+       if (evloop) {
+               _own_event_loop = false;
+               _event_loop = evloop;
+       } else {
+               _own_event_loop = true;
+               fatal << "programming error: cannot create control protocols without an existing event loop (yet)" << endmsg;
+               /*NOTREACHED*/
+       }
+
        _active = false;
+       
+       session->RouteAdded.connect (*this, MISSING_INVALIDATOR, boost::protect (boost::bind (&ControlProtocol::add_strip, this, _1)), _event_loop);
 }
 
 ControlProtocol::~ControlProtocol ()
 {
 }
 
+void
+ControlProtocol::add_strip (ARDOUR::RouteList&)
+{
+       route_list_changed();
+}
+       
 void
 ControlProtocol::next_track (uint32_t initial_id)
 {
@@ -63,14 +84,14 @@ ControlProtocol::next_track (uint32_t initial_id)
                id++;
        }
 
-       while (id < limit) {
+       while (id <= limit) {
                if ((cr = session->route_by_remote_id (id)) != 0) {
                        break;
                }
                id++;
        }
 
-       if (id == limit) {
+       if (id >= limit) {
                id = 0;
                while (id != initial_id) {
                        if ((cr = session->route_by_remote_id (id)) != 0) {
@@ -86,9 +107,9 @@ ControlProtocol::next_track (uint32_t initial_id)
 void
 ControlProtocol::prev_track (uint32_t initial_id)
 {
-       uint32_t limit = session->nroutes() - 1;
+       uint32_t limit = session->nroutes();
        boost::shared_ptr<Route> cr = route_table[0];
-       uint32_t id;
+       int32_t id;
 
        if (cr) {
                id = cr->remote_control_id ();
@@ -97,7 +118,7 @@ ControlProtocol::prev_track (uint32_t initial_id)
        }
 
        if (id == 0) {
-               id = session->nroutes() - 1;
+               id = limit;
        } else {
                id--;
        }
@@ -110,12 +131,12 @@ ControlProtocol::prev_track (uint32_t initial_id)
        }
 
        if (id < 0) {
-               id = limit;
-               while (id > initial_id) {
-                       if ((cr = session->route_by_remote_id (id)) != 0) {
+               uint32_t i = limit;
+               while (i > initial_id) {
+                       if ((cr = session->route_by_remote_id (i)) != 0) {
                                break;
                        }
-                       id--;
+                       i--;
                }
        }
 
@@ -205,7 +226,7 @@ ControlProtocol::route_get_gain (uint32_t table_index)
                return 0.0f;
        }
 
-       return r->gain ();
+       return r->amp()->gain ();
 }
 
 void
@@ -235,7 +256,7 @@ ControlProtocol::route_get_effective_gain (uint32_t table_index)
                return 0.0f;
        }
 
-       return r->effective_gain ();
+       return r->amp()->gain_control()->get_value();
 }
 
 
@@ -252,7 +273,7 @@ ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t whic
                return 0.0f;
        }
 
-       return r->peak_input_power (which_input);
+       return r->peak_meter().peak_power (which_input);
 }