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>
|
|
|
|
|
2008-12-23 01:03:45 -05:00
|
|
|
#include "ardour/midi_patch_manager.h"
|
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"
|
2008-12-23 01:03:45 -05:00
|
|
|
#include "canvas-program-change.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;
|
2008-04-29 03:28:24 -04:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
CanvasProgramChange::CanvasProgramChange(
|
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-07-27 10:09:16 -04:00
|
|
|
double event_time,
|
2009-02-15 12:30:42 -05:00
|
|
|
uint8_t channel,
|
|
|
|
uint8_t program)
|
2008-12-11 03:06:27 -05:00
|
|
|
: CanvasFlag(
|
2009-10-14 12:10:01 -04:00
|
|
|
region,
|
|
|
|
parent,
|
|
|
|
height,
|
|
|
|
ARDOUR_UI::config()->canvasvar_MidiProgramChangeOutline.get(),
|
2008-12-11 03:06:27 -05:00
|
|
|
ARDOUR_UI::config()->canvasvar_MidiProgramChangeFill.get(),
|
|
|
|
x,
|
2009-02-15 12:30:42 -05:00
|
|
|
y)
|
2008-12-23 01:03:45 -05:00
|
|
|
, _model_name(model_name)
|
|
|
|
, _custom_device_mode(custom_device_mode)
|
|
|
|
, _event_time(event_time)
|
|
|
|
, _channel(channel)
|
|
|
|
, _program(program)
|
2009-01-14 04:36:40 -05:00
|
|
|
, _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
|
|
|
}
|
|
|
|
|
|
|
|
CanvasProgramChange::~CanvasProgramChange()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
void
|
2008-12-23 01:03:45 -05:00
|
|
|
CanvasProgramChange::initialize_popup_menus()
|
|
|
|
{
|
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()
|
|
|
|
.find_channel_name_set(_model_name, _custom_device_mode, _channel);
|
|
|
|
|
|
|
|
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("_");
|
|
|
|
Glib::ustring 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) {
|
2009-01-15 17:48:23 -05:00
|
|
|
Glib::ustring 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(
|
2009-10-14 12:10:01 -04:00
|
|
|
sigc::mem_fun(*this, &CanvasProgramChange::on_patch_menu_selected),
|
|
|
|
(*patch)->patch_primary_key())) );
|
2008-12-23 01:03:45 -05:00
|
|
|
}
|
2009-01-15 17:48:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
Glib::ustring 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
|
2008-12-23 01:03:45 -05:00
|
|
|
CanvasProgramChange::on_patch_menu_selected(const PatchPrimaryKey& key)
|
|
|
|
{
|
|
|
|
cerr << " got patch program number " << key.program_number << endl;
|
|
|
|
_region.program_selected(*this, key);
|
|
|
|
}
|
|
|
|
|
2008-12-12 17:04:22 -05:00
|
|
|
bool
|
|
|
|
CanvasProgramChange::on_event(GdkEvent* ev)
|
|
|
|
{
|
|
|
|
switch (ev->type) {
|
2008-12-23 01:03:45 -05:00
|
|
|
case GDK_BUTTON_PRESS:
|
|
|
|
if (ev->button.button == 3) {
|
2009-01-14 04:36:40 -05:00
|
|
|
// lazy init
|
|
|
|
if (!_popup_initialized) {
|
|
|
|
initialize_popup_menus();
|
|
|
|
_popup_initialized = true;
|
|
|
|
}
|
2010-07-27 10:09:16 -04:00
|
|
|
_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-07-27 10:09:16 -04:00
|
|
|
case GDK_KEY_PRESS:
|
|
|
|
switch (ev->key.keyval) {
|
|
|
|
case GDK_Up:
|
|
|
|
case GDK_KP_Up:
|
|
|
|
case GDK_uparrow:
|
|
|
|
_region.previous_program(*this);
|
|
|
|
break;
|
|
|
|
case GDK_Down:
|
|
|
|
case GDK_KP_Down:
|
|
|
|
case GDK_downarrow:
|
|
|
|
_region.next_program(*this);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-12-12 17:04:22 -05:00
|
|
|
case GDK_SCROLL:
|
|
|
|
if (ev->scroll.direction == GDK_SCROLL_UP) {
|
2008-12-15 06:05:41 -05:00
|
|
|
_region.previous_program(*this);
|
2008-12-12 17:04:22 -05:00
|
|
|
return true;
|
|
|
|
} else if (ev->scroll.direction == GDK_SCROLL_DOWN) {
|
2008-12-15 06:05:41 -05:00
|
|
|
_region.next_program(*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
|
|
|
|
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;
|
|
|
|
}
|