2013-04-04 00:32:52 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2013-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2015 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-04-04 00:32:52 -04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
#include <glibmm/regex.h>
|
|
|
|
|
|
|
|
#include "gtkmm2ext/keyboard.h"
|
2017-06-28 18:20:55 -04:00
|
|
|
#include "gtkmm2ext/menu_elems.h"
|
2014-02-11 22:48:18 -05:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2014-12-13 00:37:34 -05:00
|
|
|
#include "midi++/midnam_patch.h"
|
2014-02-11 22:48:18 -05:00
|
|
|
|
|
|
|
#include "canvas/debug.h"
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "editor.h"
|
|
|
|
#include "editor_drag.h"
|
2024-01-04 21:07:52 -05:00
|
|
|
#include "midi_view.h"
|
2014-12-17 20:18:11 -05:00
|
|
|
#include "patch_change.h"
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ui_config.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
|
|
|
|
using namespace MIDI::Name;
|
|
|
|
using namespace std;
|
2014-12-17 20:18:11 -05:00
|
|
|
using Gtkmm2ext::Keyboard;
|
2013-04-04 00:32:52 -04:00
|
|
|
|
|
|
|
/** @param x x position in pixels.
|
|
|
|
*/
|
2024-01-04 21:07:52 -05:00
|
|
|
PatchChange::PatchChange (MidiView& region,
|
|
|
|
ArdourCanvas::Item* parent,
|
2020-04-03 19:47:09 -04:00
|
|
|
double height,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
ARDOUR::InstrumentInfo& info,
|
|
|
|
ARDOUR::MidiModel::PatchChangePtr patch,
|
|
|
|
Gtkmm2ext::Color outline_color,
|
|
|
|
Gtkmm2ext::Color fill_color)
|
2013-04-04 00:32:52 -04:00
|
|
|
: _region (region)
|
2013-04-04 18:45:27 -04:00
|
|
|
, _info (info)
|
2013-04-04 00:32:52 -04:00
|
|
|
, _patch (patch)
|
2020-04-03 19:47:09 -04:00
|
|
|
, _popup_initialized (false)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2020-04-03 19:47:09 -04:00
|
|
|
_flag = new ArdourCanvas::Flag (parent,
|
|
|
|
height,
|
|
|
|
outline_color,
|
|
|
|
fill_color,
|
|
|
|
ArdourCanvas::Duple (x, y),
|
|
|
|
true);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2020-04-03 19:41:32 -04:00
|
|
|
CANVAS_DEBUG_NAME (_flag, _info.get_patch_name (_patch->bank (), _patch->program (), _patch->channel ()));
|
2014-02-11 22:48:18 -05:00
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
_flag->Event.connect (sigc::mem_fun (*this, &PatchChange::event_handler));
|
2020-04-03 19:47:09 -04:00
|
|
|
_flag->set_font_description (UIConfiguration::instance ().get_SmallFont ());
|
2020-04-03 19:41:32 -04:00
|
|
|
|
|
|
|
update_name ();
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
PatchChange::~PatchChange ()
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2014-02-11 22:48:18 -05:00
|
|
|
delete _flag;
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2020-04-03 19:41:32 -04:00
|
|
|
void
|
|
|
|
PatchChange::update_name ()
|
|
|
|
{
|
|
|
|
_flag->set_text (_info.get_patch_name (_patch->bank (), _patch->program (), _patch->channel ()));
|
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
void
|
2020-04-03 19:47:09 -04:00
|
|
|
PatchChange::initialize_popup_menus ()
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2013-04-04 18:45:27 -04:00
|
|
|
using namespace MIDI::Name;
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ChannelNameSet> channel_name_set = _info.get_patches (_patch->channel ());
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
if (!channel_name_set || channel_name_set->patch_banks ().size () == 0) {
|
2013-04-04 00:32:52 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
const ChannelNameSet::PatchBanks& patch_banks = channel_name_set->patch_banks ();
|
2013-04-04 18:45:27 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
if (patch_banks.size () > 1) {
|
2013-04-04 18:45:27 -04:00
|
|
|
// fill popup menu:
|
2020-04-03 19:47:09 -04:00
|
|
|
Gtk::Menu::MenuList& patch_bank_menus = _popup.items ();
|
|
|
|
|
|
|
|
for (ChannelNameSet::PatchBanks::const_iterator bank = patch_banks.begin (); bank != patch_banks.end (); ++bank) {
|
|
|
|
Glib::RefPtr<Glib::Regex> underscores = Glib::Regex::create ("_");
|
|
|
|
std::string const& replacement (" ");
|
|
|
|
|
|
|
|
Gtk::Menu& patch_bank_menu = *manage (new Gtk::Menu ());
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
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) {
|
|
|
|
|
|
|
|
std::string name = underscores->replace ((*patch)->name ().c_str (), -1, 0, replacement);
|
|
|
|
|
|
|
|
patch_menus.push_back (
|
|
|
|
Gtk::Menu_Helpers::MenuElem (
|
|
|
|
name,
|
|
|
|
sigc::bind (sigc::mem_fun (*this, &PatchChange::on_patch_menu_selected), (*patch)->patch_primary_key ())));
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
std::string name = underscores->replace ((*bank)->name ().c_str (), -1, 0, replacement);
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
patch_bank_menus.push_back (
|
|
|
|
Gtk::Menu_Helpers::MenuElem (
|
|
|
|
name,
|
|
|
|
patch_bank_menu));
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2013-04-04 18:45:27 -04:00
|
|
|
} else {
|
|
|
|
/* only one patch bank, so make it the initial menu */
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
const PatchNameList& patches = patch_banks.front ()->patch_name_list ();
|
|
|
|
Gtk::Menu::MenuList& patch_menus = _popup.items ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
for (PatchNameList::const_iterator patch = patches.begin ();
|
|
|
|
patch != patches.end ();
|
2013-04-04 18:45:27 -04:00
|
|
|
++patch) {
|
2020-04-03 19:47:09 -04:00
|
|
|
patch_menus.push_back (Gtkmm2ext::MenuElemNoMnemonic ((*patch)->name (),
|
|
|
|
sigc::bind (sigc::mem_fun (*this, &PatchChange::on_patch_menu_selected), (*patch)->patch_primary_key ())));
|
2013-04-04 18:45:27 -04:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-03 19:47:09 -04:00
|
|
|
PatchChange::on_patch_menu_selected (const PatchPrimaryKey& key)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
|
|
|
_region.change_patch_change (*this, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PatchChange::event_handler (GdkEvent* ev)
|
|
|
|
{
|
2014-02-11 22:48:18 -05:00
|
|
|
/* XXX: icky dcast */
|
2024-01-04 21:07:52 -05:00
|
|
|
EditingContext& e = _region.editing_context();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2024-01-04 21:07:52 -05:00
|
|
|
if (!e.internal_editing ()) {
|
2014-12-06 16:05:47 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
switch (ev->type) {
|
2020-04-03 19:47:09 -04:00
|
|
|
case GDK_BUTTON_PRESS:
|
2024-01-04 21:07:52 -05:00
|
|
|
if (e.current_mouse_mode () == Editing::MouseContent) {
|
2020-04-03 19:47:09 -04:00
|
|
|
if (Gtkmm2ext::Keyboard::is_delete_event (&ev->button)) {
|
|
|
|
_region.delete_patch_change (this);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if (Gtkmm2ext::Keyboard::is_edit_event (&ev->button)) {
|
|
|
|
_region.edit_patch_change (this);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else if (ev->button.button == 1) {
|
2024-01-04 21:07:52 -05:00
|
|
|
e.drags ()->set (new PatchChangeDrag (e, this, &_region), ev);
|
2020-04-03 19:47:09 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
if (Gtkmm2ext::Keyboard::is_context_menu_event (&ev->button)) {
|
|
|
|
if (!_popup_initialized) {
|
|
|
|
initialize_popup_menus ();
|
|
|
|
_popup_initialized = true;
|
|
|
|
}
|
|
|
|
_popup.popup (ev->button.button, ev->button.time);
|
2013-04-04 00:32:52 -04:00
|
|
|
return true;
|
2020-04-03 19:47:09 -04:00
|
|
|
}
|
|
|
|
break;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
case GDK_KEY_PRESS:
|
|
|
|
switch (ev->key.keyval) {
|
|
|
|
case GDK_Up:
|
|
|
|
case GDK_KP_Up:
|
|
|
|
case GDK_uparrow:
|
|
|
|
_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, Keyboard::modifier_state_contains (ev->key.state, Keyboard::TertiaryModifier), -1);
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
2020-04-03 19:47:09 -04:00
|
|
|
break;
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
case GDK_KEY_RELEASE:
|
|
|
|
switch (ev->key.keyval) {
|
|
|
|
case GDK_BackSpace:
|
|
|
|
case GDK_Delete:
|
|
|
|
_region.delete_patch_change (this);
|
|
|
|
default:
|
|
|
|
break;
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
case GDK_SCROLL:
|
|
|
|
if (ev->scroll.direction == GDK_SCROLL_UP) {
|
|
|
|
_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, Keyboard::modifier_state_contains (ev->scroll.state, Keyboard::TertiaryModifier), -1);
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-02 20:18:40 -04:00
|
|
|
break;
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
case GDK_ENTER_NOTIFY:
|
|
|
|
_region.patch_entered (this);
|
|
|
|
break;
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
case GDK_LEAVE_NOTIFY:
|
|
|
|
_region.patch_left (this);
|
|
|
|
break;
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2020-04-03 19:47:09 -04:00
|
|
|
default:
|
|
|
|
break;
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChange::move (ArdourCanvas::Duple d)
|
|
|
|
{
|
|
|
|
_flag->move (d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChange::set_height (ArdourCanvas::Distance height)
|
|
|
|
{
|
|
|
|
_flag->set_height (height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChange::hide ()
|
|
|
|
{
|
|
|
|
_flag->hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChange::show ()
|
|
|
|
{
|
|
|
|
_flag->show ();
|
|
|
|
}
|