Fix 'live' CC sending of bar controllers after loading session (previously only worke...
authorDavid Robillard <d@drobilla.net>
Fri, 6 Jul 2007 02:37:35 +0000 (02:37 +0000)
committerDavid Robillard <d@drobilla.net>
Fri, 6 Jul 2007 02:37:35 +0000 (02:37 +0000)
git-svn-id: svn://localhost/ardour2/trunk@2116 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/automation_controller.cc
gtk2_ardour/automation_controller.h
gtk2_ardour/automation_time_axis.cc
gtk2_ardour/ladspa_pluginui.cc
gtk2_ardour/midi_time_axis.cc
libs/ardour/ardour/automatable.h
libs/ardour/ardour/automation_control.h
libs/ardour/ardour/midi_track.h
libs/ardour/automatable.cc
libs/ardour/automation_control.cc
libs/ardour/midi_track.cc

index 09d1f1e7441454086f43af33936aa28c58c88dcc..8483bab3933217d49e8175433b7a3015eba261bb 100644 (file)
@@ -61,12 +61,12 @@ AutomationController::~AutomationController()
 }
 
 boost::shared_ptr<AutomationController>
-AutomationController::create(Session& s, boost::shared_ptr<AutomationList> al, boost::shared_ptr<AutomationControl> ac)
+AutomationController::create(boost::shared_ptr<Automatable> parent, boost::shared_ptr<AutomationList> al, boost::shared_ptr<AutomationControl> ac)
 {
        Gtk::Adjustment* adjustment = manage(new Gtk::Adjustment(al->default_value(), al->get_min_y(), al->get_max_y()));
        if (!ac) {
                PBD::warning << "Creating AutomationController for " << al->parameter().to_string() << endmsg;
-               ac = boost::shared_ptr<AutomationControl>(new AutomationControl(s, al));
+               ac = parent->control_factory(al);
        }
        return boost::shared_ptr<AutomationController>(new AutomationController(ac, adjustment));
 }
