Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for get_client_name() and get_client_id() to engine #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions mididings/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down
20 changes: 20 additions & 0 deletions src/backend/alsa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/backend/alsa.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/backend/base.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/backend/jack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<jack_port_t *> const & ports,
Expand Down
4 changes: 4 additions & 0 deletions src/backend/jack.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/engine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/python_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;


Expand Down