diff options
author | Carl Hetherington <carl@carlh.net> | 2012-06-02 13:02:01 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2012-06-02 13:02:01 +0000 |
commit | 2010c0489fb1e482d54c008f6c58fc64e6c406cf (patch) | |
tree | 58e5da63dda75488ee4b3a4718294fcc887ca74c /gtk2_ardour | |
parent | e16bb2a07826592f26dd200160358bf37453bb9d (diff) |
Put MIDNAM stuff into the patch change dialog.
git-svn-id: svn://localhost/ardour2/branches/3.0@12539 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r-- | gtk2_ardour/editor_ops.cc | 8 | ||||
-rw-r--r-- | gtk2_ardour/midi_region_view.cc | 2 | ||||
-rw-r--r-- | gtk2_ardour/midi_region_view.h | 8 | ||||
-rw-r--r-- | gtk2_ardour/patch_change_dialog.cc | 234 | ||||
-rw-r--r-- | gtk2_ardour/patch_change_dialog.h | 29 |
5 files changed, 278 insertions, 3 deletions
diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 3da3042671..8b83a9ca70 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -4720,8 +4720,14 @@ Editor::insert_patch_change (bool from_context) const framepos_t p = get_preferred_edit_position (false, from_context); + /* XXX: bit of a hack; use the MIDNAM from the first selected region; + there may be more than one, but the PatchChangeDialog can only offer + one set of patch menus. + */ + MidiRegionView* first = dynamic_cast<MidiRegionView*> (rs.front ()); + Evoral::PatchChange<Evoral::MusicalTime> empty (0, 0, 0, 0); - PatchChangeDialog d (0, _session, empty, Gtk::Stock::ADD); + PatchChangeDialog d (0, _session, empty, first->model_name(), first->custom_device_mode(), Gtk::Stock::ADD); if (d.run() == RESPONSE_CANCEL) { return; diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index b61c4e477f..a455d98c7c 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -3640,7 +3640,7 @@ MidiRegionView::trim_front_ending () void MidiRegionView::edit_patch_change (ArdourCanvas::CanvasPatchChange* pc) { - PatchChangeDialog d (&_source_relative_time_converter, trackview.session(), *pc->patch (), Gtk::Stock::APPLY); + PatchChangeDialog d (&_source_relative_time_converter, trackview.session(), *pc->patch (), _model_name, _custom_device_mode, Gtk::Stock::APPLY); if (d.run () != Gtk::RESPONSE_ACCEPT) { return; } diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 8588bdfe06..ae663b8cfd 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -294,6 +294,14 @@ public: void create_note_at (framepos_t, double, double, bool); void clear_selection (bool signal = true) { clear_selection_except (0, signal); } + + std::string model_name () const { + return _model_name; + } + + std::string custom_device_mode () const { + return _custom_device_mode; + } protected: /** Allows derived types to specify their visibility requirements diff --git a/gtk2_ardour/patch_change_dialog.cc b/gtk2_ardour/patch_change_dialog.cc index 4bedf63df6..a9ad5c7839 100644 --- a/gtk2_ardour/patch_change_dialog.cc +++ b/gtk2_ardour/patch_change_dialog.cc @@ -20,10 +20,13 @@ #include <gtkmm/stock.h> #include <gtkmm/table.h> +#include <boost/algorithm/string.hpp> +#include "ardour/midi_patch_manager.h" #include "ardour/beats_frames_converter.h" #include "patch_change_dialog.h" #include "i18n.h" +using namespace std; using namespace Gtk; /** @param tc If non-0, a time converter for this patch change. If 0, time control will be desensitized */ @@ -31,14 +34,19 @@ PatchChangeDialog::PatchChangeDialog ( const ARDOUR::BeatsFramesConverter* tc, ARDOUR::Session* session, Evoral::PatchChange<Evoral::MusicalTime> const & patch, + string const & model_name, + string const & custom_device_node, const Gtk::BuiltinStockID& ok ) : ArdourDialog (_("Patch Change"), true) , _time_converter (tc) + , _model_name (model_name) + , _custom_device_mode (custom_device_node) , _time (X_("patchchangetime"), true, "", true, false) , _channel (*manage (new Adjustment (1, 1, 16, 1, 4))) , _program (*manage (new Adjustment (1, 1, 128, 1, 16))) , _bank (*manage (new Adjustment (1, 1, 16384, 1, 64))) + , _ignore_signals (false) { Table* t = manage (new Table (4, 2)); Label* l; @@ -58,13 +66,30 @@ PatchChangeDialog::PatchChangeDialog ( _time.set (_time_converter->to (patch.time ()), true); } + l = manage (new Label (_("Patch Bank"))); + l->set_alignment (0, 0.5); + t->attach (*l, 0, 1, r, r + 1); + t->attach (_bank_combo, 1, 2, r, r + 1); + ++r; + + _bank_combo.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::bank_combo_changed)); + + l = manage (new Label (_("Patch"))); + l->set_alignment (0, 0.5); + t->attach (*l, 0, 1, r, r + 1); + t->attach (_patch_combo, 1, 2, r, r + 1); + ++r; + + _patch_combo.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::patch_combo_changed)); + l = manage (new Label (_("Channel"))); l->set_alignment (0, 0.5); t->attach (*l, 0, 1, r, r + 1); t->attach (_channel, 1, 2, r, r + 1); ++r; - + _channel.set_value (patch.channel() + 1); + _channel.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::channel_changed)); l = manage (new Label (_("Program"))); l->set_alignment (0, 0.5); @@ -73,6 +98,7 @@ PatchChangeDialog::PatchChangeDialog ( ++r; _program.set_value (patch.program () + 1); + _program.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::program_changed)); l = manage (new Label (_("Bank"))); l->set_alignment (0, 0.5); @@ -81,6 +107,7 @@ PatchChangeDialog::PatchChangeDialog ( ++r; _bank.set_value (patch.bank() + 1); + _bank.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::bank_changed)); get_vbox()->add (*t); @@ -88,6 +115,10 @@ PatchChangeDialog::PatchChangeDialog ( add_button (ok, RESPONSE_ACCEPT); set_default_response (RESPONSE_ACCEPT); + fill_bank_combo (); + set_active_bank_combo (); + bank_combo_changed (); + show_all (); } @@ -107,3 +138,204 @@ PatchChangeDialog::patch () const _bank.get_value_as_int() - 1 ); } + +/** Fill the bank_combo according to the current _channel */ +void +PatchChangeDialog::fill_bank_combo () +{ + MIDI::Name::ChannelNameSet::PatchBanks const * banks = get_banks (); + if (banks == 0) { + return; + } + + for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = banks->begin(); i != banks->end(); ++i) { + string n = (*i)->name (); + boost::replace_all (n, "_", " "); + _bank_combo.append (n); + } +} + +/** Set the active value of the bank_combo, and _current_patch_bank, from the contents of _bank */ +void +PatchChangeDialog::set_active_bank_combo () +{ + _current_patch_bank.reset (); + + MIDI::Name::ChannelNameSet::PatchBanks const * banks = get_banks (); + if (banks == 0) { + return; + } + + for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = banks->begin(); i != banks->end(); ++i) { + string n = (*i)->name (); + boost::replace_all (n, "_", " "); + + MIDI::Name::PatchPrimaryKey const * key = (*i)->patch_primary_key (); + if (((key->msb << 7) | key->lsb) == _bank.get_value () - 1) { + _current_patch_bank = *i; + _ignore_signals = true; + _bank_combo.set_active_text (n); + _ignore_signals = false; + return; + } + } + + _ignore_signals = true; + _bank_combo.set_active (-1); + _ignore_signals = false; +} + +/** Update _current_patch_bank and reflect the current value of + * bank_combo in the rest of the dialog. + */ +void +PatchChangeDialog::bank_combo_changed () +{ + if (_ignore_signals) { + return; + } + + _current_patch_bank.reset (); + + MIDI::Name::ChannelNameSet::PatchBanks const * banks = get_banks (); + if (banks == 0) { + return; + } + + for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = banks->begin(); i != banks->end(); ++i) { + string n = (*i)->name (); + boost::replace_all (n, "_", " "); + if (n == _bank_combo.get_active_text()) { + _current_patch_bank = *i; + } + } + + /* Reflect */ + + fill_patch_combo (); + set_active_patch_combo (); + + MIDI::Name::PatchPrimaryKey const * key = _current_patch_bank->patch_primary_key (); + _ignore_signals = true; + _bank.set_value (((key->msb << 7) | key->lsb) + 1); + _ignore_signals = false; +} + +/** Fill the contents of the patch combo */ +void +PatchChangeDialog::fill_patch_combo () +{ + _patch_combo.clear (); + + if (_current_patch_bank == 0) { + return; + } + + const MIDI::Name::PatchBank::PatchNameList& patches = _current_patch_bank->patch_name_list (); + for (MIDI::Name::PatchBank::PatchNameList::const_iterator j = patches.begin(); j != patches.end(); ++j) { + string n = (*j)->name (); + boost::replace_all (n, "_", " "); + _patch_combo.append (n); + } +} + +/** Set the active value of the patch combo from the value of the _program entry */ +void +PatchChangeDialog::set_active_patch_combo () +{ + if (_ignore_signals) { + return; + } + + if (_current_patch_bank == 0) { + _ignore_signals = true; + _patch_combo.set_active (-1); + _ignore_signals = false; + return; + } + + const MIDI::Name::PatchBank::PatchNameList& patches = _current_patch_bank->patch_name_list (); + for (MIDI::Name::PatchBank::PatchNameList::const_iterator j = patches.begin(); j != patches.end(); ++j) { + string n = (*j)->name (); + boost::replace_all (n, "_", " "); + + MIDI::Name::PatchPrimaryKey const & key = (*j)->patch_primary_key (); + if (key.program_number == _program.get_value() - 1) { + _ignore_signals = true; + _patch_combo.set_active_text (n); + _ignore_signals = false; + return; + } + } + + _ignore_signals = true; + _patch_combo.set_active (-1); + _ignore_signals = false; +} + +/** Set _program from the current state of _patch_combo */ +void +PatchChangeDialog::patch_combo_changed () +{ + if (_ignore_signals || _current_patch_bank == 0) { + return; + } + + const MIDI::Name::PatchBank::PatchNameList& patches = _current_patch_bank->patch_name_list (); + for (MIDI::Name::PatchBank::PatchNameList::const_iterator j = patches.begin(); j != patches.end(); ++j) { + string n = (*j)->name (); + boost::replace_all (n, "_", " "); + if (n == _patch_combo.get_active_text ()) { + MIDI::Name::PatchPrimaryKey const & key = (*j)->patch_primary_key (); + _ignore_signals = true; + _program.set_value (key.program_number + 1); + _ignore_signals = false; + } + } +} + +void +PatchChangeDialog::channel_changed () +{ + fill_bank_combo (); + set_active_bank_combo (); + fill_patch_combo (); + set_active_patch_combo (); +} + +void +PatchChangeDialog::program_changed () +{ + if (_ignore_signals) { + return; + } + + set_active_patch_combo (); +} + +void +PatchChangeDialog::bank_changed () +{ + if (_ignore_signals) { + return; + } + + set_active_bank_combo (); + fill_patch_combo (); + set_active_patch_combo (); +} + +MIDI::Name::ChannelNameSet::PatchBanks const * +PatchChangeDialog::get_banks () +{ + MIDI::Name::MidiPatchManager& mpm = MIDI::Name::MidiPatchManager::instance (); + boost::shared_ptr<MIDI::Name::ChannelNameSet> channel_name_set = mpm.find_channel_name_set ( + _model_name, _custom_device_mode, _channel.get_value_as_int() - 1 + ); + + if (!channel_name_set) { + return 0; + } + + return &channel_name_set->patch_banks (); +} diff --git a/gtk2_ardour/patch_change_dialog.h b/gtk2_ardour/patch_change_dialog.h index 02eb311d48..0691260126 100644 --- a/gtk2_ardour/patch_change_dialog.h +++ b/gtk2_ardour/patch_change_dialog.h @@ -19,6 +19,8 @@ */ #include <gtkmm/spinbutton.h> +#include <gtkmm/comboboxtext.h> +#include "midi++/midnam_patch.h" #include "evoral/PatchChange.hpp" #include "ardour_dialog.h" #include "audio_clock.h" @@ -28,6 +30,12 @@ namespace ARDOUR { class Session; } +namespace MIDI { + namespace Name { + class PatchBank; + } +} + class PatchChangeDialog : public ArdourDialog { public: @@ -35,15 +43,36 @@ public: const ARDOUR::BeatsFramesConverter *, ARDOUR::Session *, Evoral::PatchChange<Evoral::MusicalTime> const &, + std::string const &, + std::string const &, const Gtk::BuiltinStockID & ); Evoral::PatchChange<Evoral::MusicalTime> patch () const; private: + void fill_bank_combo (); + void set_active_bank_combo (); + void fill_patch_combo (); + void set_active_patch_combo (); + void bank_combo_changed (); + void patch_combo_changed (); + void channel_changed (); + void bank_changed (); + void program_changed (); + + MIDI::Name::ChannelNameSet::PatchBanks const * get_banks (); + const ARDOUR::BeatsFramesConverter* _time_converter; + std::string _model_name; + std::string _custom_device_mode; AudioClock _time; Gtk::SpinButton _channel; Gtk::SpinButton _program; Gtk::SpinButton _bank; + Gtk::ComboBoxText _bank_combo; + Gtk::ComboBoxText _patch_combo; + + boost::shared_ptr<MIDI::Name::PatchBank> _current_patch_bank; + bool _ignore_signals; }; |