2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-03 08:34:29 -04:00
|
|
|
* Copyright (C) 2006-2010 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2006-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2012-2017 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015 Len Ovens <len@ovenwerks.net>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2009-12-28 18:55:33 -05:00
|
|
|
#include <sstream>
|
2008-06-02 17:41:35 -04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2018-06-21 13:05:37 -04:00
|
|
|
#ifdef COMPILER_MSVC
|
|
|
|
#include <io.h> // Microsoft's nearest equivalent to <unistd.h>
|
|
|
|
#include <ardourext/misc.h>
|
|
|
|
#else
|
|
|
|
#include <regex.h>
|
|
|
|
#endif
|
|
|
|
|
2012-06-23 01:09:02 -04:00
|
|
|
#include <glibmm/fileutils.h>
|
2011-03-25 17:21:05 -04:00
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
|
2018-06-21 13:05:37 -04:00
|
|
|
#include "pbd/compose.h"
|
|
|
|
#include "pbd/convert.h"
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/failed_constructor.h"
|
2014-06-17 07:41:29 -04:00
|
|
|
#include "pbd/file_utils.h"
|
2018-06-21 13:05:37 -04:00
|
|
|
#include "pbd/strsplit.h"
|
2016-08-29 20:41:51 -04:00
|
|
|
#include "pbd/types_convert.h"
|
2009-12-29 16:31:14 -05:00
|
|
|
#include "pbd/xml++.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "midi++/port.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2015-12-07 12:04:23 -05:00
|
|
|
#include "ardour/async_midi_port.h"
|
|
|
|
#include "ardour/audioengine.h"
|
2018-06-21 13:05:37 -04:00
|
|
|
#include "ardour/auditioner.h"
|
2009-12-29 16:31:14 -05:00
|
|
|
#include "ardour/filesystem_paths.h"
|
2009-10-29 20:21:40 -04:00
|
|
|
#include "ardour/session.h"
|
2009-12-21 13:23:07 -05:00
|
|
|
#include "ardour/midi_ui.h"
|
2018-06-21 13:05:37 -04:00
|
|
|
#include "ardour/plugin_insert.h"
|
2010-03-25 12:03:31 -04:00
|
|
|
#include "ardour/rc_configuration.h"
|
2013-08-07 22:22:11 -04:00
|
|
|
#include "ardour/midiport_manager.h"
|
2015-07-09 21:16:44 -04:00
|
|
|
#include "ardour/debug.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include "generic_midi_control_protocol.h"
|
|
|
|
#include "midicontrollable.h"
|
2009-12-28 11:49:44 -05:00
|
|
|
#include "midifunction.h"
|
2010-04-08 17:05:55 -04:00
|
|
|
#include "midiaction.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
#include "pbd/abstract_ui.cc" // instantiate template
|
|
|
|
|
2020-08-19 11:39:32 -04:00
|
|
|
#include "pbd/i18n.h"
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
2019-12-31 14:06:00 -05:00
|
|
|
using namespace Glib;
|
2009-12-28 11:49:44 -05:00
|
|
|
using namespace std;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
|
2012-04-23 06:54:34 -04:00
|
|
|
: ControlProtocol (s, _("Generic MIDI"))
|
2019-12-31 14:06:00 -05:00
|
|
|
, AbstractUI<GenericMIDIRequest> (name())
|
2015-12-07 12:04:23 -05:00
|
|
|
, connection_state (ConnectionState (0))
|
2012-03-06 20:11:22 -05:00
|
|
|
, _motorised (false)
|
2012-06-13 17:53:50 -04:00
|
|
|
, _threshold (10)
|
2009-12-29 16:31:14 -05:00
|
|
|
, gui (0)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2019-12-31 14:06:00 -05:00
|
|
|
boost::shared_ptr<ARDOUR::Port> inp;
|
|
|
|
boost::shared_ptr<ARDOUR::Port> outp;
|
|
|
|
|
|
|
|
inp = AudioEngine::instance()->register_input_port (DataType::MIDI, _("MIDI Control In"), true);
|
|
|
|
outp = AudioEngine::instance()->register_output_port (DataType::MIDI, _("MIDI Control Out"), true);
|
|
|
|
|
|
|
|
if (inp == 0 || outp == 0) {
|
|
|
|
throw failed_constructor();
|
|
|
|
}
|
|
|
|
|
|
|
|
_input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(inp);
|
|
|
|
_output_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(outp);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2016-07-08 17:09:44 -04:00
|
|
|
_input_bundle.reset (new ARDOUR::Bundle (_("Generic MIDI Control In"), true));
|
|
|
|
_output_bundle.reset (new ARDOUR::Bundle (_("Generic MIDI Control Out"), false));
|
|
|
|
|
|
|
|
_input_bundle->add_channel (
|
2019-12-31 14:06:00 -05:00
|
|
|
inp->name(),
|
2016-07-08 17:09:44 -04:00
|
|
|
ARDOUR::DataType::MIDI,
|
2019-12-31 14:06:00 -05:00
|
|
|
session->engine().make_port_name_non_relative (inp->name())
|
2016-07-08 17:09:44 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
_output_bundle->add_channel (
|
2019-12-31 14:06:00 -05:00
|
|
|
outp->name(),
|
2016-07-08 17:09:44 -04:00
|
|
|
ARDOUR::DataType::MIDI,
|
2019-12-31 14:06:00 -05:00
|
|
|
session->engine().make_port_name_non_relative (outp->name())
|
2016-07-08 17:09:44 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
session->BundleAddedOrRemoved ();
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
do_feedback = false;
|
|
|
|
_feedback_interval = 10000; // microseconds
|
|
|
|
last_feedback_time = 0;
|
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
_current_bank = 0;
|
|
|
|
_bank_size = 0;
|
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
/* these signals are emitted by our event loop thread
|
2012-04-24 16:27:13 -04:00
|
|
|
* and we may as well handle them right there in the same the same
|
|
|
|
* thread
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2019-03-22 21:09:39 -04:00
|
|
|
Controllable::StartLearning.connect_same_thread (*this, boost::bind (&GenericMidiControlProtocol::start_learning, this, _1));
|
2019-12-31 14:06:00 -05:00
|
|
|
Controllable::StopLearning.connect_same_thread (*this, boost::bind (&GenericMidiControlProtocol::stop_learning, this, _1));
|
2009-12-19 15:26:31 -05:00
|
|
|
|
2012-04-24 15:25:57 -04:00
|
|
|
/* this signal is emitted by the process() callback, and if
|
|
|
|
* send_feedback() is going to do anything, it should do it in the
|
|
|
|
* context of the process() callback itself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Session::SendFeedback.connect_same_thread (*this, boost::bind (&GenericMidiControlProtocol::send_feedback, this));
|
2013-12-13 16:56:34 -05:00
|
|
|
|
2012-04-24 15:25:57 -04:00
|
|
|
/* this one is cross-thread */
|
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
PresentationInfo::Change.connect (*this, MISSING_INVALIDATOR, boost::bind (&GenericMidiControlProtocol::reset_controllables, this), this);
|
2009-12-28 11:49:44 -05:00
|
|
|
|
2015-12-07 12:04:23 -05:00
|
|
|
/* Catch port connections and disconnections (cross-thread) */
|
2021-01-13 14:00:39 -05:00
|
|
|
ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connections, MISSING_INVALIDATOR,
|
2015-12-07 12:04:23 -05:00
|
|
|
boost::bind (&GenericMidiControlProtocol::connection_handler, this, _1, _2, _3, _4, _5),
|
2019-12-31 14:06:00 -05:00
|
|
|
this);
|
2021-01-13 14:00:39 -05:00
|
|
|
ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connections, MISSING_INVALIDATOR, boost::bind (&GenericMidiControlProtocol::ConnectionChange, this), this); /* notify GUI */
|
2015-12-07 12:04:23 -05:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
reload_maps ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
GenericMidiControlProtocol::~GenericMidiControlProtocol ()
|
2009-12-29 16:31:14 -05:00
|
|
|
{
|
2019-12-31 14:06:00 -05:00
|
|
|
if (_input_port) {
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("unregistering input port %1\n", boost::shared_ptr<ARDOUR::Port>(_input_port)->name()));
|
|
|
|
Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock());
|
|
|
|
AudioEngine::instance()->unregister_port (_input_port);
|
|
|
|
_input_port.reset ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_output_port) {
|
|
|
|
_output_port->drain (10000, 250000); /* check every 10 msecs, wait up to 1/4 second for the port to drain */
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("unregistering output port %1\n", boost::shared_ptr<ARDOUR::Port>(_output_port)->name()));
|
|
|
|
Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock());
|
|
|
|
AudioEngine::instance()->unregister_port (_output_port);
|
|
|
|
_output_port.reset ();
|
|
|
|
}
|
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
drop_all ();
|
|
|
|
tear_down_gui ();
|
|
|
|
}
|
|
|
|
|
2016-07-08 17:09:44 -04:00
|
|
|
list<boost::shared_ptr<ARDOUR::Bundle> >
|
|
|
|
GenericMidiControlProtocol::bundles ()
|
|
|
|
{
|
|
|
|
list<boost::shared_ptr<ARDOUR::Bundle> > b;
|
|
|
|
|
|
|
|
if (_input_bundle) {
|
|
|
|
b.push_back (_input_bundle);
|
|
|
|
b.push_back (_output_bundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 17:21:05 -04:00
|
|
|
static const char * const midimap_env_variable_name = "ARDOUR_MIDIMAPS_PATH";
|
2009-12-29 16:31:14 -05:00
|
|
|
static const char* const midi_map_dir_name = "midi_maps";
|
|
|
|
static const char* const midi_map_suffix = ".map";
|
|
|
|
|
2013-08-15 06:04:08 -04:00
|
|
|
Searchpath
|
2009-12-29 16:31:14 -05:00
|
|
|
system_midi_map_search_path ()
|
|
|
|
{
|
2011-03-25 17:21:05 -04:00
|
|
|
bool midimap_path_defined = false;
|
2012-06-23 01:09:42 -04:00
|
|
|
std::string spath_env (Glib::getenv (midimap_env_variable_name, midimap_path_defined));
|
2011-03-25 17:21:05 -04:00
|
|
|
|
|
|
|
if (midimap_path_defined) {
|
|
|
|
return spath_env;
|
|
|
|
}
|
|
|
|
|
2013-08-15 06:04:08 -04:00
|
|
|
Searchpath spath (ardour_data_search_path());
|
2009-12-29 16:31:14 -05:00
|
|
|
spath.add_subdirectory_to_paths(midi_map_dir_name);
|
2013-03-18 11:42:49 -04:00
|
|
|
return spath;
|
2009-12-29 16:31:14 -05:00
|
|
|
}
|
|
|
|
|
2012-06-23 01:09:42 -04:00
|
|
|
static std::string
|
2009-12-29 16:31:14 -05:00
|
|
|
user_midi_map_directory ()
|
|
|
|
{
|
2012-06-23 01:09:42 -04:00
|
|
|
return Glib::build_filename (user_config_directory(), midi_map_dir_name);
|
2009-12-29 16:31:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2013-09-05 04:47:37 -04:00
|
|
|
midi_map_filter (const string &str, void* /*arg*/)
|
2009-12-29 16:31:14 -05:00
|
|
|
{
|
|
|
|
return (str.length() > strlen(midi_map_suffix) &&
|
|
|
|
str.find (midi_map_suffix) == (str.length() - strlen (midi_map_suffix)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::reload_maps ()
|
|
|
|
{
|
2014-06-16 06:39:45 -04:00
|
|
|
vector<string> midi_maps;
|
2013-08-15 06:04:08 -04:00
|
|
|
Searchpath spath (system_midi_map_search_path());
|
2012-06-23 01:09:42 -04:00
|
|
|
spath += user_midi_map_directory ();
|
2009-12-29 16:31:14 -05:00
|
|
|
|
2014-06-19 04:26:17 -04:00
|
|
|
find_files_matching_filter (midi_maps, spath, midi_map_filter, 0, false, true);
|
2009-12-29 16:31:14 -05:00
|
|
|
|
2014-06-16 06:39:45 -04:00
|
|
|
if (midi_maps.empty()) {
|
2009-12-29 16:31:14 -05:00
|
|
|
cerr << "No MIDI maps found using " << spath.to_string() << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-16 06:39:45 -04:00
|
|
|
for (vector<string>::iterator i = midi_maps.begin(); i != midi_maps.end(); ++i) {
|
|
|
|
string fullpath = *i;
|
2009-12-29 16:31:14 -05:00
|
|
|
|
|
|
|
XMLTree tree;
|
|
|
|
|
|
|
|
if (!tree.read (fullpath.c_str())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
MapInfo mi;
|
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
std::string str;
|
|
|
|
if (!tree.root()->get_property ("name", str)) {
|
2009-12-29 16:31:14 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
mi.name = str;
|
2009-12-29 16:31:14 -05:00
|
|
|
mi.path = fullpath;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
map_info.push_back (mi);
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::drop_all ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2015-07-09 21:16:44 -04:00
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "Drop all bindings\n");
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (pending_lock);
|
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2009-12-28 11:49:44 -05:00
|
|
|
|
|
|
|
for (MIDIControllables::iterator i = controllables.begin(); i != controllables.end(); ++i) {
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
controllables.clear ();
|
|
|
|
|
|
|
|
for (MIDIPendingControllables::iterator i = pending_controllables.begin(); i != pending_controllables.end(); ++i) {
|
2017-04-16 12:55:42 -04:00
|
|
|
(*i)->connection.disconnect();
|
|
|
|
if ((*i)->own_mc) {
|
|
|
|
delete (*i)->mc;
|
|
|
|
}
|
2009-12-28 11:49:44 -05:00
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
pending_controllables.clear ();
|
|
|
|
|
|
|
|
for (MIDIFunctions::iterator i = functions.begin(); i != functions.end(); ++i) {
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
functions.clear ();
|
2010-04-08 17:05:55 -04:00
|
|
|
|
|
|
|
for (MIDIActions::iterator i = actions.begin(); i != actions.end(); ++i) {
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
actions.clear ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::drop_bindings ()
|
|
|
|
{
|
2015-07-09 21:16:44 -04:00
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "Drop bindings, leave learned\n");
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2009-12-29 16:31:14 -05:00
|
|
|
|
|
|
|
for (MIDIControllables::iterator i = controllables.begin(); i != controllables.end(); ) {
|
|
|
|
if (!(*i)->learned()) {
|
|
|
|
delete *i;
|
|
|
|
i = controllables.erase (i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MIDIFunctions::iterator i = functions.begin(); i != functions.end(); ++i) {
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
functions.clear ();
|
|
|
|
|
|
|
|
_current_binding = "";
|
|
|
|
_bank_size = 0;
|
|
|
|
_current_bank = 0;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::do_request (GenericMIDIRequest* req)
|
|
|
|
{
|
|
|
|
if (req->type == CallSlot) {
|
|
|
|
|
|
|
|
call_slot (MISSING_INVALIDATOR, req->the_slot);
|
|
|
|
|
|
|
|
} else if (req->type == Quit) {
|
|
|
|
|
|
|
|
stop ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
int
|
2019-12-31 14:06:00 -05:00
|
|
|
GenericMidiControlProtocol::stop ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2019-12-31 14:06:00 -05:00
|
|
|
BaseUI::quit ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::thread_init ()
|
|
|
|
{
|
|
|
|
pthread_set_name (event_loop_name().c_str());
|
|
|
|
|
|
|
|
PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
|
|
|
|
ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
|
|
|
|
|
|
|
|
set_thread_priority ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
GenericMidiControlProtocol::set_active (bool yn)
|
|
|
|
{
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose("GenericMIDI::set_active init with yn: '%1'\n", yn));
|
|
|
|
|
|
|
|
if (yn == active()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yn) {
|
|
|
|
BaseUI::run ();
|
|
|
|
} else {
|
|
|
|
BaseUI::quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlProtocol::set_active (yn);
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose("GenericMIDI::set_active done with yn: '%1'\n", yn));
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::set_feedback_interval (microseconds_t ms)
|
|
|
|
{
|
|
|
|
_feedback_interval = ms;
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
void
|
2008-06-02 17:41:35 -04:00
|
|
|
GenericMidiControlProtocol::send_feedback ()
|
|
|
|
{
|
2012-04-24 16:27:13 -04:00
|
|
|
/* This is executed in RT "process" context", so no blocking calls
|
|
|
|
*/
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (!do_feedback) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
microseconds_t now = get_microseconds ();
|
|
|
|
|
|
|
|
if (last_feedback_time != 0) {
|
|
|
|
if ((now - last_feedback_time) < _feedback_interval) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_send_feedback ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
last_feedback_time = now;
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
void
|
2008-06-02 17:41:35 -04:00
|
|
|
GenericMidiControlProtocol::_send_feedback ()
|
|
|
|
{
|
2012-04-24 16:27:13 -04:00
|
|
|
/* This is executed in RT "process" context", so no blocking calls
|
|
|
|
*/
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
const int32_t bufsize = 16 * 1024; /* XXX too big */
|
|
|
|
MIDI::byte buf[bufsize];
|
|
|
|
int32_t bsize = bufsize;
|
2012-03-06 10:08:17 -05:00
|
|
|
|
|
|
|
/* XXX: due to bugs in some ALSA / JACK MIDI bridges, we have to do separate
|
|
|
|
writes for each controllable here; if we send more than one MIDI message
|
|
|
|
in a single jack_midi_event_write then some bridges will only pass the
|
|
|
|
first on to ALSA.
|
|
|
|
*/
|
2012-06-28 11:37:54 -04:00
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (controllables_lock, Glib::Threads::TRY_LOCK);
|
2012-06-28 11:37:54 -04:00
|
|
|
if (!lm.locked ()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
for (MIDIControllables::iterator r = controllables.begin(); r != controllables.end(); ++r) {
|
2012-03-06 10:08:17 -05:00
|
|
|
MIDI::byte* end = (*r)->write_feedback (buf, bsize);
|
|
|
|
if (end != buf) {
|
|
|
|
_output_port->write (buf, (int32_t) (end - buf), 0);
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2019-03-22 21:09:39 -04:00
|
|
|
GenericMidiControlProtocol::start_learning (boost::weak_ptr <Controllable> wc)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2019-03-22 21:09:39 -04:00
|
|
|
boost::shared_ptr<Controllable> c = wc.lock ();
|
|
|
|
if (!c) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2015-07-20 15:37:53 -04:00
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("Learn binding: Controlable number: %1\n", c));
|
2009-12-28 11:49:44 -05:00
|
|
|
|
2017-01-21 13:20:04 -05:00
|
|
|
/* drop any existing mappings for the same controllable for which
|
|
|
|
* learning has just started.
|
|
|
|
*/
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
MIDIControllables::iterator tmp;
|
|
|
|
for (MIDIControllables::iterator i = controllables.begin(); i != controllables.end(); ) {
|
|
|
|
tmp = i;
|
|
|
|
++tmp;
|
2009-12-10 22:18:17 -05:00
|
|
|
if ((*i)->get_controllable() == c) {
|
2008-06-02 17:41:35 -04:00
|
|
|
delete (*i);
|
|
|
|
controllables.erase (i);
|
|
|
|
}
|
|
|
|
i = tmp;
|
|
|
|
}
|
|
|
|
|
2017-01-21 13:20:04 -05:00
|
|
|
/* check pending controllables (those for which a learn is underway) to
|
|
|
|
* see if it is for the same one for which learning has just started.
|
|
|
|
*/
|
|
|
|
|
2009-12-30 11:48:58 -05:00
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (pending_lock);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-30 11:48:58 -05:00
|
|
|
for (MIDIPendingControllables::iterator i = pending_controllables.begin(); i != pending_controllables.end(); ) {
|
2016-07-21 14:00:18 -04:00
|
|
|
if (((*i)->mc)->get_controllable() == c) {
|
2017-04-16 12:55:42 -04:00
|
|
|
(*i)->connection.disconnect();
|
2016-07-21 14:00:18 -04:00
|
|
|
if ((*i)->own_mc) {
|
|
|
|
delete (*i)->mc;
|
|
|
|
}
|
2009-12-30 11:48:58 -05:00
|
|
|
delete *i;
|
2017-04-16 12:55:42 -04:00
|
|
|
i = pending_controllables.erase (i);
|
|
|
|
} else {
|
|
|
|
++i;
|
2009-12-30 11:48:58 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MIDIControllable* mc = 0;
|
2016-07-21 14:00:18 -04:00
|
|
|
bool own_mc = false;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
for (MIDIControllables::iterator i = controllables.begin(); i != controllables.end(); ++i) {
|
2010-01-03 21:04:05 -05:00
|
|
|
if ((*i)->get_controllable() && ((*i)->get_controllable()->id() == c->id())) {
|
2008-06-02 17:41:35 -04:00
|
|
|
mc = *i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mc) {
|
2019-03-22 21:09:39 -04:00
|
|
|
mc = new MIDIControllable (this, *_input_port->parser(), c, false);
|
2016-07-21 14:00:18 -04:00
|
|
|
own_mc = true;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-01-21 13:20:04 -05:00
|
|
|
/* stuff the new controllable into pending */
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (pending_lock);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2016-07-21 14:00:18 -04:00
|
|
|
MIDIPendingControllable* element = new MIDIPendingControllable (mc, own_mc);
|
|
|
|
c->LearningFinished.connect_same_thread (element->connection, boost::bind (&GenericMidiControlProtocol::learning_stopped, this, mc));
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
pending_controllables.push_back (element);
|
|
|
|
}
|
|
|
|
mc->learn_about_external_control ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::learning_stopped (MIDIControllable* mc)
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (pending_lock);
|
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
for (MIDIPendingControllables::iterator i = pending_controllables.begin(); i != pending_controllables.end(); ) {
|
2016-07-21 14:00:18 -04:00
|
|
|
if ( (*i)->mc == mc) {
|
|
|
|
(*i)->connection.disconnect();
|
2009-12-20 11:50:41 -05:00
|
|
|
delete *i;
|
2017-04-16 12:55:42 -04:00
|
|
|
i = pending_controllables.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 13:20:04 -05:00
|
|
|
/* add the controllable for which learning stopped to our list of
|
|
|
|
* controllables
|
|
|
|
*/
|
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
controllables.push_back (mc);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-03-22 21:09:39 -04:00
|
|
|
GenericMidiControlProtocol::stop_learning (boost::weak_ptr<PBD::Controllable> wc)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2019-03-22 21:09:39 -04:00
|
|
|
boost::shared_ptr<Controllable> c = wc.lock ();
|
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (pending_lock);
|
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2008-06-02 17:41:35 -04:00
|
|
|
MIDIControllable* dptr = 0;
|
|
|
|
|
|
|
|
/* learning timed out, and we've been told to consider this attempt to learn to be cancelled. find the
|
|
|
|
relevant MIDIControllable and remove it from the pending list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (MIDIPendingControllables::iterator i = pending_controllables.begin(); i != pending_controllables.end(); ++i) {
|
2016-07-21 14:00:18 -04:00
|
|
|
if (((*i)->mc)->get_controllable() == c) {
|
|
|
|
(*i)->mc->stop_learning ();
|
|
|
|
dptr = (*i)->mc;
|
|
|
|
(*i)->connection.disconnect();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-12-20 11:50:41 -05:00
|
|
|
delete *i;
|
2008-06-02 17:41:35 -04:00
|
|
|
pending_controllables.erase (i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-12-18 14:31:00 -05:00
|
|
|
delete dptr;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2015-07-20 15:37:53 -04:00
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::check_used_event (int pos, int control_number)
|
|
|
|
{
|
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
|
|
|
|
|
|
|
MIDI::channel_t channel = (pos & 0xf);
|
|
|
|
MIDI::byte value = control_number;
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("checking for used event: Channel: %1 Controller: %2 value: %3\n", (int) channel, (pos & 0xf0), (int) value));
|
|
|
|
|
|
|
|
// Remove any old binding for this midi channel/type/value pair
|
|
|
|
for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end();) {
|
|
|
|
MIDIControllable* existingBinding = (*iter);
|
|
|
|
if ( (existingBinding->get_control_type() & 0xf0 ) == (pos & 0xf0) && (existingBinding->get_control_channel() & 0xf ) == channel ) {
|
|
|
|
if ( ((int) existingBinding->get_control_additional() == (int) value) || ((pos & 0xf0) == MIDI::pitchbend)) {
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "checking: found match, delete old binding.\n");
|
|
|
|
delete existingBinding;
|
|
|
|
iter = controllables.erase (iter);
|
|
|
|
} else {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MIDIFunctions::iterator iter = functions.begin(); iter != functions.end();) {
|
|
|
|
MIDIFunction* existingBinding = (*iter);
|
|
|
|
if ( (existingBinding->get_control_type() & 0xf0 ) == (pos & 0xf0) && (existingBinding->get_control_channel() & 0xf ) == channel ) {
|
|
|
|
if ( ((int) existingBinding->get_control_additional() == (int) value) || ((pos & 0xf0) == MIDI::pitchbend)) {
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "checking: found match, delete old binding.\n");
|
|
|
|
delete existingBinding;
|
|
|
|
iter = functions.erase (iter);
|
|
|
|
} else {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MIDIActions::iterator iter = actions.begin(); iter != actions.end();) {
|
|
|
|
MIDIAction* existingBinding = (*iter);
|
|
|
|
if ( (existingBinding->get_control_type() & 0xf0 ) == (pos & 0xf0) && (existingBinding->get_control_channel() & 0xf ) == channel ) {
|
|
|
|
if ( ((int) existingBinding->get_control_additional() == (int) value) || ((pos & 0xf0) == MIDI::pitchbend)) {
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "checking: found match, delete old binding.\n");
|
|
|
|
delete existingBinding;
|
|
|
|
iter = actions.erase (iter);
|
|
|
|
} else {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLNode&
|
2015-10-04 14:51:05 -04:00
|
|
|
GenericMidiControlProtocol::get_state ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2013-12-21 15:28:47 -05:00
|
|
|
XMLNode& node (ControlProtocol::get_state());
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
|
|
|
|
XMLNode* child;
|
|
|
|
|
|
|
|
child = new XMLNode (X_("Input"));
|
|
|
|
child->add_child_nocopy (boost::shared_ptr<ARDOUR::Port>(_input_port)->get_state());
|
|
|
|
node.add_child_nocopy (*child);
|
|
|
|
|
|
|
|
child = new XMLNode (X_("Output"));
|
|
|
|
child->add_child_nocopy (boost::shared_ptr<ARDOUR::Port>(_output_port)->get_state());
|
|
|
|
node.add_child_nocopy (*child);
|
|
|
|
|
2017-05-25 08:02:32 -04:00
|
|
|
node.set_property (X_("feedback-interval"), _feedback_interval);
|
2016-08-29 20:41:51 -04:00
|
|
|
node.set_property (X_("threshold"), _threshold);
|
|
|
|
node.set_property (X_("motorized"), _motorised);
|
2015-08-19 18:19:06 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
if (!_current_binding.empty()) {
|
2016-08-29 20:41:51 -04:00
|
|
|
node.set_property ("binding", _current_binding);
|
2009-12-29 16:31:14 -05:00
|
|
|
}
|
|
|
|
|
2010-11-27 12:43:32 -05:00
|
|
|
XMLNode* children = new XMLNode (X_("Controls"));
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-12-21 15:28:47 -05:00
|
|
|
node.add_child_nocopy (*children);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2008-06-02 17:41:35 -04:00
|
|
|
for (MIDIControllables::iterator i = controllables.begin(); i != controllables.end(); ++i) {
|
2009-12-29 16:31:14 -05:00
|
|
|
|
|
|
|
/* we don't care about bindings that come from a bindings map, because
|
|
|
|
they will all be reset/recreated when we load the relevant bindings
|
|
|
|
file.
|
|
|
|
*/
|
|
|
|
|
2012-12-18 20:19:48 -05:00
|
|
|
if ((*i)->get_controllable() && (*i)->learned()) {
|
2009-12-29 16:31:14 -05:00
|
|
|
children->add_child_nocopy ((*i)->get_state());
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2013-12-21 15:28:47 -05:00
|
|
|
return node;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2009-10-14 20:57:55 -04:00
|
|
|
GenericMidiControlProtocol::set_state (const XMLNode& node, int version)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
XMLNodeList nlist;
|
|
|
|
XMLNodeConstIterator niter;
|
2019-12-31 14:06:00 -05:00
|
|
|
XMLNode const* child;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2015-06-24 13:46:07 -04:00
|
|
|
if (ControlProtocol::set_state (node, version)) {
|
|
|
|
return -1;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
if ((child = node.child (X_("Input"))) != 0) {
|
|
|
|
XMLNode* portnode = child->child (Port::state_node_name.c_str());
|
|
|
|
if (portnode) {
|
|
|
|
boost::shared_ptr<ARDOUR::Port>(_input_port)->set_state (*portnode, version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((child = node.child (X_("Output"))) != 0) {
|
|
|
|
XMLNode* portnode = child->child (Port::state_node_name.c_str());
|
|
|
|
if (portnode) {
|
|
|
|
boost::shared_ptr<ARDOUR::Port>(_output_port)->set_state (*portnode, version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-25 08:02:32 -04:00
|
|
|
if (!node.get_property ("feedback-interval", _feedback_interval)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
_feedback_interval = 10000;
|
|
|
|
}
|
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
if (!node.get_property ("threshold", _threshold)) {
|
2013-06-10 12:37:09 -04:00
|
|
|
_threshold = 10;
|
|
|
|
}
|
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
if (!node.get_property ("motorized", _motorised)) {
|
2015-08-19 18:19:06 -04:00
|
|
|
_motorised = false;
|
|
|
|
}
|
|
|
|
|
2009-12-21 13:23:07 -05:00
|
|
|
boost::shared_ptr<Controllable> c;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-21 13:23:07 -05:00
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (pending_lock);
|
2009-12-21 13:23:07 -05:00
|
|
|
for (MIDIPendingControllables::iterator i = pending_controllables.begin(); i != pending_controllables.end(); ++i) {
|
2017-04-16 12:55:42 -04:00
|
|
|
(*i)->connection.disconnect();
|
|
|
|
if ((*i)->own_mc) {
|
|
|
|
delete (*i)->mc;
|
|
|
|
}
|
2009-12-21 13:23:07 -05:00
|
|
|
delete *i;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-12-21 13:23:07 -05:00
|
|
|
pending_controllables.clear ();
|
|
|
|
}
|
2009-12-29 16:31:14 -05:00
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
std::string str;
|
2015-07-13 16:47:00 -04:00
|
|
|
// midi map has to be loaded first so learned binding can go on top
|
2016-08-29 20:41:51 -04:00
|
|
|
if (node.get_property ("binding", str)) {
|
2015-07-13 16:47:00 -04:00
|
|
|
for (list<MapInfo>::iterator x = map_info.begin(); x != map_info.end(); ++x) {
|
2016-08-29 20:41:51 -04:00
|
|
|
if (str == (*x).name) {
|
2015-07-13 16:47:00 -04:00
|
|
|
load_bindings ((*x).path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-06 09:13:39 -04:00
|
|
|
/* Load up specific bindings from the
|
|
|
|
* <Controls><MidiControllable>...</MidiControllable><Controls> section
|
|
|
|
*/
|
|
|
|
|
2018-10-03 20:30:21 -04:00
|
|
|
bool load_dynamic_bindings = false;
|
|
|
|
node.get_property ("session-state", load_dynamic_bindings);
|
|
|
|
|
|
|
|
if (load_dynamic_bindings) {
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2019-12-31 14:06:00 -05:00
|
|
|
XMLNode* controls_node = node.child (X_("Controls"));
|
2012-10-17 10:36:40 -04:00
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
if (controls_node) {
|
|
|
|
|
|
|
|
nlist = controls_node->children();
|
2013-01-06 09:39:27 -05:00
|
|
|
|
2013-04-06 09:13:39 -04:00
|
|
|
if (!nlist.empty()) {
|
2019-12-31 14:06:00 -05:00
|
|
|
|
2013-04-06 09:13:39 -04:00
|
|
|
for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
PBD::ID id;
|
2019-12-31 14:06:00 -05:00
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
if ((*niter)->get_property ("id", id)) {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-07-14 19:21:19 -04:00
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("Relearned binding for session: Control ID: %1\n", id.to_s()));
|
2019-03-22 22:11:54 -04:00
|
|
|
boost::shared_ptr<PBD::Controllable> c = Controllable::by_id (id);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-06 09:13:39 -04:00
|
|
|
if (c) {
|
2019-03-22 21:09:39 -04:00
|
|
|
MIDIControllable* mc = new MIDIControllable (this, *_input_port->parser(), c, false);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-06 09:13:39 -04:00
|
|
|
if (mc->set_state (**niter, version) == 0) {
|
|
|
|
controllables.push_back (mc);
|
2017-04-16 12:55:42 -04:00
|
|
|
} else {
|
|
|
|
warning << string_compose ("Generic MIDI control: Failed to set state for Control ID: %1\n", id.to_s());
|
|
|
|
delete mc;
|
2013-04-06 09:13:39 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-06 09:13:39 -04:00
|
|
|
} else {
|
|
|
|
warning << string_compose (
|
|
|
|
_("Generic MIDI control: controllable %1 not found in session (ignored)"),
|
2015-07-10 23:17:02 -04:00
|
|
|
id.to_s()) << endmsg;
|
2013-04-06 09:13:39 -04:00
|
|
|
}
|
|
|
|
}
|
2009-12-29 16:31:14 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
2009-02-18 15:57:58 -05:00
|
|
|
}
|
2009-12-29 16:31:14 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
GenericMidiControlProtocol::set_feedback (bool yn)
|
|
|
|
{
|
|
|
|
do_feedback = yn;
|
|
|
|
last_feedback_time = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GenericMidiControlProtocol::get_feedback () const
|
|
|
|
{
|
|
|
|
return do_feedback;
|
|
|
|
}
|
2009-02-18 15:57:58 -05:00
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
int
|
|
|
|
GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
|
|
|
{
|
2015-07-09 21:16:44 -04:00
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "Load bindings: Reading midi map\n");
|
2009-12-28 11:49:44 -05:00
|
|
|
XMLTree state_tree;
|
|
|
|
|
2017-12-19 11:43:06 -05:00
|
|
|
if (!state_tree.read (xmlpath.c_str())) {
|
2009-12-28 11:49:44 -05:00
|
|
|
error << string_compose(_("Could not understand MIDI bindings file %1"), xmlpath) << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode* root = state_tree.root();
|
|
|
|
|
|
|
|
if (root->name() != X_("ArdourMIDIBindings")) {
|
|
|
|
error << string_compose (_("MIDI Bindings file %1 is not really a MIDI bindings file"), xmlpath) << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const XMLProperty* prop;
|
|
|
|
|
|
|
|
if ((prop = root->property ("version")) == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
const XMLNodeList& children (root->children());
|
|
|
|
XMLNodeConstIterator citer;
|
|
|
|
XMLNodeConstIterator gciter;
|
|
|
|
|
|
|
|
MIDIControllable* mc;
|
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
drop_all ();
|
|
|
|
|
2015-07-09 21:16:44 -04:00
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "Loading bindings\n");
|
2009-12-28 11:49:44 -05:00
|
|
|
for (citer = children.begin(); citer != children.end(); ++citer) {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
if ((*citer)->name() == "DeviceInfo") {
|
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
if ((*citer)->get_property ("bank-size", _bank_size)) {
|
2009-12-29 16:31:14 -05:00
|
|
|
_current_bank = 0;
|
|
|
|
}
|
2012-03-06 20:11:22 -05:00
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
if (!(*citer)->get_property ("motorized", _motorised)) {
|
2012-03-06 20:11:22 -05:00
|
|
|
_motorised = false;
|
|
|
|
}
|
2012-06-13 17:53:50 -04:00
|
|
|
|
2016-08-29 20:41:51 -04:00
|
|
|
if (!(*citer)->get_property ("threshold", _threshold)) {
|
2012-06-13 17:53:50 -04:00
|
|
|
_threshold = 10;
|
|
|
|
}
|
2009-12-29 16:31:14 -05:00
|
|
|
}
|
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
if ((*citer)->name() == "Binding") {
|
|
|
|
const XMLNode* child = *citer;
|
|
|
|
|
|
|
|
if (child->property ("uri")) {
|
|
|
|
/* controllable */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-04-16 12:55:42 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2009-12-28 11:49:44 -05:00
|
|
|
if ((mc = create_binding (*child)) != 0) {
|
2009-12-29 16:31:14 -05:00
|
|
|
controllables.push_back (mc);
|
2009-12-28 11:49:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (child->property ("function")) {
|
|
|
|
|
|
|
|
/* function */
|
|
|
|
MIDIFunction* mf;
|
|
|
|
|
|
|
|
if ((mf = create_function (*child)) != 0) {
|
|
|
|
functions.push_back (mf);
|
|
|
|
}
|
2010-04-08 17:05:55 -04:00
|
|
|
|
|
|
|
} else if (child->property ("action")) {
|
2016-08-29 20:41:51 -04:00
|
|
|
MIDIAction* ma;
|
2010-04-08 17:05:55 -04:00
|
|
|
|
|
|
|
if ((ma = create_action (*child)) != 0) {
|
|
|
|
actions.push_back (ma);
|
|
|
|
}
|
2016-08-29 20:41:51 -04:00
|
|
|
}
|
2009-12-28 11:49:44 -05:00
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
if ((prop = root->property ("name")) != 0) {
|
|
|
|
_current_binding = prop->value ();
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_controllables ();
|
2009-12-28 11:49:44 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
MIDIControllable*
|
|
|
|
GenericMidiControlProtocol::create_binding (const XMLNode& node)
|
|
|
|
{
|
|
|
|
const XMLProperty* prop;
|
2009-12-29 16:31:14 -05:00
|
|
|
MIDI::byte detail;
|
|
|
|
MIDI::channel_t channel;
|
2009-12-28 11:49:44 -05:00
|
|
|
string uri;
|
|
|
|
MIDI::eventType ev;
|
2009-12-29 16:31:14 -05:00
|
|
|
int intval;
|
2010-01-01 13:14:32 -05:00
|
|
|
bool momentary;
|
2018-03-03 08:04:12 -05:00
|
|
|
MIDIControllable::CtlType ctltype;
|
2015-07-24 20:34:22 -04:00
|
|
|
MIDIControllable::Encoder encoder = MIDIControllable::No_enc;
|
2015-11-23 12:26:23 -05:00
|
|
|
bool rpn_value = false;
|
|
|
|
bool nrpn_value = false;
|
|
|
|
bool rpn_change = false;
|
|
|
|
bool nrpn_change = false;
|
2009-12-28 11:49:44 -05:00
|
|
|
|
|
|
|
if ((prop = node.property (X_("ctl"))) != 0) {
|
2018-03-03 08:04:12 -05:00
|
|
|
ctltype = MIDIControllable::Ctl_Momentary;
|
|
|
|
ev = MIDI::controller;
|
|
|
|
} else if ((prop = node.property (X_("ctl-toggle"))) !=0) {
|
|
|
|
ctltype = MIDIControllable::Ctl_Toggle;
|
2009-12-28 11:49:44 -05:00
|
|
|
ev = MIDI::controller;
|
2018-06-21 22:28:11 -04:00
|
|
|
} else if ((prop = node.property (X_("ctl-dial"))) !=0) {
|
|
|
|
ctltype = MIDIControllable::Ctl_Dial;
|
|
|
|
ev = MIDI::controller;
|
2009-12-28 11:49:44 -05:00
|
|
|
} else if ((prop = node.property (X_("note"))) != 0) {
|
|
|
|
ev = MIDI::on;
|
|
|
|
} else if ((prop = node.property (X_("pgm"))) != 0) {
|
|
|
|
ev = MIDI::program;
|
2012-03-06 10:08:17 -05:00
|
|
|
} else if ((prop = node.property (X_("pb"))) != 0) {
|
|
|
|
ev = MIDI::pitchbend;
|
2015-07-24 20:34:22 -04:00
|
|
|
} else if ((prop = node.property (X_("enc-l"))) != 0) {
|
|
|
|
encoder = MIDIControllable::Enc_L;
|
|
|
|
ev = MIDI::controller;
|
|
|
|
} else if ((prop = node.property (X_("enc-r"))) != 0) {
|
|
|
|
encoder = MIDIControllable::Enc_R;
|
|
|
|
ev = MIDI::controller;
|
|
|
|
} else if ((prop = node.property (X_("enc-2"))) != 0) {
|
|
|
|
encoder = MIDIControllable::Enc_2;
|
|
|
|
ev = MIDI::controller;
|
|
|
|
} else if ((prop = node.property (X_("enc-b"))) != 0) {
|
|
|
|
encoder = MIDIControllable::Enc_B;
|
2015-07-21 02:15:53 -04:00
|
|
|
ev = MIDI::controller;
|
2015-11-23 12:26:23 -05:00
|
|
|
} else if ((prop = node.property (X_("rpn"))) != 0) {
|
|
|
|
rpn_value = true;
|
|
|
|
} else if ((prop = node.property (X_("nrpn"))) != 0) {
|
|
|
|
nrpn_value = true;
|
|
|
|
} else if ((prop = node.property (X_("rpn-delta"))) != 0) {
|
|
|
|
rpn_change = true;
|
|
|
|
} else if ((prop = node.property (X_("nrpn-delta"))) != 0) {
|
|
|
|
nrpn_change = true;
|
2009-12-28 11:49:44 -05:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
2009-12-28 11:49:44 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
detail = (MIDI::byte) intval;
|
2009-12-28 11:49:44 -05:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
if ((prop = node.property (X_("channel"))) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
channel = (MIDI::channel_t) intval;
|
|
|
|
/* adjust channel to zero-based counting */
|
|
|
|
if (channel > 0) {
|
|
|
|
channel -= 1;
|
|
|
|
}
|
2010-01-01 13:14:32 -05:00
|
|
|
|
|
|
|
if ((prop = node.property (X_("momentary"))) != 0) {
|
2016-08-31 00:45:16 -04:00
|
|
|
momentary = string_to<bool> (prop->value());
|
2010-01-01 13:14:32 -05:00
|
|
|
} else {
|
|
|
|
momentary = false;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
prop = node.property (X_("uri"));
|
|
|
|
uri = prop->value();
|
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
MIDIControllable* mc = new MIDIControllable (this, *_input_port->parser(), momentary);
|
2009-12-30 07:41:10 -05:00
|
|
|
|
|
|
|
if (mc->init (uri)) {
|
|
|
|
delete mc;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-23 12:26:23 -05:00
|
|
|
if (rpn_value) {
|
|
|
|
mc->bind_rpn_value (channel, detail);
|
|
|
|
} else if (nrpn_value) {
|
|
|
|
mc->bind_nrpn_value (channel, detail);
|
|
|
|
} else if (rpn_change) {
|
|
|
|
mc->bind_rpn_change (channel, detail);
|
|
|
|
} else if (nrpn_change) {
|
|
|
|
mc->bind_nrpn_change (channel, detail);
|
|
|
|
} else {
|
2018-03-03 08:04:12 -05:00
|
|
|
mc->set_ctltype (ctltype);
|
2015-11-23 12:26:23 -05:00
|
|
|
mc->set_encoder (encoder);
|
|
|
|
mc->bind_midi (channel, ev, detail);
|
|
|
|
}
|
2009-12-28 11:49:44 -05:00
|
|
|
|
|
|
|
return mc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::reset_controllables ()
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm2 (controllables_lock);
|
2011-08-10 11:57:03 -04:00
|
|
|
|
|
|
|
for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end(); ) {
|
2009-12-28 11:49:44 -05:00
|
|
|
MIDIControllable* existingBinding = (*iter);
|
2011-08-10 11:57:03 -04:00
|
|
|
MIDIControllables::iterator next = iter;
|
|
|
|
++next;
|
2009-12-29 16:31:14 -05:00
|
|
|
|
|
|
|
if (!existingBinding->learned()) {
|
2009-12-31 18:43:47 -05:00
|
|
|
|
2011-08-10 11:57:03 -04:00
|
|
|
/* its entirely possible that the session doesn't have
|
|
|
|
* the specified controllable (e.g. it has too few
|
2012-06-25 08:33:13 -04:00
|
|
|
* tracks). if we find this to be the case, we just leave
|
|
|
|
* the binding around, unbound, and it will do "late
|
|
|
|
* binding" (or "lazy binding") if/when any data arrives.
|
2011-08-10 11:57:03 -04:00
|
|
|
*/
|
|
|
|
|
2012-06-28 10:44:29 -04:00
|
|
|
existingBinding->lookup_controllable ();
|
2009-12-29 16:31:14 -05:00
|
|
|
}
|
2011-08-10 11:57:03 -04:00
|
|
|
|
|
|
|
iter = next;
|
2009-12-28 11:49:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-25 08:33:13 -04:00
|
|
|
boost::shared_ptr<Controllable>
|
2018-06-21 13:05:37 -04:00
|
|
|
GenericMidiControlProtocol::lookup_controllable (const string & str) const
|
2012-06-25 08:33:13 -04:00
|
|
|
{
|
2018-06-21 13:05:37 -04:00
|
|
|
boost::shared_ptr<Controllable> c;
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("lookup controllable from \"%1\"\n", str));
|
|
|
|
|
|
|
|
if (!session) {
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "no session\n");
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* step 1: split string apart */
|
|
|
|
|
|
|
|
string::size_type first_space = str.find_first_of (" ");
|
|
|
|
|
|
|
|
if (first_space == string::npos) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
string front = str.substr (0, first_space);
|
|
|
|
vector<string> path;
|
|
|
|
split (front, path, '/');
|
|
|
|
|
|
|
|
if (path.size() < 2) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
string back = str.substr (first_space);
|
|
|
|
vector<string> rest;
|
|
|
|
split (back, rest, ' ');
|
|
|
|
|
|
|
|
if (rest.empty()) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("parsed into path of %1, rest of %1\n", path.size(), rest.size()));
|
|
|
|
|
|
|
|
/* Step 2: analyse parts of the string to figure out what type of
|
|
|
|
* Stripable we're looking for
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
Selection,
|
|
|
|
PresentationOrder,
|
|
|
|
Named,
|
|
|
|
};
|
|
|
|
Type type = Named;
|
|
|
|
int id = 1;
|
|
|
|
string name;
|
|
|
|
|
|
|
|
static regex_t compiled_pattern;
|
|
|
|
static bool compiled = false;
|
|
|
|
|
|
|
|
if (!compiled) {
|
|
|
|
const char * const pattern = "^[BS]?[0-9]+";
|
|
|
|
/* this pattern compilation is not going to fail */
|
|
|
|
regcomp (&compiled_pattern, pattern, REG_EXTENDED|REG_NOSUB);
|
|
|
|
/* leak compiled pattern */
|
|
|
|
compiled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Step 3: identify what "rest" looks like - name, or simple nueric, or
|
|
|
|
* banked/selection specifier
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool matched = (regexec (&compiled_pattern, rest[0].c_str(), 0, 0, 0) == 0);
|
|
|
|
|
|
|
|
if (matched) {
|
|
|
|
bool banked = false;
|
|
|
|
|
|
|
|
if (rest[0][0] == 'B') {
|
|
|
|
banked = true;
|
|
|
|
/* already matched digits, so we know atoi() will succeed */
|
|
|
|
id = atoi (rest[0].substr (1));
|
|
|
|
type = PresentationOrder;
|
|
|
|
} else if (rest[0][0] == 'S') {
|
|
|
|
/* already matched digits, so we know atoi() will succeed */
|
|
|
|
id = atoi (rest[0].substr (1));
|
|
|
|
type = Selection;
|
|
|
|
} else if (isdigit (rest[0][0])) {
|
|
|
|
/* already matched digits, so we know atoi() will succeed */
|
|
|
|
id = atoi (rest[0]);
|
|
|
|
type = PresentationOrder;
|
|
|
|
} else {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
id -= 1; /* order is zero-based, but maps use 1-based */
|
|
|
|
|
|
|
|
if (banked) {
|
|
|
|
id += _current_bank * _bank_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
type = Named;
|
|
|
|
name = rest[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* step 4: find the reference Stripable */
|
|
|
|
|
|
|
|
boost::shared_ptr<Stripable> s;
|
|
|
|
|
|
|
|
if (path[0] == X_("route") || path[0] == X_("rid")) {
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case PresentationOrder:
|
|
|
|
s = session->get_remote_nth_stripable (id, PresentationInfo::Route);
|
|
|
|
break;
|
|
|
|
case Named:
|
|
|
|
/* name */
|
|
|
|
name = rest[0];
|
|
|
|
|
|
|
|
if (name == "Master" || name == X_("master")) {
|
|
|
|
s = session->master_out();
|
|
|
|
} else if (name == X_("control") || name == X_("listen") || name == X_("monitor") || name == "Monitor") {
|
|
|
|
s = session->monitor_out();
|
|
|
|
} else if (name == X_("auditioner")) {
|
|
|
|
s = session->the_auditioner();
|
|
|
|
} else {
|
|
|
|
s = session->route_by_name (name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Selection:
|
|
|
|
s = session->route_by_selected_count (id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (path[0] == X_("vca")) {
|
|
|
|
|
|
|
|
s = session->get_remote_nth_stripable (id, PresentationInfo::VCA);
|
|
|
|
|
|
|
|
} else if (path[0] == X_("bus")) {
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case Named:
|
|
|
|
s = session->route_by_name (name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s = session->get_remote_nth_stripable (id, PresentationInfo::Bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (path[0] == X_("track")) {
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case Named:
|
|
|
|
s = session->route_by_name (name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
s = session->get_remote_nth_stripable (id, PresentationInfo::Track);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("no stripable found for \"%1\"\n", str));
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("found stripable %1\n", s->name()));
|
|
|
|
|
|
|
|
/* step 5: find the referenced controllable for that stripable.
|
|
|
|
*
|
|
|
|
* Some controls exist only for Route, so we need that too
|
|
|
|
*/
|
|
|
|
|
|
|
|
boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s);
|
|
|
|
|
|
|
|
if (path[1] == X_("gain")) {
|
|
|
|
c = s->gain_control();
|
|
|
|
} else if (path[1] == X_("trim")) {
|
|
|
|
c = s->trim_control ();
|
|
|
|
} else if (path[1] == X_("solo")) {
|
|
|
|
c = s->solo_control();
|
|
|
|
} else if (path[1] == X_("mute")) {
|
|
|
|
c = s->mute_control();
|
|
|
|
} else if (path[1] == X_("recenable")) {
|
|
|
|
c = s->rec_enable_control ();
|
|
|
|
} else if (path[1] == X_("panwidth")) {
|
|
|
|
c = s->pan_width_control ();
|
|
|
|
} else if (path[1] == X_("pandirection") || path[1] == X_("balance")) {
|
|
|
|
c = s->pan_azimuth_control ();
|
|
|
|
} else if (path[1] == X_("plugin")) {
|
|
|
|
|
|
|
|
/* /route/plugin/parameter */
|
|
|
|
|
|
|
|
if (path.size() == 3 && rest.size() == 3) {
|
|
|
|
if (path[2] == X_("parameter")) {
|
|
|
|
|
|
|
|
int plugin = atoi (rest[1]);
|
|
|
|
int parameter_index = atoi (rest[2]);
|
|
|
|
|
|
|
|
/* revert to zero based counting */
|
|
|
|
if (plugin > 0) {
|
|
|
|
--plugin;
|
|
|
|
}
|
|
|
|
if (parameter_index > 0) {
|
|
|
|
--parameter_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r) {
|
|
|
|
boost::shared_ptr<Processor> proc = r->nth_plugin (plugin);
|
|
|
|
|
|
|
|
if (proc) {
|
|
|
|
boost::shared_ptr<PluginInsert> p = boost::dynamic_pointer_cast<PluginInsert> (proc);
|
|
|
|
if (p) {
|
|
|
|
uint32_t param;
|
|
|
|
bool ok;
|
|
|
|
param = p->plugin()->nth_parameter (parameter_index, ok);
|
|
|
|
if (ok) {
|
|
|
|
c = boost::dynamic_pointer_cast<Controllable> (proc->control (Evoral::Parameter (PluginAutomation, 0, param)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (path[1] == X_("send")) {
|
|
|
|
|
|
|
|
if (path.size() == 3 && rest.size() == 2) {
|
|
|
|
if (path[2] == X_("gain")) {
|
|
|
|
uint32_t send = atoi (rest[1]);
|
|
|
|
if (send > 0) {
|
|
|
|
--send;
|
|
|
|
}
|
|
|
|
c = s->send_level_controllable (send);
|
|
|
|
} else if (path[2] == X_("direction")) {
|
|
|
|
/* XXX not implemented yet */
|
|
|
|
|
|
|
|
} else if (path[2] == X_("enable")) {
|
|
|
|
/* XXX not implemented yet */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (path[1] == X_("eq")) {
|
|
|
|
|
|
|
|
/* /route/eq/enable */
|
|
|
|
/* /route/eq/gain/<band> */
|
|
|
|
/* /route/eq/freq/<band> */
|
|
|
|
/* /route/eq/q/<band> */
|
|
|
|
/* /route/eq/shape/<band> */
|
|
|
|
|
|
|
|
if (path.size() == 3) {
|
|
|
|
|
|
|
|
if (path[2] == X_("enable")) {
|
|
|
|
c = s->eq_enable_controllable ();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (path.size() == 4) {
|
|
|
|
|
|
|
|
int band = atoi (path[3]); /* band number */
|
|
|
|
|
|
|
|
if (path[2] == X_("gain")) {
|
|
|
|
c = s->eq_gain_controllable (band);
|
|
|
|
} else if (path[2] == X_("freq")) {
|
|
|
|
c = s->eq_freq_controllable (band);
|
|
|
|
} else if (path[2] == X_("q")) {
|
|
|
|
c = s->eq_q_controllable (band);
|
|
|
|
} else if (path[2] == X_("shape")) {
|
|
|
|
c = s->eq_shape_controllable (band);
|
|
|
|
}
|
|
|
|
}
|
2018-06-25 10:06:44 -04:00
|
|
|
|
2018-06-21 13:05:37 -04:00
|
|
|
} else if (path[1] == X_("filter")) {
|
|
|
|
|
|
|
|
/* /route/filter/hi/freq */
|
|
|
|
|
|
|
|
if (path.size() == 4) {
|
|
|
|
|
|
|
|
int filter;
|
|
|
|
|
|
|
|
if (path[2] == X_("hi")) {
|
|
|
|
filter = 1; /* high pass filter */
|
|
|
|
} else {
|
|
|
|
filter = 0; /* low pass filter */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path[3] == X_("enable")) {
|
|
|
|
c = s->filter_enable_controllable (filter);
|
|
|
|
} else if (path[3] == X_("freq")) {
|
|
|
|
c = s->filter_freq_controllable (filter);
|
|
|
|
} else if (path[3] == X_("slope")) {
|
|
|
|
c = s->filter_slope_controllable (filter);
|
|
|
|
}
|
|
|
|
|
2018-06-25 10:06:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (path[1] == X_("compressor")) {
|
|
|
|
|
|
|
|
if (path.size() == 3) {
|
|
|
|
if (path[2] == X_("enable")) {
|
|
|
|
c = s->comp_enable_controllable ();
|
|
|
|
} else if (path[2] == X_("threshold")) {
|
|
|
|
c = s->comp_threshold_controllable ();
|
|
|
|
} else if (path[2] == X_("mode")) {
|
|
|
|
c = s->comp_mode_controllable ();
|
|
|
|
} else if (path[2] == X_("speed")) {
|
|
|
|
c = s->comp_speed_controllable ();
|
|
|
|
} else if (path[2] == X_("makeup")) {
|
|
|
|
c = s->comp_makeup_controllable ();
|
2018-06-21 13:05:37 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c) {
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("found controllable \"%1\"\n", c->name()));
|
|
|
|
} else {
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, "no controllable found\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
2012-06-25 08:33:13 -04:00
|
|
|
}
|
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
MIDIFunction*
|
|
|
|
GenericMidiControlProtocol::create_function (const XMLNode& node)
|
|
|
|
{
|
|
|
|
const XMLProperty* prop;
|
2009-12-28 18:55:33 -05:00
|
|
|
int intval;
|
|
|
|
MIDI::byte detail = 0;
|
|
|
|
MIDI::channel_t channel = 0;
|
2009-12-28 11:49:44 -05:00
|
|
|
string uri;
|
|
|
|
MIDI::eventType ev;
|
2010-04-08 17:05:55 -04:00
|
|
|
MIDI::byte* data = 0;
|
|
|
|
uint32_t data_size = 0;
|
2011-08-13 12:27:29 -04:00
|
|
|
string argument;
|
2009-12-28 11:49:44 -05:00
|
|
|
|
|
|
|
if ((prop = node.property (X_("ctl"))) != 0) {
|
|
|
|
ev = MIDI::controller;
|
|
|
|
} else if ((prop = node.property (X_("note"))) != 0) {
|
|
|
|
ev = MIDI::on;
|
|
|
|
} else if ((prop = node.property (X_("pgm"))) != 0) {
|
|
|
|
ev = MIDI::program;
|
2010-04-08 17:05:55 -04:00
|
|
|
} else if ((prop = node.property (X_("sysex"))) != 0 || (prop = node.property (X_("msg"))) != 0) {
|
|
|
|
|
2019-03-23 12:35:26 -04:00
|
|
|
if (prop->name() == X_("sysex")) {
|
|
|
|
ev = MIDI::sysex;
|
|
|
|
} else {
|
|
|
|
ev = MIDI::any;
|
|
|
|
}
|
2009-12-28 18:55:33 -05:00
|
|
|
|
|
|
|
int val;
|
|
|
|
uint32_t cnt;
|
|
|
|
|
|
|
|
{
|
|
|
|
cnt = 0;
|
|
|
|
stringstream ss (prop->value());
|
|
|
|
ss << hex;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-28 18:55:33 -05:00
|
|
|
while (ss >> val) {
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
data = new MIDI::byte[cnt];
|
|
|
|
data_size = cnt;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-28 18:55:33 -05:00
|
|
|
{
|
|
|
|
stringstream ss (prop->value());
|
|
|
|
ss << hex;
|
|
|
|
cnt = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-28 18:55:33 -05:00
|
|
|
while (ss >> val) {
|
2010-04-08 17:05:55 -04:00
|
|
|
data[cnt++] = (MIDI::byte) val;
|
2009-12-28 18:55:33 -05:00
|
|
|
}
|
|
|
|
}
|
2010-04-08 17:05:55 -04:00
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
} else {
|
2009-12-28 18:55:33 -05:00
|
|
|
warning << "Binding ignored - unknown type" << endmsg;
|
2009-12-28 11:49:44 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
if (data_size == 0) {
|
2009-12-29 16:31:14 -05:00
|
|
|
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
detail = (MIDI::byte) intval;
|
|
|
|
|
2009-12-28 18:55:33 -05:00
|
|
|
if ((prop = node.property (X_("channel"))) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-28 18:55:33 -05:00
|
|
|
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
channel = (MIDI::channel_t) intval;
|
|
|
|
/* adjust channel to zero-based counting */
|
|
|
|
if (channel > 0) {
|
|
|
|
channel -= 1;
|
|
|
|
}
|
2009-12-28 11:49:44 -05:00
|
|
|
}
|
|
|
|
|
2011-08-14 13:11:33 -04:00
|
|
|
if ((prop = node.property (X_("arg"))) != 0 || (prop = node.property (X_("argument"))) != 0 || (prop = node.property (X_("arguments"))) != 0) {
|
2011-08-13 12:27:29 -04:00
|
|
|
argument = prop->value ();
|
|
|
|
}
|
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
prop = node.property (X_("function"));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
MIDIFunction* mf = new MIDIFunction (*_input_port->parser());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-08-13 12:27:29 -04:00
|
|
|
if (mf->setup (*this, prop->value(), argument, data, data_size)) {
|
2009-12-28 11:49:44 -05:00
|
|
|
delete mf;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mf->bind_midi (channel, ev, detail);
|
2009-12-28 18:55:33 -05:00
|
|
|
|
2009-12-28 11:49:44 -05:00
|
|
|
return mf;
|
|
|
|
}
|
2009-12-29 16:31:14 -05:00
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
MIDIAction*
|
|
|
|
GenericMidiControlProtocol::create_action (const XMLNode& node)
|
|
|
|
{
|
|
|
|
const XMLProperty* prop;
|
|
|
|
int intval;
|
|
|
|
MIDI::byte detail = 0;
|
|
|
|
MIDI::channel_t channel = 0;
|
|
|
|
string uri;
|
|
|
|
MIDI::eventType ev;
|
|
|
|
MIDI::byte* data = 0;
|
|
|
|
uint32_t data_size = 0;
|
|
|
|
|
|
|
|
if ((prop = node.property (X_("ctl"))) != 0) {
|
|
|
|
ev = MIDI::controller;
|
|
|
|
} else if ((prop = node.property (X_("note"))) != 0) {
|
|
|
|
ev = MIDI::on;
|
|
|
|
} else if ((prop = node.property (X_("pgm"))) != 0) {
|
|
|
|
ev = MIDI::program;
|
|
|
|
} else if ((prop = node.property (X_("sysex"))) != 0 || (prop = node.property (X_("msg"))) != 0) {
|
|
|
|
|
2019-03-23 12:35:26 -04:00
|
|
|
if (prop->name() == X_("sysex")) {
|
|
|
|
ev = MIDI::sysex;
|
|
|
|
} else {
|
|
|
|
ev = MIDI::any;
|
|
|
|
}
|
2010-04-08 17:05:55 -04:00
|
|
|
|
|
|
|
int val;
|
|
|
|
uint32_t cnt;
|
|
|
|
|
|
|
|
{
|
|
|
|
cnt = 0;
|
|
|
|
stringstream ss (prop->value());
|
|
|
|
ss << hex;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
while (ss >> val) {
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = new MIDI::byte[cnt];
|
|
|
|
data_size = cnt;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
{
|
|
|
|
stringstream ss (prop->value());
|
|
|
|
ss << hex;
|
|
|
|
cnt = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
while (ss >> val) {
|
|
|
|
data[cnt++] = (MIDI::byte) val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
warning << "Binding ignored - unknown type" << endmsg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data_size == 0) {
|
|
|
|
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
detail = (MIDI::byte) intval;
|
|
|
|
|
|
|
|
if ((prop = node.property (X_("channel"))) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
channel = (MIDI::channel_t) intval;
|
|
|
|
/* adjust channel to zero-based counting */
|
|
|
|
if (channel > 0) {
|
|
|
|
channel -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = node.property (X_("action"));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
MIDIAction* ma = new MIDIAction (*_input_port->parser());
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2010-04-08 17:05:55 -04:00
|
|
|
if (ma->init (*this, prop->value(), data, data_size)) {
|
|
|
|
delete ma;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ma->bind_midi (channel, ev, detail);
|
|
|
|
|
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
2009-12-29 16:31:14 -05:00
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::set_current_bank (uint32_t b)
|
|
|
|
{
|
|
|
|
_current_bank = b;
|
|
|
|
reset_controllables ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::next_bank ()
|
|
|
|
{
|
|
|
|
_current_bank++;
|
|
|
|
reset_controllables ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::prev_bank()
|
|
|
|
{
|
|
|
|
if (_current_bank) {
|
|
|
|
_current_bank--;
|
|
|
|
reset_controllables ();
|
|
|
|
}
|
|
|
|
}
|
2012-03-18 21:34:35 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::set_motorised (bool m)
|
|
|
|
{
|
|
|
|
_motorised = m;
|
|
|
|
}
|
2012-06-13 17:53:50 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::set_threshold (int t)
|
|
|
|
{
|
|
|
|
_threshold = t;
|
|
|
|
}
|
2015-12-07 12:04:23 -05:00
|
|
|
|
|
|
|
bool
|
|
|
|
GenericMidiControlProtocol::connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn)
|
|
|
|
{
|
2019-12-31 14:06:00 -05:00
|
|
|
bool input_was_connected = (connection_state & InputConnected);
|
|
|
|
|
2015-12-07 12:04:23 -05:00
|
|
|
if (!_input_port || !_output_port) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("connection change: %1 and %2 connected ? %3\n", name1, name2, yn));
|
|
|
|
|
2015-12-07 12:04:23 -05:00
|
|
|
string ni = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (boost::shared_ptr<ARDOUR::Port>(_input_port)->name());
|
|
|
|
string no = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (boost::shared_ptr<ARDOUR::Port>(_output_port)->name());
|
|
|
|
|
|
|
|
if (ni == name1 || ni == name2) {
|
|
|
|
if (yn) {
|
|
|
|
connection_state |= InputConnected;
|
|
|
|
} else {
|
|
|
|
connection_state &= ~InputConnected;
|
|
|
|
}
|
|
|
|
} else if (no == name1 || no == name2) {
|
|
|
|
if (yn) {
|
|
|
|
connection_state |= OutputConnected;
|
|
|
|
} else {
|
|
|
|
connection_state &= ~OutputConnected;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* not our ports */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:06:00 -05:00
|
|
|
if (connection_state & InputConnected) {
|
|
|
|
if (!input_was_connected) {
|
|
|
|
start_midi_handling ();
|
|
|
|
}
|
2015-12-07 12:04:23 -05:00
|
|
|
} else {
|
2019-12-31 14:06:00 -05:00
|
|
|
if (input_was_connected) {
|
|
|
|
stop_midi_handling ();
|
|
|
|
}
|
2015-12-07 12:04:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionChange (); /* emit signal for our GUI */
|
|
|
|
|
|
|
|
return true; /* connection status changed */
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<Port>
|
|
|
|
GenericMidiControlProtocol::output_port() const
|
|
|
|
{
|
|
|
|
return _output_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<Port>
|
|
|
|
GenericMidiControlProtocol::input_port() const
|
|
|
|
{
|
|
|
|
return _input_port;
|
|
|
|
}
|
2017-01-23 07:25:56 -05:00
|
|
|
|
|
|
|
void
|
2019-03-22 21:09:39 -04:00
|
|
|
GenericMidiControlProtocol::maybe_start_touch (boost::shared_ptr<Controllable> controllable)
|
2017-01-23 07:25:56 -05:00
|
|
|
{
|
2019-03-22 21:09:39 -04:00
|
|
|
boost::shared_ptr<AutomationControl> actl = boost::dynamic_pointer_cast<AutomationControl> (controllable);
|
2017-01-23 07:25:56 -05:00
|
|
|
if (actl) {
|
2017-09-18 12:39:17 -04:00
|
|
|
actl->start_touch (session->audible_sample ());
|
2017-01-23 07:25:56 -05:00
|
|
|
}
|
|
|
|
}
|
2019-12-31 14:06:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::start_midi_handling ()
|
|
|
|
{
|
|
|
|
/* This connection means that whenever data is ready from the input
|
|
|
|
* port, the relevant thread will invoke our ::midi_input_handler()
|
|
|
|
* method, which will read the data, and invoke the parser.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_input_port->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &GenericMidiControlProtocol::midi_input_handler), boost::weak_ptr<AsyncMIDIPort> (_input_port)));
|
|
|
|
_input_port->xthread().attach (main_loop()->get_context());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GenericMidiControlProtocol::stop_midi_handling ()
|
|
|
|
{
|
|
|
|
midi_connections.drop_connections ();
|
|
|
|
|
|
|
|
/* Note: the input handler is still active at this point, but we're no
|
|
|
|
* longer connected to any of the parser signals
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GenericMidiControlProtocol::midi_input_handler (Glib::IOCondition ioc, boost::weak_ptr<ARDOUR::AsyncMIDIPort> wport)
|
|
|
|
{
|
|
|
|
boost::shared_ptr<AsyncMIDIPort> port (wport.lock());
|
|
|
|
|
|
|
|
if (!port) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("something happend on %1\n", boost::shared_ptr<MIDI::Port>(port)->name()));
|
|
|
|
|
|
|
|
if (ioc & ~IO_IN) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioc & IO_IN) {
|
|
|
|
|
|
|
|
port->clear ();
|
|
|
|
DEBUG_TRACE (DEBUG::GenericMidi, string_compose ("data available on %1\n", boost::shared_ptr<MIDI::Port>(port)->name()));
|
|
|
|
samplepos_t now = session->engine().sample_time();
|
|
|
|
port->parse (now);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|