X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fpatch_change_dialog.cc;h=9fc6b693f7d521384461c63da31983fad5baa5d3;hb=refs%2Fheads%2Fcarl-master;hp=0ec12f93c222b450feffca4fb2c6fbba7eb23ffa;hpb=23350c195db2a8a777ca8d471174b44255c96ec4;p=ardour.git diff --git a/gtk2_ardour/patch_change_dialog.cc b/gtk2_ardour/patch_change_dialog.cc index 0ec12f93c2..9fc6b693f7 100644 --- a/gtk2_ardour/patch_change_dialog.cc +++ b/gtk2_ardour/patch_change_dialog.cc @@ -1,31 +1,40 @@ /* - Copyright (C) 2010 Paul Davis - Author: Carl Hetherington - - 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. - -*/ + * Copyright (C) 2010-2012 Carl Hetherington + * Copyright (C) 2011-2015 David Robillard + * Copyright (C) 2011-2017 Paul Davis + * Copyright (C) 2015-2019 Robin Gareus + * + * 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. + */ #include #include + #include + #include "gtkmm2ext/utils.h" -#include "ardour/midi_patch_manager.h" -#include "ardour/beats_frames_converter.h" + +#include "midi++/midnam_patch.h" + +#include "ardour/beats_samples_converter.h" +#include "ardour/instrument_info.h" + #include "patch_change_dialog.h" -#include "i18n.h" +#include "gui_thread.h" + +#include "pbd/i18n.h" using namespace std; using namespace Gtk; @@ -33,22 +42,23 @@ using namespace Gtkmm2ext; /** @param tc If non-0, a time converter for this patch change. If 0, time control will be desensitized */ PatchChangeDialog::PatchChangeDialog ( - const ARDOUR::BeatsFramesConverter* tc, - ARDOUR::Session* session, - Evoral::PatchChange const & patch, - string const & model_name, - string const & custom_device_node, - const Gtk::BuiltinStockID& ok - ) - : ArdourDialog (_("Patch Change"), true) + const ARDOUR::BeatsSamplesConverter* tc, + ARDOUR::Session* session, + Evoral::PatchChange const& patch, + ARDOUR::InstrumentInfo& info, + const Gtk::BuiltinStockID& ok, + bool allow_delete, + bool modal) + : ArdourDialog (_("Patch Change"), modal) , _time_converter (tc) - , _model_name (model_name) - , _custom_device_mode (custom_device_node) + , _info (info) , _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))) + , _bank_msb (*manage (new Adjustment (0, 0, 127, 1, 16))) + , _bank_lsb (*manage (new Adjustment (0, 0, 127, 1, 16))) , _ignore_signals (false) + , _keep_open (!modal) { Table* t = manage (new Table (4, 2)); Label* l; @@ -56,7 +66,7 @@ PatchChangeDialog::PatchChangeDialog ( int r = 0; if (_time_converter) { - + l = manage (left_aligned_label (_("Time"))); t->attach (*l, 0, 1, r, r + 1); t->attach (_time, 1, 2, r, r + 1); @@ -78,7 +88,7 @@ PatchChangeDialog::PatchChangeDialog ( 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 (left_aligned_label (_("Channel"))); @@ -97,41 +107,83 @@ PatchChangeDialog::PatchChangeDialog ( _program.set_value (patch.program () + 1); _program.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::program_changed)); - l = manage (left_aligned_label (_("Bank"))); + l = manage (left_aligned_label (_("Bank MSB"))); t->attach (*l, 0, 1, r, r + 1); - t->attach (_bank, 1, 2, r, r + 1); + t->attach (_bank_msb, 1, 2, r, r + 1); ++r; - _bank.set_value (patch.bank() + 1); - _bank.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::bank_changed)); + l = manage (left_aligned_label (_("Bank LSB"))); + t->attach (*l, 0, 1, r, r + 1); + t->attach (_bank_lsb, 1, 2, r, r + 1); + ++r; + + assert (patch.bank() != UINT16_MAX); + + _bank_msb.set_value ((patch.bank() >> 7)); + _bank_msb.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::bank_changed)); + _bank_lsb.set_value ((patch.bank() & 127)); + _bank_lsb.signal_changed().connect (sigc::mem_fun (*this, &PatchChangeDialog::bank_changed)); get_vbox()->add (*t); - add_button (Stock::CANCEL, RESPONSE_CANCEL); + if (modal) { + add_button (Stock::CANCEL, RESPONSE_CANCEL); + } add_button (ok, RESPONSE_ACCEPT); + if (allow_delete) { + add_button (Gtk::StockID(GTK_STOCK_DELETE), RESPONSE_REJECT); + } set_default_response (RESPONSE_ACCEPT); fill_bank_combo (); set_active_bank_combo (); bank_combo_changed (); + _info.Changed.connect (_info_changed_connection, invalidator (*this), + boost::bind (&PatchChangeDialog::instrument_info_changed, this), gui_context()); + show_all (); } -Evoral::PatchChange +void +PatchChangeDialog::on_response (int response_id) +{ + if (_keep_open) { + Gtk::Dialog::on_response (response_id); + } else { + ArdourDialog::on_response (response_id); + } +} + +int +PatchChangeDialog::get_14bit_bank () const +{ + return (_bank_msb.get_value_as_int() << 7) + _bank_lsb.get_value_as_int(); +} + +void +PatchChangeDialog::instrument_info_changed () +{ + _bank_combo.clear (); + _patch_combo.clear (); + fill_bank_combo (); + fill_patch_combo (); +} + +Evoral::PatchChange PatchChangeDialog::patch () const { - Evoral::MusicalTime t = 0; + Temporal::Beats t = Temporal::Beats(); if (_time_converter) { t = _time_converter->from (_time.current_time ()); } - return Evoral::PatchChange ( + return Evoral::PatchChange ( t, _channel.get_value_as_int() - 1, _program.get_value_as_int() - 1, - _bank.get_value_as_int() - 1 + get_14bit_bank () ); } @@ -139,12 +191,15 @@ PatchChangeDialog::patch () const void PatchChangeDialog::fill_bank_combo () { - MIDI::Name::ChannelNameSet::PatchBanks const * banks = get_banks (); - if (banks == 0) { + _bank_combo.clear (); + + boost::shared_ptr cns = _info.get_patches (_channel.get_value_as_int() - 1); + + if (!cns) { return; } - for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = banks->begin(); i != banks->end(); ++i) { + for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = cns->patch_banks().begin(); i != cns->patch_banks().end(); ++i) { string n = (*i)->name (); boost::replace_all (n, "_", " "); _bank_combo.append_text (n); @@ -156,18 +211,19 @@ void PatchChangeDialog::set_active_bank_combo () { _current_patch_bank.reset (); - - MIDI::Name::ChannelNameSet::PatchBanks const * banks = get_banks (); - if (banks == 0) { + + boost::shared_ptr cns = _info.get_patches (_channel.get_value_as_int() - 1); + + if (!cns) { return; } - for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = banks->begin(); i != banks->end(); ++i) { + for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = cns->patch_banks().begin(); i != cns->patch_banks().end(); ++i) { + string n = (*i)->name (); boost::replace_all (n, "_", " "); - MIDI::Name::PatchPrimaryKey const * key = (*i)->patch_primary_key (); - if (key && (key->bank_number == _bank.get_value () - 1)) { + if ((*i)->number() == get_14bit_bank()) { _current_patch_bank = *i; _ignore_signals = true; _bank_combo.set_active_text (n); @@ -190,15 +246,16 @@ PatchChangeDialog::bank_combo_changed () if (_ignore_signals) { return; } - + _current_patch_bank.reset (); - MIDI::Name::ChannelNameSet::PatchBanks const * banks = get_banks (); - if (banks == 0) { + boost::shared_ptr cns = _info.get_patches (_channel.get_value_as_int() - 1); + + if (!cns) { return; } - for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = banks->begin(); i != banks->end(); ++i) { + for (MIDI::Name::ChannelNameSet::PatchBanks::const_iterator i = cns->patch_banks().begin(); i != cns->patch_banks().end(); ++i) { string n = (*i)->name (); boost::replace_all (n, "_", " "); if (n == _bank_combo.get_active_text()) { @@ -215,10 +272,10 @@ PatchChangeDialog::bank_combo_changed () fill_patch_combo (); set_active_patch_combo (); - MIDI::Name::PatchPrimaryKey const * key = _current_patch_bank->patch_primary_key (); - if (key) { + if (_current_patch_bank->number() != UINT16_MAX) { _ignore_signals = true; - _bank.set_value (key->bank_number + 1); + _bank_msb.set_value (_current_patch_bank->number() >> 7); + _bank_lsb.set_value (_current_patch_bank->number() & 127); _ignore_signals = false; } } @@ -233,8 +290,8 @@ PatchChangeDialog::fill_patch_combo () 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) { + const MIDI::Name::PatchNameList& patches = _current_patch_bank->patch_name_list (); + for (MIDI::Name::PatchNameList::const_iterator j = patches.begin(); j != patches.end(); ++j) { string n = (*j)->name (); boost::replace_all (n, "_", " "); _patch_combo.append_text (n); @@ -255,14 +312,14 @@ PatchChangeDialog::set_active_patch_combo () _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) { + + const MIDI::Name::PatchNameList& patches = _current_patch_bank->patch_name_list (); + for (MIDI::Name::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) { + if (key.program() == _program.get_value() - 1) { _ignore_signals = true; _patch_combo.set_active_text (n); _ignore_signals = false; @@ -273,7 +330,7 @@ PatchChangeDialog::set_active_patch_combo () _ignore_signals = true; _patch_combo.set_active (-1); _ignore_signals = false; -} +} /** Set _program from the current state of _patch_combo */ void @@ -283,15 +340,19 @@ PatchChangeDialog::patch_combo_changed () 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) { + const MIDI::Name::PatchNameList& patches = _current_patch_bank->patch_name_list (); + + for (MIDI::Name::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); + _program.set_value ((*j)->program_number() + 1); + _bank_msb.set_value ((*j)->bank_number() >> 7); + _bank_lsb.set_value ((*j)->bank_number() & 127); _ignore_signals = false; + break; } } } @@ -327,17 +388,3 @@ PatchChangeDialog::bank_changed () set_active_patch_combo (); } -MIDI::Name::ChannelNameSet::PatchBanks const * -PatchChangeDialog::get_banks () -{ - MIDI::Name::MidiPatchManager& mpm = MIDI::Name::MidiPatchManager::instance (); - boost::shared_ptr 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 (); -}