-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsunvox.h
999 lines (912 loc) · 49.1 KB
/
sunvox.h
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
/*
SunVox Library (modular synthesizer)
Copyright (c) 2008 - 2023, Alexander Zolotov <nightradio@gmail.com>, WarmPlace.ru
*/
/*
Input defines (options):
SUNVOX_MAIN - for dynamic (shared) lib, adds implementation of sv_load_dll()/sv_unload_dll();
SUNVOX_STATIC_LIB - for static lib, tells the compiler that all functions should be included at build time;
*/
#ifndef __SUNVOX_H__
#define __SUNVOX_H__
#include <stdio.h>
#include <stdint.h>
/*
Constants, data types and macros
*/
#define NOTECMD_NOTE_OFF 128
#define NOTECMD_ALL_NOTES_OFF 129 /* send "note off" to all modules */
#define NOTECMD_CLEAN_SYNTHS 130 /* stop all modules - clear their internal buffers and put them into standby mode */
#define NOTECMD_STOP 131
#define NOTECMD_PLAY 132
#define NOTECMD_SET_PITCH 133 /* set the pitch specified in column XXYY, where 0x0000 - highest possible pitch, 0x7800 - lowest pitch (note C0); one semitone = 0x100 */
#define NOTECMD_PREV_TRACK 134 // apply effects to the previous track
#define NOTECMD_PATPLAY_OFF 135 // disable single pattern play mode (without STOP)
//=============== don't use these command from the pattern (jump_request variable must be used):
#define NOTECMD_PREPARE_FOR_IMMEDIATE_JUMP 136 // prepare for an immediate jump to line XXYY;
// use it ONLY before the NOTECMD_PLAY!
#define NOTECMD_JUMP 137 // jump to line XXYY
//===============
#define NOTECMD_CLEAN_MODULE 140 /* stop the module - clear its internal buffers and put it into standby mode */
typedef struct
{
uint8_t note; /* NN: 0 - nothing; 1..127 - note num; 128 - note off; 129, 130... - see NOTECMD_* defines */
uint8_t vel; /* VV: Velocity 1..129; 0 - default */
uint16_t module; /* MM: 0 - nothing; 1..65535 - module number + 1 */
uint16_t ctl; /* 0xCCEE: CC: 1..127 - controller number + 1; EE - effect */
uint16_t ctl_val; /* 0xXXYY: controller value or effect parameter */
} sunvox_note;
/* Flags for sv_init(): */
#define SV_INIT_FLAG_NO_DEBUG_OUTPUT ( 1 << 0 )
#define SV_INIT_FLAG_USER_AUDIO_CALLBACK ( 1 << 1 ) /* Offline mode: */
/* system-dependent audio stream will not be created; */
/* user calls sv_audio_callback() to get the next piece of sound stream */
#define SV_INIT_FLAG_OFFLINE ( 1 << 1 ) /* Same as SV_INIT_FLAG_USER_AUDIO_CALLBACK */
#define SV_INIT_FLAG_AUDIO_INT16 ( 1 << 2 ) /* Desired sample type of the output sound stream : int16_t */
#define SV_INIT_FLAG_AUDIO_FLOAT32 ( 1 << 3 ) /* Desired sample type of the output sound stream : float */
/* The actual sample type may be different, if SV_INIT_FLAG_USER_AUDIO_CALLBACK is not set */
#define SV_INIT_FLAG_ONE_THREAD ( 1 << 4 ) /* Audio callback and song modification are in single thread */
/* Use it with SV_INIT_FLAG_USER_AUDIO_CALLBACK only */
/* Flags for sv_get_time_map(): */
#define SV_TIME_MAP_SPEED 0
#define SV_TIME_MAP_FRAMECNT 1
/* Flags for sv_get_module_flags(): */
#define SV_MODULE_FLAG_EXISTS ( 1 << 0 )
#define SV_MODULE_FLAG_GENERATOR ( 1 << 1 ) /* Note input + Sound output */
#define SV_MODULE_FLAG_EFFECT ( 1 << 2 ) /* Sound input + Sound output */
#define SV_MODULE_FLAG_MUTE ( 1 << 3 )
#define SV_MODULE_FLAG_SOLO ( 1 << 4 )
#define SV_MODULE_FLAG_BYPASS ( 1 << 5 )
#define SV_MODULE_INPUTS_OFF 16
#define SV_MODULE_INPUTS_MASK ( 255 << SV_MODULE_INPUTS_OFF )
#define SV_MODULE_OUTPUTS_OFF ( 16 + 8 )
#define SV_MODULE_OUTPUTS_MASK ( 255 << SV_MODULE_OUTPUTS_OFF )
/*
Macros
*/
#define SV_GET_MODULE_XY( in_xy, out_x, out_y ) out_x = in_xy & 0xFFFF; if( out_x & 0x8000 ) out_x -= 0x10000; out_y = ( in_xy >> 16 ) & 0xFFFF; if( out_y & 0x8000 ) out_y -= 0x10000;
#define SV_GET_MODULE_FINETUNE( in_finetune, out_finetune, out_relative_note ) out_finetune = in_finetune & 0xFFFF; if( out_finetune & 0x8000 ) out_finetune -= 0x10000; out_relative_note = ( in_finetune >> 16 ) & 0xFFFF; if( out_relative_note & 0x8000 ) out_relative_note -= 0x10000;
#define SV_PITCH_TO_FREQUENCY( in_pitch ) ( pow( 2, ( 30720.0F - (in_pitch) ) / 3072.0F ) * 16.333984375 )
#define SV_FREQUENCY_TO_PITCH( in_freq ) ( 30720 - log2( (in_freq) / 16.333984375 ) * 3072 )
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) || defined(_WIN64)
#define OS_WIN
#define LIBNAME "sunvox.dll"
typedef LPCTSTR LIBNAME_STR_TYPE;
#else
typedef const char* LIBNAME_STR_TYPE;
#endif
#if defined(__APPLE__)
#include "TargetConditionals.h"
#ifdef TARGET_OS_MAC
#define OS_MACOS
#else
#define OS_IOS
#endif
#define OS_APPLE
#define LIBNAME "sunvox.dylib"
#endif
#if defined(__linux__) || defined(linux)
#define OS_LINUX
#define LIBNAME "./sunvox.so"
#endif
#if defined(OS_APPLE) || defined(OS_LINUX)
#define OS_UNIX
#endif
#ifdef OS_WIN
#ifdef __GNUC__
#define SUNVOX_FN_ATTR __attribute__((stdcall))
#else
#define SUNVOX_FN_ATTR __stdcall
#endif
#endif
#ifndef SUNVOX_FN_ATTR
#define SUNVOX_FN_ATTR /**/
#endif
#ifdef SUNVOX_STATIC_LIB
#ifdef __cplusplus
extern "C" {
#endif
/*
Functions
(use the functions with the label "USE LOCK/UNLOCK" within the sv_lock_slot() / sv_unlock_slot() block only!)
*/
/*
sv_init(), sv_deinit() - global sound system init/deinit
Parameters:
config - string with additional configuration in the following format: "option_name=value|option_name=value";
example: "buffer=1024|audiodriver=alsa|audiodevice=hw:0,0";
use NULL for automatic configuration;
freq - desired sample rate (Hz); min - 44100;
the actual rate may be different, if SV_INIT_FLAG_USER_AUDIO_CALLBACK is not set;
channels - only 2 supported now;
flags - mix of the SV_INIT_FLAG_xxx flags.
*/
int sv_init( const char* config, int freq, int channels, uint32_t flags ) SUNVOX_FN_ATTR;
int sv_deinit( void ) SUNVOX_FN_ATTR;
/*
sv_get_sample_rate() - get current sampling rate (it may differ from the frequency specified in sv_init())
*/
int sv_get_sample_rate( void ) SUNVOX_FN_ATTR;
/*
sv_update_input() -
handle input ON/OFF requests to enable/disable input ports of the sound card
(for example, after the Input module creation).
Call it from the main thread only, where the SunVox sound stream is not locked.
*/
int sv_update_input( void ) SUNVOX_FN_ATTR;
/*
sv_audio_callback() - get the next piece of SunVox audio from the Output module.
With sv_audio_callback() you can ignore the built-in SunVox sound output mechanism and use some other sound system.
SV_INIT_FLAG_USER_AUDIO_CALLBACK flag in sv_init() must be set.
Parameters:
buf - destination buffer of type int16_t (if SV_INIT_FLAG_AUDIO_INT16 used in sv_init())
or float (if SV_INIT_FLAG_AUDIO_FLOAT32 used in sv_init());
stereo data will be interleaved in this buffer: LRLR... (LR is a single frame (Left+Right));
frames - number of frames in destination buffer;
latency - audio latency (in frames);
out_time - buffer output time (in system ticks);
Return values: 0 - silence, the output buffer is filled with zeros; 1 - the output buffer is filled.
Example 1 (simplified, without accurate time sync) - suitable for most cases:
sv_audio_callback( buf, frames, 0, sv_get_ticks() );
Example 2 (accurate time sync) - when you need to maintain exact time intervals between incoming events (notes, commands, etc.):
user_out_time = ... ; //output time in user time space (depends on your own implementation)
user_cur_time = ... ; //current time in user time space
user_ticks_per_second = ... ; //ticks per second in user time space
user_latency = user_out_time - user_cur_time; //latency in user time space
uint32_t sunvox_latency = ( user_latency * sv_get_ticks_per_second() ) / user_ticks_per_second; //latency in system time space
uint32_t latency_frames = ( user_latency * sample_rate_Hz ) / user_ticks_per_second; //latency in frames
sv_audio_callback( buf, frames, latency_frames, sv_get_ticks() + sunvox_latency );
*/
int sv_audio_callback( void* buf, int frames, int latency, uint32_t out_time ) SUNVOX_FN_ATTR;
/*
sv_audio_callback2() - send some data to the Input module and receive the filtered data from the Output module.
It's the same as sv_audio_callback() but you also can specify the input buffer.
Parameters:
...
in_type - input buffer type: 0 - int16_t (16bit integer); 1 - float (32bit floating point);
in_channels - number of input channels;
in_buf - input buffer; stereo data must be interleaved in this buffer: LRLR... ; where the LR is the one frame (Left+Right channels);
*/
int sv_audio_callback2( void* buf, int frames, int latency, uint32_t out_time, int in_type, int in_channels, void* in_buf ) SUNVOX_FN_ATTR;
/*
sv_open_slot(), sv_close_slot(), sv_lock_slot(), sv_unlock_slot() -
open/close/lock/unlock sound slot for SunVox.
You can use several slots simultaneously (each slot with its own SunVox engine).
Use lock/unlock when you simultaneously read and modify SunVox data from different threads (for the same slot);
example:
thread 1: sv_lock_slot(0); sv_get_module_flags(0,mod1); sv_unlock_slot(0);
thread 2: sv_lock_slot(0); sv_remove_module(0,mod2); sv_unlock_slot(0);
Some functions (marked as "USE LOCK/UNLOCK") can't work without lock/unlock at all.
*/
int sv_open_slot( int slot ) SUNVOX_FN_ATTR;
int sv_close_slot( int slot ) SUNVOX_FN_ATTR;
int sv_lock_slot( int slot ) SUNVOX_FN_ATTR;
int sv_unlock_slot( int slot ) SUNVOX_FN_ATTR;
/*
sv_load(), sv_load_from_memory() -
load SunVox project from the file or from the memory block.
*/
int sv_load( int slot, const char* name ) SUNVOX_FN_ATTR;
int sv_load_from_memory( int slot, void* data, uint32_t data_size ) SUNVOX_FN_ATTR;
/*
sv_save() - save project to the file;
*/
int sv_save( int slot, const char* name ) SUNVOX_FN_ATTR;
/*
sv_play() - play from the current position;
sv_play_from_beginning() - play from the beginning (line 0);
sv_stop(): first call - stop playing; second call - reset all SunVox activity and switch the engine to standby mode;
sv_pause() - pause the audio stream on the specified slot;
sv_resume() - resume the audio stream on the specified slot;
sv_sync_resume() - wait for sync (pattern effect 0x33 on any slot) and resume the audio stream on the specified slot;
*/
int sv_play( int slot ) SUNVOX_FN_ATTR;
int sv_play_from_beginning( int slot ) SUNVOX_FN_ATTR;
int sv_stop( int slot ) SUNVOX_FN_ATTR;
int sv_pause( int slot ) SUNVOX_FN_ATTR;
int sv_resume( int slot ) SUNVOX_FN_ATTR;
int sv_sync_resume( int slot ) SUNVOX_FN_ATTR;
/*
sv_set_autostop(), sv_get_autostop() -
autostop values: 0 - disable autostop; 1 - enable autostop.
When autostop is OFF, the project plays endlessly in a loop.
*/
int sv_set_autostop( int slot, int autostop ) SUNVOX_FN_ATTR;
int sv_get_autostop( int slot ) SUNVOX_FN_ATTR;
/*
sv_end_of_song() return values: 0 - song is playing now; 1 - stopped.
*/
int sv_end_of_song( int slot ) SUNVOX_FN_ATTR;
/*
*/
int sv_rewind( int slot, int line_num ) SUNVOX_FN_ATTR;
/*
sv_volume() - set volume from 0 (min) to 256 (max 100%);
negative values are ignored;
return value: previous volume;
*/
int sv_volume( int slot, int vol ) SUNVOX_FN_ATTR;
/*
sv_set_event_t() - set the timestamp of events to be sent by sv_send_event()
Parameters:
slot;
set: 1 - set; 0 - reset (use automatic time setting - the default mode);
t: timestamp (in system ticks).
Examples:
sv_set_event_t( slot, 1, 0 ) //not specified - further events will be processed as quickly as possible
sv_set_event_t( slot, 1, sv_get_ticks() ) //time when the events will be processed = NOW + sound latancy * 2
*/
int sv_set_event_t( int slot, int set, int t ) SUNVOX_FN_ATTR;
/*
sv_send_event() - send an event (note ON, note OFF, controller change, etc.)
Parameters:
slot;
track_num - track number within the pattern;
note: 0 - nothing; 1..127 - note num; 128 - note off; 129, 130... - see NOTECMD_xxx defines;
vel: velocity 1..129; 0 - default;
module: 0 (empty) or module number + 1 (1..65535);
ctl: 0xCCEE. CC - number of a controller (1..255). EE - effect;
ctl_val: value of controller or effect.
*/
int sv_send_event( int slot, int track_num, int note, int vel, int module, int ctl, int ctl_val ) SUNVOX_FN_ATTR;
/*
*/
int sv_get_current_line( int slot ) SUNVOX_FN_ATTR; /* Get current line number */
int sv_get_current_line2( int slot ) SUNVOX_FN_ATTR; /* Get current line number in fixed point format 27.5 */
int sv_get_current_signal_level( int slot, int channel ) SUNVOX_FN_ATTR; /* From 0 to 255 */
/*
*/
const char* sv_get_song_name( int slot ) SUNVOX_FN_ATTR;
int sv_set_song_name( int slot, const char* name ) SUNVOX_FN_ATTR;
int sv_get_song_bpm( int slot ) SUNVOX_FN_ATTR;
int sv_get_song_tpl( int slot ) SUNVOX_FN_ATTR;
/*
sv_get_song_length_frames(), sv_get_song_length_lines() -
get the project length.
Frame is one discrete of the sound. Sample rate 44100 Hz means, that you hear 44100 frames per second.
*/
uint32_t sv_get_song_length_frames( int slot ) SUNVOX_FN_ATTR;
uint32_t sv_get_song_length_lines( int slot ) SUNVOX_FN_ATTR;
/*
sv_get_time_map()
Parameters:
slot;
start_line - first line to read (usually 0);
len - number of lines to read;
dest - pointer to the buffer (size = len*sizeof(uint32_t)) for storing the map values;
flags:
SV_TIME_MAP_SPEED: dest[X] = BPM | ( TPL << 16 ) (speed at the beginning of line X);
SV_TIME_MAP_FRAMECNT: dest[X] = frame counter at the beginning of line X;
Return value: 0 if successful, or negative value in case of some error.
*/
int sv_get_time_map( int slot, int start_line, int len, uint32_t* dest, int flags ) SUNVOX_FN_ATTR;
/*
sv_new_module() - create a new module;
sv_remove_module() - remove selected module;
sv_connect_module() - connect the source to the destination;
sv_disconnect_module() - disconnect the source from the destination;
*/
int sv_new_module( int slot, const char* type, const char* name, int x, int y, int z ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
int sv_remove_module( int slot, int mod_num ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
int sv_connect_module( int slot, int source, int destination ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
int sv_disconnect_module( int slot, int source, int destination ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
/*
sv_load_module() - load a module or sample; supported file formats: sunsynth, xi, wav, aiff, ogg, mp3, flac;
return value: new module number or negative value in case of some error;
sv_load_module_from_memory() - load a module or sample from the memory block;
*/
int sv_load_module( int slot, const char* file_name, int x, int y, int z ) SUNVOX_FN_ATTR;
int sv_load_module_from_memory( int slot, void* data, uint32_t data_size, int x, int y, int z ) SUNVOX_FN_ATTR;
/*
sv_sampler_load() - load a sample into the Sampler; to replace the whole sampler - set sample_slot to -1;
sv_sampler_load_from_memory() - load a sample from the memory block;
*/
int sv_sampler_load( int slot, int mod_num, const char* file_name, int sample_slot ) SUNVOX_FN_ATTR;
int sv_sampler_load_from_memory( int slot, int mod_num, void* data, uint32_t data_size, int sample_slot ) SUNVOX_FN_ATTR;
/*
sv_metamodule_load() - load a file into the MetaModule; supported file formats: sunvox, mod, xm, midi;
sv_vorbis_load() - load a file into the Vorbis Player; supported file formats: ogg;
*/
int sv_metamodule_load( int slot, int mod_num, const char* file_name ) SUNVOX_FN_ATTR;
int sv_metamodule_load_from_memory( int slot, int mod_num, void* data, uint32_t data_size ) SUNVOX_FN_ATTR;
int sv_vplayer_load( int slot, int mod_num, const char* file_name ) SUNVOX_FN_ATTR;
int sv_vplayer_load_from_memory( int slot, int mod_num, void* data, uint32_t data_size ) SUNVOX_FN_ATTR;
/*
sv_get_number_of_modules() - get the number of module slots (not the actual number of modules).
The slot can be empty or it can contain a module.
Here is the code to determine that the module slot X is not empty: ( sv_get_module_flags( slot, X ) & SV_MODULE_FLAG_EXISTS ) != 0;
*/
int sv_get_number_of_modules( int slot ) SUNVOX_FN_ATTR;
/*
sv_find_module() - find a module by name;
return value: module number or -1 (if not found);
*/
int sv_find_module( int slot, const char* name ) SUNVOX_FN_ATTR;
/*
*/
uint32_t sv_get_module_flags( int slot, int mod_num ) SUNVOX_FN_ATTR; /* SV_MODULE_FLAG_* */
/*
sv_get_module_inputs(), sv_get_module_outputs() -
get pointers to the int[] arrays with the input/output links.
Number of input links = ( module_flags & SV_MODULE_INPUTS_MASK ) >> SV_MODULE_INPUTS_OFF.
Number of output links = ( module_flags & SV_MODULE_OUTPUTS_MASK ) >> SV_MODULE_OUTPUTS_OFF.
(this is not the actual number of connections: some links may be empty (value = -1))
*/
int* sv_get_module_inputs( int slot, int mod_num ) SUNVOX_FN_ATTR;
int* sv_get_module_outputs( int slot, int mod_num ) SUNVOX_FN_ATTR;
/*
*/
const char* sv_get_module_type( int slot, int mod_num ) SUNVOX_FN_ATTR;
/*
*/
const char* sv_get_module_name( int slot, int mod_num ) SUNVOX_FN_ATTR;
int sv_set_module_name( int slot, int mod_num, const char* name ) SUNVOX_FN_ATTR;
/*
sv_get_module_xy() - get module XY coordinates packed in a single uint32 value:
( x & 0xFFFF ) | ( ( y & 0xFFFF ) << 16 )
Normal working area: 0x0 ... 1024x1024
Center: 512x512
Use SV_GET_MODULE_XY() macro to unpack X and Y.
*/
uint32_t sv_get_module_xy( int slot, int mod_num ) SUNVOX_FN_ATTR;
int sv_set_module_xy( int slot, int mod_num, int x, int y ) SUNVOX_FN_ATTR;
/*
sv_get_module_color()
sv_set_module_color()
get/set module color in the following format: 0xBBGGRR
*/
int sv_get_module_color( int slot, int mod_num ) SUNVOX_FN_ATTR;
int sv_set_module_color( int slot, int mod_num, int color ) SUNVOX_FN_ATTR;
/*
sv_get_module_finetune() - get the relative note and finetune of the module;
return value: ( finetune & 0xFFFF ) | ( ( relative_note & 0xFFFF ) << 16 ).
Use SV_GET_MODULE_FINETUNE() macro to unpack finetune and relative_note.
*/
uint32_t sv_get_module_finetune( int slot, int mod_num ) SUNVOX_FN_ATTR;
/*
sv_set_module_finetune() - change the finetune immediately;
sv_set_module_relnote() - change the relative note immediately;
*/
int sv_set_module_finetune( int slot, int mod_num, int finetune ) SUNVOX_FN_ATTR;
int sv_set_module_relnote( int slot, int mod_num, int relative_note ) SUNVOX_FN_ATTR;
/*
sv_get_module_scope2() return value = received number of samples (may be less or equal to samples_to_read).
Example:
int16_t buf[ 1024 ];
int received = sv_get_module_scope2( slot, mod_num, 0, buf, 1024 );
//buf[ 0 ] = value of the first sample (-32768...32767);
//buf[ 1 ] = value of the second sample;
//...
//buf[ received - 1 ] = value of the last received sample;
*/
uint32_t sv_get_module_scope2( int slot, int mod_num, int channel, int16_t* dest_buf, uint32_t samples_to_read ) SUNVOX_FN_ATTR;
/*
sv_module_curve() - access to the curve values of the specified module
Parameters:
slot;
mod_num - module number;
curve_num - curve number;
data - destination or source buffer;
len - number of items to read/write;
w - read (0) or write (1).
return value: number of items processed successfully.
Available curves (Y=CURVE[X]):
MultiSynth:
0 - X = note (0..127); Y = velocity (0..1); 128 items;
1 - X = velocity (0..256); Y = velocity (0..1); 257 items;
2 - X = note (0..127); Y = pitch (0..1); 128 items;
pitch range: 0 ... 16384/65535 (note0) ... 49152/65535 (note128) ... 1; semitone = 256/65535;
WaveShaper:
0 - X = input (0..255); Y = output (0..1); 256 items;
MultiCtl:
0 - X = input (0..256); Y = output (0..1); 257 items;
Analog Generator, Generator:
0 - X = drawn waveform sample number (0..31); Y = volume (-1..1); 32 items;
FMX:
0 - X = custom waveform sample number (0..255); Y = volume (-1..1); 256 items;
*/
int sv_module_curve( int slot, int mod_num, int curve_num, float* data, int len, int w ) SUNVOX_FN_ATTR;
/*
*/
int sv_get_number_of_module_ctls( int slot, int mod_num ) SUNVOX_FN_ATTR;
const char* sv_get_module_ctl_name( int slot, int mod_num, int ctl_num ) SUNVOX_FN_ATTR;
/*
sv_get_module_ctl_value() - get the value of the specified module controller
Parameters:
slot;
mod_num - module number;
ctl_num - controller number (from 0);
scaled - describes the type of the returned value:
0 - real value (0,1,2...) as it is stored inside the controller;
but the value displayed in the program interface may be different - you can use scaled=2 to get the displayed value;
1 - scaled (0x0000...0x8000) if the controller type = 0, or the real value if the controller type = 1 (enum);
this value can be used in the pattern column XXYY;
2 - final value displayed in the program interface -
in most cases it is identical to the real value (scaled=0), and sometimes it has an additional offset;
return value: value of the specified module controller.
*/
int sv_get_module_ctl_value( int slot, int mod_num, int ctl_num, int scaled ) SUNVOX_FN_ATTR;
/*
sv_set_module_ctl_value() - send the value to the specified module controller; (sv_send_event() will be used internally)
*/
int sv_set_module_ctl_value( int slot, int mod_num, int ctl_num, int val, int scaled ) SUNVOX_FN_ATTR;
/*
*/
int sv_get_module_ctl_min( int slot, int mod_num, int ctl_num, int scaled ) SUNVOX_FN_ATTR;
int sv_get_module_ctl_max( int slot, int mod_num, int ctl_num, int scaled ) SUNVOX_FN_ATTR;
int sv_get_module_ctl_offset( int slot, int mod_num, int ctl_num ) SUNVOX_FN_ATTR; /* Get display value offset */
int sv_get_module_ctl_type( int slot, int mod_num, int ctl_num ) SUNVOX_FN_ATTR; /* 0 - normal (scaled); 1 - selector (enum); */
int sv_get_module_ctl_group( int slot, int mod_num, int ctl_num ) SUNVOX_FN_ATTR;
/*
sv_new_pattern() - create a new pattern;
sv_remove_pattern() - remove selected pattern;
*/
int sv_new_pattern( int slot, int clone, int x, int y, int tracks, int lines, int icon_seed, const char* name ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
int sv_remove_pattern( int slot, int pat_num ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
/*
sv_get_number_of_patterns() - get the number of pattern slots (not the actual number of patterns).
The slot can be empty or it can contain a pattern.
Here is the code to determine that the pattern slot X is not empty: sv_get_pattern_lines( slot, X ) > 0;
*/
int sv_get_number_of_patterns( int slot ) SUNVOX_FN_ATTR;
/*
sv_find_pattern() - find a pattern by name;
return value: pattern number or -1 (if not found);
*/
int sv_find_pattern( int slot, const char* name ) SUNVOX_FN_ATTR;
/*
sv_get_pattern_x/y() - get pattern position;
return value:
x - line number (horizontal position on the timeline);
or
y - vertical position on the timeline;
*/
int sv_get_pattern_x( int slot, int pat_num ) SUNVOX_FN_ATTR;
int sv_get_pattern_y( int slot, int pat_num ) SUNVOX_FN_ATTR;
/*
sv_set_pattern_xy() - set pattern position;
Parameters:
x - line number (horizontal position on the timeline);
y - vertical position on the timeline;
*/
int sv_set_pattern_xy( int slot, int pat_num, int x, int y ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
/*
sv_get_pattern_tracks/lines() - get pattern size;
return value:
tracks - number of pattern tracks;
or
lines - number of pattern lines;
*/
int sv_get_pattern_tracks( int slot, int pat_num ) SUNVOX_FN_ATTR;
int sv_get_pattern_lines( int slot, int pat_num ) SUNVOX_FN_ATTR;
/*
*/
int sv_set_pattern_size( int slot, int pat_num, int tracks, int lines ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
/*
*/
const char* sv_get_pattern_name( int slot, int pat_num ) SUNVOX_FN_ATTR;
int sv_set_pattern_name( int slot, int pat_num, const char* name ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
/*
sv_get_pattern_data() - get the pattern buffer (for reading and writing)
containing notes (events) in the following order:
line 0: note for track 0, note for track 1, ... note for track X;
line 1: note for track 0, note for track 1, ... note for track X;
...
line X: ...
Example:
int pat_tracks = sv_get_pattern_tracks( slot, pat_num ); //number of tracks
sunvox_note* data = sv_get_pattern_data( slot, pat_num ); //get the buffer with all the pattern events (notes)
sunvox_note* n = &data[ line_number * pat_tracks + track_number ];
... and then do someting with note n ...
*/
sunvox_note* sv_get_pattern_data( int slot, int pat_num ) SUNVOX_FN_ATTR;
/*
sv_set_pattern_event() - write the pattern event to the cell at the specified line and track
nn,vv,mm,ccee,xxyy are the same as the fields of sunvox_note structure.
Only non-negative values will be written to the pattern.
Return value: 0 (sucess) or negative error code.
*/
int sv_set_pattern_event( int slot, int pat_num, int track, int line, int nn, int vv, int mm, int ccee, int xxyy ) SUNVOX_FN_ATTR;
/*
sv_get_pattern_event() - read a pattern event at the specified line and track
column (field number):
0 - note (NN);
1 - velocity (VV);
2 - module (MM);
3 - controller number or effect (CCEE);
4 - controller value or effect parameter (XXYY);
Return value: value of the specified field or negative error code.
*/
int sv_get_pattern_event( int slot, int pat_num, int track, int line, int column ) SUNVOX_FN_ATTR;
/*
sv_pattern_mute() - mute (1) / unmute (0) specified pattern;
negative values are ignored;
return value: previous state (1 - muted; 0 - unmuted) or -1 (error);
*/
int sv_pattern_mute( int slot, int pat_num, int mute ) SUNVOX_FN_ATTR; /* USE LOCK/UNLOCK! */
/*
SunVox engine uses system-provided time space, measured in system ticks (don't confuse it with the project ticks).
These ticks are required for parameters of functions such as sv_audio_callback() and sv_set_event_t().
Use sv_get_ticks() to get current tick counter (from 0 to 0xFFFFFFFF).
Use sv_get_ticks_per_second() to get the number of system ticks per second.
*/
uint32_t sv_get_ticks( void ) SUNVOX_FN_ATTR;
uint32_t sv_get_ticks_per_second( void ) SUNVOX_FN_ATTR;
/*
sv_get_log() - get the latest messages from the log
Parameters:
size - max number of bytes to read.
Return value: pointer to the null-terminated string with the latest log messages.
*/
const char* sv_get_log( int size ) SUNVOX_FN_ATTR;
#ifdef __cplusplus
} /* ...extern "C" */
#endif
/* ... SUNVOX_STATIC_LIB */
#else
/* DYNAMIC LIBRARY (DLL, SO, etc.) ... */
typedef int (SUNVOX_FN_ATTR *tsv_audio_callback)( void* buf, int frames, int latency, uint32_t out_time );
typedef int (SUNVOX_FN_ATTR *tsv_audio_callback2)( void* buf, int frames, int latency, uint32_t out_time, int in_type, int in_channels, void* in_buf );
typedef int (SUNVOX_FN_ATTR *tsv_open_slot)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_close_slot)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_lock_slot)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_unlock_slot)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_init)( const char* config, int freq, int channels, uint32_t flags );
typedef int (SUNVOX_FN_ATTR *tsv_deinit)( void );
typedef int (SUNVOX_FN_ATTR *tsv_get_sample_rate)( void );
typedef int (SUNVOX_FN_ATTR *tsv_update_input)( void );
typedef int (SUNVOX_FN_ATTR *tsv_load)( int slot, const char* name );
typedef int (SUNVOX_FN_ATTR *tsv_load_from_memory)( int slot, void* data, uint32_t data_size );
typedef int (SUNVOX_FN_ATTR *tsv_save)( int slot, const char* name );
typedef int (SUNVOX_FN_ATTR *tsv_play)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_play_from_beginning)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_stop)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_pause)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_resume)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_sync_resume)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_set_autostop)( int slot, int autostop );
typedef int (SUNVOX_FN_ATTR *tsv_get_autostop)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_end_of_song)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_rewind)( int slot, int t );
typedef int (SUNVOX_FN_ATTR *tsv_volume)( int slot, int vol );
typedef int (SUNVOX_FN_ATTR *tsv_set_event_t)( int slot, int set, int t );
typedef int (SUNVOX_FN_ATTR *tsv_send_event)( int slot, int track_num, int note, int vel, int module, int ctl, int ctl_val );
typedef int (SUNVOX_FN_ATTR *tsv_get_current_line)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_get_current_line2)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_get_current_signal_level)( int slot, int channel );
typedef const char* (SUNVOX_FN_ATTR *tsv_get_song_name)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_set_song_name)( int slot, const char* name );
typedef int (SUNVOX_FN_ATTR *tsv_get_song_bpm)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_get_song_tpl)( int slot );
typedef uint32_t (SUNVOX_FN_ATTR *tsv_get_song_length_frames)( int slot );
typedef uint32_t (SUNVOX_FN_ATTR *tsv_get_song_length_lines)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_get_time_map)( int slot, int start_line, int len, uint32_t* dest, int flags );
typedef int (SUNVOX_FN_ATTR *tsv_new_module)( int slot, const char* type, const char* name, int x, int y, int z );
typedef int (SUNVOX_FN_ATTR *tsv_remove_module)( int slot, int mod_num );
typedef int (SUNVOX_FN_ATTR *tsv_connect_module)( int slot, int source, int destination );
typedef int (SUNVOX_FN_ATTR *tsv_disconnect_module)( int slot, int source, int destination );
typedef int (SUNVOX_FN_ATTR *tsv_load_module)( int slot, const char* file_name, int x, int y, int z );
typedef int (SUNVOX_FN_ATTR *tsv_load_module_from_memory)( int slot, void* data, uint32_t data_size, int x, int y, int z );
typedef int (SUNVOX_FN_ATTR *tsv_sampler_load)( int slot, int mod_num, const char* file_name, int sample_slot );
typedef int (SUNVOX_FN_ATTR *tsv_sampler_load_from_memory)( int slot, int mod_num, void* data, uint32_t data_size, int sample_slot );
typedef int (SUNVOX_FN_ATTR *tsv_metamodule_load)( int slot, int mod_num, const char* file_name );
typedef int (SUNVOX_FN_ATTR *tsv_metamodule_load_from_memory)( int slot, int mod_num, void* data, uint32_t data_size );
typedef int (SUNVOX_FN_ATTR *tsv_vplayer_load)( int slot, int mod_num, const char* file_name );
typedef int (SUNVOX_FN_ATTR *tsv_vplayer_load_from_memory)( int slot, int mod_num, void* data, uint32_t data_size );
typedef int (SUNVOX_FN_ATTR *tsv_get_number_of_modules)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_find_module)( int slot, const char* name );
typedef uint32_t (SUNVOX_FN_ATTR *tsv_get_module_flags)( int slot, int mod_num );
typedef int* (SUNVOX_FN_ATTR *tsv_get_module_inputs)( int slot, int mod_num );
typedef int* (SUNVOX_FN_ATTR *tsv_get_module_outputs)( int slot, int mod_num );
typedef const char* (SUNVOX_FN_ATTR *tsv_get_module_type)( int slot, int mod_num );
typedef const char* (SUNVOX_FN_ATTR *tsv_get_module_name)( int slot, int mod_num );
typedef int (SUNVOX_FN_ATTR *tsv_set_module_name)( int slot, int mod_num, const char* name );
typedef uint32_t (SUNVOX_FN_ATTR *tsv_get_module_xy)( int slot, int mod_num );
typedef int (SUNVOX_FN_ATTR *tsv_set_module_xy)( int slot, int mod_num, int x, int y );
typedef int (SUNVOX_FN_ATTR *tsv_get_module_color)( int slot, int mod_num );
typedef int (SUNVOX_FN_ATTR *tsv_set_module_color)( int slot, int mod_num, int color );
typedef uint32_t (SUNVOX_FN_ATTR *tsv_get_module_finetune)( int slot, int mod_num );
typedef int (SUNVOX_FN_ATTR *tsv_set_module_finetune)( int slot, int mod_num, int finetune );
typedef int (SUNVOX_FN_ATTR *tsv_set_module_relnote)( int slot, int mod_num, int relative_note );
typedef uint32_t (SUNVOX_FN_ATTR *tsv_get_module_scope2)( int slot, int mod_num, int channel, int16_t* dest_buf, uint32_t samples_to_read );
typedef int (SUNVOX_FN_ATTR *tsv_module_curve)( int slot, int mod_num, int curve_num, float* data, int len, int w );
typedef int (SUNVOX_FN_ATTR *tsv_get_number_of_module_ctls)( int slot, int mod_num );
typedef const char* (SUNVOX_FN_ATTR *tsv_get_module_ctl_name)( int slot, int mod_num, int ctl_num );
typedef int (SUNVOX_FN_ATTR *tsv_get_module_ctl_value)( int slot, int mod_num, int ctl_num, int scaled );
typedef int (SUNVOX_FN_ATTR *tsv_set_module_ctl_value)( int slot, int mod_num, int ctl_num, int val, int scaled );
typedef int (SUNVOX_FN_ATTR *tsv_get_module_ctl_min)( int slot, int mod_num, int ctl_num, int scaled );
typedef int (SUNVOX_FN_ATTR *tsv_get_module_ctl_max)( int slot, int mod_num, int ctl_num, int scaled );
typedef int (SUNVOX_FN_ATTR *tsv_get_module_ctl_offset)( int slot, int mod_num, int ctl_num );
typedef int (SUNVOX_FN_ATTR *tsv_get_module_ctl_type)( int slot, int mod_num, int ctl_num );
typedef int (SUNVOX_FN_ATTR *tsv_get_module_ctl_group)( int slot, int mod_num, int ctl_num );
typedef int (SUNVOX_FN_ATTR *tsv_new_pattern)( int slot, int clone, int x, int y, int tracks, int lines, int icon_seed, const char* name );
typedef int (SUNVOX_FN_ATTR *tsv_remove_pattern)( int slot, int pat_num );
typedef int (SUNVOX_FN_ATTR *tsv_get_number_of_patterns)( int slot );
typedef int (SUNVOX_FN_ATTR *tsv_find_pattern)( int slot, const char* name );
typedef int (SUNVOX_FN_ATTR *tsv_get_pattern_x)( int slot, int pat_num );
typedef int (SUNVOX_FN_ATTR *tsv_get_pattern_y)( int slot, int pat_num );
typedef int (SUNVOX_FN_ATTR *tsv_set_pattern_xy)( int slot, int pat_num, int x, int y );
typedef int (SUNVOX_FN_ATTR *tsv_get_pattern_tracks)( int slot, int pat_num );
typedef int (SUNVOX_FN_ATTR *tsv_get_pattern_lines)( int slot, int pat_num );
typedef int (SUNVOX_FN_ATTR *tsv_set_pattern_size)( int slot, int pat_num, int tracks, int lines );
typedef const char* (SUNVOX_FN_ATTR *tsv_get_pattern_name)( int slot, int pat_num );
typedef int (SUNVOX_FN_ATTR *tsv_set_pattern_name)( int slot, int pat_num, const char* name );
typedef sunvox_note* (SUNVOX_FN_ATTR *tsv_get_pattern_data)( int slot, int pat_num );
typedef int (SUNVOX_FN_ATTR *tsv_set_pattern_event)( int slot, int pat_num, int track, int line, int nn, int vv, int mm, int ccee, int xxyy );
typedef int (SUNVOX_FN_ATTR *tsv_get_pattern_event)( int slot, int pat_num, int track, int line, int column );
typedef int (SUNVOX_FN_ATTR *tsv_pattern_mute)( int slot, int pat_num, int mute );
typedef uint32_t (SUNVOX_FN_ATTR *tsv_get_ticks)( void );
typedef uint32_t (SUNVOX_FN_ATTR *tsv_get_ticks_per_second)( void );
typedef const char* (SUNVOX_FN_ATTR *tsv_get_log)( int size );
#ifdef SUNVOX_MAIN
#define SV_FN_DECL
#define SV_FN_DECL2 =0
#else
#define SV_FN_DECL extern
#define SV_FN_DECL2
#endif
SV_FN_DECL tsv_audio_callback sv_audio_callback SV_FN_DECL2;
SV_FN_DECL tsv_audio_callback2 sv_audio_callback2 SV_FN_DECL2;
SV_FN_DECL tsv_open_slot sv_open_slot SV_FN_DECL2;
SV_FN_DECL tsv_close_slot sv_close_slot SV_FN_DECL2;
SV_FN_DECL tsv_lock_slot sv_lock_slot SV_FN_DECL2;
SV_FN_DECL tsv_unlock_slot sv_unlock_slot SV_FN_DECL2;
SV_FN_DECL tsv_init sv_init SV_FN_DECL2;
SV_FN_DECL tsv_deinit sv_deinit SV_FN_DECL2;
SV_FN_DECL tsv_get_sample_rate sv_get_sample_rate SV_FN_DECL2;
SV_FN_DECL tsv_update_input sv_update_input SV_FN_DECL2;
SV_FN_DECL tsv_load sv_load SV_FN_DECL2;
SV_FN_DECL tsv_load_from_memory sv_load_from_memory SV_FN_DECL2;
SV_FN_DECL tsv_save sv_save SV_FN_DECL2;
SV_FN_DECL tsv_play sv_play SV_FN_DECL2;
SV_FN_DECL tsv_play_from_beginning sv_play_from_beginning SV_FN_DECL2;
SV_FN_DECL tsv_stop sv_stop SV_FN_DECL2;
SV_FN_DECL tsv_pause sv_pause SV_FN_DECL2;
SV_FN_DECL tsv_resume sv_resume SV_FN_DECL2;
SV_FN_DECL tsv_sync_resume sv_sync_resume SV_FN_DECL2;
SV_FN_DECL tsv_set_autostop sv_set_autostop SV_FN_DECL2;
SV_FN_DECL tsv_get_autostop sv_get_autostop SV_FN_DECL2;
SV_FN_DECL tsv_end_of_song sv_end_of_song SV_FN_DECL2;
SV_FN_DECL tsv_rewind sv_rewind SV_FN_DECL2;
SV_FN_DECL tsv_volume sv_volume SV_FN_DECL2;
SV_FN_DECL tsv_set_event_t sv_set_event_t SV_FN_DECL2;
SV_FN_DECL tsv_send_event sv_send_event SV_FN_DECL2;
SV_FN_DECL tsv_get_current_line sv_get_current_line SV_FN_DECL2;
SV_FN_DECL tsv_get_current_line2 sv_get_current_line2 SV_FN_DECL2;
SV_FN_DECL tsv_get_current_signal_level sv_get_current_signal_level SV_FN_DECL2;
SV_FN_DECL tsv_get_song_name sv_get_song_name SV_FN_DECL2;
SV_FN_DECL tsv_set_song_name sv_set_song_name SV_FN_DECL2;
SV_FN_DECL tsv_get_song_bpm sv_get_song_bpm SV_FN_DECL2;
SV_FN_DECL tsv_get_song_tpl sv_get_song_tpl SV_FN_DECL2;
SV_FN_DECL tsv_get_song_length_frames sv_get_song_length_frames SV_FN_DECL2;
SV_FN_DECL tsv_get_song_length_lines sv_get_song_length_lines SV_FN_DECL2;
SV_FN_DECL tsv_get_time_map sv_get_time_map SV_FN_DECL2;
SV_FN_DECL tsv_new_module sv_new_module SV_FN_DECL2;
SV_FN_DECL tsv_remove_module sv_remove_module SV_FN_DECL2;
SV_FN_DECL tsv_connect_module sv_connect_module SV_FN_DECL2;
SV_FN_DECL tsv_disconnect_module sv_disconnect_module SV_FN_DECL2;
SV_FN_DECL tsv_load_module sv_load_module SV_FN_DECL2;
SV_FN_DECL tsv_load_module_from_memory sv_load_module_from_memory SV_FN_DECL2;
SV_FN_DECL tsv_sampler_load sv_sampler_load SV_FN_DECL2;
SV_FN_DECL tsv_sampler_load_from_memory sv_sampler_load_from_memory SV_FN_DECL2;
SV_FN_DECL tsv_metamodule_load sv_metamodule_load SV_FN_DECL2;
SV_FN_DECL tsv_metamodule_load_from_memory sv_metamodule_load_from_memory SV_FN_DECL2;
SV_FN_DECL tsv_vplayer_load sv_vplayer_load SV_FN_DECL2;
SV_FN_DECL tsv_vplayer_load_from_memory sv_vplayer_load_from_memory SV_FN_DECL2;
SV_FN_DECL tsv_get_number_of_modules sv_get_number_of_modules SV_FN_DECL2;
SV_FN_DECL tsv_find_module sv_find_module SV_FN_DECL2;
SV_FN_DECL tsv_get_module_flags sv_get_module_flags SV_FN_DECL2;
SV_FN_DECL tsv_get_module_inputs sv_get_module_inputs SV_FN_DECL2;
SV_FN_DECL tsv_get_module_outputs sv_get_module_outputs SV_FN_DECL2;
SV_FN_DECL tsv_get_module_type sv_get_module_type SV_FN_DECL2;
SV_FN_DECL tsv_get_module_name sv_get_module_name SV_FN_DECL2;
SV_FN_DECL tsv_set_module_name sv_set_module_name SV_FN_DECL2;
SV_FN_DECL tsv_get_module_xy sv_get_module_xy SV_FN_DECL2;
SV_FN_DECL tsv_set_module_xy sv_set_module_xy SV_FN_DECL2;
SV_FN_DECL tsv_get_module_color sv_get_module_color SV_FN_DECL2;
SV_FN_DECL tsv_set_module_color sv_set_module_color SV_FN_DECL2;
SV_FN_DECL tsv_get_module_finetune sv_get_module_finetune SV_FN_DECL2;
SV_FN_DECL tsv_set_module_finetune sv_set_module_finetune SV_FN_DECL2;
SV_FN_DECL tsv_set_module_relnote sv_set_module_relnote SV_FN_DECL2;
SV_FN_DECL tsv_get_module_scope2 sv_get_module_scope2 SV_FN_DECL2;
SV_FN_DECL tsv_module_curve sv_module_curve SV_FN_DECL2;
SV_FN_DECL tsv_get_number_of_module_ctls sv_get_number_of_module_ctls SV_FN_DECL2;
SV_FN_DECL tsv_get_module_ctl_name sv_get_module_ctl_name SV_FN_DECL2;
SV_FN_DECL tsv_get_module_ctl_value sv_get_module_ctl_value SV_FN_DECL2;
SV_FN_DECL tsv_set_module_ctl_value sv_set_module_ctl_value SV_FN_DECL2;
SV_FN_DECL tsv_get_module_ctl_min sv_get_module_ctl_min SV_FN_DECL2;
SV_FN_DECL tsv_get_module_ctl_max sv_get_module_ctl_max SV_FN_DECL2;
SV_FN_DECL tsv_get_module_ctl_offset sv_get_module_ctl_offset SV_FN_DECL2;
SV_FN_DECL tsv_get_module_ctl_type sv_get_module_ctl_type SV_FN_DECL2;
SV_FN_DECL tsv_get_module_ctl_group sv_get_module_ctl_group SV_FN_DECL2;
SV_FN_DECL tsv_new_pattern sv_new_pattern SV_FN_DECL2;
SV_FN_DECL tsv_remove_pattern sv_remove_pattern SV_FN_DECL2;
SV_FN_DECL tsv_get_number_of_patterns sv_get_number_of_patterns SV_FN_DECL2;
SV_FN_DECL tsv_find_pattern sv_find_pattern SV_FN_DECL2;
SV_FN_DECL tsv_get_pattern_x sv_get_pattern_x SV_FN_DECL2;
SV_FN_DECL tsv_get_pattern_y sv_get_pattern_y SV_FN_DECL2;
SV_FN_DECL tsv_set_pattern_xy sv_set_pattern_xy SV_FN_DECL2;
SV_FN_DECL tsv_get_pattern_tracks sv_get_pattern_tracks SV_FN_DECL2;
SV_FN_DECL tsv_get_pattern_lines sv_get_pattern_lines SV_FN_DECL2;
SV_FN_DECL tsv_set_pattern_size sv_set_pattern_size SV_FN_DECL2;
SV_FN_DECL tsv_get_pattern_name sv_get_pattern_name SV_FN_DECL2;
SV_FN_DECL tsv_set_pattern_name sv_set_pattern_name SV_FN_DECL2;
SV_FN_DECL tsv_get_pattern_data sv_get_pattern_data SV_FN_DECL2;
SV_FN_DECL tsv_set_pattern_event sv_set_pattern_event SV_FN_DECL2;
SV_FN_DECL tsv_get_pattern_event sv_get_pattern_event SV_FN_DECL2;
SV_FN_DECL tsv_pattern_mute sv_pattern_mute SV_FN_DECL2;
SV_FN_DECL tsv_get_ticks sv_get_ticks SV_FN_DECL2;
SV_FN_DECL tsv_get_ticks_per_second sv_get_ticks_per_second SV_FN_DECL2;
SV_FN_DECL tsv_get_log sv_get_log SV_FN_DECL2;
#ifdef SUNVOX_MAIN
#ifdef OS_WIN
#define IMPORT( Handle, Type, Function, Store ) \
{ \
Store = (Type)GetProcAddress( Handle, Function ); \
if( Store == 0 ) { fn_not_found = Function; break; } \
}
#define ERROR_MSG( msg ) MessageBoxA( 0, msg, "Error", MB_OK );
#endif
#ifdef OS_UNIX
#define IMPORT( Handle, Type, Function, Store ) \
{ \
Store = (Type)dlsym( Handle, Function ); \
if( Store == 0 ) { fn_not_found = Function; break; } \
}
#define ERROR_MSG( msg ) printf( "ERROR: %s\n", msg );
#endif
#ifdef OS_UNIX
void* g_sv_dll = NULL;
#endif
#ifdef OS_WIN
HMODULE g_sv_dll = NULL;
#endif
int sv_load_dll2( LIBNAME_STR_TYPE filename )
{
#ifdef OS_WIN
g_sv_dll = LoadLibrary( filename );
if( g_sv_dll == 0 )
{
printf( "LoadLibrary() error %d\n", GetLastError() );
ERROR_MSG( "can't load sunvox.dll" );
return -1;
}
#endif
#ifdef OS_UNIX
g_sv_dll = dlopen( filename, RTLD_NOW );
if( g_sv_dll == 0 )
{
printf( "%s\n", dlerror() );
return -1;
}
#endif
const char* fn_not_found = NULL;
while( 1 )
{
IMPORT( g_sv_dll, tsv_audio_callback, "sv_audio_callback", sv_audio_callback );
IMPORT( g_sv_dll, tsv_audio_callback2, "sv_audio_callback2", sv_audio_callback2 );
IMPORT( g_sv_dll, tsv_open_slot, "sv_open_slot", sv_open_slot );
IMPORT( g_sv_dll, tsv_close_slot, "sv_close_slot", sv_close_slot );
IMPORT( g_sv_dll, tsv_lock_slot, "sv_lock_slot", sv_lock_slot );
IMPORT( g_sv_dll, tsv_unlock_slot, "sv_unlock_slot", sv_unlock_slot );
IMPORT( g_sv_dll, tsv_init, "sv_init", sv_init );
IMPORT( g_sv_dll, tsv_deinit, "sv_deinit", sv_deinit );
IMPORT( g_sv_dll, tsv_get_sample_rate, "sv_get_sample_rate", sv_get_sample_rate );
IMPORT( g_sv_dll, tsv_update_input, "sv_update_input", sv_update_input );
IMPORT( g_sv_dll, tsv_load, "sv_load", sv_load );
IMPORT( g_sv_dll, tsv_load_from_memory, "sv_load_from_memory", sv_load_from_memory );
IMPORT( g_sv_dll, tsv_save, "sv_save", sv_save );
IMPORT( g_sv_dll, tsv_play, "sv_play", sv_play );
IMPORT( g_sv_dll, tsv_play_from_beginning, "sv_play_from_beginning", sv_play_from_beginning );
IMPORT( g_sv_dll, tsv_stop, "sv_stop", sv_stop );
IMPORT( g_sv_dll, tsv_pause, "sv_pause", sv_pause );
IMPORT( g_sv_dll, tsv_resume, "sv_resume", sv_resume );
IMPORT( g_sv_dll, tsv_sync_resume, "sv_sync_resume", sv_sync_resume );
IMPORT( g_sv_dll, tsv_set_autostop, "sv_set_autostop", sv_set_autostop );
IMPORT( g_sv_dll, tsv_get_autostop, "sv_get_autostop", sv_get_autostop );
IMPORT( g_sv_dll, tsv_end_of_song, "sv_end_of_song", sv_end_of_song );
IMPORT( g_sv_dll, tsv_rewind, "sv_rewind", sv_rewind );
IMPORT( g_sv_dll, tsv_volume, "sv_volume", sv_volume );
IMPORT( g_sv_dll, tsv_set_event_t, "sv_set_event_t", sv_set_event_t );
IMPORT( g_sv_dll, tsv_send_event, "sv_send_event", sv_send_event );
IMPORT( g_sv_dll, tsv_get_current_line, "sv_get_current_line", sv_get_current_line );
IMPORT( g_sv_dll, tsv_get_current_line2, "sv_get_current_line2", sv_get_current_line2 );
IMPORT( g_sv_dll, tsv_get_current_signal_level, "sv_get_current_signal_level", sv_get_current_signal_level );
IMPORT( g_sv_dll, tsv_get_song_name, "sv_get_song_name", sv_get_song_name );
IMPORT( g_sv_dll, tsv_set_song_name, "sv_set_song_name", sv_set_song_name );
IMPORT( g_sv_dll, tsv_get_song_bpm, "sv_get_song_bpm", sv_get_song_bpm );
IMPORT( g_sv_dll, tsv_get_song_tpl, "sv_get_song_tpl", sv_get_song_tpl );
IMPORT( g_sv_dll, tsv_get_song_length_frames, "sv_get_song_length_frames", sv_get_song_length_frames );
IMPORT( g_sv_dll, tsv_get_song_length_lines, "sv_get_song_length_lines", sv_get_song_length_lines );
IMPORT( g_sv_dll, tsv_get_time_map, "sv_get_time_map", sv_get_time_map );
IMPORT( g_sv_dll, tsv_new_module, "sv_new_module", sv_new_module );
IMPORT( g_sv_dll, tsv_remove_module, "sv_remove_module", sv_remove_module );
IMPORT( g_sv_dll, tsv_connect_module, "sv_connect_module", sv_connect_module );
IMPORT( g_sv_dll, tsv_disconnect_module, "sv_disconnect_module", sv_disconnect_module );
IMPORT( g_sv_dll, tsv_load_module, "sv_load_module", sv_load_module );
IMPORT( g_sv_dll, tsv_load_module_from_memory, "sv_load_module_from_memory", sv_load_module_from_memory );
IMPORT( g_sv_dll, tsv_sampler_load, "sv_sampler_load", sv_sampler_load );
IMPORT( g_sv_dll, tsv_sampler_load_from_memory, "sv_sampler_load_from_memory", sv_sampler_load_from_memory );
IMPORT( g_sv_dll, tsv_metamodule_load, "sv_metamodule_load", sv_metamodule_load );
IMPORT( g_sv_dll, tsv_metamodule_load_from_memory, "sv_metamodule_load_from_memory", sv_metamodule_load_from_memory );
IMPORT( g_sv_dll, tsv_vplayer_load, "sv_vplayer_load", sv_vplayer_load );
IMPORT( g_sv_dll, tsv_vplayer_load_from_memory, "sv_vplayer_load_from_memory", sv_vplayer_load_from_memory );
IMPORT( g_sv_dll, tsv_get_number_of_modules, "sv_get_number_of_modules", sv_get_number_of_modules );
IMPORT( g_sv_dll, tsv_find_module, "sv_find_module", sv_find_module );
IMPORT( g_sv_dll, tsv_get_module_flags, "sv_get_module_flags", sv_get_module_flags );
IMPORT( g_sv_dll, tsv_get_module_inputs, "sv_get_module_inputs", sv_get_module_inputs );
IMPORT( g_sv_dll, tsv_get_module_outputs, "sv_get_module_outputs", sv_get_module_outputs );
IMPORT( g_sv_dll, tsv_get_module_type, "sv_get_module_type", sv_get_module_type );
IMPORT( g_sv_dll, tsv_get_module_name, "sv_get_module_name", sv_get_module_name );
IMPORT( g_sv_dll, tsv_set_module_name, "sv_set_module_name", sv_set_module_name );
IMPORT( g_sv_dll, tsv_get_module_xy, "sv_get_module_xy", sv_get_module_xy );
IMPORT( g_sv_dll, tsv_set_module_xy, "sv_set_module_xy", sv_set_module_xy );
IMPORT( g_sv_dll, tsv_get_module_color, "sv_get_module_color", sv_get_module_color );
IMPORT( g_sv_dll, tsv_set_module_color, "sv_set_module_color", sv_set_module_color );
IMPORT( g_sv_dll, tsv_get_module_finetune, "sv_get_module_finetune", sv_get_module_finetune );
IMPORT( g_sv_dll, tsv_set_module_finetune, "sv_set_module_finetune", sv_set_module_finetune );
IMPORT( g_sv_dll, tsv_set_module_relnote, "sv_set_module_relnote", sv_set_module_relnote );
IMPORT( g_sv_dll, tsv_get_module_scope2, "sv_get_module_scope2", sv_get_module_scope2 );
IMPORT( g_sv_dll, tsv_module_curve, "sv_module_curve", sv_module_curve );
IMPORT( g_sv_dll, tsv_get_number_of_module_ctls, "sv_get_number_of_module_ctls", sv_get_number_of_module_ctls );
IMPORT( g_sv_dll, tsv_get_module_ctl_name, "sv_get_module_ctl_name", sv_get_module_ctl_name );
IMPORT( g_sv_dll, tsv_get_module_ctl_value, "sv_get_module_ctl_value", sv_get_module_ctl_value );
IMPORT( g_sv_dll, tsv_set_module_ctl_value, "sv_set_module_ctl_value", sv_set_module_ctl_value );
IMPORT( g_sv_dll, tsv_get_module_ctl_min, "sv_get_module_ctl_min", sv_get_module_ctl_min );
IMPORT( g_sv_dll, tsv_get_module_ctl_max, "sv_get_module_ctl_max", sv_get_module_ctl_max );
IMPORT( g_sv_dll, tsv_get_module_ctl_offset, "sv_get_module_ctl_offset", sv_get_module_ctl_offset );
IMPORT( g_sv_dll, tsv_get_module_ctl_type, "sv_get_module_ctl_type", sv_get_module_ctl_type );
IMPORT( g_sv_dll, tsv_get_module_ctl_group, "sv_get_module_ctl_group", sv_get_module_ctl_group );
IMPORT( g_sv_dll, tsv_new_pattern, "sv_new_pattern", sv_new_pattern );
IMPORT( g_sv_dll, tsv_remove_pattern, "sv_remove_pattern", sv_remove_pattern );
IMPORT( g_sv_dll, tsv_get_number_of_patterns, "sv_get_number_of_patterns", sv_get_number_of_patterns );
IMPORT( g_sv_dll, tsv_find_pattern, "sv_find_pattern", sv_find_pattern );
IMPORT( g_sv_dll, tsv_get_pattern_x, "sv_get_pattern_x", sv_get_pattern_x );
IMPORT( g_sv_dll, tsv_get_pattern_y, "sv_get_pattern_y", sv_get_pattern_y );
IMPORT( g_sv_dll, tsv_set_pattern_xy, "sv_set_pattern_xy", sv_set_pattern_xy );
IMPORT( g_sv_dll, tsv_get_pattern_tracks, "sv_get_pattern_tracks", sv_get_pattern_tracks );
IMPORT( g_sv_dll, tsv_get_pattern_lines, "sv_get_pattern_lines", sv_get_pattern_lines );
IMPORT( g_sv_dll, tsv_set_pattern_size, "sv_set_pattern_size", sv_set_pattern_size );
IMPORT( g_sv_dll, tsv_get_pattern_name, "sv_get_pattern_name", sv_get_pattern_name );
IMPORT( g_sv_dll, tsv_set_pattern_name, "sv_set_pattern_name", sv_set_pattern_name );
IMPORT( g_sv_dll, tsv_get_pattern_data, "sv_get_pattern_data", sv_get_pattern_data );
IMPORT( g_sv_dll, tsv_set_pattern_event, "sv_set_pattern_event", sv_set_pattern_event );
IMPORT( g_sv_dll, tsv_get_pattern_event, "sv_get_pattern_event", sv_get_pattern_event );
IMPORT( g_sv_dll, tsv_pattern_mute, "sv_pattern_mute", sv_pattern_mute );
IMPORT( g_sv_dll, tsv_get_ticks, "sv_get_ticks", sv_get_ticks );
IMPORT( g_sv_dll, tsv_get_ticks_per_second, "sv_get_ticks_per_second", sv_get_ticks_per_second );
IMPORT( g_sv_dll, tsv_get_log, "sv_get_log", sv_get_log );
break;
}
if( fn_not_found )
{
char ts[ 256 ];
sprintf( ts, "sunvox lib: %s() not found", fn_not_found );
ERROR_MSG( ts );
return -2;
}
return 0;
}
int sv_load_dll( void )
{
#ifdef OS_WIN
return sv_load_dll2( TEXT(LIBNAME) );
#else
return sv_load_dll2( LIBNAME );
#endif
return -1111;
}
int sv_unload_dll( void )
{
#ifdef OS_UNIX
if( g_sv_dll ) dlclose( g_sv_dll );
#endif
return 0;
}
#else /* ... SUNVOX_MAIN */
int sv_load_dll2( LIBNAME_STR_TYPE filename );
int sv_load_dll( void );
int sv_unload_dll( void );
#endif /* ... not SUNVOX_MAIN */
#endif /* ... DYNAMIC LIBRARY */
#endif