Normalize XML property name style, preserving old session loading (on load _ will...
[ardour.git] / gtk2_ardour / midi_time_axis.cc
index 8f762203049400b4d4a90c322c89490435bbf017..9453a05611c45ec4e7efdce44efbfc55190163fa 100644 (file)
@@ -80,18 +80,21 @@ using namespace PBD;
 using namespace Gtk;
 using namespace sigc;
 using namespace Editing;
-
+       
+// Minimum height at which a control is displayed
+static const uint32_t CHANNEL_MIN_HEIGHT = 80;
+static const uint32_t KEYBOARD_MIN_HEIGHT = 140;
 
 MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
-       : AxisView(sess) // FIXME: won't compile without this, why??
+       : AxisView(sess) // virtually inherited
        , RouteTimeAxisView(ed, sess, rt, canvas)
+       , _ignore_signals(false)  
        , _range_scroomer(0)
        , _piano_roll_header(0)
        , _note_mode(Sustained)
        , _note_mode_item(NULL)
        , _percussion_mode_item(NULL)
-       , _channel_selector(0)
-       , _midi_expander("MIDI")
+       , _midi_expander("Channel")
 {
        subplugin_menu.set_name ("ArdourContextMenu");
 
@@ -137,17 +140,20 @@ MidiTimeAxisView::MidiTimeAxisView (PublicEditor& ed, Session& sess, boost::shar
                _view->attach ();
        }
                
-       // add channel selector
-       _channel_selector = manage(new MidiMultipleChannelSelector(0xFFFF));
+       // add channel selector expander
        HBox *channel_selector_box = manage(new HBox());
-       channel_selector_box->pack_start(*_channel_selector, SHRINK, 0);
+       channel_selector_box->pack_start(_channel_selector, false, false);
        _midi_expander.add(*channel_selector_box);
        _midi_expander.property_expanded().signal_changed().connect(
                        mem_fun(this, &MidiTimeAxisView::channel_selector_toggled));
-       controls_vbox.pack_end(_midi_expander, SHRINK, 0);
-       _channel_selector->selection_changed.connect(
-               mem_fun(*midi_track()->midi_diskstream(), &MidiDiskstream::set_channel_mask));
-       
+       controls_vbox.pack_start(_midi_expander, false, false);
+       boost::shared_ptr<MidiDiskstream> diskstream = midi_track()->midi_diskstream();
+
+       // restore channel selector settings
+       _channel_selector.set_channel_mode(diskstream->get_channel_mode(), diskstream->get_channel_mask());
+       _channel_selector.mode_changed.connect(
+               mem_fun(*midi_track()->midi_diskstream(), &MidiDiskstream::set_channel_mode));
+
 }
 
 MidiTimeAxisView::~MidiTimeAxisView ()
@@ -169,11 +175,9 @@ guint32
 MidiTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
 {
        ensure_xml_node ();
-       xml_node->add_property ("shown_editor", "yes");
+       xml_node->add_property ("shown-editor", "yes");
                
        guint32 ret = TimeAxisView::show_at (y, nth, parent);
-       _piano_roll_header->show();
-       _range_scroomer->show();
        return ret;
 }
 
@@ -181,11 +185,35 @@ void
 MidiTimeAxisView::hide ()
 {
        ensure_xml_node ();
-       xml_node->add_property ("shown_editor", "no");
+       xml_node->add_property ("shown-editor", "no");
 
        TimeAxisView::hide ();
 }
 
+void
+MidiTimeAxisView::set_height (uint32_t h)
+{
+       RouteTimeAxisView::set_height (h);
+
+       if (height >= CHANNEL_MIN_HEIGHT) {
+               _midi_expander.show();
+       } else {
+               _midi_expander.hide();
+       }
+       
+       if (height >= KEYBOARD_MIN_HEIGHT) {
+               if (is_track() && _range_scroomer)
+                       _range_scroomer->show();
+               if (is_track() && _piano_roll_header)
+                       _piano_roll_header->show();
+       } else {
+               if (is_track() && _range_scroomer)
+                       _range_scroomer->hide();
+               if (is_track() && _piano_roll_header)
+                       _piano_roll_header->hide();
+       }
+}
+
 void
 MidiTimeAxisView::append_extra_display_menu_items ()
 {
@@ -198,18 +226,14 @@ MidiTimeAxisView::append_extra_display_menu_items ()
        MenuList& range_items = range_menu->items();
        range_menu->set_name ("ArdourContextMenu");
        
-       RadioMenuItem::Group range_group;
-
-       range_items.push_back (RadioMenuElem (range_group, _("Show Full Range"), bind (
+       range_items.push_back (MenuElem (_("Show Full Range"), bind (
                        mem_fun(*this, &MidiTimeAxisView::set_note_range),
                        MidiStreamView::FullRange)));
        
-       range_items.push_back (RadioMenuElem (range_group, _("Fit Contents"), bind (
+       range_items.push_back (MenuElem (_("Fit Contents"), bind (
                        mem_fun(*this, &MidiTimeAxisView::set_note_range),
                        MidiStreamView::ContentsRange)));
 
-       ((Gtk::CheckMenuItem&)range_items.back()).set_active(true);
-
        items.push_back (MenuElem (_("Note range"), *range_menu));
 }
 
@@ -223,9 +247,15 @@ MidiTimeAxisView::build_automation_action_menu ()
        MenuList& automation_items = automation_action_menu->items();
        
        automation_items.push_back (SeparatorElem());
-
        automation_items.push_back (MenuElem (_("Controller..."), 
-                                                  mem_fun(*this, &MidiTimeAxisView::add_controller_track)));
+                       mem_fun(*this, &MidiTimeAxisView::add_cc_track)));
+       automation_items.push_back (MenuElem (_("Bender"), 
+                       sigc::bind(mem_fun(*this, &MidiTimeAxisView::add_parameter_track),
+                               Evoral::Parameter(MidiPitchBenderAutomation))));
+       automation_items.push_back (MenuElem (_("Pressure"), 
+                       sigc::bind(mem_fun(*this, &MidiTimeAxisView::add_parameter_track),
+                               Evoral::Parameter(MidiChannelPressureAutomation))));
+
 }
 
 Gtk::Menu*
@@ -265,10 +295,8 @@ MidiTimeAxisView::set_note_mode(NoteMode mode)
 void
 MidiTimeAxisView::set_note_range(MidiStreamView::VisibleNoteRange range)
 {
-       //if (midi_view()->note_range() != range) {
+       if (!_ignore_signals)
                midi_view()->set_note_range(range);
-               midi_view()->redisplay_diskstream();
-       //}
 }
 
 
@@ -284,15 +312,31 @@ MidiTimeAxisView::update_range()
        }
 }
 
+void
+MidiTimeAxisView::show_all_automation ()
+{
+       if (midi_track()) {
+               const set<Evoral::Parameter> params = midi_track()->midi_diskstream()->
+                               midi_playlist()->contained_automation();
+
+               for (set<Evoral::Parameter>::const_iterator i = params.begin(); i != params.end(); ++i) {
+                       create_automation_child(*i, true);
+               }
+       }
+
+       RouteTimeAxisView::show_all_automation ();
+}
+
 void
 MidiTimeAxisView::show_existing_automation ()
 {
        if (midi_track()) {
-               const set<Parameter> params = midi_track()->midi_diskstream()->
+               const set<Evoral::Parameter> params = midi_track()->midi_diskstream()->
                                midi_playlist()->contained_automation();
 
-               for (set<Parameter>::const_iterator i = params.begin(); i != params.end(); ++i)
+               for (set<Evoral::Parameter>::const_iterator i = params.begin(); i != params.end(); ++i) {
                        create_automation_child(*i, true);
+               }
        }
 
        RouteTimeAxisView::show_existing_automation ();
@@ -301,10 +345,10 @@ MidiTimeAxisView::show_existing_automation ()
 /** Prompt for a controller with a dialog and add an automation track for it
  */
 void
-MidiTimeAxisView::add_controller_track()
+MidiTimeAxisView::add_cc_track()
 {
        int response;
-       Parameter param;
+       Evoral::Parameter param(0, 0, 0);
 
        {
                AddMidiCCTrackDialog dialog;
@@ -315,32 +359,45 @@ MidiTimeAxisView::add_controller_track()
                        param = dialog.parameter();
        }
 
-       if (response == Gtk::RESPONSE_ACCEPT)
+       if (param.type() != 0 && response == Gtk::RESPONSE_ACCEPT)
                create_automation_child(param, true);
 }
 
+
+/** Add an automation track for the given parameter (pitch bend, channel pressure).
+ */
 void
-MidiTimeAxisView::create_automation_child (Parameter param, bool show)
+MidiTimeAxisView::add_parameter_track(const Evoral::Parameter& param)
 {
-       if (param.type() == MidiCCAutomation) {
+       create_automation_child(param, true);
+}
+
+void
+MidiTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
+{
+       if (    param.type() == MidiCCAutomation ||
+                       param.type() == MidiPgmChangeAutomation ||
+                       param.type() == MidiPitchBenderAutomation ||
+                       param.type() == MidiChannelPressureAutomation
+          ) {
        
-               /* FIXME: don't create AutomationList for track itself
-                * (not actually needed or used, since the automation is region-ey) */
+               /* These controllers are region "automation", so we do not create
+                * an AutomationList/Line for the track */
+
+               AutomationTracks::iterator existing = _automation_tracks.find(param);
+               if (existing != _automation_tracks.end())
+                       return;
 
-               boost::shared_ptr<AutomationControl> c = _route->control(param);
+               boost::shared_ptr<AutomationControl> c
+                       = boost::dynamic_pointer_cast<AutomationControl>(_route->data().control(param));
 
                if (!c) {
-                       boost::shared_ptr<AutomationList> al(new ARDOUR::AutomationList(param, 0, 127, 64));
-                       c = boost::shared_ptr<AutomationControl>(_route->control_factory(al));
+                       c = boost::dynamic_pointer_cast<AutomationControl>(_route->control_factory(param));
                        _route->add_control(c);
                }
 
-               AutomationTracks::iterator existing = _automation_tracks.find(param);
-               if (existing != _automation_tracks.end())
-                       return;
-
                boost::shared_ptr<AutomationTimeAxisView> track(new AutomationTimeAxisView (_session,
-                               _route, _route, c,
+                               _route, boost::shared_ptr<ARDOUR::Automatable>(), c,
                                editor,
                                *this,
                                true,
@@ -350,7 +407,8 @@ MidiTimeAxisView::create_automation_child (Parameter param, bool show)
                add_automation_child(param, track, show);
 
        } else {
-               error << "MidiTimeAxisView: unknown automation child " << param.to_string() << endmsg;
+               error << "MidiTimeAxisView: unknown automation child "
+                       << ARDOUR::EventTypeMap::instance().to_symbol(param) << endmsg;
        }
 }
 
@@ -388,16 +446,17 @@ MidiTimeAxisView::route_active_changed ()
 void 
 MidiTimeAxisView::channel_selector_toggled()
 {
-       static TimeAxisView::TrackHeight previous_height;
-       assert(_channel_selector);
+       static uint32_t previous_height;
        
-       if(_midi_expander.property_expanded()) {
-               previous_height = height_style;
-               if(previous_height != TimeAxisView::Largest) {
-                       TimeAxisView::set_height(TimeAxisView::Large);
+       if (_midi_expander.property_expanded()) {
+               previous_height = current_height();
+               if (previous_height < TimeAxisView::hLargest) {
+                       set_height (TimeAxisView::hLarge);
                }
        } else {
-               TimeAxisView::set_height(previous_height);
+               set_height (previous_height);
        }
 }
 
+
+