Remove excessive printing during note dragging.
[ardour.git] / gtk2_ardour / automation_time_axis.cc
index 8170c42cd56a9eba10290620bcb8ca85f66186da..f14e70b52e6e03ebc28df5d00836948a224435f1 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "ardour_ui.h"
 #include "automation_time_axis.h"
+#include "route_time_axis.h"
 #include "automation_line.h"
 #include "public_editor.h"
 #include "simplerect.h"
@@ -46,23 +47,21 @@ using namespace Editing;
 
 Pango::FontDescription* AutomationTimeAxisView::name_font = 0;
 bool AutomationTimeAxisView::have_name_font = false;
+const string AutomationTimeAxisView::state_node_name = "AutomationChild";
 
 AutomationTimeAxisView::AutomationTimeAxisView (Session& s, boost::shared_ptr<Route> r,
                boost::shared_ptr<Automatable> a, boost::shared_ptr<AutomationControl> c,
                PublicEditor& e, TimeAxisView& rent, 
-               ArdourCanvas::Canvas& canvas, const string & nom, 
-               const string & state_name, const string & nomparent)
+               ArdourCanvas::Canvas& canvas, const string & nom, const string & nomparent)
 
        : AxisView (s), 
          TimeAxisView (s, e, &rent, canvas),
          _route (r),
          _control (c),
          _automatable (a),
-         _controller(AutomationController::create(s, c->list(), c)),
+         _controller(AutomationController::create(a, c->list(), c)),
          _base_rect (0),
-         _xml_node (0),
          _name (nom),
-         _state_name (state_name),
          height_button (_("h")),
          clear_button (_("clear")),
          auto_button (X_("")) /* force addition of a label */
