summaryrefslogtreecommitdiff
path: root/common/JackAPIWrapper.cpp
blob: 0e467bc43ce85c17300283de19732e82134fe02d (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
/*
Copyright (C) 2008 Grame

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
(at your option) 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.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include "types.h"
#include "jack.h"
#include "JackExports.h"
#include <dlfcn.h>
#include <stdarg.h>
#include <stdio.h>
#include <dirent.h>
#include <string.h>

#ifdef __cplusplus
extern "C"
{
#endif

	EXPORT jack_client_t * jack_client_open (const char *client_name,
            jack_options_t options,
            jack_status_t *status, ...);
    EXPORT jack_client_t * jack_client_new (const char *client_name);
	EXPORT int jack_client_name_size (void);
    EXPORT char* jack_get_client_name (jack_client_t *client);
    EXPORT int jack_internal_client_new (const char *client_name,
                                         const char *load_name,
                                         const char *load_init);
    EXPORT void jack_internal_client_close (const char *client_name);
    EXPORT int jack_is_realtime (jack_client_t *client);
    EXPORT void jack_on_shutdown (jack_client_t *client,
                                  void (*function)(void *arg), void *arg);
    EXPORT int jack_set_process_callback (jack_client_t *client,
                                          JackProcessCallback process_callback,
                                          void *arg);
	//  
	EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status);
	// new 
	EXPORT jack_nframes_t jack_cycle_wait (jack_client_t*);
	EXPORT void jack_cycle_signal (jack_client_t*, int status);
	EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg);
 	
    EXPORT int jack_set_thread_init_callback (jack_client_t *client,
            JackThreadInitCallback thread_init_callback,
            void *arg);
    EXPORT int jack_set_freewheel_callback (jack_client_t *client,
                                            JackFreewheelCallback freewheel_callback,
                                            void *arg);
    EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
    EXPORT int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
    EXPORT int jack_set_buffer_size_callback (jack_client_t *client,
            JackBufferSizeCallback bufsize_callback,
            void *arg);
    EXPORT int jack_set_sample_rate_callback (jack_client_t *client,
            JackSampleRateCallback srate_callback,
            void *arg);
  	//
	EXPORT int jack_set_client_registration_callback (jack_client_t *,
						   JackClientRegistrationCallback
						   registration_callback, void *arg);
	EXPORT int jack_set_port_registration_callback (jack_client_t *,
            JackPortRegistrationCallback
            registration_callback, void *arg);
	//
	EXPORT int jack_set_port_connect_callback (jack_client_t *,
				    JackPortConnectCallback
				    connect_callback, void *arg);
  
    EXPORT int jack_set_graph_order_callback (jack_client_t *,
            JackGraphOrderCallback graph_callback,
            void *);
    EXPORT int jack_set_xrun_callback (jack_client_t *,
                                       JackXRunCallback xrun_callback, void *arg);
    EXPORT int jack_activate (jack_client_t *client);
    EXPORT int jack_deactivate (jack_client_t *client);
    EXPORT jack_port_t * jack_port_register (jack_client_t *client,
            const char *port_name,
            const char *port_type,
            unsigned long flags,
            unsigned long buffer_size);
    EXPORT int jack_port_unregister (jack_client_t *, jack_port_t *);
    EXPORT void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
    EXPORT const char * jack_port_name (const jack_port_t *port);
    EXPORT const char * jack_port_short_name (const jack_port_t *port);
    EXPORT int jack_port_flags (const jack_port_t *port);
    EXPORT const char * jack_port_type (const jack_port_t *port);
    EXPORT int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
    EXPORT int jack_port_connected (const jack_port_t *port);
    EXPORT int jack_port_connected_to (const jack_port_t *port,
                                       const char *port_name);
    EXPORT const char ** jack_port_get_connections (const jack_port_t *port);
    EXPORT const char ** jack_port_get_all_connections (const jack_client_t *client,
            const jack_port_t *port);
    EXPORT int jack_port_tie (jack_port_t *src, jack_port_t *dst);
    EXPORT int jack_port_untie (jack_port_t *port);
    EXPORT jack_nframes_t jack_port_get_latency (jack_port_t *port);
    EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *,
            jack_port_t *port);
    EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t);
	//
    EXPORT int jack_recompute_total_latency (jack_client_t*, jack_port_t* port);
    EXPORT int jack_recompute_total_latencies (jack_client_t*);
    EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name);
	//
	EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias);
	EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias);
	EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
    EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff);
    EXPORT int jack_port_request_monitor_by_name (jack_client_t *client,
            const char *port_name, int onoff);
    EXPORT int jack_port_ensure_monitor (jack_port_t *port, int onoff);
    EXPORT int jack_port_monitoring_input (jack_port_t *port);
    EXPORT int jack_connect (jack_client_t *,
                             const char *source_port,
                             const char *destination_port);
    EXPORT int jack_disconnect (jack_client_t *,
                                const char *source_port,
                                const char *destination_port);
    EXPORT int jack_port_disconnect (jack_client_t *, jack_port_t *);
    EXPORT int jack_port_name_size(void);
    EXPORT int jack_port_type_size(void);
    EXPORT jack_nframes_t jack_get_sample_rate (jack_client_t *);
    EXPORT jack_nframes_t jack_get_buffer_size (jack_client_t *);
    EXPORT const char ** jack_get_ports (jack_client_t *,
                                         const char *port_name_pattern,
                                         const char *type_name_pattern,
                                         unsigned long flags);
    EXPORT jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
    EXPORT jack_port_t * jack_port_by_id (jack_client_t *client,
                                          jack_port_id_t port_id);
    EXPORT int jack_engine_takeover_timebase (jack_client_t *);
    EXPORT jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
	//
	EXPORT jack_time_t jack_get_time();
    EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t time);
    EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames);
  
    EXPORT jack_nframes_t jack_frame_time (const jack_client_t *);
    EXPORT jack_nframes_t jack_last_frame_time (const jack_client_t *client);
    EXPORT float jack_cpu_load (jack_client_t *client);
    EXPORT pthread_t jack_client_thread_id (jack_client_t *);
    EXPORT void jack_set_error_function (void (*func)(const char *));

    EXPORT float jack_get_max_delayed_usecs (jack_client_t *client);
    EXPORT float jack_get_xrun_delayed_usecs (jack_client_t *client);
    EXPORT void jack_reset_max_delayed_usecs (jack_client_t *client);

    EXPORT int jack_release_timebase (jack_client_t *client);
    EXPORT int jack_set_sync_callback (jack_client_t *client,
                                       JackSyncCallback sync_callback,
                                       void *arg);
    EXPORT int jack_set_sync_timeout (jack_client_t *client,
                                      jack_time_t timeout);
    EXPORT int jack_set_timebase_callback (jack_client_t *client,
                                           int conditional,
                                           JackTimebaseCallback timebase_callback,
                                           void *arg);
    EXPORT int jack_transport_locate (jack_client_t *client,
                                      jack_nframes_t frame);
    EXPORT jack_transport_state_t jack_transport_query (const jack_client_t *client,
            jack_position_t *pos);
    EXPORT jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client);
    EXPORT int jack_transport_reposition (jack_client_t *client,
                                          jack_position_t *pos);
    EXPORT void jack_transport_start (jack_client_t *client);
    EXPORT void jack_transport_stop (jack_client_t *client);
    EXPORT void jack_get_transport_info (jack_client_t *client,
                                         jack_transport_info_t *tinfo);
    EXPORT void jack_set_transport_info (jack_client_t *client,
                                         jack_transport_info_t *tinfo);

    EXPORT int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
    EXPORT int jack_client_create_thread (jack_client_t* client,
                                          pthread_t *thread,
                                          int priority,
                                          int realtime, 	// boolean
                                          void *(*start_routine)(void*),
                                          void *arg);
    EXPORT int jack_drop_real_time_scheduling (pthread_t thread);

    EXPORT char * jack_get_internal_client_name (jack_client_t *client,
            jack_intclient_t intclient);
    EXPORT jack_intclient_t jack_internal_client_handle (jack_client_t *client,
            const char *client_name,
            jack_status_t *status);
    EXPORT jack_intclient_t jack_internal_client_load (jack_client_t *client,
            const char *client_name,
            jack_options_t options,
            jack_status_t *status, ...);
    EXPORT jack_status_t jack_internal_client_unload (jack_client_t *client,
            jack_intclient_t intclient);
			
	EXPORT jack_client_t * jack_client_open (const char *client_name,
            jack_options_t options,
            jack_status_t *status, ...);
    EXPORT jack_client_t * jack_client_new (const char *client_name);
    EXPORT int jack_client_close (jack_client_t *client);

#ifdef __cplusplus
}
#endif

// Function definition

typedef void* (*jack_port_get_buffer_fun_def)(jack_port_t* port, jack_nframes_t frames);
static jack_port_get_buffer_fun_def jack_port_get_buffer_fun = 0;
EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
{
	return (*jack_port_get_buffer_fun)(port, frames);
}

typedef const char* (*jack_port_name_fun_def)(const jack_port_t* port);
static jack_port_name_fun_def jack_port_name_fun = 0;
EXPORT const char* jack_port_name(const jack_port_t* port)
{
    return (*jack_port_name_fun)(port);
}

typedef const char* (*jack_port_short_name_fun_def) (const jack_port_t* port);
static jack_port_short_name_fun_def jack_port_short_name_fun = 0;
EXPORT const char* jack_port_short_name(const jack_port_t* port)
{
    return (*jack_port_short_name_fun)(port);
}

typedef int (*jack_port_flags_fun_def)(const jack_port_t* port);
static jack_port_flags_fun_def jack_port_flags_fun = 0;
EXPORT int jack_port_flags(const jack_port_t* port)
{
    return (*jack_port_flags_fun)(port);
}

typedef const char* (*jack_port_type_fun_def)(const jack_port_t* port);
static jack_port_type_fun_def jack_port_type_fun = 0;
EXPORT const char* jack_port_type(const jack_port_t* port)
{
    return (*jack_port_type_fun)(port);
}

typedef int (*jack_port_connected_fun_def)(const jack_port_t* port);
static jack_port_connected_fun_def jack_port_connected_fun = 0;
EXPORT int jack_port_connected(const jack_port_t* port)
{
    return (*jack_port_connected_fun)(port);
}

typedef int (*jack_port_connected_to_fun_def)(const jack_port_t* port, const char* portname);
static jack_port_connected_to_fun_def jack_port_connected_to_fun = 0;
EXPORT int jack_port_connected_to(const jack_port_t* port, const char* portname)
{
    return (*jack_port_connected_to_fun)(port, portname);
}

typedef int (*jack_port_tie_fun_def)(jack_port_t* src, jack_port_t* dst);
static jack_port_tie_fun_def jack_port_tie_fun = 0;
EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
{
    return (*jack_port_tie_fun)(src, dst);
}

typedef int (*jack_port_untie_fun_def)(jack_port_t* port);
static jack_port_untie_fun_def jack_port_untie_fun = 0;
EXPORT int jack_port_untie(jack_port_t* port)
{
    return (*jack_port_untie_fun)(port);
}

typedef jack_nframes_t (*jack_port_get_latency_fun_def)(jack_port_t* port);
static jack_port_get_latency_fun_def jack_port_get_latency_fun = 0;
EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
{
     return (*jack_port_get_latency)(port);
}

typedef void (*jack_port_set_latency_fun_def)(jack_port_t* port, jack_nframes_t frames);
static jack_port_set_latency_fun_def jack_port_set_latency_fun = 0;
EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
{
    (*jack_port_set_latency_fun)(port, frames);
}

typedef int (*jack_recompute_total_latency_fun_def)(jack_client_t* ext_client, jack_port_t* port);
static jack_recompute_total_latency_fun_def jack_recompute_total_latency_fun = 0;
EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
{
	return (*jack_recompute_total_latency_fun)(ext_client, port);
}

typedef int (*jack_recompute_total_latencies_fun_def)(jack_client_t* ext_client);
static jack_recompute_total_latencies_fun_def jack_recompute_total_latencies_fun = 0;
EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
{
	return (*jack_recompute_total_latencies_fun)(ext_client);
}

typedef int (*jack_port_set_name_fun_def)(jack_port_t* port, const char* name);
static jack_port_set_name_fun_def jack_port_set_name_fun = 0;
EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
{
    return (*jack_port_set_name_fun)(port, name);
}

typedef int (*jack_port_request_monitor_fun_def)(jack_port_t* port, int onoff);
static jack_port_request_monitor_fun_def jack_port_request_monitor_fun = 0;
EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
{
    return (*jack_port_request_monitor_fun)(port, onoff);
}

typedef int (*jack_port_request_monitor_by_name_fun_def)(jack_client_t* ext_client, const char* port_name, int onoff);
static jack_port_request_monitor_by_name_fun_def jack_port_request_monitor_by_name_fun = 0;
EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
{
    return (*jack_port_request_monitor_by_name_fun)(ext_client, port_name, onoff);
}

typedef int (*jack_port_ensure_monitor_fun_def)(jack_port_t* port, int onoff);
static jack_port_ensure_monitor_fun_def jack_port_ensure_monitor_fun = 0;
EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
{
    return (*jack_port_ensure_monitor_fun)(port, onoff);
}

typedef int (*jack_port_monitoring_input_fun_def)(jack_port_t* port);
static jack_port_monitoring_input_fun_def jack_port_monitoring_input_fun = 0;
EXPORT int jack_port_monitoring_input(jack_port_t* port)
{
    return (*jack_port_monitoring_input_fun)(port);
}

typedef int (*jack_is_realtime_fun_def)(jack_client_t* ext_client);
static jack_is_realtime_fun_def jack_is_realtime_fun = 0;
EXPORT int jack_is_realtime(jack_client_t* ext_client)
{
    return (*jack_is_realtime_fun)(ext_client);
}

typedef void (*shutdown_fun)(void* arg);
typedef void (*jack_on_shutdown_fun_def)(jack_client_t* ext_client, shutdown_fun callback, void* arg);
static jack_on_shutdown_fun_def jack_on_shutdown_fun = 0;
EXPORT void jack_on_shutdown(jack_client_t* ext_client, shutdown_fun callback, void* arg)
{
    return (*jack_on_shutdown_fun)(ext_client, callback, arg);
}

typedef int (*jack_set_process_callback_fun_def)(jack_client_t* ext_client, JackProcessCallback callback, void* arg);
static jack_set_process_callback_fun_def jack_set_process_callback_fun = 0;
EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
{
    return (*jack_set_process_callback_fun)(ext_client, callback, arg);
}

typedef int (*jack_set_freewheel_callback_fun_def)(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg);
static jack_set_freewheel_callback_fun_def jack_set_freewheel_callback_fun = 0;
EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
{
    return (*jack_set_freewheel_callback_fun)(ext_client, freewheel_callback, arg);
}

typedef int (*jack_set_freewheel_fun_def)(jack_client_t* ext_client, int onoff);
static jack_set_freewheel_fun_def jack_set_freewheel_fun = 0;
EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
{
    return (*jack_set_freewheel_fun)(ext_client, onoff);
}

typedef int (*jack_set_buffer_size_fun_def)(jack_client_t* ext_client, jack_nframes_t buffer_size);
static jack_set_buffer_size_fun_def jack_set_buffer_size_fun = 0;
EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
{
    return (*jack_set_buffer_size_fun)(ext_client, buffer_size);
}

typedef int (*jack_set_buffer_size_callback_fun_def)(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg);
static jack_set_buffer_size_callback_fun_def jack_set_buffer_size_callback_fun = 0;
EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
{
    return (*jack_set_buffer_size_callback_fun)(ext_client, bufsize_callback, arg);
}

typedef int (*jack_set_sample_rate_callback_fun_def)(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg);
static jack_set_sample_rate_callback_fun_def jack_set_sample_rate_callback_fun = 0;
EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
{
    return (*jack_set_sample_rate_callback_fun)(ext_client, srate_callback, arg);
}

typedef int (*jack_set_client_registration_callback_fun_def)(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg);
static jack_set_client_registration_callback_fun_def jack_set_client_registration_callback_fun = 0;
EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
{
    return (*jack_set_client_registration_callback_fun)(ext_client, registration_callback, arg);
}

typedef int (*jack_set_port_registration_callback_fun_def)(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg);
static jack_set_port_registration_callback_fun_def jack_set_port_registration_callback_fun = 0;
EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
{
    return (*jack_set_port_registration_callback_fun)(ext_client, registration_callback, arg);
}

typedef int (*jack_set_port_connect_callback_fun_def)(jack_client_t* ext_client, JackPortConnectCallback connect_callback, void* arg);
static jack_set_port_connect_callback_fun_def jack_set_port_connect_callback_fun = 0;
EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback connect_callback, void* arg)
{
    return (*jack_set_port_connect_callback_fun)(ext_client, connect_callback, arg);
}

typedef int (*jack_set_graph_order_callback_fun_def)(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg);
static jack_set_graph_order_callback_fun_def jack_set_graph_order_callback_fun = 0;
EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
{
    return (*jack_set_graph_order_callback_fun)(ext_client, graph_callback, arg);
}

typedef int (*jack_set_xrun_callback_fun_def)(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg);
static jack_set_xrun_callback_fun_def jack_set_xrun_callback_fun = 0;
EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
{
    return (*jack_set_xrun_callback_fun)(ext_client, xrun_callback, arg);
}

typedef int (*jack_set_thread_init_callback_fun_def)(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg);
static jack_set_thread_init_callback_fun_def jack_set_thread_init_callback_fun = 0;
EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
{
    return (*jack_set_thread_init_callback_fun)(ext_client, init_callback, arg);
}

typedef int (*jack_activate_fun_def)(jack_client_t* ext_client);
static jack_activate_fun_def jack_activate_fun = 0;
EXPORT int jack_activate(jack_client_t* ext_client)
{
    return (*jack_activate_fun)(ext_client);
}

typedef int (*jack_deactivate_fun_def)(jack_client_t* ext_client);
static jack_deactivate_fun_def jack_deactivate_fun = 0;
EXPORT int jack_deactivate(jack_client_t* ext_client)
{
    return (*jack_deactivate_fun)(ext_client);
}

typedef jack_port_t* (*jack_port_register_fun_def)(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size);
static jack_port_register_fun_def jack_port_register_fun = 0;
EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
{
    return (*jack_port_register_fun)(ext_client, port_name, port_type, flags, buffer_size);
}

typedef int (*jack_port_unregister_fun_def)(jack_client_t* ext_client, jack_port_t* port);
static jack_port_unregister_fun_def jack_port_unregister_fun = 0;
EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
{
    return (*jack_port_unregister_fun)(ext_client, port);
}

typedef int (*jack_port_is_mine_fun_def)(const jack_client_t* ext_client, const jack_port_t* port);
static jack_port_is_mine_fun_def jack_port_is_mine_fun = 0;
EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
{
    return (*jack_port_is_mine_fun)(ext_client, port);
}

typedef const char** (*jack_port_get_connections_fun_def)(const jack_port_t* port);
static jack_port_get_connections_fun_def jack_port_get_connections_fun = 0;
EXPORT const char** jack_port_get_connections(const jack_port_t* port)
{
    return (*jack_port_get_connections_fun)(port);
}

// Calling client does not need to "own" the port
typedef const char** (*jack_port_get_all_connections_fun_def)(const jack_client_t* ext_client, const jack_port_t* port);
static jack_port_get_all_connections_fun_def jack_port_get_all_connections_fun = 0;
EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
{
    return (*jack_port_get_all_connections_fun)(ext_client, port);
}

typedef jack_nframes_t (*jack_port_get_total_latency_fun_def)(jack_client_t* ext_client, jack_port_t* port);
static jack_port_get_total_latency_fun_def jack_port_get_total_latency_fun = 0;
EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
{
    return (*jack_port_get_total_latency_fun)(ext_client, port);
}

typedef int (*jack_connect_fun_def)(jack_client_t* ext_client, const char* src, const char* dst);
static jack_connect_fun_def jack_connect_fun = 0;
EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
{
    return (*jack_connect_fun)(ext_client, src, dst);
}

typedef int (*jack_disconnect_fun_def)(jack_client_t* ext_client, const char* src, const char* dst);
static jack_disconnect_fun_def jack_disconnect_fun = 0;
EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
{
    return (*jack_disconnect_fun)(ext_client, src, dst);
}

typedef int (*jack_port_connect_fun_def)(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst);
static jack_port_connect_fun_def jack_port_connect_fun = 0;
EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst)
{
    return (*jack_port_connect_fun)(ext_client, src, dst);
}

typedef int (*jack_port_disconnect_fun_def)(jack_client_t* ext_client, jack_port_t* src);
static jack_port_disconnect_fun_def jack_port_disconnect_fun = 0;
EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
{
    return (*jack_port_disconnect_fun)(ext_client, src);
}

typedef jack_nframes_t (*jack_get_sample_rate_fun_def)(jack_client_t* ext_client);
static jack_get_sample_rate_fun_def jack_get_sample_rate_fun = 0;
EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
{
    return (*jack_get_sample_rate_fun)(ext_client);
}

typedef jack_nframes_t (*jack_get_buffer_size_fun_def)(jack_client_t* ext_client);
static jack_get_buffer_size_fun_def jack_get_buffer_size_fun = 0;
EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
{
	return (*jack_get_buffer_size_fun)(ext_client);
}

typedef const char** (*jack_get_ports_fun_def)(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags);
static jack_get_ports_fun_def jack_get_ports_fun = 0;
EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
{
    return (*jack_get_ports_fun)(ext_client, port_name_pattern, type_name_pattern, flags);
}

typedef jack_port_t* (*jack_port_by_name_fun_def)(jack_client_t* ext_client, const char* portname);
static jack_port_by_name_fun_def jack_port_by_name_fun = 0;
EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
{
    return (*jack_port_by_name_fun)(ext_client, portname);
}

typedef jack_port_t* (*jack_port_by_id_fun_def)(const jack_client_t* ext_client, jack_port_id_t id);
static jack_port_by_id_fun_def jack_port_by_id_fun = 0;
EXPORT jack_port_t* jack_port_by_id(const jack_client_t* ext_client, jack_port_id_t id)
{
    return (*jack_port_by_id_fun)(ext_client, id);
}

typedef int (*jack_engine_takeover_timebase_fun_def)(jack_client_t* ext_client);
static jack_engine_takeover_timebase_fun_def jack_engine_takeover_timebase_fun = 0;
EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
{
    return (*jack_engine_takeover_timebase_fun)(ext_client);
}

typedef jack_nframes_t (*jack_frames_since_cycle_start_fun_def)(const jack_client_t* ext_client);
static jack_frames_since_cycle_start_fun_def jack_frames_since_cycle_start_fun = 0;
EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
{
    return (*jack_frames_since_cycle_start_fun)(ext_client);
}

typedef jack_time_t (*jack_get_time_fun_def)();
static jack_get_time_fun_def jack_get_time_fun = 0;
EXPORT jack_time_t jack_get_time()
{
    return (*jack_get_time_fun)();
}

typedef jack_nframes_t (*jack_time_to_frames_fun_def)(const jack_client_t* ext_client, jack_time_t time);
static jack_time_to_frames_fun_def jack_time_to_frames_fun = 0;
EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
{
    return (*jack_time_to_frames_fun)(ext_client, time);
}

typedef jack_nframes_t (*jack_frame_time_fun_def)(const jack_client_t* ext_client);
static jack_frame_time_fun_def jack_frame_time_fun = 0;
EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
{
    return (*jack_frame_time_fun)(ext_client);
}

typedef jack_nframes_t (*jack_last_frame_time_fun_def)(const jack_client_t* ext_client);
static jack_last_frame_time_fun_def jack_last_frame_time_fun = 0;
EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
{
    return (*jack_last_frame_time_fun)(ext_client);
}

typedef float (*jack_cpu_load_fun_def)(jack_client_t* ext_client);
static jack_cpu_load_fun_def jack_cpu_load_fun = 0;
EXPORT float jack_cpu_load(jack_client_t* ext_client)
{
    return (*jack_cpu_load_fun)(ext_client);
}

typedef pthread_t (*jack_client_thread_id_fun_def)(jack_client_t* ext_client);
static jack_client_thread_id_fun_def jack_client_thread_id_fun = 0;
EXPORT pthread_t  jack_client_thread_id(jack_client_t* ext_client)
{
    return (*jack_client_thread_id_fun)(ext_client);
}

typedef char* (*jack_get_client_name_fun_def)(jack_client_t* ext_client);
static jack_get_client_name_fun_def jack_get_client_name_fun = 0;
EXPORT char* jack_get_client_name (jack_client_t* ext_client)
{
    return (*jack_get_client_name_fun)(ext_client);
}

typedef int (*jack_client_name_size_fun_def)(void);
static jack_client_name_size_fun_def jack_client_name_size_fun = 0;
EXPORT int jack_client_name_size(void)
{
    return (*jack_client_name_size_fun)();
}

typedef int (*jack_port_name_size_fun_def)(void);
static jack_port_name_size_fun_def jack_port_name_size_fun = 0;
EXPORT int jack_port_name_size(void)
{
    return (*jack_port_name_size_fun)();
}

// transport.h

typedef int (*jack_release_timebase_fun_def)(jack_client_t* ext_client);
static jack_release_timebase_fun_def jack_release_timebase_fun = 0;
EXPORT int jack_release_timebase(jack_client_t* ext_client)
{
    return (*jack_release_timebase_fun)(ext_client);
}

typedef int (*jack_set_sync_callback_fun_def)(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg);
static jack_set_sync_callback_fun_def jack_set_sync_callback_fun = 0;
EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
{
    return (*jack_set_sync_callback_fun)(ext_client, sync_callback, arg);
}

typedef int (*jack_set_sync_timeout_fun_def)(jack_client_t* ext_client, jack_time_t timeout);
static jack_set_sync_timeout_fun_def jack_set_sync_timeout_fun = 0;
EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
{
    return (*jack_set_sync_timeout_fun)(ext_client, timeout);
}

typedef int (*jack_set_timebase_callback_fun_def)(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg);
static jack_set_timebase_callback_fun_def jack_set_timebase_callback_fun = 0;
EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
{
    return (*jack_set_timebase_callback_fun)(ext_client, conditional, timebase_callback, arg);
}

typedef int (*jack_transport_locate_fun_def)(jack_client_t* ext_client, jack_nframes_t frame);
static jack_transport_locate_fun_def jack_transport_locate_fun = 0;
EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
{
    return (*jack_transport_locate_fun)(ext_client, frame);
}

typedef jack_transport_state_t (*jack_transport_query_fun_def)(const jack_client_t* ext_client, jack_position_t* pos);
static jack_transport_query_fun_def jack_transport_query_fun = 0;
EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
{
    return (*jack_transport_query_fun)(ext_client, pos);
}

typedef jack_nframes_t (*jack_get_current_transport_frame_fun_def)(const jack_client_t* ext_client);
static jack_get_current_transport_frame_fun_def jack_get_current_transport_frame_fun = 0;
EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
{
    return (*jack_get_current_transport_frame_fun)(ext_client);
}

typedef int (*jack_transport_reposition_fun_def)(jack_client_t* ext_client, jack_position_t* pos);
static jack_transport_reposition_fun_def jack_transport_reposition_fun = 0;
EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
{
    return (*jack_transport_reposition_fun)(ext_client, pos);
}

typedef void (*jack_transport_start_fun_def)(jack_client_t* ext_client);
static jack_transport_start_fun_def jack_transport_start_fun = 0;
EXPORT void jack_transport_start(jack_client_t* ext_client)
{
    return (*jack_transport_start_fun)(ext_client);
}

typedef void (*jack_transport_stop_fun_def)(jack_client_t* ext_client);
static jack_transport_stop_fun_def jack_transport_stop_fun = 0;
EXPORT void jack_transport_stop(jack_client_t* ext_client)
{
	return (*jack_transport_stop_fun)(ext_client);
}

// deprecated

typedef void (*jack_get_transport_info_fun_def)(jack_client_t* ext_client, jack_transport_info_t* tinfo);
static jack_get_transport_info_fun_def jack_get_transport_info_fun = 0;
EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
{
    (*jack_get_transport_info_fun)(ext_client, tinfo);
}

typedef void (*jack_set_transport_info_fun_def)(jack_client_t* ext_client, jack_transport_info_t* tinfo);
static jack_set_transport_info_fun_def jack_set_transport_info_fun = 0;
EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
{
    (*jack_set_transport_info_fun)(ext_client, tinfo);
}

// statistics.h

typedef float (*jack_get_max_delayed_usecs_fun_def)(jack_client_t* ext_client);
static jack_get_max_delayed_usecs_fun_def jack_get_max_delayed_usecs_fun = 0;
EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
{
    return (*jack_get_max_delayed_usecs_fun)(ext_client);
}

typedef float (*jack_get_xrun_delayed_usecs_fun_def)(jack_client_t* ext_client);
static jack_get_xrun_delayed_usecs_fun_def jack_get_xrun_delayed_usecs_fun = 0;
EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
{
    return (*jack_get_xrun_delayed_usecs_fun)(ext_client);
}

typedef void (*jack_reset_max_delayed_usecs_fun_def)(jack_client_t* ext_client);
static jack_reset_max_delayed_usecs_fun_def jack_reset_max_delayed_usecs_fun = 0;
EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
{
    (*jack_reset_max_delayed_usecs)(ext_client);
}

// thread.h

typedef int (*jack_acquire_real_time_scheduling_fun_def)(pthread_t thread, int priority);
static jack_acquire_real_time_scheduling_fun_def jack_acquire_real_time_scheduling_fun = 0;
EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
{
    return (*jack_acquire_real_time_scheduling_fun)(thread, priority);
}

typedef void *(*start_routine)(void*);
typedef int (*jack_client_create_thread_fun_def)(jack_client_t* client,
												pthread_t *thread,
												int priority,
												int realtime,  	// boolean 
												start_routine callback,
												void *arg);
static jack_client_create_thread_fun_def jack_client_create_thread_fun = 0;
EXPORT int jack_client_create_thread(jack_client_t* client,
                                     pthread_t *thread,
                                     int priority,
                                     int realtime,  	// boolean 
                                     start_routine callback,
                                     void *arg)
{
    return (*jack_client_create_thread_fun)(client, thread, priority, realtime, callback, arg);
}

typedef int (*jack_drop_real_time_scheduling_fun_def)(pthread_t thread);
static jack_drop_real_time_scheduling_fun_def jack_drop_real_time_scheduling_fun = 0;
EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
{
    return (*jack_drop_real_time_scheduling_fun)(thread);
}

// intclient.h

typedef char* (*jack_get_internal_client_name_fun_def)(jack_client_t* ext_client, jack_intclient_t intclient);
static jack_get_internal_client_name_fun_def jack_get_internal_client_name_fun = 0;
EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
{
    return (*jack_get_internal_client_name_fun)(ext_client, intclient);
}

typedef jack_intclient_t (*jack_internal_client_handle_fun_def)(jack_client_t* ext_client, const char* client_name, jack_status_t* status);
static jack_internal_client_handle_fun_def jack_internal_client_handle_fun = 0;
EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
{
    return (*jack_internal_client_handle_fun)(ext_client, client_name, status);
}

typedef jack_intclient_t (*jack_internal_client_load_fun_def)(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...);
static jack_internal_client_load_fun_def jack_internal_client_load_fun = 0;
EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...)
{
	va_list ap;
	va_start(ap, status);
	jack_intclient_t res =  (*jack_internal_client_load_fun)(ext_client, client_name, options, status, ap);
	va_end(ap);
	return res;
}

typedef jack_status_t (*jack_internal_client_unload_fun_def)(jack_client_t* ext_client, jack_intclient_t intclient);
static jack_internal_client_unload_fun_def jack_internal_client_unload_fun = 0;
EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
{
    return (*jack_internal_client_unload_fun)(ext_client, intclient);
}

// client
static long gClientCount = 0;
static void* gLibrary = 0;
static bool init_library();
static bool open_library();
static void close_library();

typedef jack_client_t * (*jack_client_open_fun_def)(const char *client_name, jack_options_t options, jack_status_t *status, ...);
static jack_client_open_fun_def jack_client_open_fun = 0;
EXPORT jack_client_t * jack_client_open(const char *client_name, jack_options_t options, jack_status_t *status, ...)
{
	// Library check...
	if (!open_library()) 
		return 0;
		
	va_list ap;
	va_start(ap, status);
	jack_client_t* res = (*jack_client_open_fun)(client_name, options, status, ap);
	va_end(ap);
	return res;
}

typedef jack_client_t * (*jack_client_new_fun_def)(const char *client_name);
static jack_client_new_fun_def jack_client_new_fun = 0;
EXPORT jack_client_t * jack_client_new(const char *client_name)
{
	// Library check...
	if (!open_library()) 
		return 0;
		
	return (*jack_client_new_fun)(client_name);
}

typedef int (*jack_client_close_fun_def)(jack_client_t *client);
static jack_client_close_fun_def jack_client_close_fun = 0;
EXPORT int jack_client_close(jack_client_t *client)
{	
	int res = (*jack_client_close_fun)(client);
	close_library();
	return res;
}

// Library loader
static bool get_jack_library_in_directory(const char* dir_name, char* library_name)
{
	struct dirent * dir_entry;
	DIR * dir_stream = opendir(dir_name);
	if (!dir_stream)	
		return false;
	 
	while ((dir_entry = readdir(dir_stream))) {
		if (strncmp("libjack.so", dir_entry->d_name, 10) == 0) {
            strcpy(library_name, dir_entry->d_name);
			closedir(dir_stream);
			return true;
        }
	}
	closedir(dir_stream);
	return false;
}

static bool get_jack_library(char* library_name)
{
	if (get_jack_library_in_directory("/usr/lib", library_name))
		return true;
	if (get_jack_library_in_directory("/usr/local/lib", library_name))
		return true;
	return false;
}

static bool open_library()
{
	if (gClientCount++ == 0) {
		return init_library();
	} else {
		return true;
	}
}

static void close_library()
{
	if (--gClientCount == 0) {
		dlclose(gLibrary);
	} 
}

static bool check_client(void* library)
{
	jack_client_t* client = 0; 

	// Get "new", "open" and "close" entry points...
	jack_client_new_fun = (jack_client_new_fun_def)dlsym(library, "jack_client_new");
	jack_client_close_fun = (jack_client_close_fun_def)dlsym(library, "jack_client_close");
	jack_client_open_fun = (jack_client_open_fun_def)dlsym(gLibrary, "jack_client_open");

	// Try opening a client...
	if ((client = (*jack_client_new_fun)("dummy"))) { // jackd server is running....
		(*jack_client_close_fun)(client);
		return true;
	} else {
		return false;
	}
}

static bool init_library()
{
	char library_name[64];
	void* jackLibrary = (get_jack_library(library_name)) ? dlopen(library_name, RTLD_LAZY) : 0;
	void* jackmpLibrary = dlopen("libjackmp.so", RTLD_LAZY);
	
	if (jackLibrary) {
		
		if (check_client(jackLibrary)) { // jackd is running...
			gLibrary = jackLibrary;
			if (jackmpLibrary) dlclose(jackmpLibrary);
		} else if (check_client(jackmpLibrary)) { // jackdmp is running...
			gLibrary = jackmpLibrary;
			if (jackLibrary) dlclose(jackLibrary);
		} else {
			goto error;
		}
		
	} else if (jackmpLibrary) { 
	
		if (check_client(jackmpLibrary)) { // jackd is running...
			gLibrary = jackmpLibrary;
		} else {
			goto error;
		}
		
	} else {
		printf("Jack libraries not found, failure...\n");
		goto error;
	}
	
	// Load entry points...
	jack_port_get_buffer_fun = (jack_port_get_buffer_fun_def)dlsym(gLibrary, "jack_port_get_buffer");
	jack_port_name_fun = (jack_port_name_fun_def)dlsym(gLibrary, "jack_port_name");
	jack_port_short_name_fun = (jack_port_short_name_fun_def)dlsym(gLibrary, "jack_port_short_name");
	jack_port_flags_fun = (jack_port_flags_fun_def)dlsym(gLibrary, "jack_port_flags");
	jack_port_type_fun = (jack_port_type_fun_def)dlsym(gLibrary, "jack_port_type");
	jack_port_connected_fun = (jack_port_connected_fun_def)dlsym(gLibrary, "jack_port_connected");
	jack_port_connected_to_fun = (jack_port_connected_to_fun_def)dlsym(gLibrary, "jack_port_connected_to");
	jack_port_tie_fun = (jack_port_tie_fun_def)dlsym(gLibrary, "jack_port_tie");
	jack_port_untie_fun = (jack_port_untie_fun_def)dlsym(gLibrary, "jack_port_untie");
	jack_port_get_latency_fun = (jack_port_get_latency_fun_def)dlsym(gLibrary, "jack_port_get_latency");
	jack_port_set_latency_fun = (jack_port_set_latency_fun_def)dlsym(gLibrary, "jack_port_set_latency");
	jack_recompute_total_latency_fun = (jack_recompute_total_latency_fun_def)dlsym(gLibrary, "jack_recompute_total_latency");
	jack_recompute_total_latencies_fun = (jack_recompute_total_latencies_fun_def)dlsym(gLibrary, "jack_recompute_total_latencies");
	jack_port_set_name_fun = (jack_port_set_name_fun_def)dlsym(gLibrary, "jack_port_set_name");
	jack_port_request_monitor_fun = (jack_port_request_monitor_fun_def)dlsym(gLibrary, "jack_port_request_monitor");
	jack_port_request_monitor_by_name_fun = (jack_port_request_monitor_by_name_fun_def)dlsym(gLibrary, "jack_port_request_monitor_by_name");
	jack_port_ensure_monitor_fun = (jack_port_ensure_monitor_fun_def)dlsym(gLibrary, "jack_port_ensure_monitor");
	jack_port_monitoring_input_fun = (jack_port_monitoring_input_fun_def)dlsym(gLibrary, "jack_port_monitoring_input_fun");
	jack_is_realtime_fun = (jack_is_realtime_fun_def)dlsym(gLibrary, "jack_is_realtime");
	jack_on_shutdown_fun = (jack_on_shutdown_fun_def)dlsym(gLibrary, "jack_on_shutdown");
	jack_set_process_callback_fun = (jack_set_process_callback_fun_def)dlsym(gLibrary, "jack_set_process_callback");
	jack_set_freewheel_callback_fun = (jack_set_freewheel_callback_fun_def)dlsym(gLibrary, "jack_set_freewheel_callback");
	jack_set_freewheel_fun = (jack_set_freewheel_fun_def)dlsym(gLibrary, "jack_set_freewheel");
	jack_set_buffer_size_fun = (jack_set_buffer_size_fun_def)dlsym(gLibrary, "jack_set_buffer_size");
	jack_set_buffer_size_callback_fun = (jack_set_buffer_size_callback_fun_def)dlsym(gLibrary, "jack_set_buffer_size_callback");
	jack_set_sample_rate_callback_fun = (jack_set_sample_rate_callback_fun_def)dlsym(gLibrary, "jack_set_sample_rate_callback");
	jack_set_client_registration_callback_fun = (jack_set_client_registration_callback_fun_def)dlsym(gLibrary, "jack_set_client_registration_callback");
	jack_set_port_registration_callback_fun = (jack_set_port_registration_callback_fun_def)dlsym(gLibrary, "jack_set_port_registration_callback");
	jack_set_port_connect_callback_fun = (jack_set_port_connect_callback_fun_def)dlsym(gLibrary, "jack_set_port_connect_callback");
	jack_set_graph_order_callback_fun = (jack_set_graph_order_callback_fun_def)dlsym(gLibrary, "jack_set_graph_order_callback");
	jack_set_xrun_callback_fun = (jack_set_xrun_callback_fun_def)dlsym(gLibrary, "jack_set_xrun_callback");
	jack_set_thread_init_callback_fun = (jack_set_thread_init_callback_fun_def)dlsym(gLibrary, "jack_set_thread_init_callback");
	jack_activate_fun = (jack_activate_fun_def)dlsym(gLibrary, "jack_activate");
	jack_deactivate_fun = (jack_deactivate_fun_def)dlsym(gLibrary, "jack_deactivate");
	jack_port_register_fun = (jack_port_register_fun_def)dlsym(gLibrary, "jack_port_register");
	jack_port_unregister_fun = (jack_port_unregister_fun_def)dlsym(gLibrary, "jack_port_unregister");
	jack_port_is_mine_fun = (jack_port_is_mine_fun_def)dlsym(gLibrary, "jack_port_is_mine");
	jack_port_get_connections_fun = (jack_port_get_connections_fun_def)dlsym(gLibrary, "jack_port_get_connections");
	jack_port_get_all_connections_fun = (jack_port_get_all_connections_fun_def)dlsym(gLibrary, "jack_port_get_all_connections_fun");
	jack_port_get_total_latency_fun = (jack_port_get_total_latency_fun_def)dlsym(gLibrary, "jack_port_get_total_latency");
	jack_connect_fun = (jack_connect_fun_def)dlsym(gLibrary, "jack_connect");
	jack_disconnect_fun = (jack_disconnect_fun_def)dlsym(gLibrary, "jack_disconnect");
	jack_port_connect_fun = (jack_port_connect_fun_def)dlsym(gLibrary, "jack_port_connect");
	jack_port_disconnect_fun = (jack_port_disconnect_fun_def)dlsym(gLibrary, "jack_port_disconnect");
	jack_get_sample_rate_fun = (jack_get_sample_rate_fun_def)dlsym(gLibrary, "jack_get_sample_rate");
	jack_get_buffer_size_fun = (jack_get_buffer_size_fun_def)dlsym(gLibrary, "jack_get_buffer_size");
	jack_get_ports_fun = (jack_get_ports_fun_def)dlsym(gLibrary, "jack_get_ports");
	jack_port_by_name_fun = (jack_port_by_name_fun_def)dlsym(gLibrary, "jack_port_by_name");
	jack_port_by_id_fun = (jack_port_by_id_fun_def)dlsym(gLibrary, "jack_port_by_id");
	jack_engine_takeover_timebase_fun = (jack_engine_takeover_timebase_fun_def)dlsym(gLibrary, "jack_engine_takeover_timebase");
	jack_frames_since_cycle_start_fun = (jack_frames_since_cycle_start_fun_def)dlsym(gLibrary, "jack_frames_since_cycle_start");
	jack_get_time_fun = (jack_get_time_fun_def)dlsym(gLibrary, "jack_get_time");
	jack_time_to_frames_fun = (jack_time_to_frames_fun_def)dlsym(gLibrary, "jack_time_to_frames");
	jack_frame_time_fun = (jack_frame_time_fun_def)dlsym(gLibrary, "jack_frame_time");
	jack_last_frame_time_fun = (jack_last_frame_time_fun_def)dlsym(gLibrary, "jack_last_frame_time");
	jack_cpu_load_fun = (jack_cpu_load_fun_def)dlsym(gLibrary, "jack_cpu_load");
	jack_client_thread_id_fun = (jack_client_thread_id_fun_def)dlsym(gLibrary, "jack_client_thread_id");
	jack_get_client_name_fun = (jack_get_client_name_fun_def)dlsym(gLibrary, "jack_get_client_name");
	jack_port_name_size_fun = (jack_port_name_size_fun_def)dlsym(gLibrary, "jack_port_name_size");
	jack_client_name_size_fun = (jack_client_name_size_fun_def)dlsym(gLibrary, "jack_client_name_size");
	jack_release_timebase_fun = (jack_release_timebase_fun_def)dlsym(gLibrary, "jack_release_timebase");
	jack_set_sync_callback_fun = (jack_set_sync_callback_fun_def)dlsym(gLibrary, "jack_set_sync_callback");
	jack_set_sync_timeout_fun = (jack_set_sync_timeout_fun_def)dlsym(gLibrary, "jack_set_sync_timeout");
	jack_set_timebase_callback_fun = (jack_set_timebase_callback_fun_def)dlsym(gLibrary, "jack_set_timebase_callback");
	jack_transport_locate_fun = (jack_transport_locate_fun_def)dlsym(gLibrary, "jack_transport_locate_fun");
	jack_transport_query_fun = (jack_transport_query_fun_def)dlsym(gLibrary, "jack_transport_query");
	jack_get_current_transport_frame_fun = (jack_get_current_transport_frame_fun_def)dlsym(gLibrary, "jack_get_current_transport_frame");
	jack_transport_reposition_fun = (jack_transport_reposition_fun_def)dlsym(gLibrary, "jack_transport_reposition");
	jack_transport_start_fun = (jack_transport_start_fun_def)dlsym(gLibrary, "jack_transport_start");
	jack_transport_stop_fun = (jack_transport_stop_fun_def)dlsym(gLibrary, "jack_transport_stop");
	jack_get_transport_info_fun = (jack_get_transport_info_fun_def)dlsym(gLibrary, "jack_get_transport_info");
	jack_set_transport_info_fun = (jack_set_transport_info_fun_def)dlsym(gLibrary, "jack_set_transport_info");
	jack_get_max_delayed_usecs_fun = (jack_get_max_delayed_usecs_fun_def)dlsym(gLibrary, "jack_get_max_delayed_usecs");
	jack_get_xrun_delayed_usecs_fun = (jack_get_xrun_delayed_usecs_fun_def)dlsym(gLibrary, "jack_get_xrun_delayed_usecs");
	jack_reset_max_delayed_usecs_fun = (jack_reset_max_delayed_usecs_fun_def)dlsym(gLibrary, "jack_reset_max_delayed_usecs");
	jack_acquire_real_time_scheduling_fun = (jack_acquire_real_time_scheduling_fun_def)dlsym(gLibrary, "jack_acquire_real_time_scheduling");
	jack_client_create_thread_fun = (jack_client_create_thread_fun_def)dlsym(gLibrary, "jack_client_create_thread");
	jack_drop_real_time_scheduling_fun = (jack_drop_real_time_scheduling_fun_def)dlsym(gLibrary, "jack_drop_real_time_scheduling");
	jack_get_internal_client_name_fun = (jack_get_internal_client_name_fun_def)dlsym(gLibrary, "jack_get_internal_client_name");
	jack_internal_client_handle_fun = (jack_internal_client_handle_fun_def)dlsym(gLibrary, "jack_internal_client_handle");
	jack_internal_client_load_fun = (jack_internal_client_load_fun_def)dlsym(gLibrary, "jack_internal_client_load");
	jack_internal_client_unload_fun = (jack_internal_client_unload_fun_def)dlsym(gLibrary, "jack_internal_client_unload");
	jack_client_open_fun = (jack_client_open_fun_def)dlsym(gLibrary, "jack_client_open");
	jack_client_new_fun = (jack_client_new_fun_def)dlsym(gLibrary, "jack_client_new");
	jack_client_close_fun = (jack_client_close_fun_def)dlsym(gLibrary, "jack_client_close");
	
	return true;

error:
	if (jackLibrary) 
		dlclose(jackLibrary);
	if (jackmpLibrary) 
		dlclose(jackmpLibrary);
	return false;
}