forked from DTByte-Ltd/lcb_fluidSynth
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOXTFluidsynth.lcb
More file actions
executable file
·1354 lines (1160 loc) · 60 KB
/
OXTFluidsynth.lcb
File metadata and controls
executable file
·1354 lines (1160 loc) · 60 KB
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
library org.openxtalk.library.fluidsynth
metadata version is "0.61"
metadata author is "Paul McClernan,FerrusLogic"
metadata title is "OpenXTalk.org FluidSynth"
metadata userVisible is "true" -- Show Widget in ... ?
metadata _ide is "true" -- ? default load at startup
use com.livecode.foreign
use com.livecode.string
use com.livecode.char
use com.livecode.array
use com.livecode.list
use com.livecode.engine
use com.livecode.system
private type fs_SETTINGS is Pointer
private type fs_SYNTH is Pointer
private type fs_AUIDIOdrvr is Pointer
private type fs_PLAYER is Pointer
private type fs_SOUNDFONT is Pointer
private type fs_SFPRESET is Pointer
private type fs_FILE_RENDERER is Pointer
private type fs_MIDIROUTER is Pointer
private type fs_MIDIROUTER_rule is Pointer
private type fs_MIDIdrvr is Pointer
private type fs_MIDIEvent is Pointer
constant kFLUID_OK is 0
constant kFLUID_FAILED is -1
private variable mInited as Boolean
private variable mSettings as optional fs_SETTINGS
private variable mSynth as optional fs_SYNTH
private variable mAudioDriver as optional fs_AUIDIOdrvr
private variable mPlayer as optional fs_PLAYER
private variable mSelectedSoundFont as optional fs_SOUNDFONT
-- private variable mSFCurrentPreset as optional fs_SFPRESET
private variable mSoundFont as optional fs_SOUNDFONT
private variable mSoundFontIDCount as optional CInt
private variable mMIDIDriver as optional fs_MIDIdrvr
__safe foreign handler new_fluid_settings() returns fs_SETTINGS binds to "c:libfluidsynth>new_fluid_settings"
__safe foreign handler delete_fluid_settings(in pSettings as fs_SETTINGS) returns nothing binds to "c:libfluidsynth>delete_fluid_settings"
__safe foreign handler fluid_settings_setnum(in pSettings as fs_SETTINGS, in pSettingName as ZStringNative, in pNumber as CDouble) returns CInt binds to "c:libfluidsynth>fluid_settings_setnum"
__safe foreign handler fluid_settings_getnum(in pSettings as fs_SETTINGS, in pSettingName as ZStringNative, out rNumber as CDouble) returns CInt binds to "c:libfluidsynth>fluid_settings_getnum"
__safe foreign handler fluid_settings_setint(in pSettings as fs_SETTINGS, in pSettingName as ZStringNative, in pNumber as CInt) returns CInt binds to "c:libfluidsynth>fluid_settings_setint"
__safe foreign handler fluid_settings_getint(in pSettings as fs_SETTINGS, in pSettingName as ZStringNative, out rNumber as CInt) returns CInt binds to "c:libfluidsynth>fluid_settings_getint"
__safe foreign handler fluid_settings_setstr(in pSettings as fs_SETTINGS, in pSettingName as ZStringNative, in pSettingString as ZStringNative) returns Cbool binds to "c:libfluidsynth>fluid_settings_setstr"
__safe foreign handler fluid_settings_getstr(in pSettings as fs_SETTINGS, in pSettingName as ZStringNative, out rSettingString as ZStringNative) returns CBool binds to "c:libfluidsynth>fluid_settings_getstr"
__safe foreign handler fluid_settings_getstr_default(in pSettings as fs_SETTINGS, in pSettingName as ZStringNative, out rSettingString as ZStringNative) returns CBool binds to "c:libfluidsynth>fluid_settings_getstr_default"
__safe foreign handler fluid_is_midifile(in pFilename as ZStringNative ) returns CBool binds to "c:libfluidsynth>fluid_is_midifile"
__safe foreign handler fluid_is_soundfont(in pFilename as ZStringNative ) returns CBool binds to "c:libfluidsynth>fluid_is_soundfont"
__safe foreign handler fluid_version(out rMaj as CInt, out rMin as CInt, out rMicr as CInt) returns nothing binds to "c:libfluidsynth>fluid_version"
__safe foreign handler fluid_version_str() returns Pointer binds to "c:libfluidsynth>fluid_version_str"
__safe foreign handler new_fluid_audio_driver(in pSettings as fs_SETTINGS,in pSynth as fs_SYNTH ) returns optional fs_AUIDIOdrvr binds to "c:libfluidsynth>new_fluid_audio_driver"
__safe foreign handler delete_fluid_audio_driver(in pDriver as fs_AUIDIOdrvr ) returns nothing binds to "c:libfluidsynth>delete_fluid_audio_driver"
__safe foreign handler new_fluid_synth(in pSettings as fs_SETTINGS) returns optional fs_SYNTH binds to "c:libfluidsynth>new_fluid_synth"
__safe foreign handler delete_fluid_synth(in pSynth as fs_SYNTH) returns CBool binds to "c:libfluidsynth>delete_fluid_synth"
__safe foreign handler fluid_synth_get_cpu_load(in pSynth as fs_SYNTH) returns CDouble binds to "c:libfluidsynth>fluid_synth_get_cpu_load"
__safe foreign handler fluid_synth_sfload(in pSynth as fs_SYNTH,in pFilename as ZStringNative,in pResetPresets as CBool) returns CSInt binds to "c:libfluidsynth>fluid_synth_sfload"
__safe foreign handler fluid_synth_add_sfont(in pSynth as fs_SYNTH, in pSoudFont as fs_SOUNDFONT ) returns CSInt binds to "c:libfluidsynth>fluid_synth_add_sfont"
__safe foreign handler fluid_synth_get_bank_offset(in pSynth as fs_SYNTH, in pSoudFont as fs_SOUNDFONT ) returns CUInt binds to "c:libfluidsynth>fluid_synth_get_bank_offset"
__safe foreign handler fluid_sfont_get_preset(in pSoudFont as fs_SOUNDFONT, in pBankNum as CUint, in pPreset as CUint ) returns optional fs_SFPRESET binds to "c:libfluidsynth>fluid_sfont_get_preset"
__safe foreign handler fluid_preset_get_name(in pPresetPtr as fs_SFPRESET) returns optional Pointer binds to "c:libfluidsynth>fluid_preset_get_name"
__safe foreign handler fluid_preset_get_banknum(in pPresetPtr as fs_SFPRESET) returns optional CInt binds to "c:libfluidsynth>fluid_preset_get_banknum"
__safe foreign handler fluid_preset_get_num(in pPresetPtr as fs_SFPRESET) returns optional CInt binds to "c:libfluidsynth>fluid_preset_get_num"
__safe foreign handler fluid_sfont_iteration_start(in pSoudFont as fs_SOUNDFONT ) returns nothing binds to "c:libfluidsynth>fluid_sfont_iteration_start"
__safe foreign handler fluid_sfont_iteration_next(in pSoudFont as fs_SOUNDFONT ) returns optional fs_SFPRESET binds to "c:libfluidsynth>fluid_sfont_iteration_next"
__safe foreign handler fluid_synth_remove_sfont(in pSynth as fs_SYNTH,in pSoudFont as fs_SOUNDFONT ) returns CSInt binds to "c:libfluidsynth>fluid_synth_remove_sfont"
__safe foreign handler fluid_synth_sfunload(in pSynth as fs_SYNTH, in pSFontID as CInt, in pReset as CInt) returns CSInt binds to "c:libfluidsynth>fluid_synth_sfunload"
__safe foreign handler fluid_synth_sfreload(in pSynth as fs_SYNTH, in pSFontID as CInt) returns CSInt binds to "c:libfluidsynth>fluid_synth_sfreload"
__safe foreign handler fluid_synth_get_sfont(in pSynth as fs_SYNTH, in pSFontIndex as CInt) returns optional fs_SOUNDFONT binds to "c:libfluidsynth>fluid_synth_get_sfont"
-- Index is 0 to _sfcount -1
__safe foreign handler fluid_synth_get_sfont_by_id(in pSynth as fs_SYNTH, in pSFontID as CInt) returns optional fs_SOUNDFONT binds to "c:libfluidsynth>fluid_synth_get_sfont_by_id"
__safe foreign handler fluid_synth_get_sfont_by_name(in pSynth as fs_SYNTH, in pFilename as ZStringNative, in pSFontID as CInt) returns optional fs_SOUNDFONT binds to "c:libfluidsynth>fluid_synth_get_sfont_by_name"
__safe foreign handler fluid_sfont_get_name(in pSoundFont as optional fs_SOUNDFONT) returns optional Pointer binds to "c:libfluidsynth>fluid_sfont_get_name" -- pointer to *char string
__safe foreign handler fluid_synth_sfcount(in pSynth as fs_SYNTH ) returns CInt binds to "c:libfluidsynth>fluid_synth_sfcount"
__safe foreign handler fluid_synth_system_reset(in pSynth as fs_SYNTH) returns CBool binds to "c:libfluidsynth>fluid_synth_system_reset"
__safe foreign handler fluid_synth_noteon(in pSynth as fs_SYNTH,in pChan as CInt,in pKey as CInt, in pVel as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_noteon"
__safe foreign handler fluid_synth_noteoff(in pSynth as fs_SYNTH,in pChan as CInt,in pKey as CInt ) returns CInt binds to "c:libfluidsynth>fluid_synth_noteoff"
__safe foreign handler fluid_synth_pitch_bend(in pSynth as fs_SYNTH,in pChan as CInt,in pBend as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_pitch_bend" -- bend 0-16383, 8192 as center
__safe foreign handler fluid_synth_cc(in pSynth as fs_SYNTH,in pChan as CInt,in pControllerNum as CInt, in pCCValue as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_cc"
__safe foreign handler fluid_synth_get_cc(in pSynth as fs_SYNTH,in pChan as CInt,in pControllerNum as CInt, out rCCValue as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_get_cc"
__safe foreign handler fluid_synth_program_change(in pSynth as fs_SYNTH,in pChan as CInt,in pPreset as CInt ) returns CInt binds to "c:libfluidsynth>fluid_synth_program_change"
__safe foreign handler fluid_synth_bank_select(in pSynth as fs_SYNTH,in pChan as CInt,in pBankNum as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_bank_select"
__safe foreign handler fluid_synth_program_select_by_sfont_name(in pSynth as fs_SYNTH, in pChan as CInt, in pFilename as ZStringNative, in pBankNum as CInt, in pPreset as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_program_select_by_sfont_name"
__safe foreign handler fluid_synth_program_select(in pSynth as fs_SYNTH, in pChan as CInt, in pSFontID as CInt, in pBankNum as CInt, in pPreset as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_program_select"
__safe foreign handler fluid_synth_unset_program(in pSynth as fs_SYNTH, in pChan as CInt) returns CSInt binds to "c:libfluidsynth>fluid_synth_unset_program"
__safe foreign handler fluid_synth_get_program(in pSynth as fs_SYNTH, in pChan as CInt, out rSFontID as optional CInt, out rBank as optional CInt, out rPreset as optional CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_get_program"
__safe foreign handler fluid_synth_all_notes_off(in pSynth as fs_SYNTH,in pChan as CInt) returns CSInt binds to "c:libfluidsynth>fluid_synth_all_notes_off"
__safe foreign handler fluid_synth_all_sounds_off(in pSynth as fs_SYNTH,in pChan as CInt) returns CSInt binds to "c:libfluidsynth>fluid_synth_all_sounds_off"
--pFXGroup must be in the range -1 to (fluid_synth_count_effects_groups()-1). If -1 the parameter common to all fx groups is fetched.
__safe foreign handler fluid_synth_count_effects_groups(in pSynth as fs_SYNTH) returns CInt binds to "c:libfluidsynth>fluid_synth_count_effects_groups"
__safe foreign handler fluid_synth_set_reverb_on(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pOnOff as Boolean) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_reverb_on"
-- fluid_synth_set_reverb is Deprecated in FluidSynth 2.x use the new reverb 'group' / individual settings versions
__safe foreign handler fluid_synth_set_reverb( in pSynth as fs_SYNTH, pRoomsize as CDouble, pDamp as CDouble, pWidth as CDouble, pLevel as CDouble) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_reverb"
__safe foreign handler fluid_synth_set_reverb_group_level(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pLevel as CDouble ) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_reverb_group_level"
__safe foreign handler fluid_synth_set_reverb_group_roomsize(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pSize as CDouble) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_reverb_group_roomsize"
__safe foreign handler fluid_synth_set_reverb_group_width(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pWidth as CDouble) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_reverb_group_width"
__safe foreign handler fluid_synth_set_reverb_group_damp(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pDamp as CDouble) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_reverb_group_damp"
__safe foreign handler fluid_synth_set_chorus_on(in pSynth as fs_SYNTH,in pFXGroup as CSInt, in pOnOff as CBool) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_chorus_on"
-- fluid_synth_set_reverb is Deprecated in FluidSynth 2.x use the new chorus 'group' / individual settings versions
__safe foreign handler fluid_synth_set_chorus( in pSynth as fs_SYNTH, in pChorusVoices as CInt, in pLevel as CDouble, in pSpeed as CDouble, in pDepth as CDouble, in pChorusType as CInt) \
returns CSInt binds to "c:libfluidsynth>fluid_synth_set_chorus"
__safe foreign handler fluid_synth_set_chorus_group_nr(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pChorusVoices as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_chorus_group_nr"
__safe foreign handler fluid_synth_set_chorus_group_level(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pLevel as CDouble ) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_chorus_group_level"
__safe foreign handler fluid_synth_set_chorus_group_speed(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pSize as CDouble) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_chorus_group_speed"
__safe foreign handler fluid_synth_set_chorus_group_depth(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pDamp as CDouble) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_chorus_group_depth"
__safe foreign handler fluid_synth_set_chorus_group_type(in pSynth as fs_SYNTH,in pFXGroup as CSInt,in pChorusVoices as CInt ) returns CSInt binds to "c:libfluidsynth>fluid_synth_set_chorus_group_type"
-- FLUID_CHORUS_MOD_SINE = 0, FLUID_CHORUS_MOD_TRIANGLE = 1
__safe foreign handler new_fluid_player(in pSynth as fs_SYNTH ) returns optional fs_PLAYER binds to "c:libfluidsynth>new_fluid_player"
__safe foreign handler delete_fluid_player(in pPlayer as fs_PLAYER) returns CBool binds to "c:libfluidsynth>delete_fluid_player"
__safe foreign handler fluid_player_add(in pPlayer as fs_PLAYER,in pFilename as ZStringNative) returns CInt binds to "c:libfluidsynth>fluid_player_add"
__safe foreign handler fluid_player_play(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_play"
__safe foreign handler fluid_player_stop(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_stop"
__safe foreign handler fluid_player_join(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_join"
-- pLoop = Times left to loop the playlist. -1 means loop infinitely.
__safe foreign handler fluid_player_set_loop(in pPlayer as fs_PLAYER,in pLoop as CInt) returns CInt binds to "c:libfluidsynth>fluid_player_set_loop"
__safe foreign handler fluid_player_set_bpm(in pPlayer as fs_PLAYER,in pBPM as CInt) returns CInt binds to "c:libfluidsynth>fluid_player_set_bpm"
__safe foreign handler fluid_player_get_bpm(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_get_bpm"
-- per MIDI file spec so 500000 = 120 BPM
__safe foreign handler fluid_player_set_midi_tempo(in pPlayer as fs_PLAYER,in pMicroSecsPerQrtrNote as CInt) returns CInt binds to "c:libfluidsynth>fluid_player_set_midi_tempo" -- per MIDI file spec so 500000 = 120 BPM
__safe foreign handler fluid_player_get_midi_tempo(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_get_midi_tempo" -- per MIDI file spec so 500000 = 120 BPM
__safe foreign handler fluid_player_get_status(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_get_status"
__safe foreign handler fluid_player_get_current_tick(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_get_current_tick"
__safe foreign handler fluid_player_get_total_ticks(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_get_total_ticks"
__safe foreign handler new_fluid_file_renderer(in mSynth as fs_SYNTH) returns fs_FILE_RENDERER binds to "c:libfluidsynth>new_fluid_file_renderer"
__safe foreign handler fluid_file_renderer_process_block(in pFileRenderer as fs_FILE_RENDERER) returns CSInt binds to "c:libfluidsynth>fluid_file_renderer_process_block"
__safe foreign handler delete_fluid_file_renderer(in pFileRenderer as fs_FILE_RENDERER) returns CSInt binds to "c:libfluidsynth>delete_fluid_file_renderer"
-- http://www.fluidsynth.org/api-1.x/index.html#RealtimeMIDI
__safe foreign handler new_fluid_midi_router(in pSettings as fs_SETTINGS, in pHandler as any, in pHandlerData as optional any)\
returns optional fs_MIDIROUTER binds to "c:libfluidsynth>new_fluid_midi_router"
__safe foreign handler delete_fluid_midi_router(in pPlayer as fs_MIDIROUTER) returns CBool binds to "c:libfluidsynth>delete_fluid_midi_router"
__safe foreign handler new_fluid_midi_router_rule() returns fs_MIDIROUTER_rule binds to "c:libfluidsynth>new_fluid_midi_router_rule"
__safe foreign handler delete_fluid_midi_router_rule(in pRouterRule as fs_MIDIROUTER_rule) returns CBool binds to "c:libfluidsynth>new_fluid_midi_router_rule"
public foreign handler type handle_midi_event_func_t( in pOptionalDataPtr as optional Pointer, in mMIDIEvtPtr as Pointer) returns CInt
__safe foreign handler new_fluid_midi_driver(in pSettings as fs_SETTINGS, in pHandler as handle_midi_event_func_t, in pOptionalDataPtr as optional Pointer) \
returns optional fs_MIDIdrvr binds to "c:libfluidsynth>new_fluid_midi_driver"
__safe foreign handler delete_fluid_midi_driver(in pPlayer as fs_MIDIdrvr) returns CBool binds to "c:libfluidsynth>delete_fluid_midi_driver"
__safe foreign handler fluid_midi_event_get_type(in pMIDIEvent as fs_MIDIEvent) returns Cint binds to "c:libfluidsynth>fluid_midi_event_get_type"
__safe foreign handler fluid_midi_event_get_channel(in pMIDIEvent as fs_MIDIEvent) returns Cint binds to "c:libfluidsynth>fluid_midi_event_get_channel"
__safe foreign handler fluid_midi_event_get_key(in pMIDIEvent as fs_MIDIEvent) returns Cint binds to "c:libfluidsynth>fluid_midi_event_get_key"
__safe foreign handler fluid_midi_event_get_velocity(in pMIDIEvent as fs_MIDIEvent) returns Cint binds to "c:libfluidsynth>fluid_midi_event_get_velocity"
__safe foreign handler fluid_midi_event_get_pitch(in pMIDIEvent as fs_MIDIEvent) returns Cint binds to "c:libfluidsynth>fluid_midi_event_get_pitch"
__safe foreign handler delete_fluid_midi_event(in pMIDIEvent as fs_MIDIEvent) returns nothing binds to "c:libfluidsynth>delete_fluid_midi_event"
-- FLUIDSYNTH_API int fluid_player_set_playback_callback (fluid_player_t *player, handle_midi_event_func_t handler, void *handler_data) Change the MIDI callback function. More...
-- FLUIDSYNTH_API int fluid_player_seek (fluid_player_t *player, int ticks) Seek in the currently playing file. More...
constant kMCStringEncodingUTF8 is 4
__safe foreign handler MCStringEncode(in pString as String, in pEncoding as CUInt, in pIsExternalRep as CBool, out rUTF8String as Data) returns CBool binds to "<builtin>"
__safe foreign handler MCStringCreateWithCString(in pString as Pointer, out rString as String) returns CBool binds to "<builtin>"
--foreign handler MCStringCreateWithBytes(in pBytes as Pointer, in pByteCount as LCUInt, in pEncoding as CUInt, in pIsExternalRep as CBool, out rString as String) returns CBool binds to "<builtin>"
--foreign handler MCDataConvertStringToData(in pString as String, out rData as Data) returns CBool binds to "<builtin>"
__safe foreign handler MCDataGetBytePtr(in pData as Data) returns optional Pointer binds to "<builtin>"
__safe foreign handler MCMemoryAllocate(in pSize as UIntSize, out rBlockPtr as Pointer) returns CBool binds to "<builtin>"
-- allocates a block of size pSize bytes, places the pointer into rBlockPtr and returns true - or just returns false if it fails
-- MCMemoryReallocate(T *p_block, size_t p_new_size, T*& r_new_block)
__safe foreign handler MCMemoryReallocate(in rBlockPtr as Pointer, in pSize as UIntSize, out rReAllocBlockPtr as Pointer) returns CBool binds to "<builtin>"
__safe foreign handler MCMemoryDeallocate(in rBlockPtr as Pointer) returns nothing binds to "<builtin>"
__safe foreign handler MCWidgetGetMyScriptObject(out rObject as ScriptObject) returns nothing binds to "<builtin>"
private handler fsPostMIDIinput(in tMsgType as Integer, in pChan as Integer, pNoteNum as Integer, pVelocity as optional Integer) returns nothing
expect that (pChan >= 1 and pChan <= 16 ) because "MIDI channel values must be in the range of 1 to 16"
-- variable tScriptObj as ScriptObject
-- MCWidgetGetMyScriptObject(tScriptObj)
-- log tScriptObj
-- get the target -- not allowed in Library modules
-- log the result
-- resolve script object mScriptObject
if mScriptObject exists then
if tMsgType = 144 then
post "MIDINoteOn" to mScriptObject with [ pChan , pNoteNum , pVelocity ]
-- send "MIDINoteOn" to mScriptObject with [ pChan , pNoteNum , pVelocity ]
-- execute script "get MIDINoteOn(param(1),param(2),param(3)) " of mScriptObject with [ pChan, pNoteNum, pVelocity]
-- execute script ("MIDINoteOn("& pChan &","& pNoteNum &","& pVelocity &")") in mScriptObject
-- log the message was handled
-- log the result
else if tMsgType = 128 then
post "MIDINoteOff" to mScriptObject with [ pChan , pNoteNum ]
-- send "MIDINoteOff" to mScriptObject with [ pChan , pNoteNum ]
-- execute script ("MIDINoteOff("& pChan &","& pNoteNum & ")") in mScriptObject
-- log the message was handled
-- log the result
else if tMsgType = 224 then
-- post "MIDIPitchBend" with [ tChan , tNoteNum , tVelocity ]
post "MIDIPitchBend" to mScriptObject with [ pChan , pNoteNum ]
else if tMsgType = 176 then
-- post "MIDIController" with [ tChan , tNoteNum , tVelocity ]
post "MIDIController" to mScriptObject with [ pChan , pNoteNum , pVelocity ]
end if
end if
-- log the system error message
-- com.livecode.system
-- log the result
return
end handler
public handler fsSetMIDIInTargetScriptObj(in pTargetScriptObj as optional String ) returns optional any
if pTargetScriptObj is not nothing then
resolve script object pTargetScriptObj
put the result into mScriptObject
log pTargetScriptObj
--else
-- resolve script object "this stack"
-- put the result into mScriptObject
-- log pTargetScriptObj
end if
end handler
private handler fsHandleMIDIinput(in pMyDataPtr as optional Pointer, in mMIDIEvtPtr as Pointer ) returns CInt
-- log [pMIDIEvent]
variable tChan as Integer
variable tMsgType as Integer
variable tNoteNum as Integer
variable tVelocity as Integer
put fluid_midi_event_get_type(mMIDIEvtPtr) into tMsgType
put fluid_midi_event_get_channel(mMIDIEvtPtr) + 1 into tChan
-- log [tMsgType] -- ,tChan,tNoteNum,tVelocity]
if tMsgType = 144 then
put fluid_midi_event_get_key(mMIDIEvtPtr) into tNoteNum
put fluid_midi_event_get_velocity(mMIDIEvtPtr) into tVelocity
fsPostMIDIinput(tMsgType,tChan,tNoteNum,tVelocity)
-- fluid_synth_noteon(mSynth,tChan,tNoteNum,tVelocity)
else if tMsgType = 128 then
put fluid_midi_event_get_key(mMIDIEvtPtr) into tNoteNum
-- put fluid_midi_event_get_velocity(mMIDIEvtPtr) into tVelocity
fsPostMIDIinput(tMsgType,tChan,tNoteNum,0)
-- fluid_synth_noteoff(mSynth,tChan,tNoteNum)
else if tMsgType = 224 then
put fluid_midi_event_get_pitch(mMIDIEvtPtr) into tNoteNum
fsPostMIDIinput(tMsgType,tChan,tNoteNum,0)
-- fluid_synth_pitch_bend(mSynth,tChan,tNoteNum)
else if tMsgType = 176 then
put fluid_midi_event_get_key(mMIDIEvtPtr) into tNoteNum
put fluid_midi_event_get_velocity(mMIDIEvtPtr) into tVelocity
fsPostMIDIinput(tMsgType,tChan,tNoteNum,tVelocity)
-- fluid_synth_cc(mSynth,tChan,tNoteNum,tVelocity)
end if
-- delete_fluid_midi_event(mMIDIEvtPtr)
-- put nothing into mMIDIEvtPtr
return 0
end handler
private variable mMIDIBuffer as Data
private variable mMIDIEvtPtr as optional Pointer
variable mScriptObject as ScriptObject
public handler fsInitMIDIinput(in pInputPortName as optional String, in pTargetScriptObj as optional String) -- returns optional any
if pTargetScriptObj is not nothing then
resolve script object pTargetScriptObj
put the result into mScriptObject
else
resolve script object "this stack"
put the result into mScriptObject
end if
log ["MiDI IN TARGET ", mScriptObject]
if mInited then
if mMIDIDriver is not nothing then
delete_fluid_midi_driver(mMIDIDriver)
put nothing into mMIDIDriver
end if
if pInputPortName is nothing then
put "OXT FluidSynth MIDI in" into pInputPortName
end if
variable tWasSet as Boolean
--if MCStringEncode(pInputPortName, kMCStringEncodingUTF8, false, pInputPortNameData) then
-- put MCDataGetBytePtr(pInputPortNameData) into pInputPortNameDataPtr
-- put fluid_settings_setstr(mSettings,"midi.driver","coremidi") into tWasSet
put fluid_settings_setstr(mSettings,"midi.portname", pInputPortName) into tWasSet
-- end if
-- variable tDoRunLoopFunc as MCRunloopActionCallback
-- variable tContext as optional Pointer
-- MCHandlerGetFunctionPtr(fsHandleMIDIinput,pMIDICalbackPtr)
-- if MCHandlerGetFunctionPtr(doRunLoop, tDoRunLoopFunc) then
-- MCEngineAddRunloopAction(tDoRunLoopFunc, tContext, mRunloopAction)
-- else
-- put "Unable to set run loop" into tError
-- end if
-- put MCMemoryAllocate(65536,mMIDIEvtPtr) into tDidAllocateBlock --- crashing has nothing to do with buffer size
-- put MCMemoryAllocate(256,mMIDIEvtPtr) into tDidAllocateBlock
put new_fluid_midi_driver(mSettings, fsHandleMIDIinput, nothing) into mMIDIDriver
--put new_fluid_midi_driver(mSettings, fsHandleMIDIinput , nothing) into mMIDIDriver
end if
end handler
/**
Setup the libFluidSynth Engine .
Type: function
Example:
fsEnsureInitialize()
Returns: True on success, false or error string on failure.
Description:
Attempts to load an instance of libFluidSynth.
*/
public handler fsEnsureInitialize() returns optional any
variable tStrPtr as Pointer
variable tString as String
variable tWasSet as CSInt
if mInited then
return mInited
else
put the empty list into mSoundFontList
--variable rMaj as Integer
--variable rMin as Integer
-- variable rMicr as Integer
-- fluid_version(rMaj,rMin,rMicr)
-- log [rMaj,rMin,rMicr]
put fluid_version_str() into tStrPtr
if MCStringCreateWithCString(tStrPtr, tString) then
log ["FluidSynth Version:" && tString]
end if
put new_fluid_settings() into mSettings
-- put fluid_settings_getstr_default(mSettings,"audio.driver",tStrPtr) into tWasSet
-- if MCStringCreateWithCString(tStrPtr, tString) then
-- log ["FluidSynth Default:" && tString]
-- end if
fluid_settings_setint(mSettings, "audio.jack.autoconnect", 1)
put new_fluid_synth(mSettings) into mSynth
put new_fluid_audio_driver(mSettings,mSynth) into mAudioDriver
if mAudioDriver is not nothing then
put true into mInited
return true
else
return false
end if
end if
end handler
/**
Check the ammount of CPU load the FluidSynth library is currently using.
Type: function
Example:
get fsGetCPULoad()
Returns: The ammount of CPU load the FluidSynth library is currently using.
Description:
Returns the ammount of CPU load the FluidSynth library is currently using.
*/
public handler fsGetCPULoad() returns optional any
if fsEnsureInitialize() then
if mSynth is not nothing then
return fluid_synth_get_cpu_load(mSynth)
end if
end if
end handler
/**
Get the number of SoundFonts that are loaded by the FluidSynth library
Type: function
Example:
get fsGetSoundFontCount()
Returns: The number of SoundFonts that are loaded by the FluidSynth library.
Description:
Returns the number of SoundFonts that are loaded by the FluidSynth library.
*/
public handler fsGetSoundFontCount() returns optional Integer
variable tCount as Integer
if fsEnsureInitialize() then
if mSynth is not nothing then
put fluid_synth_sfcount(mSynth) into tCount
if tCount is a number then
return tCount
end if
end if
end if
end handler
--- GOT IT WORKING!!! Is there really no EASY way to get full list of program names from a Soundfont that is built into FluidSynth (or Apple's AVAUSampler for that matter)???
public handler fsGetSFPresetListFromID(in pSFID as Integer) returns optional any
variable tStatus as Integer
variable tPreset as optional fs_SFPRESET
variable tSoundFont as optional fs_SOUNDFONT
variable tBankNum as Integer
variable tPresettNum as Integer
variable tStringPtr as optional Pointer
variable tString as optional String
variable tListString as optional String
put fluid_synth_get_sfont_by_id(mSynth, pSFID) into tSoundFont
if tSoundFont is not nothing then
put "" into tListString
-- add the sound font name (which is typically a file-path ) at beginning of list string
-- put fluid_sfont_get_name(tSoundFont) into tStringPtr
-- if not MCStringCreateWithCString(tStringPtr, tString) then
-- put "Soundfont name not found" & "\n" after tListString
-- -- return "Failed to convert const *char to String"
-- else if tString is not nothing and tString is not the empty string then
-- put tString & "\n" after tListString
-- end if
--- Build peset list text:
fluid_sfont_iteration_start(tSoundFont) -- Ensure iterator reset to first preset in the SoundFont
repeat forever
put fluid_sfont_iteration_next(tSoundFont) into tPreset
-- put fluid_sfont_get_preset(tSoundFont, pBankNum, pProgramNum ) into tPreset
if tPreset is not nothing then
put fluid_preset_get_banknum(tPreset) into tBankNum
put fluid_preset_get_num(tPreset) into tPresettNum
put fluid_preset_get_name(tPreset) into tStringPtr
if tStringPtr is not nothing then
if not MCStringCreateWithCString(tStringPtr, tString) then
-- return "Error: Couldn't get name string"
put tBankNum formatted as string &"-"& tPresettNum formatted as string &"\n" after tListString
next repeat
else
put tBankNum formatted as string &"-"& tPresettNum formatted as string &" "& tString & "\n" after tListString
next repeat /* iterator */
end if
-- else
-- return "Error: Couldn't get name string pointer"
end if
else
exit repeat
-- return "Error: Couldn't get preset"
end if
next repeat
end repeat
else
log "Error: Couldn't get soundFont"
end if
if tListString is not the empty string then
return tListString
end if
end handler
--- GOT IT WORKING!!! Is there really no EASY way to get full list of program names from a Soundfont that is built into FluidSynth (or Apple's AVAUSampler for that matter)???
public handler fsGetSFPresetInfo(in pSFID as Integer, in pBankNum as Integer, in pProgramNum as Integer) returns optional any
variable tStatus as Integer
variable tPreset as optional fs_SFPRESET
variable tSoundFont as optional fs_SOUNDFONT
variable tStringPtr as optional Pointer
variable tString as optional String
put fluid_synth_get_sfont_by_id(mSynth, pSFID) into tSoundFont
if tSoundFont is not nothing then
put fluid_sfont_get_preset(tSoundFont, pBankNum, pProgramNum ) into tPreset
if tPreset is not nothing then
put fluid_preset_get_name(tPreset) into tStringPtr
if tStringPtr is not nothing then
if not MCStringCreateWithCString(tStringPtr, tString) then
return "Error: Couldn't get name string"
else
return tString
end if
else
return "Error: Couldn't get name string pointer"
end if
else
return "Error: Couldn't get preset"
end if
else
return "Error: Couldn't get soundFont"
end if
end handler
public handler fsGetProgram(in pChan as Integer) returns optional any
variable tStatus as Integer
variable rSoundfontID as optional Integer
variable rBankNum as optional Integer
variable rPresetNum as optional Integer
put 0 into rSoundfontID
put 0 into rBankNum
put 0 into rPresetNum
put -1 into tStatus
if fsEnsureInitialize() then
if mSynth is not nothing then
put fluid_synth_get_program(mSynth, pChan - 1, rSoundfontID, rBankNum, rPresetNum) into tStatus
if tStatus = -1 then
return "Error"
else
-- log [rSoundfontID, rBankNum, rPresetNum]
return [rSoundfontID, rBankNum, rPresetNum]
-- return rSoundfontID
-- log [rSoundfontID, rBankNum, rPresetNum]
end if
else
return "Error: Synth not loaded"
end if
else
return "Error: Synth not loaded"
end if
end handler
private type LibraryHandle is optional Pointer
private variable mNSConcreteGlobalBlock as optional Pointer
constant kRTLD_LAZY is 1
private foreign handler OpenLibrary(in pPath as ZStringUTF8, in pFlag as CSInt) returns LibraryHandle binds to "dlopen"
private foreign handler GetSymbolPointer(in pHandle as LibraryHandle, in pSymbol as ZStringUTF8) returns optional Pointer binds to "dlsym"
private foreign handler CloseLibrary(in pHandle as LibraryHandle) returns CSInt binds to "dlclose"
public handler fsMIDIFileToSoundFile(in pSoundFontPath as String, in pMIDIFilePath as String, in pSoundFilePath as String ) -- returns optional any
variable tStatus as Integer
variable tSynth as fs_SYNTH
variable tSettings as fs_SETTINGS
variable tPlayer as fs_PLAYER
variable tRenderer as fs_FILE_RENDERER
if fsEnsureInitialize() then
--variable tLibSndFile as LibraryHandle
--unsafe
-- put OpenLibrary("libsndfile.1.dylib", kRTLD_LAZY) into tLibSndFile
-- put OpenLibrary("@loader_path/libsndfile.1.dylib", kRTLD_LAZY) into tLibSndFile
--end unsafe
-- if tSystLibSndFile is not nothing then
-- put GetSymbolPointer(tSystem, "_NSConcreteGlobalBlock") into mNSConcreteGlobalBlock
-- CloseLibrary(tSystem)
-- end if
-- specify the file to store the audio to
-- make sure you compiled fluidsynth with libsndfile to get a real wave file
-- otherwise this file will only contain raw s16 stereo PCM
put new_fluid_settings() into tSettings
fluid_settings_setstr(tSettings, "audio.file.name", pSoundFilePath)
fluid_settings_setstr(tSettings, "audio.file.type", "wav")
-- aiff, au, auto, avr, caf, flac, htk, iff, mat, oga, paf, pvf, raw, sd2, sds, sf, voc, w64, wav, xi
-- Default = 'auto' if libsndfile support is built in, Limited to 'raw' if compiled without libsndfile support.
-- Actual options will vary depending on libsndfile library.
fluid_settings_setstr(tSettings, "audio.file.format", "s16") -- options are double, float, s16, s24, s32, s8, u8
fluid_settings_setstr(tSettings, "audio.file.endian", "auto") -- auto, big, cpu, little ('cpu' only if libsndfile support is not built in)
-- use number of samples processed as timing source, rather than the system timer
fluid_settings_setstr(tSettings, "player.timing-source", "sample")
-- since this is a non-realtime scenario, there is no need to pin the sample data
fluid_settings_setint(tSettings, "synth.lock-memory", 0)
put new_fluid_synth(tSettings) into tSynth
if fluid_is_soundfont(pSoundFontPath) then
put fluid_synth_sfload(tSynth,pSoundFontPath,true) into tStatus
--- maybe check tStatus result for error ;-)
end if
put new_fluid_player(tSynth) into tPlayer
put new_fluid_file_renderer(tSynth) into tRenderer
fluid_player_add(tPlayer, pMIDIFilePath)
fluid_player_play(tPlayer)
repeat while fluid_player_get_status(tPlayer) = 1 -- FLUID_PLAYER_PLAYING = 1
if (fluid_file_renderer_process_block(tRenderer) is not kFLUID_OK) then
exit repeat
end if
end repeat
-- just for sure: stop the playback explicitly and wait until finished
fluid_player_stop(tPlayer)
fluid_player_join(tPlayer)
delete_fluid_file_renderer(tRenderer)
delete_fluid_player(tPlayer)
delete_fluid_synth(tSynth)
delete_fluid_settings(tSettings)
-- re-pin the sample data
-- fluid_settings_setint(tSettings, "synth.lock-memory", 1)
else
return "Error: FluidSynth not initialized!"
end if
end handler
/**
Loads a Soundbank file (SF2 or DLS) for use with MIDI playback
Example:
fsLoadSoundFont "/Path/To?My/Soundbank.sf2"
Parameters:
SoundFontPath (string): the file path to a SoundBank SF2 or DLS file
Description:
Give a file path fsLoadSoundFont attempts tp load a Soundbank file in either SoundFont2 (.sf2) or
Downloadable Sound DLS format (.dls) for use with MIDI playback.
*/
private variable mSoundFontList as optional List
public handler fsLoadSoundFont(in pFilename as optional String) returns optional any
if pFilename is nothing or pFileName is the empty string then
put fsGetFallbackSoundFont() into pFilename -- FreeFont default SoundFont
end if
variable tSoundFontID as Integer
variable tSFList as List
variable tSoundFontRecord as Array
if fsEnsureInitialize() then
if fluid_is_soundfont(pFilename) then
-- check if this soundfont has already been loaded
put fluid_synth_sfload(mSynth,pFilename,true) into tSoundFontID
if tSoundFontID is kFLUID_FAILED then
return "Error: SoundFont did not load!"
end if
else
return "Error: File May not be a valid SoundFont File!"
end if
else
return "Error: FluidSynth not initialized!"
end if
-- put tSFArray into mSoundFontList
-- log [mSoundFontList]
put mSoundFontList into tSFList
put tSoundFontID into tSoundFontRecord["ID"]
put pFilename into tSoundFontRecord["FilePath"]
push tSoundFontRecord onto tSFList
put tSFList into mSoundFontList
-- log [mSoundFontList]
return tSoundFontID formatted as string &"\t" & pFilename
end handler
public handler fsLoadedSoundFonts() returns optional any
variable tListLine as Array
variable tListStr as String
variable tList as List
if mSoundFontList is not nothing then
put mSoundFontList into tList
repeat for each element tListLine in tList
put (tListLine["ID"] formatted as string) & "\t" & tListLine["FilePath"] & "\n" after tListStr
end repeat
return tListStr
else
return "No Sound Fonts in List"
end if
end handler
public handler fsGetSoundFontNameFromID(in pSoundFontID as Integer) returns optional any
variable tString as optional String -- ZStringNative
variable tStrPtr as optional Pointer
variable tCount as optional Integer
variable tStatus as optional CSint
variable tStringList as optional String
variable tSelectedSoundFont as optional fs_SOUNDFONT
put nothing into tSelectedSoundFont
if fsEnsureInitialize() then
if mSynth is not nothing then
if pSoundFontID > -1 then
put fluid_synth_get_sfont_by_id(mSynth, pSoundFontID) into tSelectedSoundFont
if tSelectedSoundFont is not nothing then
put fluid_sfont_get_name(tSelectedSoundFont) into tStrPtr
if not MCStringCreateWithCString(tStrPtr, tString) then
put pSoundFontID formatted as string & "\t" before tString
-- return "Failed to convert const *char to String"
else if tString is not nothing and tString is not the empty string then
put pSoundFontID formatted as string &"\t" before tString
end if
return tString
else
return "Error: Soundfont ID " & (pSoundFontID formatted as string) & " not found"
end if
else
return "Error: Invalid ID"
end if
else
return "Error: No FluidSynth instance available"
end if
else
return "Error: FluidSynth not initialized"
end if
end handler
public handler fsUnloadSoundFontIndex(in pSoundFontID as Integer) returns optional any
variable tStatus as Integer
variable tSelectedSoundFont as optional fs_SOUNDFONT
put nothing into tSelectedSoundFont
if fsEnsureInitialize() then
if pSoundFontID > -1 then
put fsGetSoundFontByIndex( pSoundFontID ) into tSelectedSoundFont
log [tSelectedSoundFont]
-- if tSelectedSoundFont is not nothing then
put fluid_synth_sfunload(mSynth,pSoundFontID,0) into tStatus
-- put nothing into mSoundFont
return tStatus
--else
-- return "No Soundfont found at index " & pSoundFontIndex formatted as string
--end if
else
return nothing
end if
else
return nothing
end if
return nothing
end handler
handler fsGetSoundFontByIndex(in pSoundFontIndex as Integer) returns optional fs_SOUNDFONT
variable tCount as Integer
variable tSelectedSoundFont as optional fs_SOUNDFONT
put nothing into tSelectedSoundFont
if fsEnsureInitialize() then
if mSynth is not nothing then
if pSoundFontIndex > 0 then
subtract 1 from pSoundFontIndex
put fluid_synth_get_sfont(mSynth, pSoundFontIndex) into tSelectedSoundFont
-- log tSelectedSoundFont
if tSelectedSoundFont is not nothing then
return tSelectedSoundFont
else
return nothing
end if
else
return nothing
end if
else
return nothing
end if
else
return nothing
end if
end handler
/**
Returns the path to "FreeFont.sf2", a small fallback soundfont included with the
OpenXTalk FluidSynth library
Example:
put fsGetFallbackSoundFont() into tBasicGMSoundFont
Parameters:
Description:
A convienience function that returns the file path to FreeFont.sf2, a small
GeneralMIDI soundfont included with OpenXTalk's FluidSynth library in its extension
resources folder. This soundbank is meant as a fallback for when no other
soundbanks are available. Download a larger Soundfont for better quality playback.
*/
public handler fsGetFallbackSoundFont() returns String
variable tFallbackBank
-- if resolve file ((my resources folder) & "/FreeFont.sf2") then
-- log (my resources folder) & "/FreeFont.sf2"
put (my resources folder) & "/FreeFont.sf2" into tFallbackBank
-- else
--if resolve file ((my resources folder) & "/sf2/FreeFont.sf2") then
-- log (my resources folder) & "/sf2/FreeFont.sf2"
--put (my resources folder) & "/sf2/FreeFont.sf2" into tFallbackBank
-- end if
-- end if
return tFallbackBank
end handler
public handler fsListLoadedSoundFonts() returns String
variable tString as optional String -- ZStringNative
variable tStrPtr as optional Pointer
variable tCount as optional Integer
variable tStatus as optional CSint
variable tStringList as optional String
variable tIterate as optional Cint
variable tSelectedSoundFont as optional fs_SOUNDFONT
put nothing into tSelectedSoundFont
put the empty string into tStringList
put fsGetSoundFontCount() into tCount
log tCount
repeat with tIterate from 0 up to tCount by 1
-- put fluid_synth_get_sfont_by_id(mSynth, tIterate) into tSelectedSoundFont
put fluid_synth_get_sfont_by_id(mSynth, tIterate) into tSelectedSoundFont
if tSelectedSoundFont is not nothing then
put fluid_sfont_get_name(tSelectedSoundFont) into tStrPtr
if not MCStringCreateWithCString(tStrPtr, tString) then
put tIterate formatted as string & "\n" after tStringList
-- return "Failed to convert const *char to String"
else if tString is not nothing and tString is not the empty string then
put tIterate formatted as string && tString & "\n" after tStringList
end if
-- else
-- put tIterate formatted as string && "Error\n" after tStringList
end if
end repeat
return tStringList
end handler
public handler fsGetSoundFontNameByIndex(in tIndex as optional Integer) returns optional String
variable tString as optional String -- ZStringNative
variable tStrPtr as optional Pointer -- ZStringNative
variable tIterate as optional Integer
variable tSelectedSoundFont as optional fs_SOUNDFONT
put fsGetSoundFontByIndex( tIndex ) into mSoundFont
if mSoundFont is not nothing then
put fluid_sfont_get_name(mSoundFont) into tStrPtr
if not MCStringCreateWithCString(tStrPtr, tString) then
return "failed to convert const char * to String"
else if tString is not nothing and tString is not the empty string then
return tString
else
return "Error"
end if
else
return "No Soundfont selected"
end if
end handler
public handler fsMIDIPlayerInit() returns optional any
if mPlayer is nothing then
if fsEnsureInitialize() then
put new_fluid_player(mSynth) into mPlayer
end if
end if
end handler
public handler fsMIDIPlayerSetLoop(in pLoop as Number) returns nothing
variable tStatus as Integer
if mPlayer is not nothing then
put fluid_player_set_loop(mPlayer,pLoop) into tStatus
end if
end handler
/**
Loads a MIDI file from and a Soundbank file from file paths and prepares for playback.
Example:
fsLoadMIDIFile "/Users/Me/MIDIMusic.mid"
Parameters:
MIDIfilePath (string): the file path to a MIDI file
SoundFontPath (string): the file path to a SoundBank SF2 or DLS file
Description:
Loads a MIDI file from and a Soundbank file in either SoundFont2 or
Downloadable Sound DLS format from absolute file paths passed in and
"prerolls" the data, preparing it for playback.
*/
public handler fsLoadMIDIFile(in pFilename as String) returns optional any
variable tStatus as Integer
variable tBool as Boolean
if fsEnsureInitialize() then
if fluid_is_midifile(pFilename) then
if mPlayer is not nothing then
put delete_fluid_player(mPlayer) into tBool
put new_fluid_player(mSynth) into mPlayer
put fluid_player_add(mPlayer,pFilename) into tStatus
if tStatus is kFLUID_OK then
return true
else
return false
end if
else
put new_fluid_player(mSynth) into mPlayer
put fluid_player_add(mPlayer,pFilename) into tStatus
end if
else
return "Error: File May not be a valid MIDI File!"
end if
end if
end handler
/**
Returns the current position of a loaded sequence in MIDI ticks.
Example:
if fsMIDIPlayerCurrentTick() >= fsMIDIPlayerTotalTicks() then send playStop to me
Description:
Returns the current MIDI-tick position of the currently playing MIDI file.
Note: MIDI Ticks are an arbitrary value based on song tempo as opposed to static
measurement like microseconds.
*/
public handler fsMIDIPlayerCurrentTick() returns optional any
variable tTick as Integer
variable tBool as Boolean
if fsEnsureInitialize() then
if mPlayer is not nothing then
put fluid_player_get_current_tick(mPlayer) into tTick
return tTick
end if
end if
-- __safe foreign handler fluid_player_get_total_ticks(in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_get_total_ticks"
end handler
/**
Returns ending position of playing sequence in MIDI ticks.
Example:
if fsMIDIPlayerCurrentTick() >= fsMIDIPlayerTotalTicks() then send playStop to me
Description:
Returns the ending MIDI-tick position of the currently loaded MIDI file.
Note: MIDI Ticks are an arbitrary value based on song tempo as opposed to static
measurement like microseconds.
*/
public handler fsMIDIPlayerTotalTicks() returns optional any
variable tTicks as Integer
variable tBool as Boolean
if fsEnsureInitialize() then
if mPlayer is not nothing then
put fluid_player_get_total_ticks(mPlayer) into tTicks
return tTicks
end if
end if
-- __safe foreign handler (in pPlayer as fs_PLAYER) returns CInt binds to "c:libfluidsynth>fluid_player_get_total_ticks"
end handler
/**
Stops playback
Example:
fsMIDIPlayerStop
Description:
Stops playback of the currently playing sequence stated with fsMIDIPlayerPlay.
*/
public handler fsMIDIPlayerStop()
if mPlayer is not nothing then
fluid_player_stop(mPlayer)
delete_fluid_player(mPlayer)
put nothing into mPlayer
end if
end handler
/**
Stops playback
Example:
fsMIDIPlayerPause
Description:
Pause playback of the currently playing sequence stated with fsMIDIPlayerPlay.
*/
public handler fsMIDIPlayerPause()
if mPlayer is not nothing then
fluid_player_stop(mPlayer)
end if
end handler
/**
Plays the data that was loaded with fsLoadMIDIFile
Example:
fsMIDIPlayerPlay
Description:
Plays the data that was loaded with either AVMIDIPlayerLoad or AVMIDIPlayerLoadURLs
*/
public handler fsMIDIPlayerPlay() returns optional any
if mPlayer is not nothing then
variable tStatus as Integer
put fluid_player_play(mPlayer) into tStatus
if tStatus is kFLUID_OK then
return true
else
return false
end if
end if
end handler
/**
Checks to see if MIDI Data is currently being played back
Example:
if fsMIDIPlayerStatus() is "playing" then fsMIDIPlayerStop
Description:
A boolean that indicates if MIDI Data is currently being played back.
*/
public handler fsMIDIPlayerStatus() returns optional any
variable tStatus as Integer