Просмотр исходного кода

implemented Port.get_client_name()

Fabian Peter Hammerle 9 лет назад
Родитель
Сommit
aa9d4e074c
3 измененных файлов с 28 добавлено и 4 удалено
  1. 2 1
      examples/list-ports.py
  2. 24 1
      jack.c
  3. 2 2
      setup.py

+ 2 - 1
examples/ports-list.py → examples/list-ports.py

@@ -9,10 +9,11 @@ import argparse
 
 def run():
 
-    client = jack.Client("ports list example");
+    client = jack.Client("list ports example");
 
     for port in client.get_ports():
         print port.get_name()
+        print '\tclient: ' + port.get_client_name()
         print '\tshort: ' + port.get_short_name()
         for alias in port.get_aliases():
             print '\talias: ' + alias

+ 24 - 1
jack.c

@@ -196,6 +196,23 @@ static PyObject* port_set_short_name(Port* self, PyObject* args)
     return Py_None;
 }
 
+static PyObject* port_get_client_name(Port* self)
+{
+    // e.g. "PulseAudio JACK Sink:front-left"
+    const char* port_name = jack_port_name(self->port);
+
+    int client_name_length = strlen(port_name) - strlen(jack_port_short_name(self->port)) - 1;
+
+    // e.g. "PulseAudio JACK Sink"
+    char* client_name = (char*) malloc(jack_port_name_size());
+    strncpy(client_name, port_name, client_name_length);
+    client_name[client_name_length] = '\0';
+    PyObject* client_name_python = PyString_FromString(client_name);
+    free(client_name);
+
+    return client_name_python;
+}
+
 static PyObject* port_get_aliases(Port* self)
 {
     PyObject* aliases_list = PyList_New(0);
@@ -240,7 +257,13 @@ static PyMethodDef port_methods[] = {
         "get_short_name",
         (PyCFunction)port_get_short_name,
         METH_NOARGS,
-        "Return port's name without the preceding name of the asssociated client.",
+        "Return port's name without the preceding name of the associated client.",
+        },
+    {
+        "get_client_name",
+        (PyCFunction)port_get_client_name,
+        METH_NOARGS,
+        "Return the name of the associated client.",
         },
     {
         "set_short_name",

+ 2 - 2
setup.py

@@ -4,12 +4,12 @@ import glob
 
 setup(
     name = 'jacker',
-    version = '0.1',
+    version = '0.2',
     description = 'JACK API for Python',
     author = 'Fabian Peter Hammerle',
     author_email = 'fabian.hammerle@gmail.com',
     url = 'https://github.com/fphammerle/jacker',
-    download_url = 'https://github.com/fphammerle/jacker/tarball/0.3',
+    download_url = 'https://github.com/fphammerle/jacker/tarball/0.2',
     keywords = [],
     classifiers = [],
     ext_modules = [