This repository has been archived by the owner on Aug 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathjacklib.py
1280 lines (996 loc) · 45.5 KB
/
jacklib.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# JACK ctypes definitions for usage in python applications
# Copyright (C) 2010-2013 Filipe Coelho <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the COPYING file
# ------------------------------------------------------------------------------------------------------------
# Imports (Global)
from ctypes import *
from sys import platform
# ------------------------------------------------------------------------------------------------------------
# Load JACK shared library
try:
if platform == "darwin":
jacklib = cdll.LoadLibrary("libjack.dylib")
elif platform in ("win32", "win64", "cygwin"):
jacklib = cdll.LoadLibrary("libjack.dll")
else:
jacklib = cdll.LoadLibrary("libjack.so.0")
except:
jacklib = None
raise ImportError("JACK is not available in this system")
# ------------------------------------------------------------------------------------------------------------
# JACK2 test
try:
if jacklib.jack_get_version_string:
JACK2 = True
else:
JACK2 = False
except:
JACK2 = False
# ------------------------------------------------------------------------------------------------------------
# Pre-Types
c_enum = c_int
c_uchar = c_uint8
class _jack_port(Structure):
_fields_ = []
class _jack_client(Structure):
_fields_ = []
# ------------------------------------------------------------------------------------------------------------
# Defines
JACK_MAX_FRAMES = 4294967295
JACK_LOAD_INIT_LIMIT = 1024
JACK_DEFAULT_AUDIO_TYPE = "32 bit float mono audio"
JACK_DEFAULT_MIDI_TYPE = "8 bit raw midi"
# ------------------------------------------------------------------------------------------------------------
# Types
jack_nframes_t = c_uint32
jack_port_id_t = c_uint32
jack_time_t = c_uint64
jack_unique_t = c_uint64
jack_midi_data_t = c_uchar
jack_default_audio_sample_t = c_float
jack_options_t = c_enum # JackOptions
jack_status_t = c_enum # JackStatus
jack_transport_state_t = c_enum # JackTransportState
jack_position_bits_t = c_enum # JackPositionBits
jack_session_event_type_t = c_enum # JackSessionEventType
jack_session_flags_t = c_enum # JackSessionFlags
jack_custom_change_t = c_enum # JackCustomChange
jack_latency_callback_mode_t = c_enum # JackLatencyCallbackMode
jack_port_t = _jack_port
jack_client_t = _jack_client
jack_port_type_id_t = c_uint32 # JACK2 only
# enum JackOptions
JackNullOption = 0x00
JackNoStartServer = 0x01
JackUseExactName = 0x02
JackServerName = 0x04
JackLoadName = 0x08
JackLoadInit = 0x10
JackSessionID = 0x20
JackOpenOptions = JackSessionID|JackServerName|JackNoStartServer|JackUseExactName
JackLoadOptions = JackLoadInit|JackLoadName|JackUseExactName
# enum JackStatus
JackFailure = 0x01
JackInvalidOption = 0x02
JackNameNotUnique = 0x04
JackServerStarted = 0x08
JackServerFailed = 0x10
JackServerError = 0x20
JackNoSuchClient = 0x40
JackLoadFailure = 0x80
JackInitFailure = 0x100
JackShmFailure = 0x200
JackVersionError = 0x400
JackBackendError = 0x800
JackClientZombie = 0x1000
# enum JackLatencyCallbackMode
JackCaptureLatency = 0
JackPlaybackLatency = 1
# enum JackPortFlags
JackPortIsInput = 0x1
JackPortIsOutput = 0x2
JackPortIsPhysical = 0x4
JackPortCanMonitor = 0x8
JackPortIsTerminal = 0x10
JackPortIsControlVoltage = 0x100
# enum JackTransportState
JackTransportStopped = 0
JackTransportRolling = 1
JackTransportLooping = 2
JackTransportStarting = 3
JackTransportNetStarting = 4 # JACK2 only
# enum JackPositionBits
JackPositionBBT = 0x10
JackPositionTimecode = 0x20
JackBBTFrameOffset = 0x40
JackAudioVideoRatio = 0x80
JackVideoFrameOffset = 0x100
JACK_POSITION_MASK = JackPositionBBT|JackPositionTimecode|JackBBTFrameOffset|JackAudioVideoRatio|JackVideoFrameOffset
# enum JackSessionEventType
JackSessionSave = 1
JackSessionSaveAndQuit = 2
JackSessionSaveTemplate = 3
# enum JackSessionFlags
JackSessionSaveError = 0x01
JackSessionNeedTerminal = 0x02
# enum JackCustomChange
JackCustomRemoved = 0
JackCustomAdded = 1
JackCustomReplaced = 2
# ------------------------------------------------------------------------------------------------------------
# Structs
class jack_midi_event_t(Structure):
_fields_ = [
("time", jack_nframes_t),
("size", c_size_t),
("buffer", POINTER(jack_midi_data_t))
]
class jack_latency_range_t(Structure):
_fields_ = [
("min", jack_nframes_t),
("max", jack_nframes_t)
]
class jack_position_t(Structure):
_fields_ = [
("unique_1", jack_unique_t),
("usecs", jack_time_t),
("frame_rate", jack_nframes_t),
("frame", jack_nframes_t),
("valid", jack_position_bits_t),
("bar", c_int32),
("beat", c_int32),
("tick", c_int32),
("bar_start_tick", c_double),
("beats_per_bar", c_float),
("beat_type", c_float),
("ticks_per_beat", c_double),
("beats_per_minute", c_double),
("frame_time", c_double),
("next_time", c_double),
("bbt_offset", jack_nframes_t),
("audio_frames_per_video_frame", c_float),
("video_offset", jack_nframes_t),
("padding", ARRAY(c_int32, 7)),
("unique_2", jack_unique_t)
]
class jack_session_event_t(Structure):
_fields_ = [
("type", jack_session_event_type_t),
("session_dir", c_char_p),
("client_uuid", c_char_p),
("command_line", c_char_p),
("flags", jack_session_flags_t),
("future", c_uint32)
]
class jack_session_command_t(Structure):
_fields_ = [
("uuid", c_char_p),
("client_name", c_char_p),
("command", c_char_p),
("flags", jack_session_flags_t)
]
# ------------------------------------------------------------------------------------------------------------
# Callbacks
JackLatencyCallback = CFUNCTYPE(None, jack_latency_callback_mode_t, c_void_p)
JackProcessCallback = CFUNCTYPE(c_int, jack_nframes_t, c_void_p)
JackThreadCallback = CFUNCTYPE(c_void_p, c_void_p)
JackThreadInitCallback = CFUNCTYPE(None, c_void_p)
JackGraphOrderCallback = CFUNCTYPE(c_int, c_void_p)
JackXRunCallback = CFUNCTYPE(c_int, c_void_p)
JackBufferSizeCallback = CFUNCTYPE(c_int, jack_nframes_t, c_void_p)
JackSampleRateCallback = CFUNCTYPE(c_int, jack_nframes_t, c_void_p)
JackPortRegistrationCallback = CFUNCTYPE(None, jack_port_id_t, c_int, c_void_p)
JackClientRegistrationCallback = CFUNCTYPE(None, c_char_p, c_int, c_void_p)
JackClientRenameCallback = CFUNCTYPE(c_int, c_char_p, c_char_p, c_void_p) # JACK2 only
JackPortConnectCallback = CFUNCTYPE(None, jack_port_id_t, jack_port_id_t, c_int, c_void_p)
JackPortRenameCallback = CFUNCTYPE(c_int, jack_port_id_t, c_char_p, c_char_p, c_void_p) # JACK2 only
JackFreewheelCallback = CFUNCTYPE(None, c_int, c_void_p)
JackShutdownCallback = CFUNCTYPE(None, c_void_p)
JackInfoShutdownCallback = CFUNCTYPE(None, jack_status_t, c_char_p, c_void_p)
JackSyncCallback = CFUNCTYPE(c_int, jack_transport_state_t, POINTER(jack_position_t), c_void_p)
JackTimebaseCallback = CFUNCTYPE(None, jack_transport_state_t, jack_nframes_t, POINTER(jack_position_t), c_int, c_void_p)
JackSessionCallback = CFUNCTYPE(None, POINTER(jack_session_event_t), c_void_p)
JackCustomDataAppearanceCallback = CFUNCTYPE(None, c_char_p, c_char_p, jack_custom_change_t, c_void_p)
# ------------------------------------------------------------------------------------------------------------
# Functions
try:
jacklib.jack_get_version_string.argtypes = None
jacklib.jack_get_version_string.restype = c_char_p
except:
jacklib.jack_get_version_string = None
try:
jacklib.jack_client_open.argtypes = [c_char_p, jack_options_t, POINTER(jack_status_t), c_char_p]
jacklib.jack_client_open.restype = POINTER(jack_client_t)
except:
jacklib.jack_client_open = None
try:
jacklib.jack_client_rename.argtypes = [POINTER(jack_client_t), c_char_p]
jacklib.jack_client_rename.restype = c_char_p
except:
jacklib.jack_client_rename = None
try:
jacklib.jack_client_close.argtypes = [POINTER(jack_client_t)]
jacklib.jack_client_close.restype = c_int
except:
jacklib.jack_client_close = None
try:
jacklib.jack_client_name_size.argtypes = None
jacklib.jack_client_name_size.restype = c_int
except:
jacklib.jack_client_name_size = None
try:
jacklib.jack_get_client_name.argtypes = [POINTER(jack_client_t)]
jacklib.jack_get_client_name.restype = c_char_p
except:
jacklib.jack_get_client_name = None
try:
jacklib.jack_activate.argtypes = [POINTER(jack_client_t)]
jacklib.jack_activate.restype = c_int
except:
jacklib.jack_activate = None
try:
jacklib.jack_deactivate.argtypes = [POINTER(jack_client_t)]
jacklib.jack_deactivate.restype = c_int
except:
jacklib.jack_deactivate = None
try:
jacklib.jack_get_client_pid.argtypes = [c_char_p]
jacklib.jack_get_client_pid.restype = c_int
except:
jacklib.jack_get_client_pid = None
try:
jacklib.jack_is_realtime.argtypes = [POINTER(jack_client_t)]
jacklib.jack_is_realtime.restype = c_int
except:
jacklib.jack_is_realtime = None
def get_version_string(): # JACK2 only
if jacklib.jack_get_version_string:
return jacklib.jack_get_version_string()
return None
def client_open(client_name, options, status, uuid=""):
if jacklib.jack_client_open:
return jacklib.jack_client_open(client_name.encode("utf-8"), options, status, uuid.encode("utf-8") if uuid else None)
return None
def client_rename(client, new_name):
if jacklib.jack_client_rename:
return jacklib.jack_client_rename(client, new_name.encode("utf-8"))
return None
def client_close(client):
if jacklib.jack_client_close:
return jacklib.jack_client_close(client)
return -1
def client_name_size():
if jacklib.jack_client_name_size:
return jacklib.jack_client_name_size()
return 0
def get_client_name(client):
if jacklib.jack_get_client_name:
return jacklib.jack_get_client_name(client)
return None
def activate(client):
if jacklib.jack_activate:
return jacklib.jack_activate(client)
return -1
def deactivate(client):
if jacklib.jack_deactivate:
return jacklib.jack_deactivate(client)
return -1
def get_client_pid(name): # JACK2 only
if jacklib.jack_get_client_pid:
return jacklib.jack_get_client_pid(name.encode("utf-8"))
return 0
def is_realtime(client):
if jacklib.jack_is_realtime:
return jacklib.jack_is_realtime(client)
return 0
# ------------------------------------------------------------------------------------------------------------
# Non-Callback API
global _thread_callback
_thread_callback = None
try:
jacklib.jack_cycle_wait.argtypes = [POINTER(jack_client_t)]
jacklib.jack_cycle_wait.restype = jack_nframes_t
except:
jacklib.jack_cycle_wait = None
try:
jacklib.jack_cycle_signal.argtypes = [POINTER(jack_client_t), c_int]
jacklib.jack_cycle_signal.restype = None
except:
jacklib.jack_cycle_signal = None
try:
jacklib.jack_set_process_thread.argtypes = [POINTER(jack_client_t), JackThreadCallback, c_void_p]
jacklib.jack_set_process_thread.restype = c_int
except:
jacklib.jack_set_process_thread = None
def cycle_wait(client):
if jacklib.jack_cycle_wait:
return jacklib.jack_cycle_wait(client)
return 0
def cycle_signal(client, status):
if jacklib.jack_cycle_signal:
jacklib.jack_cycle_signal(client, status)
def set_process_thread(client, thread_callback, arg):
if jacklib.jack_set_process_thread:
global _thread_callback
_thread_callback = JackThreadCallback(thread_callback)
return jacklib.jack_set_process_thread(client, _thread_callback, arg)
return -1
# ------------------------------------------------------------------------------------------------------------
# Client Callbacks
global _thread_init_callback
global _shutdown_callback
global _info_shutdown_callback
global _process_callback
global _freewheel_callback
global _bufsize_callback
global _srate_callback
global _client_registration_callback
global _client_rename_callback
global _port_registration_callback
global _port_connect_callback
global _port_rename_callback
global _graph_callback
global _xrun_callback
global _latency_callback
_thread_init_callback = _shutdown_callback = _info_shutdown_callback = None
_process_callback = _freewheel_callback = _bufsize_callback = _srate_callback = None
_client_registration_callback = _client_rename_callback = None
_port_registration_callback = _port_connect_callback = _port_rename_callback = None
_graph_callback = _xrun_callback = _latency_callback = None
try:
jacklib.jack_set_thread_init_callback.argtypes = [POINTER(jack_client_t), JackThreadInitCallback, c_void_p]
jacklib.jack_set_thread_init_callback.restype = c_int
except:
jacklib.jack_set_thread_init_callback = None
try:
jacklib.jack_on_shutdown.argtypes = [POINTER(jack_client_t), JackShutdownCallback, c_void_p]
jacklib.jack_on_shutdown.restype = None
except:
jacklib.jack_on_shutdown = None
try:
jacklib.jack_on_info_shutdown.argtypes = [POINTER(jack_client_t), JackInfoShutdownCallback, c_void_p]
jacklib.jack_on_info_shutdown.restype = None
except:
jacklib.jack_on_info_shutdown = None
try:
jacklib.jack_set_process_callback.argtypes = [POINTER(jack_client_t), JackProcessCallback, c_void_p]
jacklib.jack_set_process_callback.restype = c_int
except:
jacklib.jack_set_process_callback = None
try:
jacklib.jack_set_freewheel_callback.argtypes = [POINTER(jack_client_t), JackFreewheelCallback, c_void_p]
jacklib.jack_set_freewheel_callback.restype = c_int
except:
jacklib.jack_set_freewheel_callback = None
try:
jacklib.jack_set_buffer_size_callback.argtypes = [POINTER(jack_client_t), JackBufferSizeCallback, c_void_p]
jacklib.jack_set_buffer_size_callback.restype = c_int
except:
jacklib.jack_set_buffer_size_callback = None
try:
jacklib.jack_set_sample_rate_callback.argtypes = [POINTER(jack_client_t), JackSampleRateCallback, c_void_p]
jacklib.jack_set_sample_rate_callback.restype = c_int
except:
jacklib.jack_set_sample_rate_callback = None
try:
jacklib.jack_set_client_registration_callback.argtypes = [POINTER(jack_client_t), JackClientRegistrationCallback, c_void_p]
jacklib.jack_set_client_registration_callback.restype = c_int
except:
jacklib.jack_set_client_registration_callback = None
try:
jacklib.jack_set_client_rename_callback.argtypes = [POINTER(jack_client_t), JackClientRenameCallback, c_void_p]
jacklib.jack_set_client_rename_callback.restype = c_int
except:
jacklib.jack_set_client_rename_callback = None
try:
jacklib.jack_set_port_registration_callback.argtypes = [POINTER(jack_client_t), JackPortRegistrationCallback, c_void_p]
jacklib.jack_set_port_registration_callback.restype = c_int
except:
jacklib.jack_set_port_registration_callback = None
try:
jacklib.jack_set_port_connect_callback.argtypes = [POINTER(jack_client_t), JackPortConnectCallback, c_void_p]
jacklib.jack_set_port_connect_callback.restype = c_int
except:
jacklib.jack_set_port_connect_callback = None
try:
jacklib.jack_set_port_rename_callback.argtypes = [POINTER(jack_client_t), JackPortRenameCallback, c_void_p]
jacklib.jack_set_port_rename_callback.restype = c_int
except:
jacklib.jack_set_port_rename_callback = None
try:
jacklib.jack_set_graph_order_callback.argtypes = [POINTER(jack_client_t), JackGraphOrderCallback, c_void_p]
jacklib.jack_set_graph_order_callback.restype = c_int
except:
jacklib.jack_set_graph_order_callback = None
try:
jacklib.jack_set_xrun_callback.argtypes = [POINTER(jack_client_t), JackXRunCallback, c_void_p]
jacklib.jack_set_xrun_callback.restype = c_int
except:
jacklib.jack_set_xrun_callback = None
try:
jacklib.jack_set_latency_callback.argtypes = [POINTER(jack_client_t), JackLatencyCallback, c_void_p]
jacklib.jack_set_latency_callback.restype = c_int
except:
jacklib.jack_set_latency_callback = None
def set_thread_init_callback(client, thread_init_callback, arg):
if jacklib.jack_set_thread_init_callback:
global _thread_init_callback
_thread_init_callback = JackThreadInitCallback(thread_init_callback)
return jacklib.jack_set_thread_init_callback(client, _thread_init_callback, arg)
return -1
def on_shutdown(client, shutdown_callback, arg):
if jacklib.jack_on_shutdown:
global _shutdown_callback
_shutdown_callback = JackShutdownCallback(shutdown_callback)
jacklib.jack_on_shutdown(client, _shutdown_callback, arg)
def on_info_shutdown(client, info_shutdown_callback, arg):
if jacklib.jack_on_info_shutdown:
global _info_shutdown_callback
_info_shutdown_callback = JackInfoShutdownCallback(info_shutdown_callback)
jacklib.jack_on_info_shutdown(client, _info_shutdown_callback, arg)
def set_process_callback(client, process_callback, arg):
if jacklib.jack_set_process_callback:
global _process_callback
_process_callback = JackProcessCallback(process_callback)
return jacklib.jack_set_process_callback(client, _process_callback, arg)
return -1
def set_freewheel_callback(client, freewheel_callback, arg):
if jacklib.jack_set_freewheel_callback:
global _freewheel_callback
_freewheel_callback = JackFreewheelCallback(freewheel_callback)
return jacklib.jack_set_freewheel_callback(client, _freewheel_callback, arg)
return -1
def set_buffer_size_callback(client, bufsize_callback, arg):
if jacklib.jack_set_buffer_size_callback:
global _bufsize_callback
_bufsize_callback = JackBufferSizeCallback(bufsize_callback)
return jacklib.jack_set_buffer_size_callback(client, _bufsize_callback, arg)
return -1
def set_sample_rate_callback(client, srate_callback, arg):
if jacklib.jack_set_sample_rate_callback:
global _srate_callback
_srate_callback = JackSampleRateCallback(srate_callback)
return jacklib.jack_set_sample_rate_callback(client, _srate_callback, arg)
return -1
def set_client_registration_callback(client, client_registration_callback, arg):
if jacklib.jack_set_client_registration_callback:
global _client_registration_callback
_client_registration_callback = JackClientRegistrationCallback(client_registration_callback)
return jacklib.jack_set_client_registration_callback(client, _client_registration_callback, arg)
return -1
def set_client_rename_callback(client, client_rename_callback, arg): # JACK2 only
if jacklib.jack_set_client_rename_callback:
global _client_rename_callback
_client_rename_callback = JackClientRenameCallback(client_rename_callback)
return jacklib.jack_set_client_rename_callback(client, _client_rename_callback, arg)
return -1
def set_port_registration_callback(client, port_registration_callback, arg):
if jacklib.jack_set_port_registration_callback:
global _port_registration_callback
_port_registration_callback = JackPortRegistrationCallback(port_registration_callback)
return jacklib.jack_set_port_registration_callback(client, _port_registration_callback, arg)
return -1
def set_port_connect_callback(client, connect_callback, arg):
if jacklib.jack_set_port_connect_callback:
global _port_connect_callback
_port_connect_callback = JackPortConnectCallback(connect_callback)
return jacklib.jack_set_port_connect_callback(client, _port_connect_callback, arg)
return -1
def set_port_rename_callback(client, rename_callback, arg): # JACK2 only
if jacklib.jack_set_port_rename_callback:
global _port_rename_callback
_port_rename_callback = JackPortRenameCallback(rename_callback)
return jacklib.jack_set_port_rename_callback(client, _port_rename_callback, arg)
return -1
def set_graph_order_callback(client, graph_callback, arg):
if jacklib.jack_set_graph_order_callback:
global _graph_callback
_graph_callback = JackGraphOrderCallback(graph_callback)
return jacklib.jack_set_graph_order_callback(client, _graph_callback, arg)
return -1
def set_xrun_callback(client, xrun_callback, arg):
if jacklib.jack_set_xrun_callback:
global _xrun_callback
_xrun_callback = JackXRunCallback(xrun_callback)
return jacklib.jack_set_xrun_callback(client, _xrun_callback, arg)
return -1
def set_latency_callback(client, latency_callback, arg):
if jacklib.jack_set_latency_callback:
global _latency_callback
_latency_callback = JackLatencyCallback(latency_callback)
return jacklib.jack_set_latency_callback(client, _latency_callback, arg)
return -1
# ------------------------------------------------------------------------------------------------------------
# Server Control
jacklib.jack_set_freewheel.argtypes = [POINTER(jack_client_t), c_int]
jacklib.jack_set_freewheel.restype = c_int
jacklib.jack_set_buffer_size.argtypes = [POINTER(jack_client_t), jack_nframes_t]
jacklib.jack_set_buffer_size.restype = c_int
jacklib.jack_get_sample_rate.argtypes = [POINTER(jack_client_t)]
jacklib.jack_get_sample_rate.restype = jack_nframes_t
jacklib.jack_get_buffer_size.argtypes = [POINTER(jack_client_t)]
jacklib.jack_get_buffer_size.restype = jack_nframes_t
jacklib.jack_engine_takeover_timebase.argtypes = [POINTER(jack_client_t)]
jacklib.jack_engine_takeover_timebase.restype = c_int
jacklib.jack_cpu_load.argtypes = [POINTER(jack_client_t)]
jacklib.jack_cpu_load.restype = c_float
def set_freewheel(client, onoff):
return jacklib.jack_set_freewheel(client, onoff)
def set_buffer_size(client, nframes):
return jacklib.jack_set_buffer_size(client, nframes)
def get_sample_rate(client):
return jacklib.jack_get_sample_rate(client)
def get_buffer_size(client):
return jacklib.jack_get_buffer_size(client)
def engine_takeover_timebase(client):
return jacklib.jack_engine_takeover_timebase(client)
def cpu_load(client):
return jacklib.jack_cpu_load(client)
# ------------------------------------------------------------------------------------------------------------
# Port Functions
jacklib.jack_port_register.argtypes = [POINTER(jack_client_t), c_char_p, c_char_p, c_ulong, c_ulong]
jacklib.jack_port_register.restype = POINTER(jack_port_t)
jacklib.jack_port_unregister.argtypes = [POINTER(jack_client_t), POINTER(jack_port_t)]
jacklib.jack_port_unregister.restype = c_int
jacklib.jack_port_get_buffer.argtypes = [POINTER(jack_port_t), jack_nframes_t]
jacklib.jack_port_get_buffer.restype = c_void_p
jacklib.jack_port_name.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_name.restype = c_char_p
jacklib.jack_port_short_name.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_short_name.restype = c_char_p
jacklib.jack_port_flags.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_flags.restype = c_int
jacklib.jack_port_type.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_type.restype = c_char_p
if JACK2:
jacklib.jack_port_type_id.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_type_id.restype = jack_port_type_id_t
jacklib.jack_port_is_mine.argtypes = [POINTER(jack_client_t), POINTER(jack_port_t)]
jacklib.jack_port_is_mine.restype = c_int
jacklib.jack_port_connected.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_connected.restype = c_int
jacklib.jack_port_connected_to.argtypes = [POINTER(jack_port_t), c_char_p]
jacklib.jack_port_connected_to.restype = c_int
jacklib.jack_port_get_connections.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_get_connections.restype = POINTER(c_char_p)
jacklib.jack_port_get_all_connections.argtypes = [POINTER(jack_client_t), POINTER(jack_port_t)]
jacklib.jack_port_get_all_connections.restype = POINTER(c_char_p)
jacklib.jack_port_tie.argtypes = [POINTER(jack_port_t), POINTER(jack_port_t)]
jacklib.jack_port_tie.restype = c_int
jacklib.jack_port_untie.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_untie.restype = c_int
jacklib.jack_port_set_name.argtypes = [POINTER(jack_port_t), c_char_p]
jacklib.jack_port_set_name.restype = c_int
jacklib.jack_port_set_alias.argtypes = [POINTER(jack_port_t), c_char_p]
jacklib.jack_port_set_alias.restype = c_int
jacklib.jack_port_unset_alias.argtypes = [POINTER(jack_port_t), c_char_p]
jacklib.jack_port_unset_alias.restype = c_int
jacklib.jack_port_get_aliases.argtypes = [POINTER(jack_port_t), POINTER(ARRAY(c_char_p, 2))]
jacklib.jack_port_get_aliases.restype = c_int
jacklib.jack_port_request_monitor.argtypes = [POINTER(jack_port_t), c_int]
jacklib.jack_port_request_monitor.restype = c_int
jacklib.jack_port_request_monitor_by_name.argtypes = [POINTER(jack_client_t), c_char_p, c_int]
jacklib.jack_port_request_monitor_by_name.restype = c_int
jacklib.jack_port_ensure_monitor.argtypes = [POINTER(jack_port_t), c_int]
jacklib.jack_port_ensure_monitor.restype = c_int
jacklib.jack_port_monitoring_input.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_monitoring_input.restype = c_int
jacklib.jack_connect.argtypes = [POINTER(jack_client_t), c_char_p, c_char_p]
jacklib.jack_connect.restype = c_int
jacklib.jack_disconnect.argtypes = [POINTER(jack_client_t), c_char_p, c_char_p]
jacklib.jack_disconnect.restype = c_int
jacklib.jack_port_disconnect.argtypes = [POINTER(jack_client_t), POINTER(jack_port_t)]
jacklib.jack_port_disconnect.restype = c_int
jacklib.jack_port_name_size.argtypes = None
jacklib.jack_port_name_size.restype = c_int
jacklib.jack_port_type_size.argtypes = None
jacklib.jack_port_type_size.restype = c_int
try:
jacklib.jack_port_type_get_buffer_size.argtypes = [POINTER(jack_client_t), c_char_p]
jacklib.jack_port_type_get_buffer_size.restype = c_size_t
except:
jacklib.jack_port_type_get_buffer_size = None
def port_register(client, port_name, port_type, flags, buffer_size):
return jacklib.jack_port_register(client, port_name.encode("utf-8"), port_type.encode("utf-8"), flags, buffer_size)
def port_unregister(client, port):
return jacklib.jack_port_unregister(client, port)
def port_get_buffer(port, nframes):
return jacklib.jack_port_get_buffer(port, nframes)
def port_name(port):
return jacklib.jack_port_name(port)
def port_short_name(port):
return jacklib.jack_port_short_name(port)
def port_flags(port):
return jacklib.jack_port_flags(port)
def port_type(port):
return jacklib.jack_port_type(port)
def port_type_id(port): # JACK2 only
return jacklib.jack_port_type_id(port)
def port_is_mine(client, port):
return jacklib.jack_port_is_mine(client, port)
def port_connected(port):
return jacklib.jack_port_connected(port)
def port_connected_to(port, port_name):
return jacklib.jack_port_connected_to(port, port_name.encode("utf-8"))
def port_get_connections(port):
return jacklib.jack_port_get_connections(port)
def port_get_all_connections(client, port):
return jacklib.jack_port_get_all_connections(client, port)
def port_tie(src, dst):
return jacklib.jack_port_tie(src, dst)
def port_untie(port):
return jacklib.jack_port_untie(port)
def port_set_name(port, port_name):
return jacklib.jack_port_set_name(port, port_name.encode("utf-8"))
def port_set_alias(port, alias):
return jacklib.jack_port_set_alias(port, alias.encode("utf-8"))
def port_unset_alias(port, alias):
return jacklib.jack_port_unset_alias(port, alias.encode("utf-8"))
def port_get_aliases(port):
# NOTE - this function has no 2nd argument in jacklib
# Instead, aliases will be passed in return value, in form of (int ret, str alias1, str alias2)
name_size = port_name_size()
alias_type = c_char_p * 2
aliases = alias_type(" ".encode("utf-8") * name_size, " ".encode("utf-8") * name_size)
ret = jacklib.jack_port_get_aliases(port, pointer(aliases))
return (ret, str(aliases[0], encoding="utf-8"), str(aliases[1], encoding="utf-8"))
def port_request_monitor(port, onoff):
return jacklib.jack_port_request_monitor(port, onoff)
def port_request_monitor_by_name(client, port_name, onoff):
return jacklib.jack_port_request_monitor_by_name(client, port_name.encode("utf-8"), onoff)
def port_ensure_monitor(port, onoff):
return jacklib.jack_port_ensure_monitor(port, onoff)
def port_monitoring_input(port):
return jacklib.jack_port_monitoring_input(port)
def connect(client, source_port, destination_port):
return jacklib.jack_connect(client, source_port.encode("utf-8"), destination_port.encode("utf-8"))
def disconnect(client, source_port, destination_port):
return jacklib.jack_disconnect(client, source_port.encode("utf-8"), destination_port.encode("utf-8"))
def port_disconnect(client, port):
return jacklib.jack_port_disconnect(client, port)
def port_name_size():
return jacklib.jack_port_name_size()
def port_type_size():
return jacklib.jack_port_type_size()
def port_type_get_buffer_size(client, port_type):
if jacklib.jack_port_type_get_buffer_size:
return jacklib.jack_port_type_get_buffer_size(client, port_type.encode("utf-8"))
return 0
# ------------------------------------------------------------------------------------------------------------
# Latency Functions
jacklib.jack_port_set_latency.argtypes = [POINTER(jack_port_t), jack_nframes_t]
jacklib.jack_port_set_latency.restype = None
try:
jacklib.jack_port_get_latency_range.argtypes = [POINTER(jack_port_t), jack_latency_callback_mode_t, POINTER(jack_latency_range_t)]
jacklib.jack_port_get_latency_range.restype = None
except:
jacklib.jack_port_get_latency_range = None
try:
jacklib.jack_port_set_latency_range.argtypes = [POINTER(jack_port_t), jack_latency_callback_mode_t, POINTER(jack_latency_range_t)]
jacklib.jack_port_set_latency_range.restype = None
except:
jacklib.jack_port_set_latency_range = None
jacklib.jack_recompute_total_latencies.argtypes = [POINTER(jack_client_t)]
jacklib.jack_recompute_total_latencies.restype = c_int
jacklib.jack_port_get_latency.argtypes = [POINTER(jack_port_t)]
jacklib.jack_port_get_latency.restype = jack_nframes_t
jacklib.jack_port_get_total_latency.argtypes = [POINTER(jack_client_t), POINTER(jack_port_t)]
jacklib.jack_port_get_total_latency.restype = jack_nframes_t
jacklib.jack_recompute_total_latency.argtypes = [POINTER(jack_client_t), POINTER(jack_port_t)]
jacklib.jack_recompute_total_latency.restype = c_int
def port_set_latency(port, nframes):
jacklib.jack_port_set_latency(port, nframes)
def port_get_latency_range(port, mode, range_):
if jacklib.jack_port_get_latency_range:
jacklib.jack_port_get_latency_range(port, mode, range_)
def port_set_latency_range(port, mode, range_):
if jacklib.jack_port_set_latency_range:
jacklib.jack_port_set_latency_range(port, mode, range_)
def recompute_total_latencies():
return jacklib.jack_recompute_total_latencies()
def port_get_latency(port):
return jacklib.jack_port_get_latency(port)
def port_get_total_latency(client, port):
return jacklib.jack_port_get_total_latency(client, port)
def recompute_total_latency(client, port):
return jacklib.jack_recompute_total_latency(client, port)
# ------------------------------------------------------------------------------------------------------------
# Port Searching
jacklib.jack_get_ports.argtypes = [POINTER(jack_client_t), c_char_p, c_char_p, c_ulong]
jacklib.jack_get_ports.restype = POINTER(c_char_p)
jacklib.jack_port_by_name.argtypes = [POINTER(jack_client_t), c_char_p]
jacklib.jack_port_by_name.restype = POINTER(jack_port_t)
jacklib.jack_port_by_id.argtypes = [POINTER(jack_client_t), jack_port_id_t]
jacklib.jack_port_by_id.restype = POINTER(jack_port_t)
def get_ports(client, port_name_pattern, type_name_pattern, flags):
return jacklib.jack_get_ports(client, port_name_pattern.encode("utf-8"), type_name_pattern.encode("utf-8"), flags)
def port_by_name(client, port_name):
return jacklib.jack_port_by_name(client, port_name.encode("utf-8"))
def port_by_id(client, port_id):
return jacklib.jack_port_by_id(client, port_id)
# ------------------------------------------------------------------------------------------------------------
# Time Functions
jacklib.jack_frames_since_cycle_start.argtypes = [POINTER(jack_client_t)]
jacklib.jack_frames_since_cycle_start.restype = jack_nframes_t
jacklib.jack_frame_time.argtypes = [POINTER(jack_client_t)]
jacklib.jack_frame_time.restype = jack_nframes_t
jacklib.jack_last_frame_time.argtypes = [POINTER(jack_client_t)]
jacklib.jack_last_frame_time.restype = jack_nframes_t
try: # JACK_OPTIONAL_WEAK_EXPORT
jacklib.jack_get_cycle_times.argtypes = [POINTER(jack_client_t), POINTER(jack_nframes_t), POINTER(jack_time_t), POINTER(jack_time_t), POINTER(c_float)]
jacklib.jack_get_cycle_times.restype = c_int
except:
jacklib.jack_get_cycle_times = None
jacklib.jack_frames_to_time.argtypes = [POINTER(jack_client_t), jack_nframes_t]
jacklib.jack_frames_to_time.restype = jack_time_t
jacklib.jack_time_to_frames.argtypes = [POINTER(jack_client_t), jack_time_t]
jacklib.jack_time_to_frames.restype = jack_nframes_t
jacklib.jack_get_time.argtypes = None
jacklib.jack_get_time.restype = jack_time_t
def frames_since_cycle_start(client):
return jacklib.jack_frames_since_cycle_start(client)
def frame_time(client):
return jacklib.jack_frame_time(client)
def last_frame_time(client):
return jacklib.jack_last_frame_time(client)
def get_cycle_times(client, current_frames, current_usecs, next_usecs, period_usecs): # JACK_OPTIONAL_WEAK_EXPORT
if jacklib.jack_frames_to_time:
return jacklib.jack_get_cycle_times(client, current_frames, current_usecs, next_usecs, period_usecs)
return -1
def frames_to_time(client, nframes):
return jacklib.jack_frames_to_time(client, nframes)
def time_to_frames(client, time):
return jacklib.jack_time_to_frames(client, time)
def get_time():
return jacklib.jack_get_time()
# ------------------------------------------------------------------------------------------------------------
# Error Output
# TODO
# ------------------------------------------------------------------------------------------------------------
# Misc
jacklib.jack_free.argtypes = [c_void_p]
jacklib.jack_free.restype = None
def free(ptr):
return jacklib.jack_free(ptr)
# ------------------------------------------------------------------------------------------------------------
# Transport
global _sync_callback
global _timebase_callback
_sync_callback = _timebase_callback = None
jacklib.jack_release_timebase.argtypes = [POINTER(jack_client_t)]
jacklib.jack_release_timebase.restype = c_int
jacklib.jack_set_sync_callback.argtypes = [POINTER(jack_client_t), JackSyncCallback, c_void_p]
jacklib.jack_set_sync_callback.restype = c_int
jacklib.jack_set_sync_timeout.argtypes = [POINTER(jack_client_t), jack_time_t]
jacklib.jack_set_sync_timeout.restype = c_int
jacklib.jack_set_timebase_callback.argtypes = [POINTER(jack_client_t), c_int, JackTimebaseCallback, c_void_p]
jacklib.jack_set_timebase_callback.restype = c_int
jacklib.jack_transport_locate.argtypes = [POINTER(jack_client_t), jack_nframes_t]
jacklib.jack_transport_locate.restype = c_int