diff --git a/mididings/engine.py b/mididings/engine.py index 3fe83030..cd973769 100644 --- a/mididings/engine.py +++ b/mididings/engine.py @@ -358,6 +358,23 @@ def time(): """ return _TheEngine().time() +def get_client_name(): + """ + Return actual client name + """ + return _TheEngine().get_client_name() + +def get_client_id(): + """ + Return client id + """ + if _setup.get_config('backend') == 'alsa': + return _TheEngine().get_client_id() + uuid = _TheEngine().get_client_uuid() + if uuid.isdigit(): + return int(uuid) + return uuid + def active(): """ Return ``True`` if the mididings engine is active (the :func:`~.run()` diff --git a/src/backend/alsa.cc b/src/backend/alsa.cc index 38f71b19..97755150 100644 --- a/src/backend/alsa.cc +++ b/src/backend/alsa.cc @@ -111,6 +111,26 @@ void ALSABackend::connect_ports( } +std::string ALSABackend::get_actual_client_name() +{ + snd_seq_client_info_t *client_info; + snd_seq_client_info_alloca(&client_info); + snd_seq_get_client_info(_seq, client_info); + std::string client_name = snd_seq_client_info_get_name(client_info); + return client_name; +} + + +int ALSABackend::get_client_id() +{ + snd_seq_client_info_t *client_info; + snd_seq_client_info_alloca(&client_info); + snd_seq_get_client_info(_seq, client_info); + int client_id = snd_seq_client_info_get_client(client_info); + return client_id; +} + + void ALSABackend::connect_ports_impl( PortConnectionMap const & port_connections, PortIdVector const & port_ids, diff --git a/src/backend/alsa.hh b/src/backend/alsa.hh index e0a623c0..b4a70aed 100644 --- a/src/backend/alsa.hh +++ b/src/backend/alsa.hh @@ -57,6 +57,10 @@ class ALSABackend virtual void connect_ports(PortConnectionMap const & in_port_connections, PortConnectionMap const & out_port_connections); + virtual std::string get_actual_client_name(); + + virtual int get_client_id(); + private: /** * Name and id of an ALSA port, including its client name/id. diff --git a/src/backend/base.hh b/src/backend/base.hh index fad2ce46..95aa3ef4 100644 --- a/src/backend/base.hh +++ b/src/backend/base.hh @@ -78,6 +78,12 @@ class BackendBase virtual void connect_ports(PortConnectionMap const &, PortConnectionMap const &) { } + virtual std::string get_actual_client_name() { } + + virtual int get_client_id() { } + + virtual std::string get_client_uuid() { } + // start MIDI processing, run init function. depending on the backend, // cycle may be called once (and not return) or periodically. virtual void start(InitFunction init, CycleFunction cycle) = 0; diff --git a/src/backend/jack.cc b/src/backend/jack.cc index 0b3ba322..ed838187 100644 --- a/src/backend/jack.cc +++ b/src/backend/jack.cc @@ -89,6 +89,20 @@ void JACKBackend::connect_ports( } +std::string JACKBackend::get_actual_client_name() +{ + std::string client_name = jack_get_client_name(_client); + return client_name; +} + + +std::string JACKBackend::get_client_uuid() +{ + std::string client_uuid = jack_get_uuid_for_client_name(_client, jack_get_client_name(_client)); + return client_uuid; +} + + void JACKBackend::connect_ports_impl( PortConnectionMap const & port_connections, std::vector const & ports, diff --git a/src/backend/jack.hh b/src/backend/jack.hh index c91f4f0a..f804e519 100644 --- a/src/backend/jack.hh +++ b/src/backend/jack.hh @@ -45,6 +45,10 @@ class JACKBackend virtual void connect_ports(PortConnectionMap const & in_port_connections, PortConnectionMap const & out_port_connections); + virtual std::string get_actual_client_name(); + + virtual std::string get_client_uuid(); + protected: // XXX this should be pure virtual. // it isn't, because the process thread is started from within the c'tor diff --git a/src/engine.hh b/src/engine.hh index 8ef943bb..57a1e8ad 100644 --- a/src/engine.hh +++ b/src/engine.hh @@ -102,6 +102,12 @@ class Engine double time(); + std::string get_client_name() const { return _backend->get_actual_client_name(); }; + + int get_client_id() const { return _backend->get_client_id(); }; + + std::string get_client_uuid() const { return _backend->get_client_uuid(); }; + PythonCaller & python_caller() const { return *_python_caller; } protected: diff --git a/src/python_module.cc b/src/python_module.cc index d95105fa..6e799c48 100644 --- a/src/python_module.cc +++ b/src/python_module.cc @@ -203,6 +203,9 @@ BOOST_PYTHON_MODULE(_mididings) .def("process_event", &Engine::process_event) .def("output_event", &Engine::output_event) .def("time", &Engine::time) + .def("get_client_name", &Engine::get_client_name) + .def("get_client_id", &Engine::get_client_id) + .def("get_client_uuid", &Engine::get_client_uuid) ;