Make range selection context menu work again.
[ardour.git] / gtk2_ardour / automation_controller.cc
index 3cb4cc5a1e8fa86db2bc0b0f548b79208ae1d3a2..6f62608f0a8c789f067a3bc1ae897841c1bd15f1 100644 (file)
 */
 
 #include <pbd/error.h>
-#include "ardour/automation_event.h"
+#include "ardour/automation_list.h"
 #include "ardour/automation_control.h"
+#include "ardour/event_type_map.h"
+#include "ardour/automatable.h"
 #include "ardour_ui.h"
 #include "utils.h"
 #include "automation_controller.h"
@@ -33,7 +35,7 @@ using namespace Gtk;
 
 
 AutomationController::AutomationController(boost::shared_ptr<AutomationControl> ac, Adjustment* adj)
-       : BarController(*adj, *ac)
+       : BarController(*adj, ac)
        , _ignore_change(false)
        , _controllable(ac)
        , _adjustment(adj)
@@ -61,12 +63,17 @@ 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,
+               const Evoral::Parameter& param,
+               boost::shared_ptr<AutomationControl> ac)
 {
-       Gtk::Adjustment* adjustment = manage(new Gtk::Adjustment(al->default_value(), al->get_min_y(), al->get_max_y()));
+       Gtk::Adjustment* adjustment = manage(new Gtk::Adjustment(param.normal(), param.min(), param.max()));
        if (!ac) {
-               PBD::warning << "Creating AutomationController for " << al->param_id().to_string() << endmsg;
-               ac = boost::shared_ptr<AutomationControl>(new AutomationControl(s, al));
+               PBD::warning << "Creating AutomationController for " << EventTypeMap::instance().to_symbol(param) << endmsg;
+               ac = boost::dynamic_pointer_cast<AutomationControl>(parent->control_factory(param));
+       } else {
+               assert(ac->parameter() == param);
        }
        return boost::shared_ptr<AutomationController>(new AutomationController(ac, adjustment));
 }
@@ -74,12 +81,13 @@ AutomationController::create(Session& s, boost::shared_ptr<AutomationList> al, b
 void
 AutomationController::update_label(char* label, int label_len)
 {
-       if (label && label_len)
+       if (label && label_len) {
                // Hack to display CC rounded to int
-               if (_controllable->list()->param_id().type() == MidiCCAutomation)
+               if (_controllable->parameter().type() == MidiCCAutomation)
                        snprintf(label, label_len, "%d", (int)_controllable->get_value());
                else
                        snprintf(label, label_len, "%.3f", _controllable->get_value());
+       }
 }
 
 void
@@ -108,13 +116,13 @@ AutomationController::value_adjusted()
 void
 AutomationController::start_touch()
 {
-       _controllable->list()->start_touch();
+       _controllable->start_touch();
 }
 
 void
 AutomationController::end_touch()
 {
-       _controllable->list()->stop_touch();
+       _controllable->stop_touch();
 }
 
 void
@@ -122,7 +130,7 @@ AutomationController::automation_state_changed ()
 {
        ENSURE_GUI_THREAD(mem_fun(*this, &AutomationController::automation_state_changed));
 
-       bool x = (_controllable->list()->automation_state() != Off);
+       bool x = (_controllable->automation_state() != Off);
        
        /* start watching automation so that things move */