mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 23:35:03 +01:00
editors for control protocols (generalized); editor for Generic MIDI that allows choosing a MIDI binding map (or none); support banking in binding URLs, and other miscellany related to generic MIDI; save+restore JACK_MidiPort connection state (but cause a crash at shutdown time)
git-svn-id: svn://localhost/ardour2/branches/3.0@6411 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
e10d0339cc
commit
77cc0f7cc8
17 changed files with 658 additions and 95 deletions
|
|
@ -200,8 +200,9 @@ PluginSelector::~PluginSelector ()
|
||||||
void
|
void
|
||||||
PluginSelector::row_clicked(GdkEventButton* event)
|
PluginSelector::row_clicked(GdkEventButton* event)
|
||||||
{
|
{
|
||||||
if (event->type == GDK_2BUTTON_PRESS)
|
if (event->type == GDK_2BUTTON_PRESS) {
|
||||||
btn_add_clicked();
|
btn_add_clicked();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
||||||
|
|
@ -765,7 +765,8 @@ private:
|
||||||
class ControlSurfacesOptions : public OptionEditorBox
|
class ControlSurfacesOptions : public OptionEditorBox
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlSurfacesOptions ()
|
ControlSurfacesOptions (ArdourDialog& parent)
|
||||||
|
: _parent (parent)
|
||||||
{
|
{
|
||||||
_store = ListStore::create (_model);
|
_store = ListStore::create (_model);
|
||||||
_view.set_model (_store);
|
_view.set_model (_store);
|
||||||
|
|
@ -777,7 +778,13 @@ public:
|
||||||
|
|
||||||
_box->pack_start (_view, false, false);
|
_box->pack_start (_view, false, false);
|
||||||
|
|
||||||
|
Label* label = manage (new Label (_("Double-click on a name to edit settings for an enabled protocol")));
|
||||||
|
|
||||||
|
_box->pack_start (*label, false, false);
|
||||||
|
label->show ();
|
||||||
|
|
||||||
_store->signal_row_changed().connect (sigc::mem_fun (*this, &ControlSurfacesOptions::model_changed));
|
_store->signal_row_changed().connect (sigc::mem_fun (*this, &ControlSurfacesOptions::model_changed));
|
||||||
|
_view.signal_button_press_event().connect_notify (sigc::mem_fun(*this, &ControlSurfacesOptions::edit_clicked));
|
||||||
}
|
}
|
||||||
|
|
||||||
void parameter_changed (std::string const &)
|
void parameter_changed (std::string const &)
|
||||||
|
|
@ -832,6 +839,38 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void edit_clicked (GdkEventButton* ev)
|
||||||
|
{
|
||||||
|
if (ev->type != GDK_2BUTTON_PRESS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
ControlProtocolInfo* cpi;
|
||||||
|
TreeModel::Row row;
|
||||||
|
|
||||||
|
row = *(_view.get_selection()->get_selected());
|
||||||
|
|
||||||
|
Window* win = row[_model.editor];
|
||||||
|
if (win && !win->is_visible()) {
|
||||||
|
win->present ();
|
||||||
|
} else {
|
||||||
|
cpi = row[_model.protocol_info];
|
||||||
|
|
||||||
|
if (cpi && cpi->protocol && cpi->protocol->has_editor ()) {
|
||||||
|
Box* box = (Box*) cpi->protocol->get_gui ();
|
||||||
|
if (box) {
|
||||||
|
string title = row[_model.name];
|
||||||
|
ArdourDialog* win = new ArdourDialog (_parent, title);
|
||||||
|
win->get_vbox()->pack_start (*box, false, false);
|
||||||
|
box->show ();
|
||||||
|
win->present ();
|
||||||
|
row[_model.editor] = win;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ControlSurfacesModelColumns : public TreeModelColumnRecord
|
class ControlSurfacesModelColumns : public TreeModelColumnRecord
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -842,17 +881,20 @@ private:
|
||||||
add (enabled);
|
add (enabled);
|
||||||
add (feedback);
|
add (feedback);
|
||||||
add (protocol_info);
|
add (protocol_info);
|
||||||
|
add (editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeModelColumn<string> name;
|
TreeModelColumn<string> name;
|
||||||
TreeModelColumn<bool> enabled;
|
TreeModelColumn<bool> enabled;
|
||||||
TreeModelColumn<bool> feedback;
|
TreeModelColumn<bool> feedback;
|
||||||
TreeModelColumn<ControlProtocolInfo*> protocol_info;
|
TreeModelColumn<ControlProtocolInfo*> protocol_info;
|
||||||
|
TreeModelColumn<Gtk::Window*> editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
Glib::RefPtr<ListStore> _store;
|
Glib::RefPtr<ListStore> _store;
|
||||||
ControlSurfacesModelColumns _model;
|
ControlSurfacesModelColumns _model;
|
||||||
TreeView _view;
|
TreeView _view;
|
||||||
|
Gtk::Window& _parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1355,7 +1397,7 @@ RCOptionEditor::RCOptionEditor ()
|
||||||
|
|
||||||
/* CONTROL SURFACES */
|
/* CONTROL SURFACES */
|
||||||
|
|
||||||
add_option (_("Control surfaces"), new ControlSurfacesOptions);
|
add_option (_("Control surfaces"), new ControlSurfacesOptions (*this));
|
||||||
|
|
||||||
ComboOption<RemoteModel>* rm = new ComboOption<RemoteModel> (
|
ComboOption<RemoteModel>* rm = new ComboOption<RemoteModel> (
|
||||||
"remote-model",
|
"remote-model",
|
||||||
|
|
|
||||||
|
|
@ -769,7 +769,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
|
||||||
/* Controllables */
|
/* Controllables */
|
||||||
|
|
||||||
boost::shared_ptr<PBD::Controllable> controllable_by_id (const PBD::ID&);
|
boost::shared_ptr<PBD::Controllable> controllable_by_id (const PBD::ID&);
|
||||||
boost::shared_ptr<PBD::Controllable> controllable_by_uri (const std::string&);
|
boost::shared_ptr<PBD::Controllable> controllable_by_rid_and_name (uint32_t, const char* const);
|
||||||
|
|
||||||
void add_controllable (boost::shared_ptr<PBD::Controllable>);
|
void add_controllable (boost::shared_ptr<PBD::Controllable>);
|
||||||
void remove_controllable (PBD::Controllable*);
|
void remove_controllable (PBD::Controllable*);
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@
|
||||||
#include <glibmm/thread.h>
|
#include <glibmm/thread.h>
|
||||||
#include <glibmm/miscutils.h>
|
#include <glibmm/miscutils.h>
|
||||||
#include <glibmm/fileutils.h>
|
#include <glibmm/fileutils.h>
|
||||||
|
#include <glibmm/thread.h>
|
||||||
|
|
||||||
#include "pbd/error.h"
|
#include "pbd/error.h"
|
||||||
#include <glibmm/thread.h>
|
|
||||||
#include "pbd/boost_debug.h"
|
#include "pbd/boost_debug.h"
|
||||||
#include "pbd/pathscanner.h"
|
#include "pbd/pathscanner.h"
|
||||||
#include "pbd/stl_delete.h"
|
#include "pbd/stl_delete.h"
|
||||||
|
|
@ -93,6 +93,8 @@
|
||||||
#include "ardour/tempo.h"
|
#include "ardour/tempo.h"
|
||||||
#include "ardour/utils.h"
|
#include "ardour/utils.h"
|
||||||
|
|
||||||
|
#include "midi++/jack.h"
|
||||||
|
|
||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -790,6 +792,7 @@ Session::hookup_io ()
|
||||||
/* Tell all IO objects to connect themselves together */
|
/* Tell all IO objects to connect themselves together */
|
||||||
|
|
||||||
IO::enable_connecting ();
|
IO::enable_connecting ();
|
||||||
|
MIDI::JACK_MidiPort::MakeConnections ();
|
||||||
|
|
||||||
/* Now reset all panners */
|
/* Now reset all panners */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2679,25 +2679,9 @@ Session::controllable_by_id (const PBD::ID& id)
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::shared_ptr<Controllable>
|
boost::shared_ptr<Controllable>
|
||||||
Session::controllable_by_uri (const std::string& uri)
|
Session::controllable_by_rid_and_name (uint32_t rid, const char* const what)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<Controllable> c;
|
boost::shared_ptr<Controllable> c;
|
||||||
string::size_type last_slash;
|
|
||||||
string useful_part;
|
|
||||||
|
|
||||||
if ((last_slash = uri.find_last_of ('/')) == string::npos) {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
useful_part = uri.substr (last_slash+1);
|
|
||||||
|
|
||||||
uint32_t rid;
|
|
||||||
char what[64];
|
|
||||||
|
|
||||||
if (sscanf (useful_part.c_str(), "rid=%" PRIu32 "?%63s", &rid, what) != 2) {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::shared_ptr<Route> r = route_by_remote_id (rid);
|
boost::shared_ptr<Route> r = route_by_remote_id (rid);
|
||||||
|
|
||||||
if (!r) {
|
if (!r) {
|
||||||
|
|
@ -2706,8 +2690,17 @@ Session::controllable_by_uri (const std::string& uri)
|
||||||
|
|
||||||
if (strncmp (what, "gain", 4) == 0) {
|
if (strncmp (what, "gain", 4) == 0) {
|
||||||
c = r->gain_control ();
|
c = r->gain_control ();
|
||||||
|
} else if (strncmp (what, "solo", 4) == 0) {
|
||||||
|
c = r->solo_control();
|
||||||
|
} else if (strncmp (what, "mute", 4) == 0) {
|
||||||
|
c = r->mute_control();
|
||||||
} else if (strncmp (what, "pan", 3) == 0) {
|
} else if (strncmp (what, "pan", 3) == 0) {
|
||||||
} else if (strncmp (what, "plugin", 6) == 0) {
|
} else if (strncmp (what, "plugin", 6) == 0) {
|
||||||
|
} else if (strncmp (what, "recenable", 9) == 0) {
|
||||||
|
boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(r);
|
||||||
|
if (t) {
|
||||||
|
c = t->rec_enable_control ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "pbd/error.h"
|
#include "pbd/error.h"
|
||||||
#include "pbd/compose.h"
|
#include "pbd/compose.h"
|
||||||
|
#include "pbd/strsplit.h"
|
||||||
|
|
||||||
#include "midi++/types.h"
|
#include "midi++/types.h"
|
||||||
#include "midi++/jack.h"
|
#include "midi++/jack.h"
|
||||||
|
|
@ -35,6 +36,9 @@ using namespace PBD;
|
||||||
|
|
||||||
pthread_t JACK_MidiPort::_process_thread;
|
pthread_t JACK_MidiPort::_process_thread;
|
||||||
|
|
||||||
|
Signal0<void> JACK_MidiPort::JackHalted;
|
||||||
|
Signal0<void> JACK_MidiPort::MakeConnections;
|
||||||
|
|
||||||
JACK_MidiPort::JACK_MidiPort(const XMLNode& node, jack_client_t* jack_client)
|
JACK_MidiPort::JACK_MidiPort(const XMLNode& node, jack_client_t* jack_client)
|
||||||
: Port(node)
|
: Port(node)
|
||||||
, _jack_client(jack_client)
|
, _jack_client(jack_client)
|
||||||
|
|
@ -47,21 +51,38 @@ JACK_MidiPort::JACK_MidiPort(const XMLNode& node, jack_client_t* jack_client)
|
||||||
if (!create_ports (node)) {
|
if (!create_ports (node)) {
|
||||||
_ok = true;
|
_ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MakeConnections.connect_same_thread (connect_connection, boost::bind (&JACK_MidiPort::make_connections, this));
|
||||||
|
JackHalted.connect_same_thread (halt_connection, boost::bind (&JACK_MidiPort::jack_halted, this));
|
||||||
|
|
||||||
|
set_state (node);
|
||||||
}
|
}
|
||||||
|
|
||||||
JACK_MidiPort::~JACK_MidiPort()
|
JACK_MidiPort::~JACK_MidiPort()
|
||||||
{
|
{
|
||||||
if (_jack_input_port) {
|
if (_jack_input_port) {
|
||||||
jack_port_unregister (_jack_client, _jack_input_port);
|
if (_jack_client) {
|
||||||
|
jack_port_unregister (_jack_client, _jack_input_port);
|
||||||
|
}
|
||||||
_jack_input_port = 0;
|
_jack_input_port = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_jack_output_port) {
|
if (_jack_output_port) {
|
||||||
jack_port_unregister (_jack_client, _jack_input_port);
|
if (_jack_client) {
|
||||||
|
jack_port_unregister (_jack_client, _jack_input_port);
|
||||||
|
}
|
||||||
_jack_input_port = 0;
|
_jack_input_port = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
JACK_MidiPort::jack_halted ()
|
||||||
|
{
|
||||||
|
_jack_client = 0;
|
||||||
|
_jack_input_port = 0;
|
||||||
|
_jack_output_port = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
JACK_MidiPort::cycle_start (nframes_t nframes)
|
JACK_MidiPort::cycle_start (nframes_t nframes)
|
||||||
{
|
{
|
||||||
|
|
@ -270,12 +291,88 @@ XMLNode&
|
||||||
JACK_MidiPort::get_state () const
|
JACK_MidiPort::get_state () const
|
||||||
{
|
{
|
||||||
XMLNode& root (Port::get_state ());
|
XMLNode& root (Port::get_state ());
|
||||||
|
|
||||||
|
if (_jack_output_port) {
|
||||||
|
|
||||||
|
const char** jc = jack_port_get_connections (_jack_output_port);
|
||||||
|
string connection_string;
|
||||||
|
if (jc) {
|
||||||
|
for (int i = 0; jc[i]; ++i) {
|
||||||
|
if (i > 0) {
|
||||||
|
connection_string += ',';
|
||||||
|
}
|
||||||
|
connection_string += jc[i];
|
||||||
|
}
|
||||||
|
free (jc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connection_string.empty()) {
|
||||||
|
root.add_property ("outbound", connection_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_jack_input_port) {
|
||||||
|
|
||||||
|
const char** jc = jack_port_get_connections (_jack_input_port);
|
||||||
|
string connection_string;
|
||||||
|
if (jc) {
|
||||||
|
for (int i = 0; jc[i]; ++i) {
|
||||||
|
if (i > 0) {
|
||||||
|
connection_string += ',';
|
||||||
|
}
|
||||||
|
connection_string += jc[i];
|
||||||
|
}
|
||||||
|
free (jc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connection_string.empty()) {
|
||||||
|
root.add_property ("inbound", connection_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
JACK_MidiPort::set_state (const XMLNode& /*node*/)
|
JACK_MidiPort::set_state (const XMLNode& node)
|
||||||
{
|
{
|
||||||
|
Port::set_state (node);
|
||||||
|
const XMLProperty* prop;
|
||||||
|
|
||||||
|
if ((prop = node.property ("outbound")) != 0 && _jack_output_port) {
|
||||||
|
_inbound_connections = prop->value ();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((prop = node.property ("inbound")) != 0 && _jack_input_port) {
|
||||||
|
_outbound_connections = prop->value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
JACK_MidiPort::make_connections ()
|
||||||
|
{
|
||||||
|
if (!_inbound_connections.empty()) {
|
||||||
|
vector<string> ports;
|
||||||
|
split (_inbound_connections, ports, ',');
|
||||||
|
for (vector<string>::iterator x = ports.begin(); x != ports.end(); ++x) {
|
||||||
|
if (_jack_client) {
|
||||||
|
jack_connect (_jack_client, jack_port_name (_jack_output_port), (*x).c_str());
|
||||||
|
/* ignore failures */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_outbound_connections.empty()) {
|
||||||
|
vector<string> ports;
|
||||||
|
split (_outbound_connections, ports, ',');
|
||||||
|
for (vector<string>::iterator x = ports.begin(); x != ports.end(); ++x) {
|
||||||
|
if (_jack_client) {
|
||||||
|
jack_connect (_jack_client, (*x).c_str(), jack_port_name (_jack_input_port));
|
||||||
|
/* ignore failures */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connect_connection.disconnect ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include <jack/midiport.h>
|
#include <jack/midiport.h>
|
||||||
|
|
||||||
#include "pbd/ringbuffer.h"
|
#include "pbd/ringbuffer.h"
|
||||||
|
#include "pbd/signals.h"
|
||||||
#include "pbd/crossthread.h"
|
#include "pbd/crossthread.h"
|
||||||
#include "evoral/EventRingBuffer.hpp"
|
#include "evoral/EventRingBuffer.hpp"
|
||||||
|
|
||||||
|
|
@ -43,7 +44,6 @@
|
||||||
namespace MIDI
|
namespace MIDI
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
class JACK_MidiPort : public Port
|
class JACK_MidiPort : public Port
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -69,7 +69,10 @@ public:
|
||||||
static bool is_process_thread();
|
static bool is_process_thread();
|
||||||
|
|
||||||
nframes_t nframes_this_cycle() const { return _nframes_this_cycle; }
|
nframes_t nframes_this_cycle() const { return _nframes_this_cycle; }
|
||||||
|
|
||||||
|
static PBD::Signal0<void> MakeConnections;
|
||||||
|
static PBD::Signal0<void> JackHalted;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string get_typestring () const {
|
std::string get_typestring () const {
|
||||||
return typestring;
|
return typestring;
|
||||||
|
|
@ -84,8 +87,13 @@ private:
|
||||||
nframes_t _last_read_index;
|
nframes_t _last_read_index;
|
||||||
timestamp_t _last_write_timestamp;
|
timestamp_t _last_write_timestamp;
|
||||||
CrossThreadChannel xthread;
|
CrossThreadChannel xthread;
|
||||||
|
std::string _inbound_connections;
|
||||||
|
std::string _outbound_connections;
|
||||||
|
PBD::Connection connect_connection;
|
||||||
|
PBD::Connection halt_connection;
|
||||||
void flush (void* jack_port_buffer);
|
void flush (void* jack_port_buffer);
|
||||||
|
void jack_halted ();
|
||||||
|
void make_connections();
|
||||||
|
|
||||||
static pthread_t _process_thread;
|
static pthread_t _process_thread;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,10 @@ class ControlProtocol : virtual public sigc::trackable, public PBD::Stateful, pu
|
||||||
|
|
||||||
std::string route_get_name (uint32_t table_index);
|
std::string route_get_name (uint32_t table_index);
|
||||||
|
|
||||||
|
virtual bool has_editor () const { return false; }
|
||||||
|
virtual void* get_gui() const { return 0; }
|
||||||
|
virtual void tear_down_gui() { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PBD::EventLoop* _event_loop;
|
PBD::EventLoop* _event_loop;
|
||||||
bool _own_event_loop;
|
bool _own_event_loop;
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,13 @@
|
||||||
|
|
||||||
#include "pbd/error.h"
|
#include "pbd/error.h"
|
||||||
#include "pbd/failed_constructor.h"
|
#include "pbd/failed_constructor.h"
|
||||||
|
#include "pbd/pathscanner.h"
|
||||||
|
#include "pbd/xml++.h"
|
||||||
|
|
||||||
#include "midi++/port.h"
|
#include "midi++/port.h"
|
||||||
#include "midi++/manager.h"
|
#include "midi++/manager.h"
|
||||||
|
|
||||||
|
#include "ardour/filesystem_paths.h"
|
||||||
#include "ardour/session.h"
|
#include "ardour/session.h"
|
||||||
#include "ardour/route.h"
|
#include "ardour/route.h"
|
||||||
#include "ardour/midi_ui.h"
|
#include "ardour/midi_ui.h"
|
||||||
|
|
@ -48,9 +51,11 @@ using namespace std;
|
||||||
|
|
||||||
GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
|
GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
|
||||||
: ControlProtocol (s, _("Generic MIDI"), midi_ui_context())
|
: ControlProtocol (s, _("Generic MIDI"), midi_ui_context())
|
||||||
|
, gui (0)
|
||||||
{
|
{
|
||||||
MIDI::Manager* mm = MIDI::Manager::instance();
|
|
||||||
|
|
||||||
|
MIDI::Manager* mm = MIDI::Manager::instance();
|
||||||
|
|
||||||
/* XXX it might be nice to run "control" through i18n, but thats a bit tricky because
|
/* XXX it might be nice to run "control" through i18n, but thats a bit tricky because
|
||||||
the name is defined in ardour.rc which is likely not internationalized.
|
the name is defined in ardour.rc which is likely not internationalized.
|
||||||
*/
|
*/
|
||||||
|
|
@ -66,6 +71,9 @@ GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
|
||||||
_feedback_interval = 10000; // microseconds
|
_feedback_interval = 10000; // microseconds
|
||||||
last_feedback_time = 0;
|
last_feedback_time = 0;
|
||||||
|
|
||||||
|
_current_bank = 0;
|
||||||
|
_bank_size = 0;
|
||||||
|
|
||||||
/* XXX is it right to do all these in the same thread as whatever emits the signal? */
|
/* XXX is it right to do all these in the same thread as whatever emits the signal? */
|
||||||
|
|
||||||
Controllable::StartLearning.connect_same_thread (*this, boost::bind (&GenericMidiControlProtocol::start_learning, this, _1));
|
Controllable::StartLearning.connect_same_thread (*this, boost::bind (&GenericMidiControlProtocol::start_learning, this, _1));
|
||||||
|
|
@ -75,13 +83,93 @@ GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
|
||||||
|
|
||||||
Session::SendFeedback.connect (*this, boost::bind (&GenericMidiControlProtocol::send_feedback, this), midi_ui_context());;
|
Session::SendFeedback.connect (*this, boost::bind (&GenericMidiControlProtocol::send_feedback, this), midi_ui_context());;
|
||||||
|
|
||||||
std::string xmlpath = "/tmp/midi.map";
|
reload_maps ();
|
||||||
|
|
||||||
load_bindings (xmlpath);
|
|
||||||
reset_controllables ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GenericMidiControlProtocol::~GenericMidiControlProtocol ()
|
GenericMidiControlProtocol::~GenericMidiControlProtocol ()
|
||||||
|
{
|
||||||
|
drop_all ();
|
||||||
|
tear_down_gui ();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* const midi_map_dir_name = "midi_maps";
|
||||||
|
static const char* const midi_map_suffix = ".map";
|
||||||
|
|
||||||
|
static sys::path
|
||||||
|
system_midi_map_search_path ()
|
||||||
|
{
|
||||||
|
SearchPath spath(system_data_search_path());
|
||||||
|
spath.add_subdirectory_to_paths(midi_map_dir_name);
|
||||||
|
|
||||||
|
// just return the first directory in the search path that exists
|
||||||
|
SearchPath::const_iterator i = std::find_if(spath.begin(), spath.end(), sys::exists);
|
||||||
|
|
||||||
|
if (i == spath.end()) return sys::path();
|
||||||
|
|
||||||
|
return *i;
|
||||||
|
}
|
||||||
|
|
||||||
|
static sys::path
|
||||||
|
user_midi_map_directory ()
|
||||||
|
{
|
||||||
|
sys::path p(user_config_directory());
|
||||||
|
p /= midi_map_dir_name;
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
midi_map_filter (const string &str, void */*arg*/)
|
||||||
|
{
|
||||||
|
return (str.length() > strlen(midi_map_suffix) &&
|
||||||
|
str.find (midi_map_suffix) == (str.length() - strlen (midi_map_suffix)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GenericMidiControlProtocol::reload_maps ()
|
||||||
|
{
|
||||||
|
vector<string *> *midi_maps;
|
||||||
|
PathScanner scanner;
|
||||||
|
SearchPath spath (system_midi_map_search_path());
|
||||||
|
spath += user_midi_map_directory ();
|
||||||
|
|
||||||
|
midi_maps = scanner (spath.to_string(), midi_map_filter, 0, false, true);
|
||||||
|
|
||||||
|
if (!midi_maps) {
|
||||||
|
cerr << "No MIDI maps found using " << spath.to_string() << endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cerr << "Found " << midi_maps->size() << " MIDI maps along " << spath.to_string() << endl;
|
||||||
|
|
||||||
|
for (vector<string*>::iterator i = midi_maps->begin(); i != midi_maps->end(); ++i) {
|
||||||
|
string fullpath = *(*i);
|
||||||
|
|
||||||
|
XMLTree tree;
|
||||||
|
|
||||||
|
if (!tree.read (fullpath.c_str())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
MapInfo mi;
|
||||||
|
|
||||||
|
XMLProperty* prop = tree.root()->property ("name");
|
||||||
|
|
||||||
|
if (!prop) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
mi.name = prop->value ();
|
||||||
|
mi.path = fullpath;
|
||||||
|
|
||||||
|
map_info.push_back (mi);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete midi_maps;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GenericMidiControlProtocol::drop_all ()
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lm (pending_lock);
|
Glib::Mutex::Lock lm (pending_lock);
|
||||||
Glib::Mutex::Lock lm2 (controllables_lock);
|
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||||
|
|
@ -102,6 +190,30 @@ GenericMidiControlProtocol::~GenericMidiControlProtocol ()
|
||||||
functions.clear ();
|
functions.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GenericMidiControlProtocol::drop_bindings ()
|
||||||
|
{
|
||||||
|
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
GenericMidiControlProtocol::set_active (bool /*yn*/)
|
GenericMidiControlProtocol::set_active (bool /*yn*/)
|
||||||
{
|
{
|
||||||
|
|
@ -237,7 +349,7 @@ GenericMidiControlProtocol::learning_stopped (MIDIControllable* mc)
|
||||||
i = tmp;
|
i = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
controllables.insert (mc);
|
controllables.push_back (mc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -314,8 +426,9 @@ GenericMidiControlProtocol::create_binding (PBD::Controllable* control, int pos,
|
||||||
// Update the MIDI Controllable based on the the pos param
|
// Update the MIDI Controllable based on the the pos param
|
||||||
// Here is where a table lookup for user mappings could go; for now we'll just wing it...
|
// Here is where a table lookup for user mappings could go; for now we'll just wing it...
|
||||||
mc->bind_midi(channel, MIDI::controller, value);
|
mc->bind_midi(channel, MIDI::controller, value);
|
||||||
|
mc->set_learned (true);
|
||||||
controllables.insert (mc);
|
|
||||||
|
controllables.push_back (mc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,13 +443,25 @@ GenericMidiControlProtocol::get_state ()
|
||||||
snprintf (buf, sizeof (buf), "%" PRIu64, _feedback_interval);
|
snprintf (buf, sizeof (buf), "%" PRIu64, _feedback_interval);
|
||||||
node->add_property (X_("feedback_interval"), buf);
|
node->add_property (X_("feedback_interval"), buf);
|
||||||
|
|
||||||
|
if (!_current_binding.empty()) {
|
||||||
|
node->add_property ("binding", _current_binding);
|
||||||
|
}
|
||||||
|
|
||||||
XMLNode* children = new XMLNode (X_("controls"));
|
XMLNode* children = new XMLNode (X_("controls"));
|
||||||
|
|
||||||
node->add_child_nocopy (*children);
|
node->add_child_nocopy (*children);
|
||||||
|
|
||||||
Glib::Mutex::Lock lm2 (controllables_lock);
|
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||||
for (MIDIControllables::iterator i = controllables.begin(); i != controllables.end(); ++i) {
|
for (MIDIControllables::iterator i = controllables.begin(); i != controllables.end(); ++i) {
|
||||||
children->add_child_nocopy ((*i)->get_state());
|
|
||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ((*i)->learned()) {
|
||||||
|
children->add_child_nocopy ((*i)->get_state());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return *node;
|
return *node;
|
||||||
|
|
@ -372,37 +497,50 @@ GenericMidiControlProtocol::set_state (const XMLNode& node, int version)
|
||||||
}
|
}
|
||||||
pending_controllables.clear ();
|
pending_controllables.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::Mutex::Lock lm2 (controllables_lock);
|
{
|
||||||
controllables.clear ();
|
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||||
nlist = node.children(); // "controls"
|
controllables.clear ();
|
||||||
|
nlist = node.children(); // "controls"
|
||||||
if (nlist.empty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
nlist = nlist.front()->children ();
|
|
||||||
|
|
||||||
for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
|
if (nlist.empty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ((prop = (*niter)->property ("id")) != 0) {
|
nlist = nlist.front()->children ();
|
||||||
|
|
||||||
|
for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
|
||||||
|
|
||||||
ID id = prop->value ();
|
if ((prop = (*niter)->property ("id")) != 0) {
|
||||||
c = session->controllable_by_id (id);
|
|
||||||
|
|
||||||
if (c) {
|
|
||||||
MIDIControllable* mc = new MIDIControllable (*_port, *c);
|
|
||||||
if (mc->set_state (**niter, version) == 0) {
|
|
||||||
controllables.insert (mc);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
ID id = prop->value ();
|
||||||
warning << string_compose (
|
c = session->controllable_by_id (id);
|
||||||
_("Generic MIDI control: controllable %1 not found in session (ignored)"),
|
|
||||||
id) << endmsg;
|
if (c) {
|
||||||
|
MIDIControllable* mc = new MIDIControllable (*_port, *c);
|
||||||
|
if (mc->set_state (**niter, version) == 0) {
|
||||||
|
controllables.push_back (mc);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
warning << string_compose (
|
||||||
|
_("Generic MIDI control: controllable %1 not found in session (ignored)"),
|
||||||
|
id) << endmsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((prop = node.property ("binding")) != 0) {
|
||||||
|
for (list<MapInfo>::iterator x = map_info.begin(); x != map_info.end(); ++x) {
|
||||||
|
if (prop->value() == (*x).name) {
|
||||||
|
load_bindings ((*x).path);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -420,6 +558,9 @@ GenericMidiControlProtocol::get_feedback () const
|
||||||
return do_feedback;
|
return do_feedback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
||||||
{
|
{
|
||||||
|
|
@ -456,7 +597,19 @@ GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
||||||
|
|
||||||
MIDIControllable* mc;
|
MIDIControllable* mc;
|
||||||
|
|
||||||
|
drop_all ();
|
||||||
|
|
||||||
for (citer = children.begin(); citer != children.end(); ++citer) {
|
for (citer = children.begin(); citer != children.end(); ++citer) {
|
||||||
|
|
||||||
|
if ((*citer)->name() == "DeviceInfo") {
|
||||||
|
const XMLProperty* prop;
|
||||||
|
|
||||||
|
if ((prop = (*citer)->property ("bank-size")) != 0) {
|
||||||
|
_bank_size = atoi (prop->value());
|
||||||
|
_current_bank = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((*citer)->name() == "Binding") {
|
if ((*citer)->name() == "Binding") {
|
||||||
const XMLNode* child = *citer;
|
const XMLNode* child = *citer;
|
||||||
|
|
||||||
|
|
@ -465,7 +618,7 @@ GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
||||||
|
|
||||||
if ((mc = create_binding (*child)) != 0) {
|
if ((mc = create_binding (*child)) != 0) {
|
||||||
Glib::Mutex::Lock lm2 (controllables_lock);
|
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||||
controllables.insert (mc);
|
controllables.push_back (mc);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (child->property ("function")) {
|
} else if (child->property ("function")) {
|
||||||
|
|
@ -481,6 +634,12 @@ GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((prop = root->property ("name")) != 0) {
|
||||||
|
_current_binding = prop->value ();
|
||||||
|
}
|
||||||
|
|
||||||
|
reset_controllables ();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -489,18 +648,11 @@ MIDIControllable*
|
||||||
GenericMidiControlProtocol::create_binding (const XMLNode& node)
|
GenericMidiControlProtocol::create_binding (const XMLNode& node)
|
||||||
{
|
{
|
||||||
const XMLProperty* prop;
|
const XMLProperty* prop;
|
||||||
int detail;
|
MIDI::byte detail;
|
||||||
int channel;
|
MIDI::channel_t channel;
|
||||||
string uri;
|
string uri;
|
||||||
MIDI::eventType ev;
|
MIDI::eventType ev;
|
||||||
|
int intval;
|
||||||
if ((prop = node.property (X_("channel"))) == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sscanf (prop->value().c_str(), "%d", &channel) != 1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((prop = node.property (X_("ctl"))) != 0) {
|
if ((prop = node.property (X_("ctl"))) != 0) {
|
||||||
ev = MIDI::controller;
|
ev = MIDI::controller;
|
||||||
|
|
@ -511,18 +663,33 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf (prop->value().c_str(), "%d", &detail) != 1) {
|
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
detail = (MIDI::byte) intval;
|
||||||
|
|
||||||
|
if ((prop = node.property (X_("channel"))) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_("uri"));
|
prop = node.property (X_("uri"));
|
||||||
uri = prop->value();
|
uri = prop->value();
|
||||||
|
|
||||||
MIDIControllable* mc = new MIDIControllable (*_port, uri, false);
|
MIDIControllable* mc = new MIDIControllable (*_port, uri, false);
|
||||||
mc->bind_midi (channel, ev, detail);
|
mc->bind_midi (channel, ev, detail);
|
||||||
|
|
||||||
cerr << "New MC with URI = " << uri << endl;
|
cerr << "New MC with URI " << uri << " on channel " << (int) channel << " detail = " << (int) detail << endl;
|
||||||
|
|
||||||
return mc;
|
return mc;
|
||||||
}
|
}
|
||||||
|
|
@ -534,9 +701,59 @@ GenericMidiControlProtocol::reset_controllables ()
|
||||||
|
|
||||||
for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end(); ++iter) {
|
for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end(); ++iter) {
|
||||||
MIDIControllable* existingBinding = (*iter);
|
MIDIControllable* existingBinding = (*iter);
|
||||||
|
|
||||||
boost::shared_ptr<Controllable> c = session->controllable_by_uri (existingBinding->current_uri());
|
if (!existingBinding->learned()) {
|
||||||
existingBinding->set_controllable (c.get());
|
cerr << "Look for " << existingBinding->current_uri() << endl;
|
||||||
|
|
||||||
|
/* parse URI to get remote control ID and "what" is to be controlled */
|
||||||
|
|
||||||
|
std::string uri = existingBinding->current_uri();
|
||||||
|
string::size_type last_slash;
|
||||||
|
string useful_part;
|
||||||
|
|
||||||
|
if ((last_slash = uri.find_last_of ('/')) == string::npos) {
|
||||||
|
existingBinding->set_controllable (0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
useful_part = uri.substr (last_slash+1);
|
||||||
|
|
||||||
|
char ridstr[64];
|
||||||
|
char what[64];
|
||||||
|
|
||||||
|
if (sscanf (useful_part.c_str(), "rid=%63[^?]?%63s", ridstr, what) != 2) {
|
||||||
|
existingBinding->set_controllable (0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* now parse RID string and determine if its a bank-driven ID */
|
||||||
|
|
||||||
|
uint32_t rid;
|
||||||
|
|
||||||
|
if (strncmp (ridstr, "B-", 2) == 0) {
|
||||||
|
|
||||||
|
if (sscanf (&ridstr[2], "%" PRIu32, &rid) != 1) {
|
||||||
|
existingBinding->set_controllable (0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
rid += _bank_size * _current_bank;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (sscanf (&ridstr[2], "%" PRIu32, &rid) != 1) {
|
||||||
|
existingBinding->set_controllable (0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* go get it (allowed to fail) */
|
||||||
|
|
||||||
|
cerr << "Look for controllable via " << rid << " and " << what << endl;
|
||||||
|
|
||||||
|
boost::shared_ptr<Controllable> c = session->controllable_by_rid_and_name (rid, what);
|
||||||
|
cerr << "\tgot " << c << endl;
|
||||||
|
existingBinding->set_controllable (c.get());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -588,7 +805,6 @@ GenericMidiControlProtocol::create_function (const XMLNode& node)
|
||||||
|
|
||||||
while (ss >> val) {
|
while (ss >> val) {
|
||||||
sysex[cnt++] = (MIDI::byte) val;
|
sysex[cnt++] = (MIDI::byte) val;
|
||||||
cerr << hex << (int) sysex[cnt-1] << dec << ' ' << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -598,6 +814,12 @@ GenericMidiControlProtocol::create_function (const XMLNode& node)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sysex_size == 0) {
|
if (sysex_size == 0) {
|
||||||
|
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
detail = (MIDI::byte) intval;
|
||||||
|
|
||||||
if ((prop = node.property (X_("channel"))) == 0) {
|
if ((prop = node.property (X_("channel"))) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -610,12 +832,6 @@ GenericMidiControlProtocol::create_function (const XMLNode& node)
|
||||||
if (channel > 0) {
|
if (channel > 0) {
|
||||||
channel -= 1;
|
channel -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
detail = (MIDI::byte) intval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prop = node.property (X_("function"));
|
prop = node.property (X_("function"));
|
||||||
|
|
@ -627,9 +843,32 @@ GenericMidiControlProtocol::create_function (const XMLNode& node)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cerr << "New MF with function = " << prop->value() << " on channel " << (int) channel << " detail = " << (int) detail << endl;
|
||||||
mf->bind_midi (channel, ev, detail);
|
mf->bind_midi (channel, ev, detail);
|
||||||
|
|
||||||
cerr << "New MF with function = " << prop->value() << endl;
|
|
||||||
|
|
||||||
return mf;
|
return mf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
#ifndef ardour_generic_midi_control_protocol_h
|
#ifndef ardour_generic_midi_control_protocol_h
|
||||||
#define ardour_generic_midi_control_protocol_h
|
#define ardour_generic_midi_control_protocol_h
|
||||||
|
|
||||||
#include <set>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <glibmm/thread.h>
|
#include <glibmm/thread.h>
|
||||||
#include "ardour/types.h"
|
#include "ardour/types.h"
|
||||||
|
|
@ -59,6 +58,27 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
|
||||||
XMLNode& get_state ();
|
XMLNode& get_state ();
|
||||||
int set_state (const XMLNode&, int version);
|
int set_state (const XMLNode&, int version);
|
||||||
|
|
||||||
|
bool has_editor () const { return true; }
|
||||||
|
void* get_gui () const;
|
||||||
|
void tear_down_gui ();
|
||||||
|
|
||||||
|
int load_bindings (const std::string&);
|
||||||
|
void drop_bindings ();
|
||||||
|
|
||||||
|
std::string current_binding() const { return _current_binding; }
|
||||||
|
|
||||||
|
struct MapInfo {
|
||||||
|
std::string name;
|
||||||
|
std::string path;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::list<MapInfo> map_info;
|
||||||
|
void reload_maps ();
|
||||||
|
|
||||||
|
void set_current_bank (uint32_t);
|
||||||
|
void next_bank ();
|
||||||
|
void prev_bank ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MIDI::Port* _port;
|
MIDI::Port* _port;
|
||||||
ARDOUR::microseconds_t _feedback_interval;
|
ARDOUR::microseconds_t _feedback_interval;
|
||||||
|
|
@ -68,7 +88,7 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
|
||||||
void _send_feedback ();
|
void _send_feedback ();
|
||||||
void send_feedback ();
|
void send_feedback ();
|
||||||
|
|
||||||
typedef std::set<MIDIControllable*> MIDIControllables;
|
typedef std::list<MIDIControllable*> MIDIControllables;
|
||||||
MIDIControllables controllables;
|
MIDIControllables controllables;
|
||||||
|
|
||||||
typedef std::list<MIDIFunction*> MIDIFunctions;
|
typedef std::list<MIDIFunction*> MIDIFunctions;
|
||||||
|
|
@ -88,11 +108,18 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
|
||||||
void create_binding (PBD::Controllable*, int, int);
|
void create_binding (PBD::Controllable*, int, int);
|
||||||
void delete_binding (PBD::Controllable*);
|
void delete_binding (PBD::Controllable*);
|
||||||
|
|
||||||
int load_bindings (const std::string&);
|
|
||||||
MIDIControllable* create_binding (const XMLNode&);
|
MIDIControllable* create_binding (const XMLNode&);
|
||||||
MIDIFunction* create_function (const XMLNode&);
|
MIDIFunction* create_function (const XMLNode&);
|
||||||
|
|
||||||
void reset_controllables ();
|
void reset_controllables ();
|
||||||
|
void drop_all ();
|
||||||
|
|
||||||
|
std::string _current_binding;
|
||||||
|
uint32_t _bank_size;
|
||||||
|
uint32_t _current_bank;
|
||||||
|
|
||||||
|
mutable void *gui;
|
||||||
|
void build_gui ();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* ardour_generic_midi_control_protocol_h */
|
#endif /* ardour_generic_midi_control_protocol_h */
|
||||||
|
|
|
||||||
112
libs/surfaces/generic_midi/gmcp_gui.cc
Normal file
112
libs/surfaces/generic_midi/gmcp_gui.cc
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <gtkmm/comboboxtext.h>
|
||||||
|
#include <gtkmm/label.h>
|
||||||
|
#include <gtkmm/box.h>
|
||||||
|
|
||||||
|
#include "gtkmm2ext/utils.h"
|
||||||
|
|
||||||
|
#include "generic_midi_control_protocol.h"
|
||||||
|
|
||||||
|
#include "i18n.h"
|
||||||
|
|
||||||
|
class GMCPGUI : public Gtk::VBox
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GMCPGUI (GenericMidiControlProtocol&);
|
||||||
|
~GMCPGUI ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
GenericMidiControlProtocol& cp;
|
||||||
|
Gtk::ComboBoxText map_combo;
|
||||||
|
|
||||||
|
void binding_changed ();
|
||||||
|
};
|
||||||
|
|
||||||
|
using namespace PBD;
|
||||||
|
using namespace ARDOUR;
|
||||||
|
using namespace std;
|
||||||
|
using namespace Gtk;
|
||||||
|
using namespace Gtkmm2ext;
|
||||||
|
|
||||||
|
void*
|
||||||
|
GenericMidiControlProtocol::get_gui () const
|
||||||
|
{
|
||||||
|
if (!gui) {
|
||||||
|
const_cast<GenericMidiControlProtocol*>(this)->build_gui ();
|
||||||
|
}
|
||||||
|
return gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GenericMidiControlProtocol::tear_down_gui ()
|
||||||
|
{
|
||||||
|
delete (GMCPGUI*) gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GenericMidiControlProtocol::build_gui ()
|
||||||
|
{
|
||||||
|
gui = (void*) new GMCPGUI (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------*/
|
||||||
|
|
||||||
|
GMCPGUI::GMCPGUI (GenericMidiControlProtocol& p)
|
||||||
|
: cp (p)
|
||||||
|
{
|
||||||
|
vector<string> popdowns;
|
||||||
|
popdowns.push_back (_("Reset All"));
|
||||||
|
|
||||||
|
for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
|
||||||
|
popdowns.push_back ((*x).name);
|
||||||
|
}
|
||||||
|
|
||||||
|
set_popdown_strings (map_combo, popdowns, true, 5, 2);
|
||||||
|
|
||||||
|
if (cp.current_binding().empty()) {
|
||||||
|
map_combo.set_active_text (popdowns[0]);
|
||||||
|
} else {
|
||||||
|
map_combo.set_active_text (cp.current_binding());
|
||||||
|
}
|
||||||
|
|
||||||
|
map_combo.signal_changed().connect (sigc::mem_fun (*this, &GMCPGUI::binding_changed));
|
||||||
|
|
||||||
|
set_border_width (12);
|
||||||
|
|
||||||
|
Label* label = manage (new Label (_("Available MIDI bindings:")));
|
||||||
|
HBox* hpack = manage (new HBox);
|
||||||
|
|
||||||
|
hpack->set_spacing (6);
|
||||||
|
hpack->pack_start (*label, false, false);
|
||||||
|
hpack->pack_start (map_combo, false, false);
|
||||||
|
|
||||||
|
pack_start (*hpack, false, false);
|
||||||
|
|
||||||
|
map_combo.show ();
|
||||||
|
label->show ();
|
||||||
|
hpack->show ();
|
||||||
|
}
|
||||||
|
|
||||||
|
GMCPGUI::~GMCPGUI ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
GMCPGUI::binding_changed ()
|
||||||
|
{
|
||||||
|
string str = map_combo.get_active_text ();
|
||||||
|
|
||||||
|
if (str == _("Reset All")) {
|
||||||
|
cp.drop_bindings ();
|
||||||
|
} else {
|
||||||
|
for (list<GenericMidiControlProtocol::MapInfo>::iterator x = cp.map_info.begin(); x != cp.map_info.end(); ++x) {
|
||||||
|
if (str == (*x).name) {
|
||||||
|
cp.load_bindings ((*x).path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
libs/surfaces/generic_midi/i18n.h
Normal file
16
libs/surfaces/generic_midi/i18n.h
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef __i18n_h__
|
||||||
|
#define __i18n_h__
|
||||||
|
|
||||||
|
#include "pbd/compose.h"
|
||||||
|
#include "pbd/convert.h"
|
||||||
|
#include "gettext.h"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define _(Text) dgettext (PACKAGE,Text)
|
||||||
|
#define N_(Text) gettext_noop (Text)
|
||||||
|
#define X_(Text) Text
|
||||||
|
#define I18N(Array) PBD::internationalize (PACKAGE, Array)
|
||||||
|
|
||||||
|
#endif // __i18n_h__
|
||||||
|
|
@ -55,6 +55,7 @@ MIDIControllable::~MIDIControllable ()
|
||||||
void
|
void
|
||||||
MIDIControllable::init ()
|
MIDIControllable::init ()
|
||||||
{
|
{
|
||||||
|
_learned = false;
|
||||||
setting = false;
|
setting = false;
|
||||||
last_value = 0; // got a better idea ?
|
last_value = 0; // got a better idea ?
|
||||||
control_type = none;
|
control_type = none;
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,9 @@ class MIDIControllable : public PBD::Stateful
|
||||||
float control_to_midi(float val);
|
float control_to_midi(float val);
|
||||||
float midi_to_control(float val);
|
float midi_to_control(float val);
|
||||||
|
|
||||||
|
void set_learned (bool yn) { _learned = yn; }
|
||||||
|
bool learned() const { return _learned; }
|
||||||
|
|
||||||
MIDI::Port& get_port() const { return _port; }
|
MIDI::Port& get_port() const { return _port; }
|
||||||
PBD::Controllable* get_controllable() const { return controllable; }
|
PBD::Controllable* get_controllable() const { return controllable; }
|
||||||
void set_controllable (PBD::Controllable*);
|
void set_controllable (PBD::Controllable*);
|
||||||
|
|
@ -86,6 +89,7 @@ class MIDIControllable : public PBD::Stateful
|
||||||
bool setting;
|
bool setting;
|
||||||
MIDI::byte last_value;
|
MIDI::byte last_value;
|
||||||
bool bistate;
|
bool bistate;
|
||||||
|
bool _learned;
|
||||||
int midi_msg_id; /* controller ID or note number */
|
int midi_msg_id; /* controller ID or note number */
|
||||||
PBD::ScopedConnection midi_sense_connection[2];
|
PBD::ScopedConnection midi_sense_connection[2];
|
||||||
PBD::ScopedConnection midi_learn_connection;
|
PBD::ScopedConnection midi_learn_connection;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
#include "midi++/port.h"
|
#include "midi++/port.h"
|
||||||
|
|
||||||
#include "midifunction.h"
|
#include "midifunction.h"
|
||||||
#include "control_protocol/basic_ui.h"
|
#include "generic_midi_control_protocol.h"
|
||||||
|
|
||||||
using namespace MIDI;
|
using namespace MIDI;
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ MIDIFunction::~MIDIFunction ()
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
MIDIFunction::init (BasicUI& ui, const std::string& function_name, MIDI::byte* sysex_data, size_t sysex_sz)
|
MIDIFunction::init (GenericMidiControlProtocol& ui, const std::string& function_name, MIDI::byte* sysex_data, size_t sysex_sz)
|
||||||
{
|
{
|
||||||
if (strcasecmp (function_name.c_str(), "transport-stop") == 0) {
|
if (strcasecmp (function_name.c_str(), "transport-stop") == 0) {
|
||||||
_function = TransportStop;
|
_function = TransportStop;
|
||||||
|
|
@ -56,6 +56,10 @@ MIDIFunction::init (BasicUI& ui, const std::string& function_name, MIDI::byte* s
|
||||||
_function = TransportRecordEnable;
|
_function = TransportRecordEnable;
|
||||||
} else if (strcasecmp (function_name.c_str(), "rec-disable") == 0) {
|
} else if (strcasecmp (function_name.c_str(), "rec-disable") == 0) {
|
||||||
_function = TransportRecordDisable;
|
_function = TransportRecordDisable;
|
||||||
|
} else if (strcasecmp (function_name.c_str(), "next-bank") == 0) {
|
||||||
|
_function = NextBank;
|
||||||
|
} else if (strcasecmp (function_name.c_str(), "prev-bank") == 0) {
|
||||||
|
_function = PrevBank;
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -75,6 +79,14 @@ void
|
||||||
MIDIFunction::execute ()
|
MIDIFunction::execute ()
|
||||||
{
|
{
|
||||||
switch (_function) {
|
switch (_function) {
|
||||||
|
case NextBank:
|
||||||
|
_ui->next_bank();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PrevBank:
|
||||||
|
_ui->prev_bank();
|
||||||
|
break;
|
||||||
|
|
||||||
case TransportStop:
|
case TransportStop:
|
||||||
_ui->transport_stop ();
|
_ui->transport_stop ();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,14 @@ namespace MIDI {
|
||||||
class Parser;
|
class Parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
class BasicUI;
|
class GenericMidiControlProtocol;
|
||||||
|
|
||||||
class MIDIFunction : public PBD::Stateful
|
class MIDIFunction : public PBD::Stateful
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Function {
|
enum Function {
|
||||||
|
NextBank,
|
||||||
|
PrevBank,
|
||||||
TransportRoll,
|
TransportRoll,
|
||||||
TransportStop,
|
TransportStop,
|
||||||
TransportZero,
|
TransportZero,
|
||||||
|
|
@ -54,7 +56,7 @@ class MIDIFunction : public PBD::Stateful
|
||||||
MIDIFunction (MIDI::Port&);
|
MIDIFunction (MIDI::Port&);
|
||||||
virtual ~MIDIFunction ();
|
virtual ~MIDIFunction ();
|
||||||
|
|
||||||
int init (BasicUI&, const std::string& function_name, MIDI::byte* sysex = 0, size_t ssize = 0);
|
int init (GenericMidiControlProtocol&, const std::string& function_name, MIDI::byte* sysex = 0, size_t ssize = 0);
|
||||||
|
|
||||||
MIDI::Port& get_port() const { return _port; }
|
MIDI::Port& get_port() const { return _port; }
|
||||||
const std::string& function_name() const { return _function_name; }
|
const std::string& function_name() const { return _function_name; }
|
||||||
|
|
@ -69,7 +71,7 @@ class MIDIFunction : public PBD::Stateful
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Function _function;
|
Function _function;
|
||||||
BasicUI* _ui;
|
GenericMidiControlProtocol* _ui;
|
||||||
std::string _function_name;
|
std::string _function_name;
|
||||||
MIDI::Port& _port;
|
MIDI::Port& _port;
|
||||||
PBD::ScopedConnection midi_sense_connection[2];
|
PBD::ScopedConnection midi_sense_connection[2];
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ def build(bld):
|
||||||
obj = bld.new_task_gen('cxx', 'shlib')
|
obj = bld.new_task_gen('cxx', 'shlib')
|
||||||
obj.source = '''
|
obj.source = '''
|
||||||
generic_midi_control_protocol.cc
|
generic_midi_control_protocol.cc
|
||||||
|
gmcp_gui.cc
|
||||||
interface.cc
|
interface.cc
|
||||||
midicontrollable.cc
|
midicontrollable.cc
|
||||||
midifunction.cc
|
midifunction.cc
|
||||||
|
|
@ -31,7 +32,8 @@ def build(bld):
|
||||||
obj.includes = ['.', './generic_midi']
|
obj.includes = ['.', './generic_midi']
|
||||||
obj.name = 'libardour_generic_midi'
|
obj.name = 'libardour_generic_midi'
|
||||||
obj.target = 'ardour_generic_midi'
|
obj.target = 'ardour_generic_midi'
|
||||||
obj.uselib_local = 'libardour libardour_cp'
|
obj.uselib = 'GTKMM GTK GDK'
|
||||||
|
obj.uselib_local = 'libardour libardour_cp libgtkmm2ext libpbd'
|
||||||
obj.vnum = LIBARDOUR_GENERIC_MIDI_LIB_VERSION
|
obj.vnum = LIBARDOUR_GENERIC_MIDI_LIB_VERSION
|
||||||
obj.install_path = os.path.join(bld.env['LIBDIR'], 'ardour3', 'surfaces')
|
obj.install_path = os.path.join(bld.env['LIBDIR'], 'ardour3', 'surfaces')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue