Переглянути джерело

implemented Client.connect()

Fabian Peter Hammerle 9 роки тому
батько
коміт
cf25784001
2 змінених файлів з 41 додано та 2 видалено
  1. 39 0
      jack.c
  2. 2 2
      setup.py

+ 39 - 0
jack.c

@@ -20,6 +20,7 @@ typedef struct {
 
 static PyObject* error;
 static PyObject* failure;
+static PyObject* connection_exists;
 
 static PyTypeObject port_type = {
     PyObject_HEAD_INIT(NULL)
@@ -159,6 +160,34 @@ static PyObject* client_activate(Client* self) {
         return Py_None;
     }
 }
+#include <stdio.h>
+static PyObject* client_connect(Client* self, PyObject* args)
+{
+    PyObject *source_port_python, *target_port_python;
+    // The object’s reference count is not increased.
+    if(!PyArg_ParseTuple(args, "O!O!", &port_type, &source_port_python, &port_type, &target_port_python)) {
+        return NULL;
+    }
+
+    Port* source_port = (Port*) source_port_python;
+    Port* target_port = (Port*) target_port_python;
+
+    int return_code = jack_connect(
+            self->client,
+            jack_port_name(source_port->port),
+            jack_port_name(target_port->port)
+            );
+
+    if(return_code) {
+        if(return_code == EEXIST) {
+            PyErr_SetString(connection_exists, "The specified ports are already connected.");
+        }
+        return NULL;
+    } else {
+        Py_INCREF(Py_None);
+        return Py_None;
+    }
+}
 
 static PyObject* client_get_name(Client* self)
 {
@@ -271,6 +300,12 @@ static PyMethodDef client_methods[] = {
         METH_NOARGS,
         "Tell the Jack server that the program is ready to start processing audio.",
         },
+    {
+        "connect",
+        (PyCFunction)client_connect,
+        METH_VARARGS,
+        "Establish a connection between two ports.",
+        },
     {
         "get_name",
         (PyCFunction)client_get_name,
@@ -472,6 +507,10 @@ PyMODINIT_FUNC initjack()
     Py_INCREF(failure);
     PyModule_AddObject(module, "Failure", failure);
 
+    connection_exists = PyErr_NewException((char*)"jack.ConnectionExists", error, NULL);
+    Py_INCREF(connection_exists);
+    PyModule_AddObject(module, "ConnectionExists", connection_exists);
+
     static PyTypeObject client_type = {
         PyObject_HEAD_INIT(NULL)
         };

+ 2 - 2
setup.py

@@ -4,12 +4,12 @@ import glob
 
 setup(
     name = 'jacker',
-    version = '0.2.1',
+    version = '0.3',
     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.2.1',
+    download_url = 'https://github.com/fphammerle/jacker/tarball/0.3',
     keywords = [],
     classifiers = [],
     ext_modules = [