2010-12-28 13:43:22 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2000-2010 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2008-04-29 03:28:24 -04:00
|
|
|
#include <iostream>
|
2008-12-23 01:03:45 -05:00
|
|
|
|
2009-01-15 17:48:23 -05:00
|
|
|
#include <glibmm/regex.h>
|
|
|
|
|
2010-12-20 08:30:31 -05:00
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2008-12-23 01:03:45 -05:00
|
|
|
#include "ardour/midi_patch_manager.h"
|
2011-07-27 15:11:39 -04:00
|
|
|
|
2008-04-29 17:58:05 -04:00
|
|
|
#include "ardour_ui.h"
|
2008-12-15 06:05:41 -05:00
|
|
|
#include "midi_region_view.h"
|
2010-12-28 13:43:22 -05:00
|
|
|
#include "canvas_patch_change.h"
|
2010-12-19 22:42:59 -05:00
|
|
|
#include "editor.h"
|
|
|
|
#include "editor_drag.h"
|
2008-04-29 03:28:24 -04:00
|
|
|
|
2008-04-29 17:58:05 -04:00
|
|
|
using namespace Gnome::Canvas;
|
2008-12-23 01:03:45 -05:00
|
|
|
using namespace MIDI::Name;
|
2011-07-27 15:11:39 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2008-04-29 03:28:24 -04:00
|
|
|
using namespace std;
|
|
|
|
|
2010-12-19 22:42:59 -05:00
|
|
|
/** @param x x position in pixels.
|
|
|
|
*/
|
2010-12-28 13:43:22 -05:00
|
|
|
CanvasPatchChange::CanvasPatchChange(
|
2009-02-15 12:30:42 -05:00
|
|
|
MidiRegionView& region,
|
|
|
|
Group& parent,
|
2009-02-16 00:54:12 -05:00
|
|
|
const string& text,
|
2009-02-15 12:30:42 -05:00
|
|
|
double height,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
string& model_name,
|
|
|
|
string& custom_device_mode,
|
2010-12-28 13:43:22 -05:00
|
|
|
ARDOUR::MidiModel::PatchChangePtr patch)
|
2008-12-11 03:06:27 -05:00
|
|
|
: CanvasFlag(
|
2009-10-14 12:10:01 -04:00
|
|
|
region,
|
|
|
|
parent,
|
|
|
|
height,
|
2010-12-28 13:43:22 -05:00
|
|
|
ARDOUR_UI::config()->canvasvar_MidiPatchChangeOutline.get(),
|
|
|
|
ARDOUR_UI::config()->canvasvar_MidiPatchChangeFill.get(),
|
2008-12-11 03:06:27 -05:00
|
|
|
x,
|
2009-02-15 12:30:42 -05:00
|
|
|
y)
|
2010-12-28 13:43:22 -05:00
|
|
|
, _model_name(model_name)
|
|
|
|
, _custom_device_mode(custom_device_mode)
|
|
|
|
, _patch (patch)
|
|
|
|
, _popup_initialized(false)
|
2008-04-29 03:28:24 -04:00
|
|
|
{
|
2008-12-11 03:06:27 -05:00
|
|
|
set_text(text);
|
2008-04-29 03:28:24 -04:00
|
|
|
}
|
|
|
|
|
2010-12-28 13:43:22 -05:00
|
|
|
CanvasPatchChange::~CanvasPatchChange()
|
2008-04-29 03:28:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2010-12-28 13:43:22 -05:00
|
|
|
CanvasPatchChange::initialize_popup_menus()
|
2008-12-23 01:03:45 -05:00
|
|
|
{
|
2009-10-14 12:10:01 -04:00
|
|
|
boost::shared_ptr<ChannelNameSet> channel_name_set =
|
2008-12-23 01:03:45 -05:00
|
|
|
MidiPatchManager::instance()
|
2010-12-28 13:43:22 -05:00
|
|
|
.find_channel_name_set(_model_name, _custom_device_mode, _patch->channel());
|
2008-12-23 01:03:45 -05:00
|
|
|
|
|
|
|
if (!channel_name_set) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-23 01:03:45 -05:00
|
|
|
const ChannelNameSet::PatchBanks& patch_banks = channel_name_set->patch_banks();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-23 01:03:45 -05:00
|
|
|
// fill popup menu:
|
|
|
|
Gtk::Menu::MenuList& patch_bank_menus = _popup.items();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-23 01:03:45 -05:00
|
|
|
for (ChannelNameSet::PatchBanks::const_iterator bank = patch_banks.begin();
|
|
|
|
bank != patch_banks.end();
|
|
|
|
++bank) {
|
2009-01-15 17:48:23 -05:00
|
|
|
Glib::RefPtr<Glib::Regex> underscores = Glib::Regex::create("_");
|
2010-09-14 12:51:02 -04:00
|
|
|
std::string replacement(" ");
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-23 01:03:45 -05:00
|
|
|
Gtk::Menu& patch_bank_menu = *manage(new Gtk::Menu());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-23 01:03:45 -05:00
|
|
|
const PatchBank::PatchNameList& patches = (*bank)->patch_name_list();
|
|
|
|
Gtk::Menu::MenuList& patch_menus = patch_bank_menu.items();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-23 01:03:45 -05:00
|
|
|
for (PatchBank::PatchNameList::const_iterator patch = patches.begin();
|
|
|
|
patch != patches.end();
|
|
|
|
++patch) {
|
2010-09-14 12:51:02 -04:00
|
|
|
std::string name = underscores->replace((*patch)->name().c_str(), -1, 0, replacement);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-23 01:03:45 -05:00
|
|
|
patch_menus.push_back(
|
|
|
|
Gtk::Menu_Helpers::MenuElem(
|
2009-10-14 12:10:01 -04:00
|
|
|
name,
|
2008-12-23 01:03:45 -05:00
|
|
|
sigc::bind(
|
2010-12-28 13:43:22 -05:00
|
|
|
sigc::mem_fun(*this, &CanvasPatchChange::on_patch_menu_selected),
|
2009-10-14 12:10:01 -04:00
|
|
|
(*patch)->patch_primary_key())) );
|
2008-12-23 01:03:45 -05:00
|
|
|
}
|
2009-01-15 17:48:23 -05:00
|
|
|
|
|
|
|
|
2010-09-14 12:51:02 -04:00
|
|
|
std::string name = underscores->replace((*bank)->name().c_str(), -1, 0, replacement);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
|
|
|
patch_bank_menus.push_back(
|
2008-12-23 01:03:45 -05:00
|
|
|
Gtk::Menu_Helpers::MenuElem(
|
2009-10-14 12:10:01 -04:00
|
|
|
name,
|
|
|
|
patch_bank_menu) );
|
2008-12-23 01:03:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2010-12-28 13:43:22 -05:00
|
|
|
CanvasPatchChange::on_patch_menu_selected(const PatchPrimaryKey& key)
|
2008-12-23 01:03:45 -05:00
|
|
|
{
|
2010-12-28 13:43:22 -05:00
|
|
|
_region.change_patch_change (*this, key);
|
2008-12-23 01:03:45 -05:00
|
|
|
}
|
|
|
|
|
2008-12-12 17:04:22 -05:00
|
|
|
bool
|
2010-12-28 13:43:22 -05:00
|
|
|
CanvasPatchChange::on_event (GdkEvent* ev)
|
2008-12-12 17:04:22 -05:00
|
|
|
{
|
|
|
|
switch (ev->type) {
|
2008-12-23 01:03:45 -05:00
|
|
|
case GDK_BUTTON_PRESS:
|
2010-12-20 08:30:31 -05:00
|
|
|
{
|
|
|
|
/* XXX: icky dcast */
|
|
|
|
Editor* e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
|
|
|
|
if (e->current_mouse_mode() == Editing::MouseObject && e->internal_editing()) {
|
|
|
|
|
|
|
|
if (Gtkmm2ext::Keyboard::is_delete_event (&ev->button)) {
|
|
|
|
|
2010-12-28 13:43:22 -05:00
|
|
|
_region.delete_patch_change (this);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if (Gtkmm2ext::Keyboard::is_edit_event (&ev->button)) {
|
|
|
|
|
|
|
|
_region.edit_patch_change (this);
|
2010-12-20 08:30:31 -05:00
|
|
|
return true;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-12-20 08:30:31 -05:00
|
|
|
} else if (ev->button.button == 1) {
|
2010-12-28 13:43:22 -05:00
|
|
|
e->drags()->set (new PatchChangeDrag (e, this, &_region), ev);
|
2010-12-19 22:42:59 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 08:30:31 -05:00
|
|
|
|
|
|
|
if (ev->button.button == 3) {
|
2009-01-14 04:36:40 -05:00
|
|
|
if (!_popup_initialized) {
|
|
|
|
initialize_popup_menus();
|
|
|
|
_popup_initialized = true;
|
|
|
|
}
|
2011-07-19 20:01:08 -04:00
|
|
|
if (!_popup.items().empty()) {
|
|
|
|
_popup.popup(ev->button.button, ev->button.time);
|
|
|
|
}
|
2008-12-23 01:03:45 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
2010-12-20 08:30:31 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-11-25 15:37:39 -05:00
|
|
|
case GDK_KEY_PRESS:
|
|
|
|
switch (ev->key.keyval) {
|
|
|
|
case GDK_Up:
|
|
|
|
case GDK_KP_Up:
|
|
|
|
case GDK_uparrow:
|
2011-07-27 15:11:39 -04:00
|
|
|
if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
|
|
|
|
_region.previous_bank (*this);
|
|
|
|
} else {
|
|
|
|
_region.previous_patch (*this);
|
|
|
|
}
|
2010-11-25 15:37:39 -05:00
|
|
|
break;
|
|
|
|
case GDK_Down:
|
|
|
|
case GDK_KP_Down:
|
|
|
|
case GDK_downarrow:
|
2011-07-27 15:11:39 -04:00
|
|
|
if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
|
|
|
|
_region.next_bank (*this);
|
|
|
|
} else {
|
|
|
|
_region.next_patch (*this);
|
|
|
|
}
|
2010-11-25 15:37:39 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-27 10:09:16 -04:00
|
|
|
|
2008-12-12 17:04:22 -05:00
|
|
|
case GDK_SCROLL:
|
|
|
|
if (ev->scroll.direction == GDK_SCROLL_UP) {
|
2011-07-27 15:11:39 -04:00
|
|
|
if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
|
|
|
|
_region.previous_bank (*this);
|
|
|
|
} else {
|
|
|
|
_region.previous_patch (*this);
|
|
|
|
}
|
2008-12-12 17:04:22 -05:00
|
|
|
return true;
|
|
|
|
} else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
|
2011-07-27 15:11:39 -04:00
|
|
|
if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
|
|
|
|
_region.next_bank (*this);
|
|
|
|
} else {
|
|
|
|
_region.next_patch (*this);
|
|
|
|
}
|
2008-12-12 17:04:22 -05:00
|
|
|
return true;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-12-23 01:03:45 -05:00
|
|
|
break;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-12-28 13:43:22 -05:00
|
|
|
case GDK_ENTER_NOTIFY:
|
|
|
|
_region.patch_entered (this);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_LEAVE_NOTIFY:
|
|
|
|
_region.patch_left (this);
|
|
|
|
break;
|
|
|
|
|
2008-12-12 17:04:22 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-12 17:04:22 -05:00
|
|
|
return false;
|
|
|
|
}
|