Debian Codegraph @

src/host-web/chuck_emscripten.h

raw symbols SCIP
1 //-----------------------------------------------------------------------------
2 // name: chuck_emscripten.h
3 // desc: emscripten binding agent for web assembly compilation
4 // e.g., used for WebChucK and Chunity web target
5 //
6 // author: Jack Atherton
7 // date: created 4/19/17
8 //-----------------------------------------------------------------------------
9 #pragma once
10
11 #include "chuck.h"
12 #include "emscripten.h"
13
14 // for Chunity
15 #define UNITY_INTERFACE EXPORT
16
17 // C linkage
18 extern "C"
19 {
20 // these functions return the new shred id, or 0 on failure
21 t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckCode( unsigned int chuckID, const char * code );
22 t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckCodeWithReplacementDac( unsigned int chuckID, const char * code, const char * replacement_dac );
23 t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFile( unsigned int chuckID, const char * filename );
24 t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithReplacementDac( unsigned int chuckID, const char * filename, const char * replacement_dac );
25 t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgs( unsigned int chuckID, const char * filename, const char * args );
26 t_CKUINT EMSCRIPTEN_KEEPALIVE runChuckFileWithArgsWithReplacementDac( unsigned int chuckID, const char * filename, const char * args, const char * replacement_dac );
27
28 // various replace
29 t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckCode( unsigned int chuckID, unsigned int shredID, const char * code );
30 t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckCodeWithReplacementDac( unsigned int chuckID, unsigned int shredID, const char * code, const char * replacement_dac );
31 t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckFile( unsigned int chuckID, unsigned int shredID, const char * filename );
32 t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckFileWithReplacementDac( unsigned int chuckID, unsigned int shredID, const char * filename, const char * replacement_dac );
33 t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckFileWithArgs( unsigned int chuckID, unsigned int shredID, const char * filename, const char * args );
34 t_CKUINT EMSCRIPTEN_KEEPALIVE replaceChuckFileWithArgsWithReplacementDac( unsigned int chuckID, unsigned int shredID, const char * filename, const char * args, const char * replacement_dac );
35
36 // shred operations
37 bool EMSCRIPTEN_KEEPALIVE isShredActive( unsigned int chuckID, unsigned int shredID );
38 bool EMSCRIPTEN_KEEPALIVE removeShred( unsigned int chuckID, unsigned int shredID );
39
40 // chuck globals: int
41 bool EMSCRIPTEN_KEEPALIVE setChuckInt( unsigned int chuckID, const char * name, t_CKINT val );
42 // NOTE: we don't use callbacks in JavaScript compilation because JS is non-preemptive,
43 // so we don't have to worry about our code getting interrupted
44 t_CKINT EMSCRIPTEN_KEEPALIVE getChuckInt( unsigned int chuckID, const char * name );
45
46 // chuck globals: float
47 bool EMSCRIPTEN_KEEPALIVE setChuckFloat( unsigned int chuckID, const char * name, t_CKFLOAT val );
48 t_CKFLOAT EMSCRIPTEN_KEEPALIVE getChuckFloat( unsigned int chuckID, const char * name );
49
50 // chuck globals: string
51 bool EMSCRIPTEN_KEEPALIVE setChuckString( unsigned int chuckID, const char * name, const char * val );
52 // TODO: still necessary to use callback for string, so we don't have to worry about garbage collection?
53 bool EMSCRIPTEN_KEEPALIVE getChuckString( unsigned int chuckID, const char * name, void (* callback)(const char *) );
54
55 // chuck globals: event
56 bool EMSCRIPTEN_KEEPALIVE signalChuckEvent( unsigned int chuckID, const char * name );
57 bool EMSCRIPTEN_KEEPALIVE broadcastChuckEvent( unsigned int chuckID, const char * name );
58 bool EMSCRIPTEN_KEEPALIVE listenForChuckEventOnce( unsigned int chuckID, const char * name, void (* callback)(void) );
59 bool EMSCRIPTEN_KEEPALIVE startListeningForChuckEvent( unsigned int chuckID, const char * name, void (* callback)(void) );
60 bool EMSCRIPTEN_KEEPALIVE stopListeningForChuckEvent( unsigned int chuckID, const char * name, void (* callback)(void) );
61
62 // get ugen samples
63 bool EMSCRIPTEN_KEEPALIVE getGlobalUGenSamples( unsigned int chuckID, const char * name, SAMPLE * buffer, int numSamples );
64
65 // int array methods
66 bool EMSCRIPTEN_KEEPALIVE setGlobalIntArray( unsigned int chuckID, const char * name, t_CKINT arrayValues[], unsigned int numValues );
67 // TODO: still necessary to use callback for arrays, so we don't have to worry about garbage collection?
68 bool EMSCRIPTEN_KEEPALIVE getGlobalIntArray( unsigned int chuckID, const char * name, void (* callback)(t_CKINT[], t_CKUINT));
69 bool EMSCRIPTEN_KEEPALIVE setGlobalIntArrayValue( unsigned int chuckID, const char * name, unsigned int index, t_CKINT value );
70 t_CKINT EMSCRIPTEN_KEEPALIVE getGlobalIntArrayValue( unsigned int chuckID, const char * name, unsigned int index );
71 bool EMSCRIPTEN_KEEPALIVE setGlobalAssociativeIntArrayValue( unsigned int chuckID, const char * name, char * key, t_CKINT value );
72 t_CKINT EMSCRIPTEN_KEEPALIVE getGlobalAssociativeIntArrayValue( unsigned int chuckID, const char * name, char * key );
73 // TODO: set entire dict, add to dict in batch; get entire dict
74
75 // float array methods
76 bool EMSCRIPTEN_KEEPALIVE setGlobalFloatArray( unsigned int chuckID, const char * name, t_CKFLOAT arrayValues[], unsigned int numValues );
77 // TODO: still necessary to use callback for arrays, so we don't have to worry about garbage collection?
78 bool EMSCRIPTEN_KEEPALIVE getGlobalFloatArray( unsigned int chuckID, const char * name, void (* callback)(t_CKFLOAT[], t_CKUINT));
79 bool EMSCRIPTEN_KEEPALIVE setGlobalFloatArrayValue( unsigned int chuckID, const char * name, unsigned int index, t_CKFLOAT value );
80 t_CKFLOAT EMSCRIPTEN_KEEPALIVE getGlobalFloatArrayValue( unsigned int chuckID, const char * name, unsigned int index );
81 bool EMSCRIPTEN_KEEPALIVE setGlobalAssociativeFloatArrayValue( unsigned int chuckID, const char * name, char * key, t_CKFLOAT value );
82 t_CKFLOAT EMSCRIPTEN_KEEPALIVE getGlobalAssociativeFloatArrayValue( unsigned int chuckID, const char * name, char * key );
83
84 // chuck instances and instancing
85 bool EMSCRIPTEN_KEEPALIVE initChuckInstance( unsigned int chuckID, unsigned int sampleRate, unsigned int inChannels, unsigned int outChannels );
86 bool EMSCRIPTEN_KEEPALIVE clearChuckInstance( unsigned int chuckID );
87 bool EMSCRIPTEN_KEEPALIVE clearGlobals( unsigned int chuckID );
88 bool EMSCRIPTEN_KEEPALIVE cleanupChuckInstance( unsigned int chuckID );
89 bool EMSCRIPTEN_KEEPALIVE chuckManualAudioCallback( unsigned int chuckID, float * inBuffer, float * outBuffer, unsigned int numFrames, unsigned int inChannels, unsigned int outChannels );
90 void EMSCRIPTEN_KEEPALIVE cleanRegisteredChucks();
91
92 // I/O
93 bool EMSCRIPTEN_KEEPALIVE setChoutCallback( unsigned int chuckID, void (* callback)(const char *) );
94 bool EMSCRIPTEN_KEEPALIVE setCherrCallback( unsigned int chuckID, void (* callback)(const char *) );
95 bool EMSCRIPTEN_KEEPALIVE setStdoutCallback( void (* callback)(const char *) );
96 bool EMSCRIPTEN_KEEPALIVE setStderrCallback( void (* callback)(const char *) );
97
98 // data
99 bool EMSCRIPTEN_KEEPALIVE setDataDir( const char * dir );
100
101 // log
102 bool EMSCRIPTEN_KEEPALIVE setLogLevel( unsigned int level );
103
104 // set param
105 bool EMSCRIPTEN_KEEPALIVE setParamInt( unsigned int chuckID, const char * key, t_CKINT val );
106 bool EMSCRIPTEN_KEEPALIVE setParamFloat( unsigned int chuckID, const char * key, t_CKFLOAT val );
107 bool EMSCRIPTEN_KEEPALIVE setParamString( unsigned int chuckID, const char * key, const char * val );
108 // get param
109 t_CKINT EMSCRIPTEN_KEEPALIVE getParamInt( unsigned int chuckID, const char * key );
110 t_CKFLOAT EMSCRIPTEN_KEEPALIVE getParamFloat( unsigned int chuckID, const char * key );
111 const char * EMSCRIPTEN_KEEPALIVE getParamString( unsigned int chuckID, const char * key );
112
113 // get chuck time
114 t_CKTIME EMSCRIPTEN_KEEPALIVE getChuckNow( unsigned int chuckID );
115
116 // runtime import API (TDB) | 1.5.3.5 (ge)
117 t_CKBOOL EMSCRIPTEN_KEEPALIVE importModule( unsigned int chuckID, const char * path );
118
119 } // extern "C"