From 5f6630034919bde73ffa603e7420c8af2c3c16f7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 17 Dec 2014 20:18:11 -0500 Subject: [PATCH] Support stepping bank by shift+scroll/arrow. --- gtk2_ardour/midi_region_view.cc | 9 +++++--- gtk2_ardour/midi_region_view.h | 7 ++++-- gtk2_ardour/patch_change.cc | 41 ++++++++++++++++++--------------- gtk2_ardour/patch_change.h | 37 +++++++++++++---------------- 4 files changed, 49 insertions(+), 45 deletions(-) diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 11534dd035..6b6d40f93c 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -1984,11 +1984,14 @@ MidiRegionView::delete_patch_change (PatchChange* pc) } void -MidiRegionView::step_patch (PatchChange& patch, int dbank, int dprog) +MidiRegionView::step_patch (PatchChange& patch, bool bank, int delta) { MIDI::Name::PatchPrimaryKey key = patch_change_to_patch_key(patch.patch()); - key.set_bank(key.bank() + dbank); - key.set_program(key.program() + dprog); + if (bank) { + key.set_bank(key.bank() + delta); + } else { + key.set_program(key.program() + delta); + } change_patch_change(patch, key); } diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index a07a46825f..7280ba6e4e 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -153,8 +153,11 @@ public: void delete_sysex (SysEx*); - /** Change a patch to the next or previous bank/program. */ - void step_patch (PatchChange& patch, int dbank, int dprog); + /** Change a patch to the next or previous bank/program. + * @param bank If true, step bank, otherwise, step program. + * @param delta Amount to adjust number. + */ + void step_patch (PatchChange& patch, bool bank, int delta); /** Displays all patch change events in the region as flags on the canvas. */ diff --git a/gtk2_ardour/patch_change.cc b/gtk2_ardour/patch_change.cc index 844a129b1d..925a0f3b23 100644 --- a/gtk2_ardour/patch_change.cc +++ b/gtk2_ardour/patch_change.cc @@ -31,25 +31,25 @@ #include "canvas/debug.h" #include "ardour_ui.h" -#include "midi_region_view.h" -#include "patch_change.h" #include "editor.h" #include "editor_drag.h" +#include "midi_region_view.h" +#include "patch_change.h" using namespace MIDI::Name; using namespace std; +using Gtkmm2ext::Keyboard; /** @param x x position in pixels. */ -PatchChange::PatchChange( - MidiRegionView& region, - ArdourCanvas::Container* parent, - const string& text, - double height, - double x, - double y, - ARDOUR::InstrumentInfo& info, - ARDOUR::MidiModel::PatchChangePtr patch) +PatchChange::PatchChange(MidiRegionView& region, + ArdourCanvas::Container* parent, + const string& text, + double height, + double x, + double y, + ARDOUR::InstrumentInfo& info, + ARDOUR::MidiModel::PatchChangePtr patch) : _region (region) , _info (info) , _patch (patch) @@ -60,8 +60,7 @@ PatchChange::PatchChange( height, ARDOUR_UI::config()->color ("midi patch change outline"), ARDOUR_UI::config()->color_mod ("midi patch change fill", "midi patch change fill"), - ArdourCanvas::Duple (x, y) - ); + ArdourCanvas::Duple (x, y)); CANVAS_DEBUG_NAME (_flag, text); @@ -199,13 +198,15 @@ PatchChange::event_handler (GdkEvent* ev) case GDK_Up: case GDK_KP_Up: case GDK_uparrow: - _region.step_patch (*this, 0, -1); - break; + _region.step_patch( + *this, Keyboard::modifier_state_contains(ev->key.state, Keyboard::TertiaryModifier), 1); + return true; case GDK_Down: case GDK_KP_Down: case GDK_downarrow: - _region.step_patch (*this, 0, 1); - break; + _region.step_patch( + *this, Keyboard::modifier_state_contains(ev->key.state, Keyboard::TertiaryModifier), -1); + return true; default: break; } @@ -213,10 +214,12 @@ PatchChange::event_handler (GdkEvent* ev) case GDK_SCROLL: if (ev->scroll.direction == GDK_SCROLL_UP) { - _region.step_patch (*this, 0, -1); + _region.step_patch( + *this, Keyboard::modifier_state_contains(ev->scroll.state, Keyboard::TertiaryModifier), 1); return true; } else if (ev->scroll.direction == GDK_SCROLL_DOWN) { - _region.step_patch (*this, 0, 1); + _region.step_patch( + *this, Keyboard::modifier_state_contains(ev->scroll.state, Keyboard::TertiaryModifier), -1); return true; } break; diff --git a/gtk2_ardour/patch_change.h b/gtk2_ardour/patch_change.h index a087c2a090..a734daf797 100644 --- a/gtk2_ardour/patch_change.h +++ b/gtk2_ardour/patch_change.h @@ -33,45 +33,40 @@ namespace MIDI { class PatchChange { public: - PatchChange( - MidiRegionView& region, - ArdourCanvas::Container* parent, - const std::string& text, - double height, - double x, - double y, - ARDOUR::InstrumentInfo& info, - ARDOUR::MidiModel::PatchChangePtr patch - ); + PatchChange(MidiRegionView& region, + ArdourCanvas::Container* parent, + const std::string& text, + double height, + double x, + double y, + ARDOUR::InstrumentInfo& info, + ARDOUR::MidiModel::PatchChangePtr patch); ~PatchChange(); - ARDOUR::MidiModel::PatchChangePtr patch () const { return _patch; } - void initialize_popup_menus(); void on_patch_menu_selected(const MIDI::Name::PatchPrimaryKey& key); - ArdourCanvas::Item* canvas_item () const { - return _flag; - } void move (ArdourCanvas::Duple); void set_height (ArdourCanvas::Distance); void hide (); void show (); - ArdourCanvas::Item& item() const { return *_flag; } + ARDOUR::MidiModel::PatchChangePtr patch() const { return _patch; } + ArdourCanvas::Item* canvas_item() const { return _flag; } + ArdourCanvas::Item& item() const { return *_flag; } private: bool event_handler (GdkEvent *); - MidiRegionView& _region; - ARDOUR::InstrumentInfo& _info; + MidiRegionView& _region; + ARDOUR::InstrumentInfo& _info; ARDOUR::MidiModel::PatchChangePtr _patch; - Gtk::Menu _popup; - bool _popup_initialized; - ArdourCanvas::Flag* _flag; + Gtk::Menu _popup; + bool _popup_initialized; + ArdourCanvas::Flag* _flag; }; #endif /* __PATCH_CHANGE_H__ */