diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2009-12-29 21:31:14 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2009-12-29 21:31:14 +0000 |
commit | 77cc0f7cc84df5e242898cef0abb7d633de64d8c (patch) | |
tree | 71ec1c03dec23ac52949138cf8b5f7a1afb8e5ba | |
parent | e10d0339ccd3659e0de58db29131e528571bc8c4 (diff) |
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
-rw-r--r-- | gtk2_ardour/plugin_selector.cc | 3 | ||||
-rw-r--r-- | gtk2_ardour/rc_option_editor.cc | 46 | ||||
-rw-r--r-- | libs/ardour/ardour/session.h | 2 | ||||
-rw-r--r-- | libs/ardour/session.cc | 5 | ||||
-rw-r--r-- | libs/ardour/session_state.cc | 27 | ||||
-rw-r--r-- | libs/midi++2/jack_midiport.cc | 103 | ||||
-rw-r--r-- | libs/midi++2/midi++/jack.h | 14 | ||||
-rw-r--r-- | libs/surfaces/control_protocol/control_protocol/control_protocol.h | 4 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/generic_midi_control_protocol.cc | 355 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/generic_midi_control_protocol.h | 33 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/gmcp_gui.cc | 112 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/i18n.h | 16 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/midicontrollable.cc | 1 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/midicontrollable.h | 4 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/midifunction.cc | 16 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/midifunction.h | 8 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/wscript | 4 |
17 files changed, 658 insertions, 95 deletions
diff --git a/gtk2_ardour/plugin_selector.cc b/gtk2_ardour/plugin_selector.cc index 63ec9abf37..2800343784 100644 --- a/gtk2_ardour/plugin_selector.cc +++ b/gtk2_ardour/plugin_selector.cc @@ -200,8 +200,9 @@ PluginSelector::~PluginSelector () void PluginSelector::row_clicked(GdkEventButton* event) { - if (event->type == GDK_2BUTTON_PRESS) + if (event->type == GDK_2BUTTON_PRESS) { btn_add_clicked(); + } } bool diff --git a/gtk2_ardour/rc_option_editor.cc b/gtk2_ardour/rc_option_editor.cc index 4a5bce4674..e35ec0026d 100644 --- a/gtk2_ardour/rc_option_editor.cc +++ b/gtk2_ardour/rc_option_editor.cc @@ -765,7 +765,8 @@ private: class ControlSurfacesOptions : public OptionEditorBox { public: - ControlSurfacesOptions () + ControlSurfacesOptions (ArdourDialog& parent) + : _parent (parent) { _store = ListStore::create (_model); _view.set_model (_store); @@ -777,7 +778,13 @@ public: _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)); + _view.signal_button_press_event().connect_notify (sigc::mem_fun(*this, &ControlSurfacesOptions::edit_clicked)); } 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 { public: @@ -842,17 +881,20 @@ private: add (enabled); add (feedback); add (protocol_info); + add (editor); } TreeModelColumn<string> name; TreeModelColumn<bool> enabled; TreeModelColumn<bool> feedback; TreeModelColumn<ControlProtocolInfo*> protocol_info; + TreeModelColumn<Gtk::Window*> editor; }; Glib::RefPtr<ListStore> _store; ControlSurfacesModelColumns _model; TreeView _view; + Gtk::Window& _parent; }; @@ -1355,7 +1397,7 @@ RCOptionEditor::RCOptionEditor () /* CONTROL SURFACES */ - add_option (_("Control surfaces"), new ControlSurfacesOptions); + add_option (_("Control surfaces"), new ControlSurfacesOptions (*this)); ComboOption<RemoteModel>* rm = new ComboOption<RemoteModel> ( "remote-model", diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index a21bc04690..6f695e4755 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -769,7 +769,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi /* Controllables */ 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 remove_controllable (PBD::Controllable*); diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index b3c0ed29fb..19aca23c34 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -32,9 +32,9 @@ #include <glibmm/thread.h> #include <glibmm/miscutils.h> #include <glibmm/fileutils.h> +#include <glibmm/thread.h> #include "pbd/error.h" -#include <glibmm/thread.h> #include "pbd/boost_debug.h" #include "pbd/pathscanner.h" #include "pbd/stl_delete.h" @@ -93,6 +93,8 @@ #include "ardour/tempo.h" #include "ardour/utils.h" +#include "midi++/jack.h" + #include "i18n.h" using namespace std; @@ -790,6 +792,7 @@ Session::hookup_io () /* Tell all IO objects to connect themselves together */ IO::enable_connecting (); + MIDI::JACK_MidiPort::MakeConnections (); /* Now reset all panners */ diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index 8ff076f759..6a72777c7c 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -2679,25 +2679,9 @@ Session::controllable_by_id (const PBD::ID& id) } 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; - 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); if (!r) { @@ -2706,8 +2690,17 @@ Session::controllable_by_uri (const std::string& uri) if (strncmp (what, "gain", 4) == 0) { 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, "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; diff --git a/libs/midi++2/jack_midiport.cc b/libs/midi++2/jack_midiport.cc index ab6c598c8d..35e9ade1a3 100644 --- a/libs/midi++2/jack_midiport.cc +++ b/libs/midi++2/jack_midiport.cc @@ -25,6 +25,7 @@ #include "pbd/error.h" #include "pbd/compose.h" +#include "pbd/strsplit.h" #include "midi++/types.h" #include "midi++/jack.h" @@ -35,6 +36,9 @@ using namespace PBD; 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) : Port(node) , _jack_client(jack_client) @@ -47,22 +51,39 @@ JACK_MidiPort::JACK_MidiPort(const XMLNode& node, jack_client_t* jack_client) if (!create_ports (node)) { _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() { 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; } 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; } } void +JACK_MidiPort::jack_halted () +{ + _jack_client = 0; + _jack_input_port = 0; + _jack_output_port = 0; +} + +void JACK_MidiPort::cycle_start (nframes_t nframes) { Port::cycle_start(nframes); @@ -270,12 +291,88 @@ XMLNode& JACK_MidiPort::get_state () const { 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; } 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 diff --git a/libs/midi++2/midi++/jack.h b/libs/midi++2/midi++/jack.h index 18a6f3df68..fbc640b161 100644 --- a/libs/midi++2/midi++/jack.h +++ b/libs/midi++2/midi++/jack.h @@ -34,6 +34,7 @@ #include <jack/midiport.h> #include "pbd/ringbuffer.h" +#include "pbd/signals.h" #include "pbd/crossthread.h" #include "evoral/EventRingBuffer.hpp" @@ -43,7 +44,6 @@ namespace MIDI { - class JACK_MidiPort : public Port { public: @@ -69,7 +69,10 @@ public: static bool is_process_thread(); nframes_t nframes_this_cycle() const { return _nframes_this_cycle; } - + + static PBD::Signal0<void> MakeConnections; + static PBD::Signal0<void> JackHalted; + protected: std::string get_typestring () const { return typestring; @@ -84,8 +87,13 @@ private: nframes_t _last_read_index; timestamp_t _last_write_timestamp; 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 jack_halted (); + void make_connections(); static pthread_t _process_thread; diff --git a/libs/surfaces/control_protocol/control_protocol/control_protocol.h b/libs/surfaces/control_protocol/control_protocol/control_protocol.h index b3d44a15aa..559da08d33 100644 --- a/libs/surfaces/control_protocol/control_protocol/control_protocol.h +++ b/libs/surfaces/control_protocol/control_protocol/control_protocol.h @@ -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; diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc index d0d74f4c12..e7fa9018c9 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc @@ -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,14 +83,94 @@ 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" + + if (nlist.empty()) { + return 0; + } - for (niter = nlist.begin(); niter != nlist.end(); ++niter) { + nlist = nlist.front()->children (); - if ((prop = (*niter)->property ("id")) != 0) { - - ID id = prop->value (); - c = session->controllable_by_id (id); + for (niter = nlist.begin(); niter != nlist.end(); ++niter) { - 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 (); + } +} diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.h b/libs/surfaces/generic_midi/generic_midi_control_protocol.h index 0c476f2418..050bde5050 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.h +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.h @@ -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 */ diff --git a/libs/surfaces/generic_midi/gmcp_gui.cc b/libs/surfaces/generic_midi/gmcp_gui.cc new file mode 100644 index 0000000000..38bbdbe00a --- /dev/null +++ b/libs/surfaces/generic_midi/gmcp_gui.cc @@ -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; + } + } + } +} diff --git a/libs/surfaces/generic_midi/i18n.h b/libs/surfaces/generic_midi/i18n.h new file mode 100644 index 0000000000..dcbbfcf52e --- /dev/null +++ b/libs/surfaces/generic_midi/i18n.h @@ -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__ diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc index 9c808af005..6b0a08b620 100644 --- a/libs/surfaces/generic_midi/midicontrollable.cc +++ b/libs/surfaces/generic_midi/midicontrollable.cc @@ -55,6 +55,7 @@ MIDIControllable::~MIDIControllable () void MIDIControllable::init () { + _learned = false; setting = false; last_value = 0; // got a better idea ? control_type = none; diff --git a/libs/surfaces/generic_midi/midicontrollable.h b/libs/surfaces/generic_midi/midicontrollable.h index b6f7da5639..cd42afde56 100644 --- a/libs/surfaces/generic_midi/midicontrollable.h +++ b/libs/surfaces/generic_midi/midicontrollable.h @@ -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; diff --git a/libs/surfaces/generic_midi/midifunction.cc b/libs/surfaces/generic_midi/midifunction.cc index 609aca3bbc..d6cbdb9a6e 100644 --- a/libs/surfaces/generic_midi/midifunction.cc +++ b/libs/surfaces/generic_midi/midifunction.cc @@ -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; diff --git a/libs/surfaces/generic_midi/midifunction.h b/libs/surfaces/generic_midi/midifunction.h index 8931e2c9eb..bc019cfb3c 100644 --- a/libs/surfaces/generic_midi/midifunction.h +++ b/libs/surfaces/generic_midi/midifunction.h @@ -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]; diff --git a/libs/surfaces/generic_midi/wscript b/libs/surfaces/generic_midi/wscript index 89e427323f..5926e0e9da 100644 --- a/libs/surfaces/generic_midi/wscript +++ b/libs/surfaces/generic_midi/wscript @@ -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') |