@@ -78,6 +77,9 @@ AutomationTimeAxisView::AutomationTimeAxisView (Session& s, boost::shared_ptr<Ro
        auto_touch_item = 0;
        auto_write_item = 0;
        auto_play_item = 0;
+       mode_discrete_item = 0;
+       mode_line_item = 0;
+
        ignore_state_request = false;
        first_call_to_set_height = true;
        
@@ -187,14 +189,15 @@ AutomationTimeAxisView::AutomationTimeAxisView (Session& s, boost::shared_ptr<Ro
 
        controls_frame.set_shadow_type (Gtk::SHADOW_ETCHED_OUT);
 
-       XMLNode* xml_node = get_parent_with_state()->get_child_xml_node (_state_name);
+       XMLNode* xml_node = get_parent_with_state()->get_automation_child_xml_node (
+                       _control->parameter());
 
        if (xml_node) {
                set_state (*xml_node);
        } 
                
        boost::shared_ptr<AutomationLine> line(new AutomationLine (
-                               _control->list()->parameter().to_string(),
+                               _control->parameter().to_string(),
                                *this,
                                *canvas_display,
                                _control->list()));
@@ -247,7 +250,7 @@ AutomationTimeAxisView::set_automation_state (AutoState state)
        if (!ignore_state_request) {
                if (_route == _automatable) { // FIXME: ew
                        _route->set_parameter_automation_state (
-                                       _control->list()->parameter(),
+                                       _control->parameter(),
                                        state);
                }
 
@@ -320,6 +323,31 @@ AutomationTimeAxisView::automation_state_changed ()
        }
 }
 
+void
+AutomationTimeAxisView::interpolation_changed ()
+{      
+       AutomationList::InterpolationStyle style = _control->list()->interpolation();
+       
+       if (mode_line_item && mode_discrete_item) {
+               if (style == AutomationList::Discrete) {
+                       mode_discrete_item->set_active(true);
+                       mode_line_item->set_active(false);
+               } else {
+                       mode_line_item->set_active(true);
+                       mode_discrete_item->set_active(false);
+               }
+       }
+       
+       _line->set_interpolation(style);
+}
+
+void
+AutomationTimeAxisView::set_interpolation (AutomationList::InterpolationStyle style)
+{
+       _control->list()->set_interpolation(style);
+       _line->set_interpolation(style);
+}
+
 void
 AutomationTimeAxisView::height_clicked ()
 {
@@ -338,12 +366,10 @@ void
 AutomationTimeAxisView::set_height (TrackHeight ht)
 {
        uint32_t h = height_to_pixels (ht);
-       bool changed = (height != (uint32_t) h);
-
-       //bool changed_between_small_and_normal = ( (ht == Small || ht == Smaller) ^ (height_style == Small || height_style == Smaller) );
-
-       TimeAxisView* state_parent = get_parent_with_state ();
-       XMLNode* xml_node = state_parent->get_child_xml_node (_state_name);
+       bool changed = (height != (uint32_t) h) || first_call_to_set_height;
+       
+       if (first_call_to_set_height)
+               first_call_to_set_height = false;
 
        TimeAxisView::set_height (ht);
        _base_rect->property_y2() = h;
@@ -355,6 +381,11 @@ AutomationTimeAxisView::set_height (TrackHeight ht)
                (*i)->set_height ();
        }
 
+       TimeAxisView* state_parent = get_parent_with_state ();
+       assert(state_parent);
+
+       XMLNode* xml_node = state_parent->get_automation_child_xml_node(_control->parameter());
+       assert(xml_node);
 
        switch (ht) {
        case Largest:
@@ -382,67 +413,63 @@ AutomationTimeAxisView::set_height (TrackHeight ht)
                break;
        }
 
-       //if (changed_between_small_and_normal || first_call_to_set_height) {
-               first_call_to_set_height = false;
-               switch (ht) {
-                       case Normal:
+       switch (ht) {
+               case Large:
+               case Larger:
+               case Largest:
+                       _controller->show ();
+
+               case Normal:
+                       if (ht == Normal)
                                _controller->hide();
 
-                               controls_table.remove (name_hbox);
-
-                               if (plugname) {
-                                       if (plugname_packed) {
-                                               controls_table.remove (*plugname);
-                                               plugname_packed = false;
-                                       }
-                                       controls_table.attach (*plugname, 1, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
-                                       plugname_packed = true;
-                                       controls_table.attach (name_hbox, 1, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
-                               } else {
-                                       controls_table.attach (name_hbox, 1, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
-                               }
-                               hide_name_entry ();
-                               show_name_label ();
-                               name_hbox.show_all ();
-
-                               auto_button.show();
-                               height_button.show();
-                               clear_button.show();
-                               hide_button.show_all();
-                               break;
-                       
-                       case Large:
-                       case Larger:
-                       case Largest:
-                               _controller->show ();
-                               break;
+                       controls_table.remove (name_hbox);
 
-                       case Smaller:
-                               _controller->hide();
-                       
-                       case Small:
-
-                               controls_table.remove (name_hbox);
-                               if (plugname) {
-                                       if (plugname_packed) {
-                                               controls_table.remove (*plugname);
-                                               plugname_packed = false;
-                                       }
+                       if (plugname) {
+                               if (plugname_packed) {
+                                       controls_table.remove (*plugname);
+                                       plugname_packed = false;
                                }
+                               controls_table.attach (*plugname, 1, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+                               plugname_packed = true;
+                               controls_table.attach (name_hbox, 1, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+                       } else {
                                controls_table.attach (name_hbox, 1, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
-                               controls_table.hide_all ();
-                               hide_name_entry ();
-                               show_name_label ();
-                               name_hbox.show_all ();
-
-                               auto_button.hide();
-                               height_button.hide();
-                               clear_button.hide();
-                               hide_button.hide();
-                               break;
-               }
+                       }
+                       hide_name_entry ();
+                       show_name_label ();
+                       name_hbox.show_all ();
+
+                       auto_button.show();
+                       height_button.show();
+                       clear_button.show();
+                       hide_button.show_all();
+                       break;
+
+               case Smaller:
+                       _controller->hide();
 
-       //}
+               case Small:
+
+                       controls_table.remove (name_hbox);
+                       if (plugname) {
+                               if (plugname_packed) {
+                                       controls_table.remove (*plugname);
+                                       plugname_packed = false;
+                               }
+                       }
+                       controls_table.attach (name_hbox, 1, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
+                       controls_table.hide_all ();
+                       hide_name_entry ();
+                       show_name_label ();
+                       name_hbox.show_all ();
+
+                       auto_button.hide();
+                       height_button.hide();
+                       clear_button.hide();
+                       hide_button.hide();
+                       break;
+       }
 
        if (changed) {
                /* only emit the signal if the height really changed */
@@ -494,6 +521,8 @@ AutomationTimeAxisView::build_display_menu ()
        items.push_back (MenuElem (_("Clear"), mem_fun(*this, &AutomationTimeAxisView::clear_clicked)));
        items.push_back (SeparatorElem());
 
+       /* state menu */
+
        Menu* auto_state_menu = manage (new Menu);
        auto_state_menu->set_name ("ArdourContextMenu");
        MenuList& as_items = auto_state_menu->items();
@@ -515,10 +544,35 @@ AutomationTimeAxisView::build_display_menu ()
        auto_touch_item = dynamic_cast<CheckMenuItem*>(&as_items.back());
 
        items.push_back (MenuElem (_("State"), *auto_state_menu));
+       
+       /* mode menu */
+       
+       if (_control->parameter().type() == MidiCCAutomation) {
+               Menu* auto_mode_menu = manage (new Menu);
+               auto_mode_menu->set_name ("ArdourContextMenu");
+               MenuList& am_items = auto_mode_menu->items();
+       
+               RadioMenuItem::Group group;
+
+               am_items.push_back (RadioMenuElem (group, _("Discrete"), bind (
+                                               mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
+                                               AutomationList::Discrete)));
+               mode_discrete_item = dynamic_cast<CheckMenuItem*>(&am_items.back());
+               //mode_discrete_item->set_active(_control->list()->interpolation() == AutomationList::Discrete);
+
+               am_items.push_back (RadioMenuElem (group, _("Line"), bind (
+                                               mem_fun(*this, &AutomationTimeAxisView::set_interpolation),
+                                               AutomationList::Linear)));
+               mode_line_item = dynamic_cast<CheckMenuItem*>(&am_items.back());
+               //mode_line_item->set_active(_control->list()->interpolation() == AutomationList::Linear);
+
+               items.push_back (MenuElem (_("Mode"), *auto_mode_menu));
+       }
 
        /* make sure the automation menu state is correct */
 
        automation_state_changed ();
+       interpolation_changed ();
 }
 
 void
@@ -816,28 +870,16 @@ AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
        line->show();
 }
 
-void
-AutomationTimeAxisView::show_all_control_points ()
-{
-       _line->show_all_control_points ();
-}
-
-void
-AutomationTimeAxisView::hide_all_but_selected_control_points ()
-{
-       _line->hide_all_but_selected_control_points ();
-}
-
 void
 AutomationTimeAxisView::entered()
 {
-       show_all_control_points ();
+       _line->track_entered();
 }
 
 void
 AutomationTimeAxisView::exited ()
 {
-       hide_all_but_selected_control_points ();
+       _line->track_exited();
 }
 
 void
@@ -866,25 +908,25 @@ AutomationTimeAxisView::set_state (const XMLNode& node)
 
        kids = node.children ();
 
-       //snprintf (buf, sizeof(buf), "Port_%" PRIu32, param.id());
-               
        for (iter = kids.begin(); iter != kids.end(); ++iter) {
-               if ((*iter)->name() == _control->list()->parameter().to_string()) {
                
-                       XMLProperty *shown = (*iter)->property("shown_editor");
-                       
-                       if (shown && shown->value() == "yes") {
-                               set_marked_for_display(true);
-                               canvas_display->show(); /* FIXME: necessary? show_at? */
+               if ((*iter)->name() == state_node_name) {
+                       XMLProperty* type = (*iter)->property("automation-id");
+
+                       if (type && type->value() == _control->parameter().to_string()) {
+                               XMLProperty *shown = (*iter)->property("shown_editor");
+
+                               if (shown && shown->value() == "yes") {
+                                       set_marked_for_display(true);
+                                       canvas_display->show(); /* FIXME: necessary? show_at? */
+                               }
+                               break;
                        }
-                       break;
                }
        }
 
        if (!_marked_for_display)
                hide();
-
-       // FIXME: _xml_node = &node?
 }
 
 XMLNode*
@@ -893,54 +935,17 @@ AutomationTimeAxisView::get_state_node ()
        TimeAxisView* state_parent = get_parent_with_state ();
 
        if (state_parent) {
-               return state_parent->get_child_xml_node (_state_name);
+               return state_parent->get_automation_child_xml_node (_control->parameter());
        } else {
                return 0;
        }
 }
 
-void
-AutomationTimeAxisView::ensure_xml_node ()
-{
-       if ((_automatable != _route) && _xml_node == 0) {
-               if ((_xml_node = _automatable->extra_xml ("GUI")) == 0) {
-                       _xml_node = new XMLNode ("GUI");
-                       _automatable->add_extra_xml (*_xml_node);
-               }
-       }
-}
-
 void
 AutomationTimeAxisView::update_extra_xml_shown (bool editor_shown)
 {
-       if (_automatable == _route)
-               return;
-
-       char buf[32];
-       
-       ensure_xml_node ();
-
-       XMLNodeList nlist = _xml_node->children ();
-       XMLNodeConstIterator i;
-       XMLNode * port_node = 0;
-
-       /* FIXME: these parsed XML node names need to go */
-       //snprintf (buf, sizeof(buf), "Port_%" PRIu32, _param.id());
-
-       for (i = nlist.begin(); i != nlist.end(); ++i) {
-               /* FIXME: legacy session loading */
-               if ((*i)->name() == _control->list()->parameter().to_string()) {
-                       port_node = (*i);
-                       break;
-               }
-       }
-
-       if (!port_node) {
-               port_node = new XMLNode(buf);
-               _xml_node->add_child_nocopy(*port_node);
-       }
-       
-       port_node->add_property ("shown_editor", editor_shown ? "yes": "no");
+       XMLNode* xml_node = get_state_node();
+       xml_node->add_property ("shown", editor_shown ? "yes" : "no");
 }
 
 guint32