2017-09-07 18:30:55 -04:00
|
|
|
/*
|
2022-02-07 19:25:19 -05:00
|
|
|
* Copyright (C) 2017-2022 Robin Gareus <robin@gareus.org>
|
2017-09-07 18:30:55 -04:00
|
|
|
*
|
2019-08-02 17:26:43 -04:00
|
|
|
* 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.
|
2017-09-07 18:30:55 -04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-08-02 17:26:43 -04:00
|
|
|
* 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.
|
2017-09-07 18:30:55 -04:00
|
|
|
*/
|
|
|
|
|
2017-09-07 22:58:25 -04:00
|
|
|
#include <bitset>
|
2020-04-19 10:32:33 -04:00
|
|
|
#include <map>
|
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
#include <gtkmm/frame.h>
|
|
|
|
|
|
|
|
#include "pbd/unwind.h"
|
2017-09-07 19:35:43 -04:00
|
|
|
|
2019-10-25 15:13:51 -04:00
|
|
|
#include "evoral/PatchChange.h"
|
2022-02-08 17:08:23 -05:00
|
|
|
#include "evoral/midi_events.h"
|
2017-09-07 19:35:43 -04:00
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
#include "midi++/midnam_patch.h"
|
2017-09-07 19:35:43 -04:00
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
#include "ardour/instrument_info.h"
|
|
|
|
#include "ardour/midi_track.h"
|
2017-09-09 12:17:42 -04:00
|
|
|
#include "ardour/plugin_insert.h"
|
2022-02-08 17:08:23 -05:00
|
|
|
#include "ardour/triggerbox.h"
|
2017-09-07 18:30:55 -04:00
|
|
|
|
2017-09-07 22:58:25 -04:00
|
|
|
#include "gtkmm2ext/menu_elems.h"
|
2017-09-14 13:22:44 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2017-09-07 18:30:55 -04:00
|
|
|
#include "widgets/tooltips.h"
|
|
|
|
|
|
|
|
#include "gui_thread.h"
|
|
|
|
#include "patch_change_widget.h"
|
|
|
|
#include "ui_config.h"
|
|
|
|
|
|
|
|
#include "pbd/i18n.h"
|
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
2022-02-09 12:59:15 -05:00
|
|
|
PatchBankList::PatchBankList ()
|
|
|
|
: _bank_msb_spin (*manage (new Adjustment (0, 0, 127, 1, 16)))
|
2017-09-07 18:30:55 -04:00
|
|
|
, _bank_lsb_spin (*manage (new Adjustment (0, 0, 127, 1, 16)))
|
|
|
|
, _program_table (/*rows*/ 16, /*cols*/ 8, true)
|
2022-02-07 19:25:19 -05:00
|
|
|
, _ignore_spin_btn_signals (false)
|
2017-09-07 18:30:55 -04:00
|
|
|
{
|
|
|
|
_program_table.set_spacings (1);
|
2022-03-02 12:26:23 -05:00
|
|
|
_bank_select.disable_scrolling (); /* changing bank refills the dropdown */
|
2017-09-09 12:17:42 -04:00
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
for (uint8_t pgm = 0; pgm < 128; ++pgm) {
|
|
|
|
_program_btn[pgm].set_text_ellipsize (Pango::ELLIPSIZE_END);
|
|
|
|
_program_btn[pgm].set_layout_ellipsize_width (PANGO_SCALE * 112 * UIConfiguration::instance ().get_ui_scale ());
|
|
|
|
int row = pgm % 16;
|
|
|
|
int col = pgm / 16;
|
|
|
|
_program_table.attach (_program_btn[pgm], col, col + 1, row, row + 1);
|
2022-02-07 19:25:19 -05:00
|
|
|
_program_btn[pgm].signal_clicked.connect (sigc::bind (sigc::mem_fun (*this, &PatchBankList::select_program), pgm));
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
|
2022-02-08 17:20:40 -05:00
|
|
|
_bank_msb_spin.signal_changed ().connect (sigc::mem_fun (*this, &PatchBankList::select_bank_spin));
|
|
|
|
_bank_lsb_spin.signal_changed ().connect (sigc::mem_fun (*this, &PatchBankList::select_bank_spin));
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
|
2022-02-07 19:25:19 -05:00
|
|
|
PatchBankList::~PatchBankList ()
|
2017-09-07 18:30:55 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-19 10:32:33 -04:00
|
|
|
/* allow to sort bank-name by use-count */
|
|
|
|
template <typename A, typename B>
|
2022-02-08 17:20:40 -05:00
|
|
|
static std::multimap<B, A>
|
|
|
|
flip_map (std::map<A, B> const& src)
|
2020-04-19 10:32:33 -04:00
|
|
|
{
|
2022-02-08 17:20:40 -05:00
|
|
|
std::multimap<B, A> dst;
|
2020-04-19 10:32:33 -04:00
|
|
|
|
2022-02-08 17:20:40 -05:00
|
|
|
for (typename std::map<A, B>::const_iterator it = src.begin (); it != src.end (); ++it) {
|
2020-04-19 10:32:33 -04:00
|
|
|
dst.insert (std::pair<B, A> (it->second, it->first));
|
|
|
|
}
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
PatchBankList::refill (std::shared_ptr<MIDI::Name::ChannelNameSet> cns, int const b)
|
2017-09-07 18:30:55 -04:00
|
|
|
{
|
|
|
|
using namespace Menu_Helpers;
|
2017-09-07 22:58:25 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2020-04-19 10:32:33 -04:00
|
|
|
using namespace MIDI::Name;
|
2017-09-07 18:30:55 -04:00
|
|
|
|
|
|
|
_current_patch_bank.reset ();
|
|
|
|
_bank_select.clear_items ();
|
|
|
|
|
|
|
|
{
|
2019-07-17 10:36:01 -04:00
|
|
|
PBD::Unwinder<bool> uw (_ignore_spin_btn_signals, true);
|
2017-09-07 18:30:55 -04:00
|
|
|
_bank_msb_spin.set_value (b >> 7);
|
|
|
|
_bank_lsb_spin.set_value (b & 127);
|
|
|
|
}
|
|
|
|
|
2020-04-19 10:32:33 -04:00
|
|
|
typedef std::map<std::string, unsigned int> BankName;
|
2022-02-08 17:20:40 -05:00
|
|
|
typedef std::map<uint16_t, BankName> BankSet;
|
2020-04-19 10:32:33 -04:00
|
|
|
|
2022-02-08 17:20:40 -05:00
|
|
|
bool bank_set = false;
|
2020-04-19 10:32:33 -04:00
|
|
|
std::bitset<128> unset_notes;
|
2022-02-08 17:20:40 -05:00
|
|
|
BankSet generic_banks;
|
2020-04-19 10:32:33 -04:00
|
|
|
|
|
|
|
unset_notes.set ();
|
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
if (cns) {
|
2020-04-19 10:32:33 -04:00
|
|
|
const ChannelNameSet::PatchBanks& patch_banks = cns->patch_banks ();
|
|
|
|
for (ChannelNameSet::PatchBanks::const_iterator bank = patch_banks.begin (); bank != patch_banks.end (); ++bank) {
|
|
|
|
if ((*bank)->number () != UINT16_MAX) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* no shared MIDI bank for this PatchBanks,
|
|
|
|
* iterate over all programs in the patchbank, collect "<ControlChange>"
|
|
|
|
*/
|
|
|
|
const PatchNameList& patches = (*bank)->patch_name_list ();
|
|
|
|
for (PatchNameList::const_iterator patch = patches.begin (); patch != patches.end (); ++patch) {
|
|
|
|
BankName& bn (generic_banks[(*patch)->bank_number ()]);
|
|
|
|
++bn[(*bank)->name ()];
|
|
|
|
|
|
|
|
if ((*patch)->bank_number () != b) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-08 17:20:40 -05:00
|
|
|
|
|
|
|
const std::string n = (*patch)->name ();
|
2020-04-19 10:32:33 -04:00
|
|
|
MIDI::Name::PatchPrimaryKey const& key = (*patch)->patch_primary_key ();
|
|
|
|
|
2022-02-08 17:20:40 -05:00
|
|
|
const uint8_t pgm = key.program ();
|
2020-04-19 10:32:33 -04:00
|
|
|
_program_btn[pgm].set_text (n);
|
|
|
|
set_tooltip (_program_btn[pgm], string_compose (_("%1 (Pgm-%2)"),
|
2022-02-08 17:20:40 -05:00
|
|
|
Gtkmm2ext::markup_escape_text (n), (int)(pgm + 1)));
|
2020-04-19 10:32:33 -04:00
|
|
|
unset_notes.reset (pgm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ChannelNameSet::PatchBanks::const_iterator bank = patch_banks.begin (); bank != patch_banks.end (); ++bank) {
|
|
|
|
if ((*bank)->number () == UINT16_MAX) {
|
2018-07-24 15:35:14 -04:00
|
|
|
continue;
|
|
|
|
}
|
2020-04-19 10:32:33 -04:00
|
|
|
generic_banks.erase ((*bank)->number ());
|
|
|
|
std::string n = (*bank)->name ();
|
2022-02-07 19:25:19 -05:00
|
|
|
_bank_select.AddMenuElem (MenuElemNoMnemonic (n, sigc::bind (sigc::mem_fun (*this, &PatchBankList::select_bank), (*bank)->number ())));
|
2020-04-19 10:32:33 -04:00
|
|
|
if ((*bank)->number () == b) {
|
|
|
|
_current_patch_bank = *bank;
|
2017-09-07 18:30:55 -04:00
|
|
|
_bank_select.set_text (n);
|
|
|
|
}
|
|
|
|
}
|
2020-04-19 10:32:33 -04:00
|
|
|
|
2022-02-08 17:20:40 -05:00
|
|
|
for (BankSet::const_iterator i = generic_banks.begin (); i != generic_banks.end (); ++i) {
|
2020-04-19 10:32:33 -04:00
|
|
|
std::string n = string_compose (_("Bank %1"), (i->first) + 1);
|
|
|
|
#if 1
|
2022-02-08 17:20:40 -05:00
|
|
|
typedef std::multimap<unsigned int, std::string> BankByCnt;
|
|
|
|
|
|
|
|
BankByCnt bc (flip_map (i->second));
|
2020-04-19 10:32:33 -04:00
|
|
|
unsigned int cnt = 0; // pick top three
|
2022-02-08 17:20:40 -05:00
|
|
|
for (BankByCnt::reverse_iterator j = bc.rbegin (); j != bc.rend () && cnt < 3; ++j, ++cnt) {
|
2020-04-19 10:32:33 -04:00
|
|
|
n += " (" + j->second + ")";
|
|
|
|
if (n.size () > 64) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bc.size () > cnt) {
|
|
|
|
n += " (...)";
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-07 19:25:19 -05:00
|
|
|
_bank_select.AddMenuElem (MenuElemNoMnemonic (n, sigc::bind (sigc::mem_fun (*this, &PatchBankList::select_bank), i->first)));
|
2020-04-19 10:32:33 -04:00
|
|
|
if (i->first == b) {
|
|
|
|
_bank_select.set_text (n);
|
|
|
|
bank_set = true;
|
|
|
|
}
|
|
|
|
}
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
|
2020-04-19 10:32:33 -04:00
|
|
|
if (!_current_patch_bank && !bank_set) {
|
|
|
|
std::string n = string_compose (_("Bank %1"), b + 1);
|
2022-02-07 19:25:19 -05:00
|
|
|
_bank_select.AddMenuElem (MenuElemNoMnemonic (n, sigc::bind (sigc::mem_fun (*this, &PatchBankList::select_bank), b)));
|
2017-09-07 18:30:55 -04:00
|
|
|
_bank_select.set_text (n);
|
|
|
|
}
|
|
|
|
|
2020-04-19 10:32:33 -04:00
|
|
|
/* refill_program_list */
|
2017-09-07 18:30:55 -04:00
|
|
|
|
|
|
|
if (_current_patch_bank) {
|
|
|
|
const MIDI::Name::PatchNameList& patches = _current_patch_bank->patch_name_list ();
|
2022-02-08 17:20:40 -05:00
|
|
|
for (MIDI::Name::PatchNameList::const_iterator i = patches.begin (); i != patches.end (); ++i) {
|
|
|
|
const std::string n = (*i)->name ();
|
2017-09-07 18:30:55 -04:00
|
|
|
MIDI::Name::PatchPrimaryKey const& key = (*i)->patch_primary_key ();
|
|
|
|
|
2022-02-08 17:20:40 -05:00
|
|
|
const uint8_t pgm = key.program ();
|
2017-09-07 18:30:55 -04:00
|
|
|
_program_btn[pgm].set_text (n);
|
2017-09-14 13:22:44 -04:00
|
|
|
set_tooltip (_program_btn[pgm], string_compose (_("%1 (Pgm-%2)"),
|
2022-02-08 17:20:40 -05:00
|
|
|
Gtkmm2ext::markup_escape_text (n), (int)(pgm + 1)));
|
2017-09-07 22:58:25 -04:00
|
|
|
unset_notes.reset (pgm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-19 10:32:33 -04:00
|
|
|
bool shade = unset_notes.count () != 128;
|
|
|
|
|
2017-09-07 22:58:25 -04:00
|
|
|
for (uint8_t pgm = 0; pgm < 128; ++pgm) {
|
|
|
|
if (!unset_notes.test (pgm)) {
|
2017-09-08 12:15:02 -04:00
|
|
|
_program_btn[pgm].set_name (X_("patch change button"));
|
2017-09-07 22:58:25 -04:00
|
|
|
continue;
|
|
|
|
}
|
2022-02-08 17:20:40 -05:00
|
|
|
std::string n = string_compose (_("Pgm-%1"), (int)(pgm + 1));
|
2017-09-07 22:58:25 -04:00
|
|
|
_program_btn[pgm].set_text (n);
|
2020-04-19 10:32:33 -04:00
|
|
|
if (shade) {
|
2020-04-19 10:54:07 -04:00
|
|
|
_program_btn[pgm].set_name (X_("patch change button unnamed"));
|
2020-04-19 10:32:33 -04:00
|
|
|
} else {
|
|
|
|
_program_btn[pgm].set_name (X_("patch change button"));
|
2020-04-19 10:54:07 -04:00
|
|
|
continue;
|
2020-04-19 10:32:33 -04:00
|
|
|
}
|
2017-09-07 22:58:25 -04:00
|
|
|
set_tooltip (_program_btn[pgm], n);
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-02-07 19:25:19 -05:00
|
|
|
PatchBankList::select_bank_spin ()
|
2017-09-07 18:30:55 -04:00
|
|
|
{
|
|
|
|
if (_ignore_spin_btn_signals) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-08 17:20:40 -05:00
|
|
|
const uint32_t b = (_bank_msb_spin.get_value_as_int () << 7) + _bank_lsb_spin.get_value_as_int ();
|
2017-09-07 18:30:55 -04:00
|
|
|
select_bank (b);
|
|
|
|
}
|
|
|
|
|
2022-02-07 19:25:19 -05:00
|
|
|
void
|
|
|
|
PatchBankList::set_active_pgm (uint8_t p)
|
|
|
|
{
|
|
|
|
for (uint8_t pgm = 0; pgm < 128; ++pgm) {
|
|
|
|
_program_btn[pgm].set_active (pgm == p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************************************************************************/
|
|
|
|
|
2022-02-09 12:59:15 -05:00
|
|
|
PatchChangeTab::PatchChangeTab (int channel)
|
|
|
|
: _enable_btn (_("Override Patch Changes"), ArdourWidgets::ArdourButton::led_default_elements)
|
2022-02-08 17:08:23 -05:00
|
|
|
, _channel (channel)
|
|
|
|
, _bank (0)
|
|
|
|
, _ignore_callback (false)
|
|
|
|
{
|
|
|
|
Box* box;
|
|
|
|
box = manage (new HBox ());
|
|
|
|
box->set_border_width (2);
|
|
|
|
box->set_spacing (4);
|
|
|
|
box->pack_start (_enable_btn, false, false);
|
|
|
|
box->pack_start (*manage (new Label (_("Bank:"))), false, false);
|
|
|
|
box->pack_start (_bank_select, true, true);
|
|
|
|
box->pack_start (*manage (new Label (_("MSB:"))), false, false);
|
|
|
|
box->pack_start (_bank_msb_spin, false, false);
|
|
|
|
box->pack_start (*manage (new Label (_("LSB:"))), false, false);
|
|
|
|
box->pack_start (_bank_lsb_spin, false, false);
|
|
|
|
|
|
|
|
pack_start (*box, false, false);
|
|
|
|
|
|
|
|
_program_table.set_spacings (1);
|
|
|
|
pack_start (_program_table, true, true);
|
|
|
|
|
|
|
|
set_spacing (4);
|
|
|
|
show_all ();
|
|
|
|
|
|
|
|
_enable_btn.signal_clicked.connect (sigc::mem_fun (*this, &PatchChangeTab::enable_toggle));
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
reset (std::shared_ptr<ARDOUR::Route> (), std::shared_ptr<ARDOUR::MIDITrigger>());
|
2022-02-09 12:59:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
PatchChangeTab::reset (std::shared_ptr<ARDOUR::Route> r, std::shared_ptr<MIDITrigger> t)
|
2022-02-09 12:59:15 -05:00
|
|
|
{
|
|
|
|
_route = r;
|
|
|
|
_trigger = t;
|
|
|
|
_connections.drop_connections ();
|
|
|
|
|
|
|
|
if (!r || !t) {
|
|
|
|
_enable_btn.set_active (false);
|
|
|
|
refill_banks ();
|
|
|
|
return;
|
2022-02-08 17:08:23 -05:00
|
|
|
}
|
2022-02-09 12:59:15 -05:00
|
|
|
|
|
|
|
if (_trigger->patch_change_set (_channel)) {
|
|
|
|
_bank = _trigger->patch_change (_channel).bank ();
|
|
|
|
_enable_btn.set_active (true);
|
|
|
|
} else {
|
|
|
|
_enable_btn.set_active (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
_route->instrument_info().Changed.connect (_connections, invalidator (*this), boost::bind (&PatchChangeTab::instrument_info_changed, this), gui_context ());
|
|
|
|
_trigger->PropertyChanged.connect (_connections, invalidator (*this), boost::bind (&PatchChangeTab::trigger_property_changed, this, _1), gui_context ());
|
|
|
|
|
2022-02-08 17:08:23 -05:00
|
|
|
refill_banks ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeTab::enable_toggle ()
|
|
|
|
{
|
2022-02-09 12:59:15 -05:00
|
|
|
if (_ignore_callback || !_trigger) {
|
2022-02-08 17:08:23 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_enable_btn.get_active ()) {
|
|
|
|
_trigger->unset_patch_change (_channel);
|
|
|
|
} else {
|
|
|
|
select_program (program ());
|
|
|
|
}
|
|
|
|
update_sensitivity ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeTab::update_sensitivity ()
|
|
|
|
{
|
2022-02-09 12:59:15 -05:00
|
|
|
bool en = _trigger ? _trigger->patch_change_set (_channel) : false;
|
|
|
|
_enable_btn.set_sensitive (_trigger ? true : false /* _trigger->region () ? true : false) : false */);
|
2022-02-08 17:08:23 -05:00
|
|
|
_program_table.set_sensitive (en);
|
|
|
|
_bank_select.set_sensitive (en);
|
|
|
|
_bank_msb_spin.set_sensitive (en);
|
|
|
|
_bank_lsb_spin.set_sensitive (en);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeTab::trigger_property_changed (PBD::PropertyChange const& what_changed)
|
|
|
|
{
|
|
|
|
if (what_changed.contains (Properties::patch_change)) {
|
|
|
|
PBD::Unwinder<bool> uw (_ignore_callback, true);
|
|
|
|
_enable_btn.set_active (_trigger->patch_change_set (_channel));
|
|
|
|
refill_banks ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeTab::select_bank (uint32_t bank)
|
|
|
|
{
|
|
|
|
_bank = bank;
|
|
|
|
select_program (program ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeTab::select_program (uint8_t pgm)
|
|
|
|
{
|
2022-02-09 12:59:15 -05:00
|
|
|
if (pgm > 127 || !_trigger) {
|
2022-02-08 17:08:23 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Evoral::PatchChange<MidiBuffer::TimeType> pc (0, _channel, pgm, _bank);
|
|
|
|
_trigger->set_patch_change (pc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeTab::refresh ()
|
|
|
|
{
|
|
|
|
refill_banks ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeTab::refill_banks ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MIDI::Name::ChannelNameSet> cns;
|
2022-02-09 12:59:15 -05:00
|
|
|
if (_route) {
|
|
|
|
cns = _route->instrument_info ().get_patches (_channel);
|
|
|
|
}
|
|
|
|
update_sensitivity ();
|
|
|
|
refill (cns, bank ());
|
2022-02-08 17:08:23 -05:00
|
|
|
set_active_pgm (program ());
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2022-02-09 12:59:15 -05:00
|
|
|
PatchChangeTab::bank () const
|
2022-02-08 17:08:23 -05:00
|
|
|
{
|
2022-02-09 12:59:15 -05:00
|
|
|
if (_trigger && _trigger->patch_change_set (_channel)) {
|
2022-02-08 17:08:23 -05:00
|
|
|
return _trigger->patch_change (_channel).bank ();
|
|
|
|
}
|
|
|
|
return _bank;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
PatchChangeTab::program () const
|
|
|
|
{
|
2022-02-09 12:59:15 -05:00
|
|
|
if (_trigger && _trigger->patch_change_set (_channel)) {
|
2022-02-08 17:08:23 -05:00
|
|
|
return _trigger->patch_change (_channel).program ();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeTab::instrument_info_changed ()
|
|
|
|
{
|
|
|
|
refill_banks ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************************************************************************/
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
PatchChangeWidget::PatchChangeWidget (std::shared_ptr<ARDOUR::Route> r)
|
2022-02-09 12:59:15 -05:00
|
|
|
: _route (r)
|
|
|
|
, _info (r->instrument_info ())
|
2022-02-07 19:25:19 -05:00
|
|
|
, _channel (-1)
|
|
|
|
, _no_notifications (false)
|
|
|
|
, _audition_enable (_("Audition on Change"), ArdourWidgets::ArdourButton::led_default_elements)
|
|
|
|
, _audition_start_spin (*manage (new Adjustment (48, 0, 127, 1, 16)))
|
|
|
|
, _audition_end_spin (*manage (new Adjustment (60, 0, 127, 1, 16)))
|
|
|
|
, _audition_velocity (*manage (new Adjustment (100, 1, 127, 1, 16)))
|
|
|
|
, _audition_note_on (false)
|
|
|
|
{
|
|
|
|
Box* box;
|
|
|
|
box = manage (new HBox ());
|
|
|
|
box->set_border_width (2);
|
|
|
|
box->set_spacing (4);
|
|
|
|
box->pack_start (*manage (new Label (_("Channel:"))), false, false);
|
|
|
|
box->pack_start (_channel_select, false, false);
|
|
|
|
box->pack_start (*manage (new Label (_("Bank:"))), false, false);
|
|
|
|
box->pack_start (_bank_select, true, true);
|
|
|
|
box->pack_start (*manage (new Label (_("MSB:"))), false, false);
|
|
|
|
box->pack_start (_bank_msb_spin, false, false);
|
|
|
|
box->pack_start (*manage (new Label (_("LSB:"))), false, false);
|
|
|
|
box->pack_start (_bank_lsb_spin, false, false);
|
|
|
|
|
|
|
|
pack_start (*box, false, false);
|
|
|
|
|
|
|
|
_program_table.set_spacings (1);
|
|
|
|
pack_start (_program_table, true, true);
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if (!std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
2022-02-08 17:08:23 -05:00
|
|
|
pack_start (*manage (new Label (_("Note: Patch Selection is volatile (only Midi-Tracks retain bank/patch selection)."))), false, false);
|
2022-02-07 19:25:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
box = manage (new HBox ());
|
|
|
|
box->set_spacing (4);
|
|
|
|
box->pack_start (_audition_enable, false, false);
|
|
|
|
box->pack_start (*manage (new Label (_("Start Note:"))), false, false);
|
|
|
|
box->pack_start (_audition_start_spin, false, false);
|
|
|
|
box->pack_start (*manage (new Label (_("End Note:"))), false, false);
|
|
|
|
box->pack_start (_audition_end_spin, false, false);
|
|
|
|
box->pack_start (*manage (new Label (_("Velocity:"))), false, false);
|
|
|
|
box->pack_start (_audition_velocity, false, false);
|
|
|
|
|
|
|
|
Box* box2 = manage (new HBox ());
|
|
|
|
box2->pack_start (*box, true, false);
|
|
|
|
box2->set_border_width (2);
|
|
|
|
pack_start (*box2, false, false);
|
|
|
|
|
|
|
|
for (uint32_t chn = 0; chn < 16; ++chn) {
|
|
|
|
using namespace Menu_Helpers;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
char buf[8];
|
2022-02-08 17:20:40 -05:00
|
|
|
snprintf (buf, sizeof (buf), "%d", chn + 1);
|
2022-02-07 19:25:19 -05:00
|
|
|
_channel_select.AddMenuElem (MenuElemNoMnemonic (buf, sigc::bind (sigc::mem_fun (*this, &PatchChangeWidget::select_channel), chn)));
|
|
|
|
}
|
|
|
|
|
|
|
|
_piano.set_monophonic (true);
|
|
|
|
_piano.NoteOn.connect (sigc::mem_fun (*this, &PatchChangeWidget::_note_on_event_handler));
|
|
|
|
_piano.NoteOff.connect (sigc::mem_fun (*this, &PatchChangeWidget::note_off_event_handler));
|
|
|
|
|
2022-01-26 16:29:36 -05:00
|
|
|
_piano.set_can_focus ();
|
2022-02-07 19:25:19 -05:00
|
|
|
pack_start (_piano, false, false);
|
|
|
|
|
|
|
|
_audition_start_spin.set_sensitive (false);
|
|
|
|
_audition_end_spin.set_sensitive (false);
|
|
|
|
|
|
|
|
_audition_enable.signal_clicked.connect (sigc::mem_fun (*this, &PatchChangeWidget::audition_toggle));
|
2022-02-08 17:20:40 -05:00
|
|
|
_audition_start_spin.signal_changed ().connect (sigc::bind (sigc::mem_fun (*this, &PatchChangeWidget::check_note_range), false));
|
|
|
|
_audition_end_spin.signal_changed ().connect (sigc::bind (sigc::mem_fun (*this, &PatchChangeWidget::check_note_range), true));
|
2022-02-07 19:25:19 -05:00
|
|
|
|
|
|
|
set_spacing (4);
|
|
|
|
show_all ();
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if (!std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
2022-02-07 19:25:19 -05:00
|
|
|
processors_changed ();
|
2022-02-09 12:59:15 -05:00
|
|
|
_route->processors_changed.connect (_route_connections, invalidator (*this),
|
|
|
|
boost::bind (&PatchChangeWidget::processors_changed, this), gui_context ());
|
2022-02-07 19:25:19 -05:00
|
|
|
}
|
2022-02-09 12:59:15 -05:00
|
|
|
|
|
|
|
_info.Changed.connect (_route_connections, invalidator (*this),
|
|
|
|
boost::bind (&PatchChangeWidget::instrument_info_changed, this), gui_context ());
|
2022-02-07 19:25:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PatchChangeWidget::~PatchChangeWidget ()
|
|
|
|
{
|
|
|
|
cancel_audition ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::refresh ()
|
|
|
|
{
|
2022-01-26 15:21:06 -05:00
|
|
|
if (get_visible ()) {
|
2022-02-07 19:25:19 -05:00
|
|
|
on_show ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::on_show ()
|
|
|
|
{
|
|
|
|
Gtk::VBox::on_show ();
|
|
|
|
cancel_audition ();
|
|
|
|
_channel = -1;
|
|
|
|
select_channel (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::on_hide ()
|
|
|
|
{
|
|
|
|
Gtk::VBox::on_hide ();
|
|
|
|
_ac_connections.drop_connections ();
|
|
|
|
cancel_audition ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::select_channel (uint8_t chn)
|
|
|
|
{
|
|
|
|
assert (_route);
|
|
|
|
assert (chn < 16);
|
|
|
|
|
|
|
|
if (_channel == chn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel_audition ();
|
|
|
|
|
|
|
|
_channel_select.set_text (string_compose ("%1", (int)(chn + 1)));
|
2022-02-08 17:20:40 -05:00
|
|
|
_channel = chn;
|
2022-02-07 19:25:19 -05:00
|
|
|
_no_notifications = false;
|
|
|
|
|
|
|
|
_ac_connections.drop_connections ();
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
|
|
|
std::shared_ptr<AutomationControl> bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_MSB_BANK), true);
|
|
|
|
std::shared_ptr<AutomationControl> bank_lsb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_LSB_BANK), true);
|
|
|
|
std::shared_ptr<AutomationControl> program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, chn), true);
|
2022-02-07 19:25:19 -05:00
|
|
|
|
|
|
|
bank_msb->Changed.connect (_ac_connections, invalidator (*this),
|
2022-02-08 17:20:40 -05:00
|
|
|
boost::bind (&PatchChangeWidget::bank_changed, this), gui_context ());
|
2022-02-07 19:25:19 -05:00
|
|
|
bank_lsb->Changed.connect (_ac_connections, invalidator (*this),
|
2022-02-08 17:20:40 -05:00
|
|
|
boost::bind (&PatchChangeWidget::bank_changed, this), gui_context ());
|
2022-02-07 19:25:19 -05:00
|
|
|
program->Changed.connect (_ac_connections, invalidator (*this),
|
2022-02-08 17:20:40 -05:00
|
|
|
boost::bind (&PatchChangeWidget::program_changed, this), gui_context ());
|
2023-02-16 18:33:28 -05:00
|
|
|
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
|
2022-02-08 17:20:40 -05:00
|
|
|
if (pi->plugin ()->knows_bank_patch ()) {
|
2022-02-07 19:25:19 -05:00
|
|
|
pi->plugin ()->BankPatchChange.connect (_ac_connections, invalidator (*this),
|
2022-02-08 17:20:40 -05:00
|
|
|
boost::bind (&PatchChangeWidget::bankpatch_changed, this, _1), gui_context ());
|
2022-02-07 19:25:19 -05:00
|
|
|
} else {
|
|
|
|
_no_notifications = true;
|
|
|
|
// TODO add note: instrument does not report changes.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refill_banks ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::refill_banks ()
|
|
|
|
{
|
|
|
|
cancel_audition ();
|
2022-02-09 12:59:15 -05:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MIDI::Name::ChannelNameSet> cns = _info.get_patches (_channel);
|
2022-02-09 12:59:15 -05:00
|
|
|
refill (cns, bank (_channel));
|
2022-02-07 19:25:19 -05:00
|
|
|
program_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***** user GUI actions *****/
|
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
void
|
|
|
|
PatchChangeWidget::select_bank (uint32_t bank)
|
|
|
|
{
|
2017-09-07 19:35:43 -04:00
|
|
|
cancel_audition ();
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
|
|
|
std::shared_ptr<AutomationControl> bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, _channel, MIDI_CTL_MSB_BANK), true);
|
|
|
|
std::shared_ptr<AutomationControl> bank_lsb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, _channel, MIDI_CTL_LSB_BANK), true);
|
2017-09-09 12:17:42 -04:00
|
|
|
|
|
|
|
bank_msb->set_value (bank >> 7, PBD::Controllable::NoGroup);
|
|
|
|
bank_lsb->set_value (bank & 127, PBD::Controllable::NoGroup);
|
2023-02-16 18:33:28 -05:00
|
|
|
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
|
2017-09-09 12:17:42 -04:00
|
|
|
uint8_t event[3];
|
|
|
|
event[0] = (MIDI_CMD_CONTROL | _channel);
|
|
|
|
event[1] = 0x00;
|
|
|
|
event[2] = bank >> 7;
|
2020-09-19 18:59:23 -04:00
|
|
|
pi->write_immediate_event (Evoral::MIDI_EVENT, 3, event);
|
2017-09-09 12:17:42 -04:00
|
|
|
|
|
|
|
event[1] = 0x20;
|
|
|
|
event[2] = bank & 127;
|
2020-09-19 18:59:23 -04:00
|
|
|
pi->write_immediate_event (Evoral::MIDI_EVENT, 3, event);
|
2017-09-09 12:17:42 -04:00
|
|
|
}
|
2017-09-07 18:30:55 -04:00
|
|
|
|
2017-09-07 22:58:25 -04:00
|
|
|
select_program (program (_channel));
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::select_program (uint8_t pgm)
|
|
|
|
{
|
2017-09-07 19:35:43 -04:00
|
|
|
cancel_audition ();
|
2017-09-09 12:17:42 -04:00
|
|
|
if (_no_notifications) {
|
|
|
|
program_changed ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pgm > 127) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-07 19:35:43 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
|
|
|
std::shared_ptr<AutomationControl> program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, _channel), true);
|
2017-09-09 12:17:42 -04:00
|
|
|
program->set_value (pgm, PBD::Controllable::NoGroup);
|
2023-02-16 18:33:28 -05:00
|
|
|
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
|
2017-09-09 12:17:42 -04:00
|
|
|
uint8_t event[2];
|
|
|
|
event[0] = (MIDI_CMD_PGM_CHANGE | _channel);
|
|
|
|
event[1] = pgm;
|
2020-09-19 18:59:23 -04:00
|
|
|
pi->write_immediate_event (Evoral::MIDI_EVENT, 2, event);
|
2017-09-09 12:17:42 -04:00
|
|
|
}
|
2017-09-07 19:35:43 -04:00
|
|
|
|
|
|
|
audition ();
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ***** callbacks, external changes *****/
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::bank_changed ()
|
|
|
|
{
|
|
|
|
refill_banks ();
|
|
|
|
}
|
|
|
|
|
2017-09-09 12:17:42 -04:00
|
|
|
void
|
|
|
|
PatchChangeWidget::bankpatch_changed (uint8_t chn)
|
|
|
|
{
|
|
|
|
if (chn == _channel) {
|
|
|
|
refill_banks ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
void
|
|
|
|
PatchChangeWidget::program_changed ()
|
|
|
|
{
|
|
|
|
uint8_t p = program (_channel);
|
2022-02-07 19:25:19 -05:00
|
|
|
set_active_pgm (p);
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::instrument_info_changed ()
|
|
|
|
{
|
|
|
|
refill_banks ();
|
|
|
|
}
|
|
|
|
|
2017-09-09 12:17:42 -04:00
|
|
|
void
|
|
|
|
PatchChangeWidget::processors_changed ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
assert (!std::dynamic_pointer_cast<MidiTrack> (_route));
|
2017-09-09 12:17:42 -04:00
|
|
|
if (_route->the_instrument ()) {
|
|
|
|
set_sensitive (true);
|
|
|
|
} else {
|
|
|
|
set_sensitive (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-07 19:35:43 -04:00
|
|
|
/* ***** play notes *****/
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::audition_toggle ()
|
|
|
|
{
|
|
|
|
_audition_enable.set_active (!_audition_enable.get_active ());
|
2022-02-08 17:20:40 -05:00
|
|
|
if (_audition_enable.get_active ()) {
|
2017-09-07 19:35:43 -04:00
|
|
|
_audition_start_spin.set_sensitive (true);
|
|
|
|
_audition_end_spin.set_sensitive (true);
|
|
|
|
} else {
|
|
|
|
cancel_audition ();
|
|
|
|
_audition_start_spin.set_sensitive (false);
|
|
|
|
_audition_end_spin.set_sensitive (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::check_note_range (bool upper)
|
|
|
|
{
|
|
|
|
int s = _audition_start_spin.get_value_as_int ();
|
|
|
|
int e = _audition_end_spin.get_value_as_int ();
|
|
|
|
if (s <= e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (upper) {
|
|
|
|
_audition_start_spin.set_value (e);
|
|
|
|
} else {
|
|
|
|
_audition_end_spin.set_value (s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::cancel_audition ()
|
|
|
|
{
|
2022-02-08 17:20:40 -05:00
|
|
|
_note_queue_connection.disconnect ();
|
2017-09-07 19:35:43 -04:00
|
|
|
|
|
|
|
if (_audition_note_on) {
|
2017-09-09 12:17:42 -04:00
|
|
|
note_off_event_handler (_audition_note_num);
|
2019-10-24 13:43:46 -04:00
|
|
|
_piano.set_note_off (_audition_note_num);
|
2017-09-07 19:35:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::audition ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
if (!std::dynamic_pointer_cast<MidiTrack> (_route) && !std::dynamic_pointer_cast<PluginInsert> (_route)) {
|
2017-09-07 19:35:43 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_channel > 16) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_note_queue_connection.connected ()) {
|
|
|
|
cancel_audition ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_audition_enable.get_active ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (!_audition_note_on);
|
|
|
|
_audition_note_num = _audition_start_spin.get_value_as_int ();
|
|
|
|
|
2022-02-08 17:20:40 -05:00
|
|
|
_note_queue_connection = Glib::signal_timeout ().connect (sigc::bind (sigc::mem_fun (&PatchChangeWidget::audition_next), this), 250);
|
2017-09-07 19:35:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
PatchChangeWidget::audition_next ()
|
|
|
|
{
|
|
|
|
if (_audition_note_on) {
|
2017-09-09 12:17:42 -04:00
|
|
|
note_off_event_handler (_audition_note_num);
|
2019-10-24 13:43:46 -04:00
|
|
|
_piano.set_note_off (_audition_note_num);
|
2022-02-08 17:20:40 -05:00
|
|
|
return ++_audition_note_num <= _audition_end_spin.get_value_as_int () && _audition_enable.get_active ();
|
2017-09-07 19:35:43 -04:00
|
|
|
} else {
|
2017-09-14 13:00:08 -04:00
|
|
|
note_on_event_handler (_audition_note_num, true);
|
2019-10-24 13:43:46 -04:00
|
|
|
_piano.set_note_on (_audition_note_num);
|
2017-09-07 19:35:43 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-09-07 18:30:55 -04:00
|
|
|
|
2017-09-07 21:32:31 -04:00
|
|
|
void
|
2019-10-24 13:43:46 -04:00
|
|
|
PatchChangeWidget::_note_on_event_handler (int note, int)
|
2017-09-07 21:32:31 -04:00
|
|
|
{
|
2022-02-08 17:20:40 -05:00
|
|
|
note_on_event_handler (note, false);
|
2017-09-07 21:32:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-09-14 13:00:08 -04:00
|
|
|
PatchChangeWidget::note_on_event_handler (int note, bool for_audition)
|
2017-09-07 21:32:31 -04:00
|
|
|
{
|
2017-09-14 13:00:08 -04:00
|
|
|
if (!for_audition) {
|
|
|
|
cancel_audition ();
|
2019-10-24 13:43:46 -04:00
|
|
|
_piano.grab_focus ();
|
2017-09-14 13:00:08 -04:00
|
|
|
}
|
2017-09-07 21:32:31 -04:00
|
|
|
uint8_t event[3];
|
|
|
|
event[0] = (MIDI_CMD_NOTE_ON | _channel);
|
|
|
|
event[1] = note;
|
|
|
|
event[2] = _audition_velocity.get_value_as_int ();
|
2022-02-08 17:20:40 -05:00
|
|
|
|
|
|
|
_audition_note_on = true;
|
2017-09-07 21:32:31 -04:00
|
|
|
_audition_note_num = note;
|
2017-09-09 12:17:42 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::shared_ptr<MidiTrack> mt = std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
2020-09-19 18:59:23 -04:00
|
|
|
mt->write_immediate_event (Evoral::MIDI_EVENT, 3, event);
|
2023-02-16 18:33:28 -05:00
|
|
|
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
|
2020-09-19 18:59:23 -04:00
|
|
|
pi->write_immediate_event (Evoral::MIDI_EVENT, 3, event);
|
2017-09-09 12:17:42 -04:00
|
|
|
}
|
2017-09-07 21:32:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PatchChangeWidget::note_off_event_handler (int note)
|
|
|
|
{
|
|
|
|
uint8_t event[3];
|
|
|
|
event[0] = (MIDI_CMD_NOTE_OFF | _channel);
|
|
|
|
event[1] = note;
|
|
|
|
event[2] = 0;
|
2022-02-08 17:20:40 -05:00
|
|
|
|
2017-09-07 21:32:31 -04:00
|
|
|
_audition_note_on = false;
|
2017-09-09 12:17:42 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::shared_ptr<MidiTrack> mt = std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
2020-09-19 18:59:23 -04:00
|
|
|
mt->write_immediate_event (Evoral::MIDI_EVENT, 3, event);
|
2023-02-16 18:33:28 -05:00
|
|
|
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
|
2020-09-19 18:59:23 -04:00
|
|
|
pi->write_immediate_event (Evoral::MIDI_EVENT, 3, event);
|
2017-09-09 12:17:42 -04:00
|
|
|
}
|
2017-09-07 21:32:31 -04:00
|
|
|
}
|
|
|
|
|
2017-09-07 18:30:55 -04:00
|
|
|
/* ***** query info *****/
|
|
|
|
|
|
|
|
int
|
|
|
|
PatchChangeWidget::bank (uint8_t chn) const
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::shared_ptr<MidiTrack> mt = std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
|
|
|
std::shared_ptr<AutomationControl> bank_msb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_MSB_BANK), true);
|
|
|
|
std::shared_ptr<AutomationControl> bank_lsb = _route->automation_control (Evoral::Parameter (MidiCCAutomation, chn, MIDI_CTL_LSB_BANK), true);
|
2017-09-09 12:17:42 -04:00
|
|
|
|
2022-02-08 17:20:40 -05:00
|
|
|
return ((int)bank_msb->get_value () << 7) + (int)bank_lsb->get_value ();
|
2023-02-16 18:33:28 -05:00
|
|
|
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
|
2022-02-08 17:20:40 -05:00
|
|
|
uint32_t bankpatch = pi->plugin ()->bank_patch (chn);
|
2017-09-09 12:17:42 -04:00
|
|
|
if (bankpatch != UINT32_MAX) {
|
|
|
|
return bankpatch >> 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
|
2017-09-07 21:32:31 -04:00
|
|
|
uint8_t
|
2017-09-07 18:30:55 -04:00
|
|
|
PatchChangeWidget::program (uint8_t chn) const
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::shared_ptr<MidiTrack> mt = std::dynamic_pointer_cast<MidiTrack> (_route)) {
|
|
|
|
std::shared_ptr<AutomationControl> program = _route->automation_control (Evoral::Parameter (MidiPgmChangeAutomation, chn), true);
|
2022-02-08 17:20:40 -05:00
|
|
|
return program->get_value ();
|
2023-02-16 18:33:28 -05:00
|
|
|
} else if (std::shared_ptr<PluginInsert> pi = std::dynamic_pointer_cast<PluginInsert> (_route->the_instrument ())) {
|
2022-02-08 17:20:40 -05:00
|
|
|
uint32_t bankpatch = pi->plugin ()->bank_patch (chn);
|
2017-09-09 12:17:42 -04:00
|
|
|
if (bankpatch != UINT32_MAX) {
|
|
|
|
return bankpatch & 127;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 255;
|
2017-09-07 18:30:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************************************************/
|
|
|
|
|
2022-02-09 12:59:15 -05:00
|
|
|
PatchChangeTriggerWindow::PatchChangeTriggerWindow ()
|
|
|
|
: ArdourWindow (_("Trigger Patch Select"))
|
2022-02-08 17:08:23 -05:00
|
|
|
{
|
|
|
|
for (uint32_t chn = 0; chn < 16; ++chn) {
|
2022-02-09 12:59:15 -05:00
|
|
|
_w[chn] = manage (new PatchChangeTab (chn));
|
2022-02-08 17:08:23 -05:00
|
|
|
_notebook.append_page (*_w[chn], string_compose (_("Chn %1"), chn + 1));
|
|
|
|
}
|
2022-02-09 12:59:15 -05:00
|
|
|
_notebook.show_all ();
|
|
|
|
add (_notebook);
|
|
|
|
|
|
|
|
_notebook.signal_switch_page ().connect (sigc::mem_fun (*this, &PatchChangeTriggerWindow::on_switch_page));
|
2022-02-08 17:08:23 -05:00
|
|
|
|
|
|
|
_notebook.set_current_page (0);
|
2022-02-09 12:59:15 -05:00
|
|
|
}
|
2022-02-08 17:08:23 -05:00
|
|
|
|
2022-02-09 12:59:15 -05:00
|
|
|
void
|
|
|
|
PatchChangeTriggerWindow::clear ()
|
|
|
|
{
|
|
|
|
_route_connection.disconnect ();
|
|
|
|
|
|
|
|
set_title (_("Trigger Patch Select"));
|
|
|
|
|
|
|
|
for (uint32_t chn = 0; chn < 16; ++chn) {
|
2023-02-16 18:33:28 -05:00
|
|
|
_w[chn]->reset (std::shared_ptr<ARDOUR::Route> (), std::shared_ptr<ARDOUR::MIDITrigger>());
|
2022-02-09 12:59:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
PatchChangeTriggerWindow::reset (std::shared_ptr<Route> r, std::shared_ptr<MIDITrigger> t)
|
2022-02-09 12:59:15 -05:00
|
|
|
{
|
|
|
|
if (!r || !t) {
|
|
|
|
clear ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_title (string_compose (_("Select Patch for \"%1\" - \"%2\""), r->name (), t->name ()));
|
|
|
|
|
|
|
|
r->DropReferences.connect (_route_connection, invalidator(*this), boost::bind (&PatchChangeTriggerWindow::clear, this), gui_context());
|
|
|
|
|
2022-02-24 15:33:03 -05:00
|
|
|
/* only show tabs for the chans that this region uses */
|
|
|
|
Evoral::SMF::UsedChannels used = t->used_channels();
|
|
|
|
uint32_t first_used_chan = 15;
|
|
|
|
for (uint32_t chn = 0; chn < 16; ++chn) {
|
|
|
|
if (used.test(chn)) {
|
|
|
|
if (chn < first_used_chan) {
|
|
|
|
first_used_chan = chn;
|
|
|
|
}
|
|
|
|
_w[chn]->show();
|
|
|
|
} else {
|
|
|
|
_w[chn]->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-09 12:59:15 -05:00
|
|
|
for (uint32_t chn = 0; chn < 16; ++chn) {
|
|
|
|
_w[chn]->reset (r, t);
|
|
|
|
}
|
2022-02-24 15:33:03 -05:00
|
|
|
|
|
|
|
_notebook.set_current_page (first_used_chan);
|
2022-02-08 17:08:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-02-09 12:59:15 -05:00
|
|
|
PatchChangeTriggerWindow::on_switch_page (GtkNotebookPage*, guint page_num)
|
2022-02-08 17:08:23 -05:00
|
|
|
{
|
|
|
|
_w[page_num]->refresh ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************************************************/
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
PatchChangeGridDialog::PatchChangeGridDialog (std::shared_ptr<ARDOUR::Route> r)
|
2022-02-08 17:20:40 -05:00
|
|
|
: ArdourDialog (string_compose (_("Select Patch for \"%1\""), r->name ()), false, false)
|
2017-09-07 18:30:55 -04:00
|
|
|
, w (r)
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
r->PropertyChanged.connect (_route_connection, invalidator (*this), boost::bind (&PatchChangeGridDialog::route_property_changed, this, _1, std::weak_ptr<Route> (r)), gui_context ());
|
2022-02-08 17:20:40 -05:00
|
|
|
get_vbox ()->add (w);
|
2017-09-07 18:30:55 -04:00
|
|
|
w.show ();
|
|
|
|
}
|
2017-09-08 13:37:48 -04:00
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
PatchChangeGridDialog::route_property_changed (const PBD::PropertyChange& what_changed, std::weak_ptr<Route> wr)
|
2017-09-08 13:37:48 -04:00
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<ARDOUR::Route> r = wr.lock ();
|
2017-09-08 13:37:48 -04:00
|
|
|
if (r && what_changed.contains (ARDOUR::Properties::name)) {
|
2022-02-08 17:20:40 -05:00
|
|
|
set_title (string_compose (_("Select Patch for \"%1\""), r->name ()));
|
2017-09-08 13:37:48 -04:00
|
|
|
}
|
|
|
|
}
|