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
|
|
|
|
2012-06-12 00:05:10 -04:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2009-01-15 17:48:23 -05:00
|
|
|
|
2012-06-17 09:37:52 -04:00
|
|
|
#include "pbd/stacktrace.h"
|
|
|
|
|
2010-12-20 08:30:31 -05:00
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2012-06-11 18:59:35 -04:00
|
|
|
#include "ardour/instrument_info.h"
|
2013-01-20 03:56:00 -05:00
|
|
|
#include "midi++/midnam_patch.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(
|
2013-01-19 21:49:07 -05:00
|
|
|
MidiRegionView& region,
|
|
|
|
Group& parent,
|
|
|
|
const string& text,
|
|
|
|
double height,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
ARDOUR::InstrumentInfo& info,
|
|
|
|
ARDOUR::MidiModel::PatchChangePtr patch,
|
|
|
|
bool active_channel)
|
2008-12-11 03:06:27 -05:00
|
|
|
: CanvasFlag(
|
2013-01-19 21:49:07 -05:00
|
|
|
region,
|
|
|
|
parent,
|
|
|
|
height,
|
2013-01-19 22:47:01 -05:00
|
|
|
(active_channel
|
|
|
|
? ARDOUR_UI::config()->canvasvar_MidiPatchChangeOutline.get()
|
|
|
|
: ARDOUR_UI::config()->canvasvar_MidiPatchChangeInactiveChannelOutline.get()),
|
|
|
|
(active_channel
|
|
|
|
? ARDOUR_UI::config()->canvasvar_MidiPatchChangeFill.get()
|
|
|
|
: ARDOUR_UI::config()->canvasvar_MidiPatchChangeInactiveChannelFill.get()),
|
2013-01-19 21:49:07 -05:00
|
|
|
x,
|
|
|
|
y)
|
2012-06-11 18:59:35 -04:00
|
|
|
, _info (info)
|
2010-12-28 13:43:22 -05:00
|
|
|
, _patch (patch)
|
|
|
|
, _popup_initialized(false)
|
2008-04-29 03:28:24 -04:00
|
|
|
{
|
2012-06-11 18:59:35 -04: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
|
|
|
{
|
2012-06-11 18:59:35 -04:00
|
|
|
boost::shared_ptr<ChannelNameSet> channel_name_set = _info.get_patches (_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
|
|
|
|
2012-06-15 22:52:09 -04:00
|
|
|
if (patch_banks.size() > 1) {
|
|
|
|
// fill popup menu:
|
|
|
|
Gtk::Menu::MenuList& patch_bank_menus = _popup.items();
|
|
|
|
|
|
|
|
for (ChannelNameSet::PatchBanks::const_iterator bank = patch_banks.begin();
|
|
|
|
bank != patch_banks.end();
|
|
|
|
++bank) {
|
|
|
|
Gtk::Menu& patch_bank_menu = *manage(new Gtk::Menu());
|
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
const PatchNameList& patches = (*bank)->patch_name_list();
|
2012-06-15 22:52:09 -04:00
|
|
|
Gtk::Menu::MenuList& patch_menus = patch_bank_menu.items();
|
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
for (PatchNameList::const_iterator patch = patches.begin();
|
2012-06-15 22:52:09 -04:00
|
|
|
patch != patches.end();
|
|
|
|
++patch) {
|
|
|
|
std::string name = (*patch)->name();
|
|
|
|
boost::replace_all (name, "_", " ");
|
|
|
|
|
|
|
|
patch_menus.push_back(
|
|
|
|
Gtk::Menu_Helpers::MenuElem(
|
|
|
|
name,
|
2013-01-19 21:49:07 -05:00
|
|
|
sigc::bind(sigc::mem_fun(*this, &CanvasPatchChange::on_patch_menu_selected),
|
|
|
|
(*patch)->patch_primary_key())) );
|
2012-06-15 22:52:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string name = (*bank)->name();
|
|
|
|
boost::replace_all (name, "_", " ");
|
|
|
|
|
|
|
|
patch_bank_menus.push_back(
|
|
|
|
Gtk::Menu_Helpers::MenuElem(
|
|
|
|
name,
|
|
|
|
patch_bank_menu) );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* only one patch bank, so make it the initial menu */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
const PatchNameList& patches = patch_banks.front()->patch_name_list();
|
2012-06-15 22:52:09 -04:00
|
|
|
Gtk::Menu::MenuList& patch_menus = _popup.items();
|
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
for (PatchNameList::const_iterator patch = patches.begin();
|
2008-12-23 01:03:45 -05:00
|
|
|
patch != patches.end();
|
|
|
|
++patch) {
|
2012-06-12 00:05:10 -04:00
|
|
|
std::string name = (*patch)->name();
|
|
|
|
boost::replace_all (name, "_", " ");
|
2012-06-15 22:52:09 -04:00
|
|
|
|
2013-01-19 21:49:07 -05:00
|
|
|
patch_menus.push_back (
|
|
|
|
Gtk::Menu_Helpers::MenuElem (
|
|
|
|
name,
|
|
|
|
sigc::bind (sigc::mem_fun(*this, &CanvasPatchChange::on_patch_menu_selected),
|
|
|
|
(*patch)->patch_primary_key())));
|
2008-12-23 01:03:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-15 22:52:09 -04: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
|
|
|
}
|
|
|
|
|
2013-01-19 22:09:43 -05:00
|
|
|
static bool
|
|
|
|
in_edit_mode(Editor* editor)
|
|
|
|
{
|
|
|
|
return (editor->internal_editing() &&
|
|
|
|
(editor->current_mouse_mode() == Editing::MouseObject ||
|
|
|
|
editor->current_mouse_mode() == Editing::MouseDraw));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-06-17 09:37:52 -04:00
|
|
|
Editor* e;
|
|
|
|
|
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 */
|
2012-06-17 09:37:52 -04:00
|
|
|
e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
|
2013-01-19 22:09:43 -05:00
|
|
|
if (in_edit_mode(e)) {
|
2010-12-20 08:30:31 -05:00
|
|
|
|
|
|
|
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;
|
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:
|
2012-07-15 10:43:38 -04:00
|
|
|
if (Keyboard::modifier_state_contains (ev->key.state, Keyboard::PrimaryModifier)) {
|
2011-07-27 15:11:39 -04:00
|
|
|
_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:
|
2012-07-15 10:43:38 -04:00
|
|
|
if (Keyboard::modifier_state_contains (ev->key.state, Keyboard::PrimaryModifier)) {
|
2011-07-27 15:11:39 -04:00
|
|
|
_region.next_bank (*this);
|
|
|
|
} else {
|
|
|
|
_region.next_patch (*this);
|
|
|
|
}
|
2010-11-25 15:37:39 -05:00
|
|
|
break;
|
2012-06-17 09:37:52 -04:00
|
|
|
case GDK_Delete:
|
|
|
|
case GDK_BackSpace:
|
|
|
|
_region.delete_patch_change (this);
|
|
|
|
break;
|
2010-11-25 15:37:39 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-27 10:09:16 -04:00
|
|
|
|
2008-12-12 17:04:22 -05:00
|
|
|
case GDK_SCROLL:
|
2012-06-11 18:59:35 -04:00
|
|
|
/* XXX: icky dcast */
|
2012-06-17 09:37:52 -04:00
|
|
|
e = dynamic_cast<Editor*> (&_region.get_time_axis_view().editor());
|
2013-01-19 22:09:43 -05:00
|
|
|
if (in_edit_mode(e)) {
|
2012-06-11 18:59:35 -04:00
|
|
|
if (ev->scroll.direction == GDK_SCROLL_UP) {
|
|
|
|
if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
|
|
|
|
_region.previous_bank (*this);
|
|
|
|
} else {
|
|
|
|
_region.previous_patch (*this);
|
|
|
|
}
|
|
|
|
} else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
|
|
|
|
if (Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::PrimaryModifier)) {
|
|
|
|
_region.next_bank (*this);
|
|
|
|
} else {
|
|
|
|
_region.next_patch (*this);
|
|
|
|
}
|
2011-07-27 15:11:39 -04:00
|
|
|
}
|
2012-06-17 09:37:52 -04:00
|
|
|
return true;
|
2012-06-11 18:59:35 -04:00
|
|
|
break;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2012-06-17 09:37:52 -04: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);
|
2013-01-19 21:49:07 -05:00
|
|
|
return true;
|
2010-12-28 13:43:22 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_LEAVE_NOTIFY:
|
|
|
|
_region.patch_left (this);
|
2013-01-19 21:49:07 -05:00
|
|
|
return true;
|
2010-12-28 13:43:22 -05:00
|
|
|
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;
|
|
|
|
}
|