Preference Dropdown to limit Automatable Parameters
[ardour.git] / gtk2_ardour / patch_change.cc
index bdc4e71afe9230ddb4ad4d0ae1f3faba32c89638..739cda4702d431d5275c3c2801d870f4aae0403f 100644 (file)
 #include <glibmm/regex.h>
 
 #include "gtkmm2ext/keyboard.h"
+#include "gtkmm2ext/menu_elems.h"
 #include "gtkmm2ext/utils.h"
 
 #include "midi++/midnam_patch.h"
 
 #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"
+#include "ui_config.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,
+                        Gtkmm2ext::Color               outline_color,
+                        Gtkmm2ext::Color               fill_color)
        : _region (region)
        , _info (info)
        , _patch (patch)
@@ -58,15 +61,15 @@ PatchChange::PatchChange(
        _flag = new ArdourCanvas::Flag (
                parent,
                height,
-               ARDOUR_UI::config()->color ("MidiPatchChangeOutline"),
-               ARDOUR_UI::config()->color ("MidiPatchChangeFill"),
-               ArdourCanvas::Duple (x, y)
-               );
-       
+               outline_color,
+               fill_color,
+               ArdourCanvas::Duple (x, y),
+               true);
+
        CANVAS_DEBUG_NAME (_flag, text);
 
        _flag->Event.connect (sigc::mem_fun (*this, &PatchChange::event_handler));
-       _flag->set_font_description (ARDOUR_UI::config()->get_SmallFont());
+       _flag->set_font_description (UIConfiguration::instance().get_SmallFont());
        _flag->set_text(text);
 }
 
@@ -82,7 +85,7 @@ PatchChange::initialize_popup_menus()
 
        boost::shared_ptr<ChannelNameSet> channel_name_set = _info.get_patches (_patch->channel());
 
-       if (!channel_name_set) {
+       if (!channel_name_set || channel_name_set->patch_banks().size () == 0) {
                return;
        }
 
@@ -98,12 +101,12 @@ PatchChange::initialize_popup_menus()
                     ++bank) {
                        Glib::RefPtr<Glib::Regex> underscores = Glib::Regex::create("_");
                        std::string replacement(" ");
-                       
+
                        Gtk::Menu& patch_bank_menu = *manage(new Gtk::Menu());
-                       
+
                        const PatchNameList& patches = (*bank)->patch_name_list();
                        Gtk::Menu::MenuList& patch_menus = patch_bank_menu.items();
-               
+
                        for (PatchNameList::const_iterator patch = patches.begin();
                             patch != patches.end();
                             ++patch) {
@@ -131,18 +134,12 @@ PatchChange::initialize_popup_menus()
 
                const PatchNameList& patches = patch_banks.front()->patch_name_list();
                Gtk::Menu::MenuList& patch_menus = _popup.items();
-               
+
                for (PatchNameList::const_iterator patch = patches.begin();
                     patch != patches.end();
                     ++patch) {
-                       std::string name = (*patch)->name();
-                       boost::replace_all (name, "_", " ");
-                       
-                       patch_menus.push_back (
-                               Gtk::Menu_Helpers::MenuElem (
-                                       name,
-                                       sigc::bind (sigc::mem_fun(*this, &PatchChange::on_patch_menu_selected),
-                                                   (*patch)->patch_primary_key())));
+                       patch_menus.push_back (Gtkmm2ext::MenuElemNoMnemonic ((*patch)->name(),
+                                               sigc::bind (sigc::mem_fun(*this, &PatchChange::on_patch_menu_selected), (*patch)->patch_primary_key())));
                }
        }
 }
@@ -160,13 +157,12 @@ PatchChange::event_handler (GdkEvent* ev)
        Editor* e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
 
        if (!e->internal_editing()) {
-               // not in internal edit mode, so no patch change editing
                return false;
        }
 
        switch (ev->type) {
        case GDK_BUTTON_PRESS:
-               if (e->current_mouse_mode() == Editing::MouseObject) {
+               if (e->current_mouse_mode() == Editing::MouseContent) {
 
                        if (Gtkmm2ext::Keyboard::is_delete_event (&ev->button)) {
 
@@ -177,14 +173,14 @@ PatchChange::event_handler (GdkEvent* ev)
 
                                _region.edit_patch_change (this);
                                return true;
-                               
+
                        } else if (ev->button.button == 1) {
                                e->drags()->set (new PatchChangeDrag (e, this, &_region), ev);
                                return true;
                        }
                }
 
-               if (ev->button.button == 3) {
+               if (Gtkmm2ext::Keyboard::is_context_menu_event (&ev->button)) {
                        if (!_popup_initialized) {
                                initialize_popup_menus();
                                _popup_initialized = true;
@@ -199,13 +195,25 @@ PatchChange::event_handler (GdkEvent* ev)
                case GDK_Up:
                case GDK_KP_Up:
                case GDK_uparrow:
-                       _region.previous_patch (*this);
-                       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.next_patch (*this);
+                       _region.step_patch(
+                               *this, Keyboard::modifier_state_contains(ev->key.state, Keyboard::TertiaryModifier), -1);
+                       return true;
+               default:
                        break;
+               }
+               break;
+
+       case GDK_KEY_RELEASE:
+               switch (ev->key.keyval) {
+               case GDK_BackSpace:
+               case GDK_Delete:
+                       _region.delete_patch_change (this);
                default:
                        break;
                }
@@ -213,10 +221,12 @@ PatchChange::event_handler (GdkEvent* ev)
 
        case GDK_SCROLL:
                if (ev->scroll.direction == GDK_SCROLL_UP) {
-                       _region.previous_patch (*this);
+                       _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.next_patch (*this);
+                       _region.step_patch(
+                               *this, Keyboard::modifier_state_contains(ev->scroll.state, Keyboard::TertiaryModifier), -1);
                        return true;
                }
                break;