From 0fe8ea55644ad70bcb10b4b2c840370fdc2339c5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 5 May 2014 14:38:16 +0000 Subject: Support Jack CV and OSC via metadata. git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@5398 a436a847-0d15-0410-975c-d299462d15a1 --- src/Configuration.cpp | 10 +++++--- src/Configuration.hpp | 4 ++-- src/JackDriver.cpp | 64 ++++++++++++++++++++++++++++++++++---------------- src/Legend.hpp | 10 +++++--- src/PatchageCanvas.cpp | 17 +++++++++----- 5 files changed, 71 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 74bcb25..152c2f0 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -30,7 +30,9 @@ static const char* port_type_names[N_PORT_TYPES] = { "JACK_AUDIO", "JACK_MIDI", - "ALSA_MIDI" + "ALSA_MIDI", + "JACK_OSC", + "JACK_CV" }; Configuration::Configuration() @@ -41,8 +43,10 @@ Configuration::Configuration() , _show_toolbar(true) { _port_colors[JACK_AUDIO] = _default_port_colors[JACK_AUDIO] = 0x3E5E00FF; - _port_colors[JACK_MIDI] = _default_port_colors[JACK_MIDI] = 0x650300FF; - _port_colors[ALSA_MIDI] = _default_port_colors[ALSA_MIDI] = 0x2D0043FF; + _port_colors[JACK_MIDI] = _default_port_colors[JACK_MIDI] = 0x650300FF; + _port_colors[ALSA_MIDI] = _default_port_colors[ALSA_MIDI] = 0x2D0043FF; + _port_colors[JACK_OSC] = _default_port_colors[JACK_OSC] = 0x4100FEFF; + _port_colors[JACK_CV] = _default_port_colors[JACK_CV] = 0x005E4EFF; } bool diff --git a/src/Configuration.hpp b/src/Configuration.hpp index 2f502be..a80c581 100644 --- a/src/Configuration.hpp +++ b/src/Configuration.hpp @@ -27,9 +27,9 @@ enum ModuleType { Input, Output, InputOutput }; -enum PortType { JACK_AUDIO, JACK_MIDI, ALSA_MIDI }; +enum PortType { JACK_AUDIO, JACK_MIDI, ALSA_MIDI, JACK_OSC, JACK_CV }; -#define N_PORT_TYPES 3 +#define N_PORT_TYPES 5 struct Coord { Coord(double x_=0, double y_=0) : x(x_), y(y_) {} diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 56119c6..7e73de6 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -33,6 +33,7 @@ #include "patchage_config.h" #ifdef HAVE_JACK_METADATA #include +#include "jackey.h" #endif using std::endl; @@ -110,7 +111,10 @@ JackDriver::detach() static bool is_jack_port(const PatchagePort* port) { - return port->type() == JACK_AUDIO || port->type() == JACK_MIDI; + return (port->type() == JACK_AUDIO || + port->type() == JACK_MIDI || + port->type() == JACK_OSC || + port->type() == JACK_CV); } /** Destroy all JACK (canvas) ports. @@ -176,35 +180,54 @@ JackDriver::create_port_view(Patchage* patchage, PatchagePort* JackDriver::create_port(PatchageModule& parent, jack_port_t* port, PortID id) { - assert(port); - const char* const type_str = jack_port_type(port); - PortType port_type; + if (!port) { + return NULL; + } + + const char* const type_str = jack_port_type(port); + char* pretty_name = NULL; + char* datatype = NULL; + PortType port_type; + +#ifdef HAVE_JACK_METADATA + const jack_uuid_t uuid = jack_port_uuid(port); + jack_get_property(uuid, JACK_METADATA_PRETTY_NAME, &pretty_name, &datatype); +#endif if (!strcmp(type_str, JACK_DEFAULT_AUDIO_TYPE)) { - port_type = JACK_AUDIO; + char* signal_type = NULL; +#ifdef HAVE_JACK_METADATA + jack_get_property(uuid, JACKEY_SIGNAL_TYPE, &signal_type, &datatype); + jack_free(datatype); +#endif + if (signal_type && !strcmp(signal_type, "CV")) { + port_type = JACK_CV; + jack_free(signal_type); + } else { + port_type = JACK_AUDIO; + } } else if (!strcmp(type_str, JACK_DEFAULT_MIDI_TYPE)) { - port_type = JACK_MIDI; + char* event_types = NULL; +#ifdef HAVE_JACK_METADATA + jack_get_property(uuid, JACKEY_EVENT_TYPES, &event_types, &datatype); + jack_free(datatype); +#endif + if (event_types && !strcmp(event_types, "OSC")) { + port_type = JACK_OSC; + jack_free(event_types); + } else { + port_type = JACK_MIDI; + } } else { _app->warning_msg((format("Jack: Port `%1%' has unknown type `%2%'.") % jack_port_name(port) % type_str).str()); + jack_free(pretty_name); return NULL; } - std::string label; -#ifdef HAVE_JACK_METADATA - const jack_uuid_t uuid = jack_port_uuid(port); - char* pretty_name = NULL; - char* type = NULL; - jack_get_property(uuid, JACK_METADATA_PRETTY_NAME, &pretty_name, &type); - if (pretty_name) { - label = pretty_name; - } - jack_free(pretty_name); - jack_free(type); -#endif - PatchagePort* ret( - new PatchagePort(parent, port_type, jack_port_short_name(port), label, + new PatchagePort(parent, port_type, jack_port_short_name(port), + pretty_name ? pretty_name : "", (jack_port_flags(port) & JackPortIsInput), _app->conf()->get_port_color(port_type), _app->show_human_names())); @@ -213,6 +236,7 @@ JackDriver::create_port(PatchageModule& parent, jack_port_t* port, PortID id) dynamic_cast(parent.canvas())->index_port(id, ret); } + jack_free(pretty_name); return ret; } diff --git a/src/Legend.hpp b/src/Legend.hpp index 4c8f57f..2e9fabf 100644 --- a/src/Legend.hpp +++ b/src/Legend.hpp @@ -25,9 +25,13 @@ class Legend : public Gtk::HBox { public: Legend(const Configuration& configuration) { - add_button(JACK_AUDIO, "Audio", configuration.get_port_color(JACK_AUDIO)); - add_button(JACK_MIDI, "JACK MIDI", configuration.get_port_color(JACK_MIDI)); - add_button(ALSA_MIDI, "ALSA MIDI", configuration.get_port_color(ALSA_MIDI)); + add_button(JACK_AUDIO, "Audio", configuration.get_port_color(JACK_AUDIO)); +#ifdef HAVE_JACK_METADATA + add_button(JACK_CV, "CV", configuration.get_port_color(JACK_CV)); + add_button(JACK_OSC, "OSC", configuration.get_port_color(JACK_OSC)); +#endif + add_button(JACK_MIDI, "MIDI", configuration.get_port_color(JACK_MIDI)); + add_button(ALSA_MIDI, "ALSA MIDI", configuration.get_port_color(ALSA_MIDI)); show_all_children(); } diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index cbee58b..7a9cacc 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -215,8 +215,11 @@ PatchageCanvas::connect(Ganv::Node* port1, if (!p1 || !p2) return; - if ((p1->type() == JACK_AUDIO && p2->type() == JACK_AUDIO) - || ((p1->type() == JACK_MIDI && p2->type() == JACK_MIDI))) { + if ((p1->type() == JACK_AUDIO && p2->type() == JACK_AUDIO) || + (p1->type() == JACK_MIDI && p2->type() == JACK_MIDI) | + (p1->type() == JACK_AUDIO && p2->type() == JACK_CV) || + (p1->type() == JACK_CV && p2->type() == JACK_CV) || + (p1->type() == JACK_OSC && p2->type() == JACK_OSC)) { #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) _app->jack_driver()->connect(p1, p2); #endif @@ -250,17 +253,19 @@ PatchageCanvas::disconnect(Ganv::Node* port1, return; } - if ((input->type() == JACK_AUDIO && output->type() == JACK_AUDIO) - || (input->type() == JACK_MIDI && output->type() == JACK_MIDI)) { + if (input->type() == JACK_AUDIO || + input->type() == JACK_MIDI || + input->type() == JACK_CV || + input->type() == JACK_OSC) { #if defined(PATCHAGE_LIBJACK) || defined(HAVE_JACK_DBUS) _app->jack_driver()->disconnect(output, input); #endif #ifdef HAVE_ALSA - } else if (input->type() == ALSA_MIDI && output->type() == ALSA_MIDI) { + } else if (input->type() == ALSA_MIDI) { _app->alsa_driver()->disconnect(output, input); #endif } else { - _app->error_msg("Attempt to disconnect ports with mismatched types."); + _app->error_msg("Attempt to disconnect ports with strange types."); } } -- cgit v1.2.1