2 Copyright (C) 2000-2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <boost/algorithm/string.hpp>
24 #include "gtkmm2ext/keyboard.h"
25 #include "ardour/instrument_info.h"
27 #include "ardour_ui.h"
28 #include "midi_region_view.h"
29 #include "canvas_patch_change.h"
31 #include "editor_drag.h"
33 using namespace Gnome::Canvas;
34 using namespace MIDI::Name;
35 using namespace Gtkmm2ext;
38 /** @param x x position in pixels.
40 CanvasPatchChange::CanvasPatchChange(
41 MidiRegionView& region,
47 ARDOUR::InstrumentInfo& info,
48 ARDOUR::MidiModel::PatchChangePtr patch,
55 ARDOUR_UI::config()->canvasvar_MidiPatchChangeOutline.get() :
56 ARDOUR_UI::config()->canvasvar_MidiPatchChangeInactiveChannelOutline.get(),
58 ARDOUR_UI::config()->canvasvar_MidiPatchChangeFill.get() :
59 ARDOUR_UI::config()->canvasvar_MidiPatchChangeInactiveChannelFill.get(),
64 , _popup_initialized(false)
69 CanvasPatchChange::~CanvasPatchChange()
74 CanvasPatchChange::initialize_popup_menus()
76 boost::shared_ptr<ChannelNameSet> channel_name_set = _info.get_patches (_patch->channel());
78 if (!channel_name_set) {
82 const ChannelNameSet::PatchBanks& patch_banks = channel_name_set->patch_banks();
84 if (patch_banks.size() > 1) {
86 Gtk::Menu::MenuList& patch_bank_menus = _popup.items();
88 for (ChannelNameSet::PatchBanks::const_iterator bank = patch_banks.begin();
89 bank != patch_banks.end();
91 Gtk::Menu& patch_bank_menu = *manage(new Gtk::Menu());
93 const PatchBank::PatchNameList& patches = (*bank)->patch_name_list();
94 Gtk::Menu::MenuList& patch_menus = patch_bank_menu.items();
96 for (PatchBank::PatchNameList::const_iterator patch = patches.begin();
97 patch != patches.end();
99 std::string name = (*patch)->name();
100 boost::replace_all (name, "_", " ");
102 patch_menus.push_back(
103 Gtk::Menu_Helpers::MenuElem(
106 sigc::mem_fun(*this, &CanvasPatchChange::on_patch_menu_selected),
107 (*patch)->patch_primary_key())) );
110 std::string name = (*bank)->name();
111 boost::replace_all (name, "_", " ");
113 patch_bank_menus.push_back(
114 Gtk::Menu_Helpers::MenuElem(
119 /* only one patch bank, so make it the initial menu */
121 const PatchBank::PatchNameList& patches = patch_banks.front()->patch_name_list();
122 Gtk::Menu::MenuList& patch_menus = _popup.items();
124 for (PatchBank::PatchNameList::const_iterator patch = patches.begin();
125 patch != patches.end();
127 std::string name = (*patch)->name();
128 boost::replace_all (name, "_", " ");
130 patch_menus.push_back (Gtk::Menu_Helpers::MenuElem (name,
132 sigc::mem_fun(*this, &CanvasPatchChange::on_patch_menu_selected),
133 (*patch)->patch_primary_key())));
139 CanvasPatchChange::on_patch_menu_selected(const PatchPrimaryKey& key)
141 _region.change_patch_change (*this, key);
145 CanvasPatchChange::on_event (GdkEvent* ev)
148 case GDK_BUTTON_PRESS:
150 /* XXX: icky dcast */
151 Editor* e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
152 if (e->current_mouse_mode() == Editing::MouseObject && e->internal_editing()) {
154 if (Gtkmm2ext::Keyboard::is_delete_event (&ev->button)) {
156 _region.delete_patch_change (this);
159 } else if (Gtkmm2ext::Keyboard::is_edit_event (&ev->button)) {
161 _region.edit_patch_change (this);
164 } else if (ev->button.button == 1) {
165 e->drags()->set (new PatchChangeDrag (e, this, &_region), ev);
170 if (ev->button.button == 3) {
171 if (!_popup_initialized) {
172 initialize_popup_menus();
173 _popup_initialized = true;
175 if (!_popup.items().empty()) {
176 _popup.popup(ev->button.button, ev->button.time);
184 switch (ev->key.keyval) {
188 if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
189 _region.previous_bank (*this);
191 _region.previous_patch (*this);
197 if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
198 _region.next_bank (*this);
200 _region.next_patch (*this);
210 /* XXX: icky dcast */
211 Editor* e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
212 if (e->current_mouse_mode() == Editing::MouseObject && e->internal_editing()) {
213 if (ev->scroll.direction == GDK_SCROLL_UP) {
214 if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
215 _region.previous_bank (*this);
217 _region.previous_patch (*this);
220 } else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
221 if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
222 _region.next_bank (*this);
224 _region.next_patch (*this);
232 case GDK_ENTER_NOTIFY:
233 _region.patch_entered (this);
236 case GDK_LEAVE_NOTIFY:
237 _region.patch_left (this);