-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathminiAudicle.h
282 lines (230 loc) · 9.4 KB
/
miniAudicle.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
/*----------------------------------------------------------------------------
miniAudicle:
integrated developement environment for ChucK audio programming language
Copyright (c) 2005-2013 Spencer Salazar. All rights reserved.
http://chuck.cs.princeton.edu/
http://soundlab.cs.princeton.edu/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
U.S.A.
-----------------------------------------------------------------------------*/
//-----------------------------------------------------------------------------
// file: miniAudicle.h
// desc: platform-independent miniAudicle interface
//
// author: Spencer Salazar ([email protected])
// date: Autumn 2005
//-----------------------------------------------------------------------------
#ifndef __MINIAUDICLE_H__
#define __MINIAUDICLE_H__
#include "chuck_def.h"
#include "chuck_compile.h"
#include "chuck_type.h"
#include "util_thread.h"
#ifndef __CHIP_MODE__
#include "RtAudio/RtAudio.h"
#endif // __CHIP_MODE__
#include <map>
#include <string>
#include <vector>
#include <queue>
// forward reference
class ChucK;
struct miniAudicle_Code
{
std::string code_text;
std::string name;
t_CKUINT shred_id;
t_CKUINT shred_group_id;
t_CKBOOL running;
// void * syntax_highlighting;
};
struct miniAudicle_SyntaxHighlighting
{
t_CKUINT length;
t_CKBYTE r;
t_CKBYTE g;
t_CKBYTE b;
miniAudicle_SyntaxHighlighting * next;
};
typedef t_CKUINT t_DOCID;
enum t_OTF_RESULT
{
OTF_SUCCESS,
OTF_MINI_ERROR,
OTF_VM_ERROR,
OTF_COMPILE_ERROR,
OTF_VM_TIMEOUT,
OTF_UNDEFINED
};
// global event names | 1.5.4.4 (ge) added
// (for communicating with chuck scripts e.g., for recording)
#define MA_GLOBAL_EVENT_RECORDING "MINIAUDICLE_GLOBAL_EVENT_RECORDING"
//-----------------------------------------------------------------------------
// name: class miniAudicle
// desc: primary interface to miniAudicle systems
//-----------------------------------------------------------------------------
class miniAudicle
{
public:
miniAudicle();
~miniAudicle();
t_OTF_RESULT run_code( std::string & code, std::string & name,
std::vector< std::string > & args, std::string & filepath,
t_CKUINT docid, t_CKUINT & shred_id, std::string & out );
t_OTF_RESULT replace_code( std::string & code, std::string & name,
std::vector< std::string > & args, std::string & filepath,
t_CKUINT docid, t_CKUINT & shred_id,
std::string & out );
t_OTF_RESULT remove_code( t_CKUINT docid, t_CKUINT & shred_id,
std::string & out, const std::string & globalEventName = "" );
t_OTF_RESULT remove_shred( t_CKUINT docid, t_CKUINT shred_id, std::string & out );
t_OTF_RESULT removeall( t_CKUINT docid, std::string & out );
t_OTF_RESULT removelast( t_CKUINT docid, std::string & out );
t_OTF_RESULT clearvm( t_CKUINT docid, std::string & out );
t_OTF_RESULT status( Chuck_VM_Status * status);
t_OTF_RESULT handle_reply( t_CKUINT docid, std::string & out );
t_CKINT abort_current_shred();
struct _doc_otf_result { t_OTF_RESULT result; t_CKUINT shred_id; std::string output; t_CKINT line; };
t_CKBOOL process_reply();
t_CKBOOL get_last_result( t_CKUINT docid, t_OTF_RESULT * result,
std::string * out, t_CKINT * line_num );
t_CKBOOL get_last_result( t_CKUINT docid, _doc_otf_result * result );
t_CKUINT allocate_document_id();
void free_document_id( t_CKUINT docid );
t_CKUINT shred_count();
t_CKBOOL start_vm();
t_CKBOOL stop_vm();
t_CKBOOL is_on();
t_CKBOOL get_new_class_names( std::vector< std::string > & v);
t_CKBOOL highlight_line( std::string & line,
miniAudicle_SyntaxHighlighting * sh );
// probe audio devices | 1.5.0.1 (ge) added driver argument
// driver names subject to underlying system availability
// possible names include: "alsa", "pulse", "oss", "jack",
// "coreaudio", "directsound", "asio", "wasapi"
// see audio system (e.g., ChucKAudio.cpp) for more information
t_CKBOOL probe( const char * driver );
// get the ChucK instance | 1.5.0.6 (ge) added
// ChucK * chuck() { return m_chuck; }
#ifndef __CHIP_MODE__
const std::vector< RtAudio::DeviceInfo > & get_interfaces();
t_CKINT get_default_output_interface();
t_CKINT get_default_input_interface();
#endif // __CHIP_MODE__
void set_log_level( t_CKINT n );
t_CKINT get_log_level();
t_CKBOOL set_num_inputs( t_CKUINT num );
t_CKUINT get_num_inputs();
t_CKBOOL set_num_outputs( t_CKUINT num );
t_CKUINT get_num_outputs();
t_CKBOOL set_enable_audio( t_CKBOOL en );
t_CKBOOL get_enable_audio();
t_CKBOOL set_enable_network_thread( t_CKBOOL en );
t_CKBOOL get_enable_network_thread();
t_CKBOOL set_dac( t_CKUINT dac );
t_CKUINT get_dac();
t_CKBOOL set_adc( t_CKUINT adc );
t_CKUINT get_adc();
t_CKBOOL set_sample_rate( t_CKUINT srate );
t_CKUINT get_sample_rate();
t_CKBOOL set_buffer_size( t_CKUINT size );
t_CKUINT get_buffer_size();
t_CKBOOL set_blocking( t_CKBOOL block );
t_CKBOOL get_blocking();
t_CKBOOL set_enable_std_system( t_CKBOOL enable );
t_CKBOOL get_enable_std_system();
t_CKBOOL set_library_paths( std::list< std::string > & paths );
t_CKBOOL get_library_paths( std::list< std::string > & paths );
t_CKBOOL set_named_chugins( std::list< std::string > & chugins );
t_CKBOOL get_named_chugins( std::list< std::string > & chugins );
t_CKBOOL add_query_func(t_CKBOOL (*func)(Chuck_Env *));
// 1.5.0.1 (ge) added (see probe() above for more information)
t_CKBOOL set_driver( const char * driver );
// 1.5.0.6 (ge) set console column width, in # of characters
// this helps chuck snippet code when a line of code is too long for the console
void set_console_column_width_hint( t_CKUINT columnWidth );
// set the console callback function
void set_ck_console_callback(void (*callback)(const char *));
protected:
std::map< t_CKUINT, std::vector< t_CKUINT > * > documents; // maps documents to shreds
struct _doc_shred { t_CKUINT docid; std::vector< t_CKUINT >::size_type index; };
std::map< t_CKUINT, _doc_shred > shreds;
// maps shreds to documents and an index in the document's corresponding shred vector
// i.e. documents[shreds[shred_id].docid]->at( shreds[shred_id].index ) == shred_id
std::map< t_CKUINT, _doc_otf_result > last_result; // last error string for a given docid
std::queue< t_CKUINT > otf_docids; // FIFO of docids that correspond to pending OTF message replys
t_CKUINT vm_sleep_time; // length of time (microseconds) to sleep-wait for a vm reply
t_CKUINT vm_sleep_max; // max number of times to sleep-wait for a vm reply
t_CKUINT vm_status_timeouts;
t_CKUINT vm_status_timeouts_max;
t_CKUINT next_document_id;
t_CKBOOL vm_on;
CHUCK_THREAD vm_tid;
CHUCK_THREAD otf_tid;
ChucK * m_chuck;
Chuck_VM * vm;
Chuck_Compiler * compiler;
Chuck_VM_Status ** status_bufs;
size_t num_status_bufs;
size_t status_bufs_read, status_bufs_write;
#ifndef __CHIP_MODE__
std::vector< RtAudio::DeviceInfo > interfaces;
t_CKINT default_input;
t_CKINT default_output;
#endif // __CHIP_MODE__
void (*m_console_callback)(const char *);
std::map< std::string, t_CKINT > * class_names;
struct _vm_options
{
t_CKUINT dac;
t_CKUINT adc;
t_CKUINT srate;
t_CKUINT num_inputs;
t_CKUINT num_outputs;
t_CKUINT buffer_size;
t_CKUINT num_buffers;
t_CKBOOL enable_audio;
t_CKBOOL enable_network;
t_CKBOOL enable_block;
t_CKBOOL force_srate;
std::string driver;
std::list< std::string > library_paths;
std::list< std::string > named_chugins;
std::list< t_CKBOOL (*)(Chuck_Env *) > query_funcs;
} vm_options;
};
// quickly determine if the two vectors are equal
inline int compare_shred_vectors( const std::vector< Chuck_VM_Shred_Status * > & a,
const std::vector< Chuck_VM_Shred_Status * > & b )
{
std::vector< Chuck_VM_Shred_Status * >::size_type i,
lenA = a.size(), lenB = b.size();
if( lenA != lenB )
return 1;
if( lenA == 0 )
return 0;
Chuck_VM_Shred_Status * cvmssA, * cvmssB;
for( i = 0; i < lenA; i++ )
{
cvmssA = a[i];
cvmssB = b[i];
if( cvmssA->xid != cvmssB->xid ||
cvmssA->start != cvmssB->start )
/* a shred is uniquely defined by ( shred id, start time ) */
{
return 1;
}
}
return 0;
}
#endif // __MINIAUDICLE__H__