mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-04 04:39:33 +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
|
|
@ -98,6 +98,10 @@ class ControlProtocol : virtual public sigc::trackable, public PBD::Stateful, pu
|
|||
|
||||
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:
|
||||
PBD::EventLoop* _event_loop;
|
||||
bool _own_event_loop;
|
||||
|
|
|
|||
|
|
@ -25,10 +25,13 @@
|
|||
|
||||
#include "pbd/error.h"
|
||||
#include "pbd/failed_constructor.h"
|
||||
#include "pbd/pathscanner.h"
|
||||
#include "pbd/xml++.h"
|
||||
|
||||
#include "midi++/port.h"
|
||||
#include "midi++/manager.h"
|
||||
|
||||
#include "ardour/filesystem_paths.h"
|
||||
#include "ardour/session.h"
|
||||
#include "ardour/route.h"
|
||||
#include "ardour/midi_ui.h"
|
||||
|
|
@ -48,9 +51,11 @@ using namespace std;
|
|||
|
||||
GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
|
||||
: 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
|
||||
the name is defined in ardour.rc which is likely not internationalized.
|
||||
*/
|
||||
|
|
@ -66,6 +71,9 @@ GenericMidiControlProtocol::GenericMidiControlProtocol (Session& s)
|
|||
_feedback_interval = 10000; // microseconds
|
||||
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? */
|
||||
|
||||
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());;
|
||||
|
||||
std::string xmlpath = "/tmp/midi.map";
|
||||
|
||||
load_bindings (xmlpath);
|
||||
reset_controllables ();
|
||||
reload_maps ();
|
||||
}
|
||||
|
||||
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 lm2 (controllables_lock);
|
||||
|
|
@ -102,6 +190,30 @@ GenericMidiControlProtocol::~GenericMidiControlProtocol ()
|
|||
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
|
||||
GenericMidiControlProtocol::set_active (bool /*yn*/)
|
||||
{
|
||||
|
|
@ -237,7 +349,7 @@ GenericMidiControlProtocol::learning_stopped (MIDIControllable* mc)
|
|||
i = tmp;
|
||||
}
|
||||
|
||||
controllables.insert (mc);
|
||||
controllables.push_back (mc);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -314,8 +426,9 @@ GenericMidiControlProtocol::create_binding (PBD::Controllable* control, int pos,
|
|||
// 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...
|
||||
mc->bind_midi(channel, MIDI::controller, value);
|
||||
|
||||
controllables.insert (mc);
|
||||
mc->set_learned (true);
|
||||
|
||||
controllables.push_back (mc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -330,13 +443,25 @@ GenericMidiControlProtocol::get_state ()
|
|||
snprintf (buf, sizeof (buf), "%" PRIu64, _feedback_interval);
|
||||
node->add_property (X_("feedback_interval"), buf);
|
||||
|
||||
if (!_current_binding.empty()) {
|
||||
node->add_property ("binding", _current_binding);
|
||||
}
|
||||
|
||||
XMLNode* children = new XMLNode (X_("controls"));
|
||||
|
||||
node->add_child_nocopy (*children);
|
||||
|
||||
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||
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;
|
||||
|
|
@ -372,37 +497,50 @@ GenericMidiControlProtocol::set_state (const XMLNode& node, int version)
|
|||
}
|
||||
pending_controllables.clear ();
|
||||
}
|
||||
|
||||
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||
controllables.clear ();
|
||||
nlist = node.children(); // "controls"
|
||||
|
||||
if (nlist.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
nlist = nlist.front()->children ();
|
||||
|
||||
{
|
||||
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||
controllables.clear ();
|
||||
nlist = node.children(); // "controls"
|
||||
|
||||
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 ();
|
||||
c = session->controllable_by_id (id);
|
||||
|
||||
if (c) {
|
||||
MIDIControllable* mc = new MIDIControllable (*_port, *c);
|
||||
if (mc->set_state (**niter, version) == 0) {
|
||||
controllables.insert (mc);
|
||||
}
|
||||
if ((prop = (*niter)->property ("id")) != 0) {
|
||||
|
||||
} else {
|
||||
warning << string_compose (
|
||||
_("Generic MIDI control: controllable %1 not found in session (ignored)"),
|
||||
id) << endmsg;
|
||||
ID id = prop->value ();
|
||||
c = session->controllable_by_id (id);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -420,6 +558,9 @@ GenericMidiControlProtocol::get_feedback () const
|
|||
return do_feedback;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int
|
||||
GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
||||
{
|
||||
|
|
@ -456,7 +597,19 @@ GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
|||
|
||||
MIDIControllable* mc;
|
||||
|
||||
drop_all ();
|
||||
|
||||
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") {
|
||||
const XMLNode* child = *citer;
|
||||
|
||||
|
|
@ -465,7 +618,7 @@ GenericMidiControlProtocol::load_bindings (const string& xmlpath)
|
|||
|
||||
if ((mc = create_binding (*child)) != 0) {
|
||||
Glib::Mutex::Lock lm2 (controllables_lock);
|
||||
controllables.insert (mc);
|
||||
controllables.push_back (mc);
|
||||
}
|
||||
|
||||
} 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;
|
||||
}
|
||||
|
|
@ -489,18 +648,11 @@ MIDIControllable*
|
|||
GenericMidiControlProtocol::create_binding (const XMLNode& node)
|
||||
{
|
||||
const XMLProperty* prop;
|
||||
int detail;
|
||||
int channel;
|
||||
MIDI::byte detail;
|
||||
MIDI::channel_t channel;
|
||||
string uri;
|
||||
MIDI::eventType ev;
|
||||
|
||||
if ((prop = node.property (X_("channel"))) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sscanf (prop->value().c_str(), "%d", &channel) != 1) {
|
||||
return 0;
|
||||
}
|
||||
int intval;
|
||||
|
||||
if ((prop = node.property (X_("ctl"))) != 0) {
|
||||
ev = MIDI::controller;
|
||||
|
|
@ -511,18 +663,33 @@ GenericMidiControlProtocol::create_binding (const XMLNode& node)
|
|||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sscanf (prop->value().c_str(), "%d", &detail) != 1) {
|
||||
|
||||
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
||||
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"));
|
||||
uri = prop->value();
|
||||
|
||||
MIDIControllable* mc = new MIDIControllable (*_port, uri, false);
|
||||
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;
|
||||
}
|
||||
|
|
@ -534,9 +701,59 @@ GenericMidiControlProtocol::reset_controllables ()
|
|||
|
||||
for (MIDIControllables::iterator iter = controllables.begin(); iter != controllables.end(); ++iter) {
|
||||
MIDIControllable* existingBinding = (*iter);
|
||||
|
||||
boost::shared_ptr<Controllable> c = session->controllable_by_uri (existingBinding->current_uri());
|
||||
existingBinding->set_controllable (c.get());
|
||||
|
||||
if (!existingBinding->learned()) {
|
||||
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) {
|
||||
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 (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
detail = (MIDI::byte) intval;
|
||||
|
||||
if ((prop = node.property (X_("channel"))) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -610,12 +832,6 @@ GenericMidiControlProtocol::create_function (const XMLNode& node)
|
|||
if (channel > 0) {
|
||||
channel -= 1;
|
||||
}
|
||||
|
||||
if (sscanf (prop->value().c_str(), "%d", &intval) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
detail = (MIDI::byte) intval;
|
||||
}
|
||||
|
||||
prop = node.property (X_("function"));
|
||||
|
|
@ -627,9 +843,32 @@ GenericMidiControlProtocol::create_function (const XMLNode& node)
|
|||
return 0;
|
||||
}
|
||||
|
||||
cerr << "New MF with function = " << prop->value() << " on channel " << (int) channel << " detail = " << (int) detail << endl;
|
||||
mf->bind_midi (channel, ev, detail);
|
||||
|
||||
cerr << "New MF with function = " << prop->value() << endl;
|
||||
|
||||
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
|
||||
#define ardour_generic_midi_control_protocol_h
|
||||
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <glibmm/thread.h>
|
||||
#include "ardour/types.h"
|
||||
|
|
@ -59,6 +58,27 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
|
|||
XMLNode& get_state ();
|
||||
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:
|
||||
MIDI::Port* _port;
|
||||
ARDOUR::microseconds_t _feedback_interval;
|
||||
|
|
@ -68,7 +88,7 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
|
|||
void _send_feedback ();
|
||||
void send_feedback ();
|
||||
|
||||
typedef std::set<MIDIControllable*> MIDIControllables;
|
||||
typedef std::list<MIDIControllable*> MIDIControllables;
|
||||
MIDIControllables controllables;
|
||||
|
||||
typedef std::list<MIDIFunction*> MIDIFunctions;
|
||||
|
|
@ -88,11 +108,18 @@ class GenericMidiControlProtocol : public ARDOUR::ControlProtocol {
|
|||
void create_binding (PBD::Controllable*, int, int);
|
||||
void delete_binding (PBD::Controllable*);
|
||||
|
||||
int load_bindings (const std::string&);
|
||||
MIDIControllable* create_binding (const XMLNode&);
|
||||
MIDIFunction* create_function (const XMLNode&);
|
||||
|
||||
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 */
|
||||
|
|
|
|||
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
|
||||
MIDIControllable::init ()
|
||||
{
|
||||
_learned = false;
|
||||
setting = false;
|
||||
last_value = 0; // got a better idea ?
|
||||
control_type = none;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,9 @@ class MIDIControllable : public PBD::Stateful
|
|||
float control_to_midi(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; }
|
||||
PBD::Controllable* get_controllable() const { return controllable; }
|
||||
void set_controllable (PBD::Controllable*);
|
||||
|
|
@ -86,6 +89,7 @@ class MIDIControllable : public PBD::Stateful
|
|||
bool setting;
|
||||
MIDI::byte last_value;
|
||||
bool bistate;
|
||||
bool _learned;
|
||||
int midi_msg_id; /* controller ID or note number */
|
||||
PBD::ScopedConnection midi_sense_connection[2];
|
||||
PBD::ScopedConnection midi_learn_connection;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#include "midi++/port.h"
|
||||
|
||||
#include "midifunction.h"
|
||||
#include "control_protocol/basic_ui.h"
|
||||
#include "generic_midi_control_protocol.h"
|
||||
|
||||
using namespace MIDI;
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ MIDIFunction::~MIDIFunction ()
|
|||
}
|
||||
|
||||
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) {
|
||||
_function = TransportStop;
|
||||
|
|
@ -56,6 +56,10 @@ MIDIFunction::init (BasicUI& ui, const std::string& function_name, MIDI::byte* s
|
|||
_function = TransportRecordEnable;
|
||||
} else if (strcasecmp (function_name.c_str(), "rec-disable") == 0) {
|
||||
_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 {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -75,6 +79,14 @@ void
|
|||
MIDIFunction::execute ()
|
||||
{
|
||||
switch (_function) {
|
||||
case NextBank:
|
||||
_ui->next_bank();
|
||||
break;
|
||||
|
||||
case PrevBank:
|
||||
_ui->prev_bank();
|
||||
break;
|
||||
|
||||
case TransportStop:
|
||||
_ui->transport_stop ();
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -35,12 +35,14 @@ namespace MIDI {
|
|||
class Parser;
|
||||
}
|
||||
|
||||
class BasicUI;
|
||||
class GenericMidiControlProtocol;
|
||||
|
||||
class MIDIFunction : public PBD::Stateful
|
||||
{
|
||||
public:
|
||||
enum Function {
|
||||
NextBank,
|
||||
PrevBank,
|
||||
TransportRoll,
|
||||
TransportStop,
|
||||
TransportZero,
|
||||
|
|
@ -54,7 +56,7 @@ class MIDIFunction : public PBD::Stateful
|
|||
MIDIFunction (MIDI::Port&);
|
||||
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; }
|
||||
const std::string& function_name() const { return _function_name; }
|
||||
|
|
@ -69,7 +71,7 @@ class MIDIFunction : public PBD::Stateful
|
|||
|
||||
private:
|
||||
Function _function;
|
||||
BasicUI* _ui;
|
||||
GenericMidiControlProtocol* _ui;
|
||||
std::string _function_name;
|
||||
MIDI::Port& _port;
|
||||
PBD::ScopedConnection midi_sense_connection[2];
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ def build(bld):
|
|||
obj = bld.new_task_gen('cxx', 'shlib')
|
||||
obj.source = '''
|
||||
generic_midi_control_protocol.cc
|
||||
gmcp_gui.cc
|
||||
interface.cc
|
||||
midicontrollable.cc
|
||||
midifunction.cc
|
||||
|
|
@ -31,7 +32,8 @@ def build(bld):
|
|||
obj.includes = ['.', './generic_midi']
|
||||
obj.name = 'libardour_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.install_path = os.path.join(bld.env['LIBDIR'], 'ardour3', 'surfaces')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue