jack.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. #include <python2.7/Python.h>
  2. #include <jack/jack.h>
  3. typedef struct {
  4. PyObject_HEAD
  5. jack_client_t* client;
  6. PyObject* port_registered_callback;
  7. PyObject* port_registered_callback_argument;
  8. PyObject* port_renamed_callback;
  9. PyObject* port_renamed_callback_argument;
  10. PyObject* port_unregistered_callback;
  11. PyObject* port_unregistered_callback_argument;
  12. PyObject* shutdown_callback;
  13. PyObject* shutdown_callback_argument;
  14. } Client;
  15. typedef struct {
  16. PyObject_HEAD
  17. jack_port_t* port;
  18. } Port;
  19. static PyObject* error;
  20. static PyObject* failure;
  21. static PyObject* connection_exists;
  22. static PyTypeObject port_type = {
  23. PyObject_HEAD_INIT(NULL)
  24. };
  25. static PyObject* python_import(const char* name)
  26. {
  27. PyObject* python_name = PyString_FromString(name);
  28. PyObject* object = PyImport_Import(python_name);
  29. Py_DECREF(python_name);
  30. return object;
  31. }
  32. long get_reference_count(PyObject* object)
  33. {
  34. PyObject* sys = python_import("sys");
  35. PyObject* getrefcount = PyObject_GetAttrString(sys, "getrefcount");
  36. // Return the reference count of the object.
  37. // The count returned is generally one higher than you might expect,
  38. // because it includes the (temporary) reference as an argument to getrefcount().
  39. PyObject* argument_list = PyTuple_Pack(1, object);
  40. PyObject* result = PyObject_CallObject(getrefcount, argument_list);
  41. Py_DECREF(argument_list);
  42. long count;
  43. if(!result) {
  44. PyErr_PrintEx(0);
  45. count = -2;
  46. } else {
  47. count = PyInt_AsLong(result);
  48. Py_DECREF(result);
  49. }
  50. Py_DECREF(getrefcount);
  51. Py_DECREF(sys);
  52. return count;
  53. }
  54. static void jack_registration_callback(jack_port_id_t port_id, int registered, void* arg)
  55. {
  56. // register: non-zero if the port is being registered, zero if the port is being unregistered
  57. Client* client = (Client*)arg;
  58. PyObject* callback;
  59. PyObject* callback_argument;
  60. if(registered) {
  61. callback = client->port_registered_callback;
  62. callback_argument = client->port_registered_callback_argument;
  63. } else {
  64. callback = client->port_unregistered_callback;
  65. callback_argument = client->port_unregistered_callback_argument;
  66. }
  67. if(callback) {
  68. // Ensure that the current thread is ready to call the Python API.
  69. // No Python API calls are allowed before this call.
  70. PyGILState_STATE gil_state = PyGILState_Ensure();
  71. Port* port = PyObject_New(Port, &port_type);
  72. port->port = jack_port_by_id(client->client, port_id);
  73. // 'O' increases reference count
  74. PyObject* callback_argument_list;
  75. if(callback_argument) {
  76. callback_argument_list = Py_BuildValue("(O,O,O)", (PyObject*)client, (PyObject*)port, callback_argument);
  77. } else {
  78. callback_argument_list = Py_BuildValue("(O,O)", (PyObject*)client, (PyObject*)port);
  79. }
  80. PyObject* result = PyObject_CallObject(callback, callback_argument_list);
  81. Py_DECREF(callback_argument_list);
  82. if(!result) {
  83. PyErr_PrintEx(0);
  84. } else {
  85. Py_DECREF(result);
  86. }
  87. // Release the thread. No Python API calls are allowed beyond this point.
  88. PyGILState_Release(gil_state);
  89. }
  90. }
  91. // typedef int (*JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void *arg);
  92. static int jack_port_renamed_callback(jack_port_id_t port_id, const char* old_name, const char* new_name, void* arg)
  93. {
  94. int return_code = 0;
  95. Client* client = (Client*)arg;
  96. if(client->port_renamed_callback) {
  97. // Ensure that the current thread is ready to call the Python API.
  98. // No Python API calls are allowed before this call.
  99. PyGILState_STATE gil_state = PyGILState_Ensure();
  100. Port* port = PyObject_New(Port, &port_type);
  101. port->port = jack_port_by_id(client->client, port_id);
  102. // 'O' increases reference count
  103. PyObject* callback_argument_list = Py_BuildValue(
  104. "(O,O,s,s,O)",
  105. (PyObject*)client,
  106. (PyObject*)port,
  107. old_name,
  108. new_name,
  109. client->port_renamed_callback_argument
  110. );
  111. PyObject* result = PyObject_CallObject(client->port_renamed_callback, callback_argument_list);
  112. Py_DECREF(callback_argument_list);
  113. if(!result) {
  114. PyErr_PrintEx(0);
  115. return_code = -1;
  116. } else {
  117. Py_DECREF(result);
  118. return_code = 0;
  119. }
  120. // Release the thread. No Python API calls are allowed beyond this point.
  121. PyGILState_Release(gil_state);
  122. }
  123. return return_code;
  124. }
  125. // typedef void(* JackInfoShutdownCallback)(jack_status_t code, const char *reason, void *arg)
  126. static void jack_shutdown_callback(jack_status_t code, const char* reason, void* arg)
  127. {
  128. Client* client = (Client*)arg;
  129. if(client->shutdown_callback) {
  130. // Ensure that the current thread is ready to call the Python API.
  131. // No Python API calls are allowed before this call.
  132. PyGILState_STATE gil_state = PyGILState_Ensure();
  133. // 'O' increases reference count
  134. PyObject* callback_argument_list = NULL;
  135. if(client->shutdown_callback_argument) {
  136. callback_argument_list = Py_BuildValue(
  137. "(O,s,O)",
  138. (PyObject*)client,
  139. reason,
  140. client->shutdown_callback_argument
  141. );
  142. } else {
  143. callback_argument_list = Py_BuildValue(
  144. "(O,s)",
  145. (PyObject*)client,
  146. reason
  147. );
  148. }
  149. PyObject* result = PyObject_CallObject(client->shutdown_callback, callback_argument_list);
  150. Py_DECREF(callback_argument_list);
  151. if(!result) {
  152. PyErr_PrintEx(0);
  153. } else {
  154. Py_DECREF(result);
  155. }
  156. // Release the thread. No Python API calls are allowed beyond this point.
  157. PyGILState_Release(gil_state);
  158. }
  159. }
  160. static PyObject* client___new__(PyTypeObject* type, PyObject* args, PyObject* kwargs)
  161. {
  162. Client* self = (Client*)type->tp_alloc(type, 0);
  163. if(self) {
  164. char* client_name;
  165. unsigned char use_exact_name = 0;
  166. char* server_name = NULL;
  167. static char* kwlist[] = {"client_name", "use_exact_name", "server_name", NULL};
  168. if(!PyArg_ParseTupleAndKeywords(
  169. args, kwargs, "s|bs", kwlist,
  170. &client_name, &use_exact_name, &server_name
  171. )) {
  172. return NULL;
  173. }
  174. jack_options_t open_options = JackNullOption;
  175. if(server_name) {
  176. open_options |= JackServerName;
  177. }
  178. if(use_exact_name) {
  179. open_options |= JackUseExactName;
  180. }
  181. jack_status_t status;
  182. self->client = jack_client_open(client_name, open_options, &status, server_name);
  183. if(!self->client) {
  184. if(status & JackNameNotUnique) {
  185. PyErr_SetString(error, "The desired client name was not unique.");
  186. } else if(status & JackServerError) {
  187. PyErr_SetString(error, "Communication error with the JACK server.");
  188. } else if(status & JackFailure) {
  189. PyErr_SetString(failure, "Overall operation failed.");
  190. }
  191. return NULL;
  192. }
  193. self->port_registered_callback = NULL;
  194. self->port_unregistered_callback = NULL;
  195. int error_code = jack_set_port_registration_callback(
  196. self->client,
  197. jack_registration_callback,
  198. (void*)self
  199. );
  200. if(error_code) {
  201. PyErr_SetString(error, "Could not set port registration callback.");
  202. return NULL;
  203. }
  204. self->port_renamed_callback = NULL;
  205. self->port_renamed_callback_argument = NULL;
  206. error_code = jack_set_port_rename_callback(
  207. self->client,
  208. jack_port_renamed_callback,
  209. (void*)self
  210. );
  211. if(error_code) {
  212. PyErr_SetString(error, "Could not set port rename callback.");
  213. return NULL;
  214. }
  215. self->shutdown_callback = NULL;
  216. self->shutdown_callback_argument = NULL;
  217. jack_on_info_shutdown(
  218. self->client,
  219. jack_shutdown_callback,
  220. (void*)self
  221. );
  222. }
  223. return (PyObject*)self;
  224. }
  225. static PyObject* client_activate(Client* self) {
  226. int error_code = jack_activate(self->client);
  227. if(error_code) {
  228. PyErr_SetString(error, "");
  229. return NULL;
  230. } else {
  231. Py_INCREF(Py_None);
  232. return Py_None;
  233. }
  234. }
  235. static PyObject* client_deactivate(Client* self) {
  236. int error_code = jack_deactivate(self->client);
  237. if(error_code) {
  238. PyErr_SetString(error, "");
  239. return NULL;
  240. } else {
  241. Py_INCREF(Py_None);
  242. return Py_None;
  243. }
  244. }
  245. #include <stdio.h>
  246. static PyObject* client_connect(Client* self, PyObject* args)
  247. {
  248. PyObject *source_port_python, *target_port_python;
  249. // The object’s reference count is not increased.
  250. if(!PyArg_ParseTuple(args, "O!O!", &port_type, &source_port_python, &port_type, &target_port_python)) {
  251. return NULL;
  252. }
  253. Port* source_port = (Port*) source_port_python;
  254. Port* target_port = (Port*) target_port_python;
  255. int return_code = jack_connect(
  256. self->client,
  257. jack_port_name(source_port->port),
  258. jack_port_name(target_port->port)
  259. );
  260. if(return_code) {
  261. if(return_code == EEXIST) {
  262. PyErr_SetString(connection_exists, "The specified ports are already connected.");
  263. }
  264. return NULL;
  265. } else {
  266. Py_INCREF(Py_None);
  267. return Py_None;
  268. }
  269. }
  270. static PyObject* client_get_name(Client* self)
  271. {
  272. return (PyObject*)PyString_FromString(jack_get_client_name(self->client));
  273. }
  274. static PyObject* client_get_ports(Client* self)
  275. {
  276. PyObject* ports = PyList_New(0);
  277. if(!ports) {
  278. return NULL;
  279. }
  280. const char** port_names = jack_get_ports(self->client, NULL, NULL, 0);
  281. int port_index;
  282. for(port_index = 0; port_names[port_index] != NULL; port_index++) {
  283. Port* port = PyObject_New(Port, &port_type);
  284. port->port = jack_port_by_name(self->client, port_names[port_index]);
  285. if(PyList_Append(ports, (PyObject*)port)) {
  286. return NULL;
  287. }
  288. }
  289. jack_free(port_names);
  290. return ports;
  291. }
  292. static PyObject* client_set_port_registered_callback(Client* self, PyObject* args)
  293. {
  294. PyObject* callback = 0;
  295. PyObject* callback_argument = 0;
  296. if(!PyArg_ParseTuple(args, "O|O", &callback, &callback_argument)) {
  297. return NULL;
  298. }
  299. if(!PyCallable_Check(callback)) {
  300. PyErr_SetString(PyExc_TypeError, "Parameter must be callable.");
  301. return NULL;
  302. }
  303. Py_XINCREF(callback);
  304. Py_XDECREF(self->port_registered_callback);
  305. self->port_registered_callback = callback;
  306. Py_XINCREF(callback_argument);
  307. Py_XDECREF(self->port_registered_callback_argument);
  308. self->port_registered_callback_argument = callback_argument;
  309. Py_INCREF(Py_None);
  310. return Py_None;
  311. }
  312. static PyObject* client_set_port_unregistered_callback(Client* self, PyObject* args)
  313. {
  314. PyObject* callback = 0;
  315. PyObject* callback_argument = 0;
  316. if(!PyArg_ParseTuple(args, "O|O", &callback, &callback_argument)) {
  317. return NULL;
  318. }
  319. if(!PyCallable_Check(callback)) {
  320. PyErr_SetString(PyExc_TypeError, "Parameter must be callable.");
  321. return NULL;
  322. }
  323. Py_XINCREF(callback);
  324. Py_XDECREF(self->port_unregistered_callback);
  325. self->port_unregistered_callback = callback;
  326. Py_XINCREF(callback_argument);
  327. Py_XDECREF(self->port_unregistered_callback_argument);
  328. self->port_unregistered_callback_argument = callback_argument;
  329. Py_INCREF(Py_None);
  330. return Py_None;
  331. }
  332. static PyObject* client_set_port_renamed_callback(Client* self, PyObject* args)
  333. {
  334. PyObject* callback = 0;
  335. PyObject* callback_argument = 0;
  336. if(!PyArg_ParseTuple(args, "O|O", &callback, &callback_argument)) {
  337. return NULL;
  338. }
  339. if(!PyCallable_Check(callback)) {
  340. PyErr_SetString(PyExc_TypeError, "Parameter must be callable.");
  341. return NULL;
  342. }
  343. Py_XINCREF(callback);
  344. Py_XDECREF(self->port_renamed_callback);
  345. self->port_renamed_callback = callback;
  346. Py_XINCREF(callback_argument);
  347. Py_XDECREF(self->port_renamed_callback_argument);
  348. self->port_renamed_callback_argument = callback_argument;
  349. Py_INCREF(Py_None);
  350. return Py_None;
  351. }
  352. static PyObject* client_set_shutdown_callback(Client* self, PyObject* args)
  353. {
  354. PyObject* callback = 0;
  355. PyObject* callback_argument = 0;
  356. if(!PyArg_ParseTuple(args, "O|O", &callback, &callback_argument)) {
  357. return NULL;
  358. }
  359. if(!PyCallable_Check(callback)) {
  360. PyErr_SetString(PyExc_TypeError, "Parameter must be callable.");
  361. return NULL;
  362. }
  363. Py_XINCREF(callback);
  364. Py_XDECREF(self->shutdown_callback);
  365. self->shutdown_callback = callback;
  366. Py_XINCREF(callback_argument);
  367. Py_XDECREF(self->shutdown_callback_argument);
  368. self->shutdown_callback_argument = callback_argument;
  369. Py_INCREF(Py_None);
  370. return Py_None;
  371. }
  372. static void client_dealloc(Client* self)
  373. {
  374. jack_client_close(self->client);
  375. Py_XDECREF(self->port_registered_callback);
  376. Py_XDECREF(self->port_registered_callback_argument);
  377. Py_XDECREF(self->port_renamed_callback);
  378. Py_XDECREF(self->port_renamed_callback_argument);
  379. Py_XDECREF(self->port_unregistered_callback);
  380. Py_XDECREF(self->port_unregistered_callback_argument);
  381. Py_XDECREF(self->shutdown_callback);
  382. Py_XDECREF(self->shutdown_callback_argument);
  383. self->ob_type->tp_free((PyObject*)self);
  384. }
  385. static PyMethodDef client_methods[] = {
  386. {
  387. "activate",
  388. (PyCFunction)client_activate,
  389. METH_NOARGS,
  390. "Tell the Jack server that the program is ready to start processing audio.",
  391. },
  392. {
  393. "connect",
  394. (PyCFunction)client_connect,
  395. METH_VARARGS,
  396. "Establish a connection between two ports.",
  397. },
  398. {
  399. "deactivate",
  400. (PyCFunction)client_deactivate,
  401. METH_NOARGS,
  402. "Tell the Jack server that the program is ready to start processing audio.",
  403. },
  404. {
  405. "get_name",
  406. (PyCFunction)client_get_name,
  407. METH_NOARGS,
  408. "Return client's actual name.",
  409. },
  410. {
  411. "get_ports",
  412. (PyCFunction)client_get_ports,
  413. METH_NOARGS,
  414. "Return list of ports.",
  415. },
  416. {
  417. "set_port_registered_callback",
  418. (PyCFunction)client_set_port_registered_callback,
  419. METH_VARARGS,
  420. "Tell the JACK server to call a function whenever a port is registered.",
  421. },
  422. {
  423. "set_port_unregistered_callback",
  424. (PyCFunction)client_set_port_unregistered_callback,
  425. METH_VARARGS,
  426. "Tell the JACK server to call a function whenever a port is unregistered.",
  427. },
  428. {
  429. "set_port_renamed_callback",
  430. (PyCFunction)client_set_port_renamed_callback,
  431. METH_VARARGS,
  432. "Tell the JACK server to call a function whenever a port is renamed.",
  433. },
  434. {
  435. "set_shutdown_callback",
  436. (PyCFunction)client_set_shutdown_callback,
  437. METH_VARARGS,
  438. "Tell the JACK server to call a function when the server shuts down the client.",
  439. },
  440. {NULL},
  441. };
  442. static PyObject* port_is_input(Port* self)
  443. {
  444. // The flags "JackPortIsInput" and "JackPortIsOutput" are mutually exclusive.
  445. return (PyObject*)PyBool_FromLong(jack_port_flags(self->port) & JackPortIsInput);
  446. }
  447. static PyObject* port_is_output(Port* self)
  448. {
  449. // The flags "JackPortIsInput" and "JackPortIsOutput" are mutually exclusive.
  450. return (PyObject*)PyBool_FromLong(jack_port_flags(self->port) & JackPortIsOutput);
  451. }
  452. static PyObject* port_get_name(Port* self)
  453. {
  454. return (PyObject*)PyString_FromString(jack_port_name(self->port));
  455. }
  456. static PyObject* port_get_short_name(Port* self)
  457. {
  458. return (PyObject*)PyString_FromString(jack_port_short_name(self->port));
  459. }
  460. static PyObject* port_get_type(Port* self)
  461. {
  462. return (PyObject*)PyString_FromString(jack_port_type(self->port));
  463. }
  464. static PyObject* port_set_short_name(Port* self, PyObject* args)
  465. {
  466. const char* name;
  467. if(!PyArg_ParseTuple(args, "s", &name)) {
  468. return NULL;
  469. }
  470. // 0 on success, otherwise a non-zero error code.
  471. if(jack_port_set_name(self->port, name)) {
  472. return NULL;
  473. }
  474. Py_INCREF(Py_None);
  475. return Py_None;
  476. }
  477. static PyObject* port_get_client_name(Port* self)
  478. {
  479. // e.g. "PulseAudio JACK Sink:front-left"
  480. const char* port_name = jack_port_name(self->port);
  481. int client_name_length = strlen(port_name) - strlen(jack_port_short_name(self->port)) - 1;
  482. // e.g. "PulseAudio JACK Sink"
  483. char* client_name = (char*) malloc(jack_port_name_size());
  484. strncpy(client_name, port_name, client_name_length);
  485. client_name[client_name_length] = '\0';
  486. PyObject* client_name_python = PyString_FromString(client_name);
  487. free(client_name);
  488. return client_name_python;
  489. }
  490. static PyObject* port_get_aliases(Port* self)
  491. {
  492. PyObject* aliases_list = PyList_New(0);
  493. if(!aliases_list) {
  494. return NULL;
  495. }
  496. char* aliases[2];
  497. aliases[0] = (char*) malloc(jack_port_name_size());
  498. aliases[1] = (char*) malloc(jack_port_name_size());
  499. int alias_count = jack_port_get_aliases(self->port, aliases);
  500. int alias_index;
  501. for(alias_index = 0; alias_index < alias_count; alias_index++) {
  502. PyList_Append(aliases_list, PyString_FromString(aliases[alias_index]));
  503. }
  504. free(aliases[0]);
  505. free(aliases[1]);
  506. return aliases_list;
  507. }
  508. static PyObject* port___repr__(Port* self)
  509. {
  510. static PyObject* format;
  511. if(!format) {
  512. format = PyString_FromString("jack.Port(name = '%s', type = '%s')");
  513. }
  514. PyObject* args = Py_BuildValue(
  515. "(s,s)",
  516. jack_port_name(self->port),
  517. jack_port_type(self->port)
  518. );
  519. PyObject* repr = PyString_Format(format, args);
  520. Py_DECREF(args);
  521. return repr;
  522. }
  523. static PyMethodDef port_methods[] = {
  524. {
  525. "is_input",
  526. (PyCFunction)port_is_input,
  527. METH_NOARGS,
  528. "Return true if the port can receive data.",
  529. },
  530. {
  531. "is_output",
  532. (PyCFunction)port_is_output,
  533. METH_NOARGS,
  534. "Return true if data can be read from the port.",
  535. },
  536. {
  537. "get_name",
  538. (PyCFunction)port_get_name,
  539. METH_NOARGS,
  540. "Return port's name.",
  541. },
  542. {
  543. "get_short_name",
  544. (PyCFunction)port_get_short_name,
  545. METH_NOARGS,
  546. "Return port's name without the preceding name of the associated client.",
  547. },
  548. {
  549. "get_type",
  550. (PyCFunction)port_get_type,
  551. METH_NOARGS,
  552. "Return port's type.",
  553. },
  554. {
  555. "get_client_name",
  556. (PyCFunction)port_get_client_name,
  557. METH_NOARGS,
  558. "Return the name of the associated client.",
  559. },
  560. {
  561. "set_short_name",
  562. (PyCFunction)port_set_short_name,
  563. METH_VARARGS,
  564. "Modify a port's short name. May be called at any time.",
  565. },
  566. {
  567. "get_aliases",
  568. (PyCFunction)port_get_aliases,
  569. METH_NOARGS,
  570. "Return list of assigned aliases.",
  571. },
  572. {NULL},
  573. };
  574. #ifndef PyMODINIT_FUNC // declarations for DLL import/export
  575. #define PyMODINIT_FUNC void
  576. #endif
  577. PyMODINIT_FUNC initjack(void)
  578. {
  579. // Initialize and acquire the global interpreter lock.
  580. // This must be done in the main thread before creating engaging in any thread operations.
  581. PyEval_InitThreads();
  582. PyObject* module = Py_InitModule("jack", NULL);
  583. if(!module) {
  584. return;
  585. }
  586. error = PyErr_NewException((char*)"jack.Error", NULL, NULL);
  587. Py_INCREF(error);
  588. PyModule_AddObject(module, "Error", error);
  589. failure = PyErr_NewException((char*)"jack.Failure", error, NULL);
  590. Py_INCREF(failure);
  591. PyModule_AddObject(module, "Failure", failure);
  592. connection_exists = PyErr_NewException((char*)"jack.ConnectionExists", error, NULL);
  593. Py_INCREF(connection_exists);
  594. PyModule_AddObject(module, "ConnectionExists", connection_exists);
  595. static PyTypeObject client_type = {
  596. PyObject_HEAD_INIT(NULL)
  597. };
  598. client_type.tp_name = "jack.Client";
  599. client_type.tp_basicsize = sizeof(Client);
  600. client_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  601. client_type.tp_new = client___new__;
  602. client_type.tp_dealloc = (destructor)client_dealloc;
  603. client_type.tp_methods = client_methods;
  604. if(PyType_Ready(&client_type) < 0) {
  605. return;
  606. }
  607. Py_INCREF(&client_type);
  608. PyModule_AddObject(module, "Client", (PyObject*)&client_type);
  609. port_type.tp_name = "jack.Port";
  610. port_type.tp_basicsize = sizeof(Port);
  611. port_type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  612. // Forbid direct instantiation.
  613. port_type.tp_new = NULL;
  614. port_type.tp_repr = (reprfunc)port___repr__;
  615. port_type.tp_methods = port_methods;
  616. if(PyType_Ready(&port_type) < 0) {
  617. return;
  618. }
  619. Py_INCREF(&port_type);
  620. PyModule_AddObject(module, "Port", (PyObject*)&port_type);
  621. }