Another not-quite-there-but-better commit.
[ardour.git] / gtk2_ardour / midi_time_axis.cc
index 9300986960b590f92577f9cd9e4ba0aef9770d7d..541a49d35088ac70d65c839db4ed07ca92d406ec 100644 (file)
@@ -37,7 +37,7 @@
 
 #include <ardour/midi_playlist.h>
 #include <ardour/midi_diskstream.h>
-#include <ardour/insert.h>
+#include <ardour/processor.h>
 #include <ardour/ladspa_plugin.h>
 #include <ardour/location.h>
 #include <ardour/playlist.h>
@@ -48,6 +48,8 @@
 #include "ardour_ui.h"
 #include "midi_time_axis.h"
 #include "automation_time_axis.h"
+#include "automation_line.h"
+#include "add_midi_cc_track_dialog.h"
 #include "canvas_impl.h"
 #include "crossfade_view.h"
 #include "enums.h"
@@ -59,8 +61,6 @@
 #include "point_selection.h"
 #include "prompter.h"
 #include "public_editor.h"
-#include "redirect_automation_line.h"
-#include "redirect_automation_time_axis.h"
 #include "region_view.h"
 #include "rgb_macros.h"
 #include "selection.h"
@@ -98,13 +98,13 @@ MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shar
 
        /* map current state of the route */
 
-       redirects_changed (0);
+       processors_changed ();
 
        ensure_xml_node ();
 
        set_state (*xml_node);
        
-       _route->redirects_changed.connect (mem_fun(*this, &MidiTimeAxisView::redirects_changed));
+       _route->processors_changed.connect (mem_fun(*this, &MidiTimeAxisView::processors_changed));
 
        if (is_track()) {
 
@@ -116,13 +116,12 @@ MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shar
                _view->RegionViewAdded.connect (mem_fun(*this, &MidiTimeAxisView::region_view_added));
                _view->attach ();
 
-       } else { /* bus */
+       } /*else { // no MIDI busses yet
 
-               throw; // what the?
                controls_ebox.set_name ("MidiBusControlsBaseUnselected");
                controls_base_selected_name = "MidiBusControlsBaseSelected";
                controls_base_unselected_name = "MidiBusControlsBaseUnselected";
-       }
+       }*/
 }
 
 MidiTimeAxisView::~MidiTimeAxisView ()
@@ -148,51 +147,62 @@ MidiTimeAxisView::hide ()
 }
 
 void
-MidiTimeAxisView::set_state (const XMLNode& node)
+MidiTimeAxisView::build_automation_action_menu ()
 {
-       const XMLProperty *prop;
-       
-       TimeAxisView::set_state (node);
-       
-       if ((prop = node.property ("shown_editor")) != 0) {
-               if (prop->value() == "no") {
-                       _marked_for_display = false;
-               } else {
-                       _marked_for_display = true;
-               }
-       } else {
-               _marked_for_display = true;
-       }
-       
-       XMLNodeList nlist = node.children();
-       XMLNodeConstIterator niter;
-       XMLNode *child_node;
+       using namespace Menu_Helpers;
+
+       RouteTimeAxisView::build_automation_action_menu ();
+
+       MenuList& automation_items = automation_action_menu->items();
        
-       for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
-               child_node = *niter;
-               
-               // uh... do stuff..
+       automation_items.push_back (SeparatorElem());
+
+       automation_items.push_back (MenuElem (_("Controller..."), 
+                                                  mem_fun(*this, &MidiTimeAxisView::add_controller_track)));
+}
+
+/** Prompt for a controller with a dialog and add an automation track for it
+ */
+void
+MidiTimeAxisView::add_controller_track()
+{
+       AddMidiCCTrackDialog dialog;
+       dialog.set_transient_for(editor);
+       int response = dialog.run();
+       if (response == Gtk::RESPONSE_ACCEPT) {
+               ParamID param = dialog.parameter();
+               create_automation_child(param);
        }
 }
 
-// FIXME: duplicated in audio_time_axis.cc
-/*static string 
-legalize_for_xml_node (string str)
+void
+MidiTimeAxisView::create_automation_child (ParamID param)
 {
-       string::size_type pos;
-       string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
-       string legal;
+       if (param.type() == MidiCCAutomation) {
+       
+               /* FIXME: this all probably leaks */
 
-       legal = str;
-       pos = 0;
+               boost::shared_ptr<AutomationControl> c =_route->control(param);
 
-       while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
-               legal.replace (pos, 1, "_");
-               pos += 1;
-       }
+               if (!c) {
+                       boost::shared_ptr<AutomationList> al(new ARDOUR::AutomationList(param, 0, 127, 64));
+                       c = boost::shared_ptr<AutomationControl>(new AutomationControl(_session, al));
+                       _route->add_control(c);
+               }
 
-       return legal;
-}*/
+               boost::shared_ptr<AutomationTimeAxisView> track(new AutomationTimeAxisView (_session,
+                               _route, _route, c,
+                               editor,
+                               *this,
+                               parent_canvas,
+                               _route->describe_parameter(param),
+                               c->list()->param_id().to_string() /* FIXME: correct state name? */));
+               add_automation_child(param, track);
+
+       } else {
+               error << "MidiTimeAxisView: unknown automation child " << param.to_string() << endmsg;
+       }
+}
 
 void
 MidiTimeAxisView::route_active_changed ()
@@ -225,9 +235,3 @@ MidiTimeAxisView::route_active_changed ()
        }
 }
 
-XMLNode* 
-MidiTimeAxisView::get_child_xml_node (const string & childname)
-{
-       return RouteUI::get_child_xml_node (childname);
-}
-