index 0f98e5f083d521a3a2e23bc84d34c57842171046..8a244113c4056d5e65becd37fba700f565a9f76d 100644 (file)
@@ -29,13 +29,14 @@ namespace ARDOUR {
        class Session;
        class AutomationList;
        class AutomationControl;
+       class Automatable;
 }
 
 
 class AutomationController : public Gtkmm2ext::BarController {
 public:
        static boost::shared_ptr<AutomationController> create(
-                       ARDOUR::Session& s,
+                       boost::shared_ptr<ARDOUR::Automatable> parent,
                        boost::shared_ptr<ARDOUR::AutomationList> al,
                        boost::shared_ptr<ARDOUR::AutomationControl> ac);
 
index 28d8ba326f1a911a73c32b66738d29ae8144cc1c..5c5cd53dec48e17f004fc0cdb9a574e98a2810d1 100644 (file)
@@ -59,7 +59,7 @@ AutomationTimeAxisView::AutomationTimeAxisView (Session& s, boost::shared_ptr<Ro
          _route (r),
          _control (c),
          _automatable (a),
-         _controller(AutomationController::create(s, c->list(), c)),
+         _controller(AutomationController::create(a, c->list(), c)),
          _base_rect (0),
          _name (nom),
          height_button (_("h")),
index ffab3c18f91bc7db13167e994d53559c4b047501..7abee4fe23292087c5f82848f44ca2c26fe7a613 100644 (file)
@@ -456,7 +456,7 @@ LadspaPluginUI::build_control_ui (guint32 port_index, boost::shared_ptr<Automati
                } else {
                        //sigc::slot<void,char*,uint32_t> pslot = sigc::bind (mem_fun(*this, &LadspaPluginUI::print_parameter), (uint32_t) port_index);
 
-                       control_ui->controller = AutomationController::create(insert->session(), mcontrol->list(), mcontrol);
+                       control_ui->controller = AutomationController::create(insert, mcontrol->list(), mcontrol);
                        control_ui->controller->set_size_request (200, req.height);
                        control_ui->controller->set_name (X_("PluginSlider"));
                        control_ui->controller->set_style (BarController::LeftToRight);
index 7f43d3b638e5c1e5475b318d662bf77ea95e862b..a843659cbc671ee88831b819bab07f322b75db4d 100644 (file)
@@ -199,7 +199,7 @@ MidiTimeAxisView::create_automation_child (Parameter param, bool show)
 
                if (!c) {
                        boost::shared_ptr<AutomationList> al(new ARDOUR::AutomationList(param, 0, 127, 64));
-                       c = boost::shared_ptr<AutomationControl>(new MidiTrack::MidiControl(midi_track(), al));
+                       c = boost::shared_ptr<AutomationControl>(_route->control_factory(al));
                        _route->add_control(c);
                }
 
index 6100f60b80fa3adf850682ba8e982ce98fa0e8c7..a48029734ace945c161e1fce3355a76190d0ecd5 100644 (file)
@@ -49,6 +49,8 @@ public:
        virtual boost::shared_ptr<AutomationControl> control(Parameter id, bool create_if_missing=false);
        virtual boost::shared_ptr<const AutomationControl> control(Parameter id) const;
        
+       boost::shared_ptr<AutomationControl> control_factory(boost::shared_ptr<AutomationList> list);
+       
        typedef std::map<Parameter,boost::shared_ptr<AutomationControl> > Controls;
        Controls controls() { return _controls; }
 
index cc0aee5326494be5666f69bf9380b3eaf8fca38f..68ac5797dc10a5528b74f36e4196e0347143f486 100644 (file)
@@ -29,6 +29,7 @@ namespace ARDOUR {
 
 class AutomationList;
 class Session;
+class Automatable;
 
 
 /** A PBD:Controllable with associated automation data (AutomationList)
@@ -36,7 +37,8 @@ class Session;
 class AutomationControl : public PBD::Controllable
 {
 public:
-       AutomationControl(ARDOUR::Session&, boost::shared_ptr<ARDOUR::AutomationList>,
+       AutomationControl(ARDOUR::Session&,
+                       boost::shared_ptr<ARDOUR::AutomationList>,
                        std::string name="unnamed controllable");
 
        void set_value(float val);
index a6e28405f858d3fa67f714f557aad6b8e7f8d435..aea032f72577bb8f3f342964639301698a448543 100644 (file)
@@ -75,17 +75,18 @@ public:
        bool write_immediate_event(size_t size, const Byte* buf);
        
        struct MidiControl : public AutomationControl {
-           MidiControl(boost::shared_ptr<MidiTrack> route, boost::shared_ptr<AutomationList> al)
+           MidiControl(MidiTrack* route, boost::shared_ptr<AutomationList> al)
                        : AutomationControl (route->session(), al, al->parameter().to_string())
                        , _route (route)
                {}
         
            void set_value (float val);
    
-               boost::weak_ptr<MidiTrack> _route;
+               MidiTrack* _route;
        };
-
+       
 protected:
+
        XMLNode& state (bool full);
        
        int _set_state (const XMLNode&, bool call_base);
index 5b30877edcc9fc1d624ea5dddde799beed4449d1..885034056dcacfea69c0c2ac8bb1bd85daea9fb7 100644 (file)
@@ -26,6 +26,7 @@
 #include <pbd/enumwriter.h>
 #include <ardour/session.h>
 #include <ardour/automatable.h>
+#include <ardour/midi_track.h>
 
 #include "i18n.h"
 
@@ -33,7 +34,6 @@ using namespace std;
 using namespace ARDOUR;
 using namespace PBD;
 
-
 Automatable::Automatable(Session& _session, const string& name)
        : SessionObject(_session, name)
        , _last_automation_snapshot(0)
@@ -169,9 +169,8 @@ Automatable::control (Parameter parameter, bool create_if_missing)
        } else if (create_if_missing) {
                boost::shared_ptr<AutomationList> al (new AutomationList (
                                        parameter, FLT_MIN, FLT_MAX, default_parameter_value (parameter)));
-               boost::shared_ptr<AutomationControl> ac (new AutomationControl(_session, al));
+               boost::shared_ptr<AutomationControl> ac(control_factory(al));
                add_control(ac);
-               cerr << "WARNING: Default AutomationControl created for " << parameter.to_string() << endl;
                return ac;
 
        } else {
@@ -301,7 +300,7 @@ Automatable::set_automation_state (const XMLNode& node, Parameter legacy_param)
                        if (existing)
                                existing->set_list(al);
                        else
-                               add_control(boost::shared_ptr<AutomationControl>(new AutomationControl(_session, al)));
+                               add_control(control_factory(al));
 
                } else {
                        error << "Expected AutomationList node, got '" << (*niter)->name() << endmsg;
@@ -452,3 +451,15 @@ Automatable::transport_stopped (nframes_t now)
        }
 }
 
+/* FIXME: this probably doesn't belong here */
+boost::shared_ptr<AutomationControl>
+Automatable::control_factory(boost::shared_ptr<AutomationList> list)
+{
+       if (list->parameter().type() == MidiCCAutomation) {
+               // FIXME: this will die horribly if this is not a MidiTrack
+               return boost::shared_ptr<AutomationControl>(new MidiTrack::MidiControl((MidiTrack*)this, list));
+       } else {
+               cerr << "WARNING: Default AutomationControl created for " << list->parameter().to_string() << endl;
+               return boost::shared_ptr<AutomationControl>(new AutomationControl(_session, list));
+       }
+}
index bbeec65669e0f3130497971f251b52aef5e1baed..73d5819bc4bcf19d7da47648d8e3d140e08c4654 100644 (file)
@@ -22,6 +22,7 @@
 #include <ardour/automation_control.h>
 #include <ardour/session.h>
 #include <ardour/automatable.h>
+#include <ardour/midi_track.h>
 
 using namespace std;
 using namespace ARDOUR;
index aa23e3d92bec3b1c83142a3e7db2ca697727fad0..6e52bb19c0635e34bc6be0e93cead650ae53d26e 100644 (file)
@@ -716,11 +716,9 @@ MidiTrack::MidiControl::set_value(float val)
        assert(val >= 0);
        assert(val <= 127.0);
 
-       boost::shared_ptr<MidiTrack> midi_track = _route.lock();
-
-       if (midi_track && !_list->automation_playback()) {
+       if ( ! _list->automation_playback()) {
                Byte ev[3] = { MIDI_CMD_CONTROL, _list->parameter().id(), (int)val };
-               midi_track->write_immediate_event(3,  ev);
+               _route->write_immediate_event(3,  ev);
        }
 
        AutomationControl::set_value(val);