Mercurial > hg > beaglert
comparison projects/basic_libpd/s_stuff.h @ 230:af211ee57867 mergingClockSync
Working basic_libpd
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sat, 09 Apr 2016 08:19:09 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
229:c768ed1055b0 | 230:af211ee57867 |
---|---|
1 /* Copyright (c) 1997-1999 Miller Puckette. | |
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL | |
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ | |
4 | |
5 /* Audio and MIDI I/O, and other scheduling and system stuff. */ | |
6 | |
7 /* NOTE: this file describes Pd implementation details which may change | |
8 in future releases. The public (stable) API is in m_pd.h. */ | |
9 | |
10 /* in s_path.c */ | |
11 | |
12 typedef struct _namelist /* element in a linked list of stored strings */ | |
13 { | |
14 struct _namelist *nl_next; /* next in list */ | |
15 char *nl_string; /* the string */ | |
16 } t_namelist; | |
17 | |
18 t_namelist *namelist_append(t_namelist *listwas, const char *s, int allowdup); | |
19 t_namelist *namelist_append_files(t_namelist *listwas, const char *s); | |
20 void namelist_free(t_namelist *listwas); | |
21 char *namelist_get(t_namelist *namelist, int n); | |
22 void sys_setextrapath(const char *p); | |
23 extern int sys_usestdpath; | |
24 extern t_namelist *sys_externlist; | |
25 extern t_namelist *sys_searchpath; | |
26 extern t_namelist *sys_helppath; | |
27 int sys_open_absolute(const char *name, const char* ext, | |
28 char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp); | |
29 int sys_trytoopenone(const char *dir, const char *name, const char* ext, | |
30 char *dirresult, char **nameresult, unsigned int size, int bin); | |
31 t_symbol *sys_decodedialog(t_symbol *s); | |
32 | |
33 /* s_file.c */ | |
34 | |
35 void sys_loadpreferences( void); | |
36 void sys_savepreferences( void); | |
37 extern int sys_defeatrt; | |
38 extern t_symbol *sys_flags; | |
39 | |
40 /* s_main.c */ | |
41 extern int sys_debuglevel; | |
42 extern int sys_verbose; | |
43 extern int sys_noloadbang; | |
44 extern int sys_nogui; | |
45 extern char *sys_guicmd; | |
46 | |
47 EXTERN int sys_nearestfontsize(int fontsize); | |
48 EXTERN int sys_hostfontsize(int fontsize); | |
49 | |
50 extern int sys_defaultfont; | |
51 EXTERN t_symbol *sys_libdir; /* library directory for auxilliary files */ | |
52 extern t_symbol *sys_guidir; /* directory holding pd_gui, u_pdsend, etc */ | |
53 | |
54 /* s_loader.c */ | |
55 | |
56 typedef int (*loader_t)(t_canvas *canvas, char *classname); /* callback type */ | |
57 EXTERN int sys_load_lib(t_canvas *canvas, char *filename); | |
58 EXTERN void sys_register_loader(loader_t loader); | |
59 | |
60 /* s_audio.c */ | |
61 | |
62 #define SENDDACS_NO 0 /* return values for sys_send_dacs() */ | |
63 #define SENDDACS_YES 1 | |
64 #define SENDDACS_SLEPT 2 | |
65 | |
66 #define DEFDACBLKSIZE 8 | |
67 extern int sys_schedblocksize; /* audio block size for scheduler */ | |
68 extern int sys_hipriority; /* real-time flag, true if priority boosted */ | |
69 EXTERN t_sample *sys_soundout; | |
70 EXTERN t_sample *sys_soundin; | |
71 extern int sys_inchannels; | |
72 extern int sys_outchannels; | |
73 extern int sys_advance_samples; /* scheduler advance in samples */ | |
74 extern int sys_blocksize; /* audio I/O block size in sample frames */ | |
75 extern t_float sys_dacsr; | |
76 extern int sys_schedadvance; | |
77 extern int sys_sleepgrain; | |
78 EXTERN void sys_set_audio_settings(int naudioindev, int *audioindev, | |
79 int nchindev, int *chindev, | |
80 int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev, | |
81 int srate, int advance, int callback, int blocksize); | |
82 /* the same as above, but reopens the audio subsystem if needed */ | |
83 EXTERN void sys_set_audio_settings_reopen(int naudioindev, int *audioindev, | |
84 int nchindev, int *chindev, | |
85 int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev, | |
86 int srate, int advance, int callback, int blocksize); | |
87 EXTERN void sys_reopen_audio( void); | |
88 EXTERN void sys_close_audio(void); | |
89 /* return true if the interface prefers always being open (ala jack) : */ | |
90 EXTERN int audio_shouldkeepopen( void); | |
91 EXTERN int audio_isopen( void); /* true if audio interface is open */ | |
92 EXTERN int sys_audiodevnametonumber(int output, const char *name); | |
93 EXTERN void sys_audiodevnumbertoname(int output, int devno, char *name, | |
94 int namesize); | |
95 | |
96 int sys_send_dacs(void); | |
97 void sys_reportidle(void); | |
98 void sys_set_priority(int higher); | |
99 void sys_audiobuf(int nbufs); | |
100 void sys_getmeters(t_sample *inmax, t_sample *outmax); | |
101 void sys_listdevs(void); | |
102 void sys_setblocksize(int n); | |
103 | |
104 EXTERN void sys_get_audio_devs(char *indevlist, int *nindevs, | |
105 char *outdevlist, int *noutdevs, int *canmulti, int *cancallback, | |
106 int maxndev, int devdescsize); | |
107 EXTERN void sys_get_audio_apis(char *buf); | |
108 | |
109 /* s_midi.c */ | |
110 #define MAXMIDIINDEV 16 /* max. number of input ports */ | |
111 #define MAXMIDIOUTDEV 16 /* max. number of output ports */ | |
112 extern int sys_midiapi; | |
113 extern int sys_nmidiin; | |
114 extern int sys_nmidiout; | |
115 extern int sys_midiindevlist[]; | |
116 extern int sys_midioutdevlist[]; | |
117 | |
118 EXTERN void sys_open_midi(int nmidiin, int *midiinvec, | |
119 int nmidiout, int *midioutvec, int enable); | |
120 | |
121 EXTERN void sys_get_midi_apis(char *buf); | |
122 EXTERN void sys_get_midi_devs(char *indevlist, int *nindevs, | |
123 char *outdevlist, int *noutdevs, | |
124 int maxndev, int devdescsize); | |
125 EXTERN void sys_get_midi_params(int *pnmidiindev, int *pmidiindev, | |
126 int *pnmidioutdev, int *pmidioutdev); | |
127 EXTERN int sys_mididevnametonumber(int output, const char *name); | |
128 EXTERN void sys_mididevnumbertoname(int output, int devno, char *name, | |
129 int namesize); | |
130 | |
131 EXTERN void sys_reopen_midi( void); | |
132 EXTERN void sys_close_midi( void); | |
133 EXTERN void sys_putmidimess(int portno, int a, int b, int c); | |
134 EXTERN void sys_putmidibyte(int portno, int a); | |
135 EXTERN void sys_poll_midi(void); | |
136 EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime); | |
137 EXTERN void sys_midibytein(int portno, int byte); | |
138 | |
139 /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */ | |
140 void midi_getdevs(char *indevlist, int *nindevs, | |
141 char *outdevlist, int *noutdevs, int maxndev, int devdescsize); | |
142 void sys_do_open_midi(int nmidiindev, int *midiindev, | |
143 int nmidioutdev, int *midioutdev); | |
144 | |
145 #ifdef USEAPI_ALSA | |
146 EXTERN void sys_alsa_putmidimess(int portno, int a, int b, int c); | |
147 EXTERN void sys_alsa_putmidibyte(int portno, int a); | |
148 EXTERN void sys_alsa_poll_midi(void); | |
149 EXTERN void sys_alsa_setmiditimediff(double inbuftime, double outbuftime); | |
150 EXTERN void sys_alsa_midibytein(int portno, int byte); | |
151 EXTERN void sys_alsa_close_midi( void); | |
152 | |
153 | |
154 /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */ | |
155 void midi_alsa_getdevs(char *indevlist, int *nindevs, | |
156 char *outdevlist, int *noutdevs, int maxndev, int devdescsize); | |
157 void sys_alsa_do_open_midi(int nmidiindev, int *midiindev, | |
158 int nmidioutdev, int *midioutdev); | |
159 #endif | |
160 | |
161 /* m_sched.c */ | |
162 EXTERN void sys_log_error(int type); | |
163 #define ERR_NOTHING 0 | |
164 #define ERR_ADCSLEPT 1 | |
165 #define ERR_DACSLEPT 2 | |
166 #define ERR_RESYNC 3 | |
167 #define ERR_DATALATE 4 | |
168 | |
169 #define SCHED_AUDIO_NONE 0 | |
170 #define SCHED_AUDIO_POLL 1 | |
171 #define SCHED_AUDIO_CALLBACK 2 | |
172 void sched_set_using_audio(int flag); | |
173 | |
174 /* s_inter.c */ | |
175 | |
176 EXTERN void sys_microsleep(int microsec); | |
177 EXTERN void sys_init_fdpoll(void); | |
178 | |
179 EXTERN void sys_bail(int exitcode); | |
180 EXTERN int sys_pollgui(void); | |
181 | |
182 EXTERN_STRUCT _socketreceiver; | |
183 #define t_socketreceiver struct _socketreceiver | |
184 | |
185 typedef void (*t_socketnotifier)(void *x, int n); | |
186 typedef void (*t_socketreceivefn)(void *x, t_binbuf *b); | |
187 | |
188 EXTERN t_socketreceiver *socketreceiver_new(void *owner, | |
189 t_socketnotifier notifier, t_socketreceivefn socketreceivefn, int udp); | |
190 EXTERN void socketreceiver_read(t_socketreceiver *x, int fd); | |
191 EXTERN void sys_sockerror(char *s); | |
192 EXTERN void sys_closesocket(int fd); | |
193 | |
194 typedef void (*t_fdpollfn)(void *ptr, int fd); | |
195 EXTERN void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr); | |
196 EXTERN void sys_rmpollfn(int fd); | |
197 #if defined(USEAPI_OSS) || defined(USEAPI_ALSA) | |
198 void sys_setalarm(int microsec); | |
199 #endif | |
200 | |
201 #define API_NONE 0 | |
202 #define API_ALSA 1 | |
203 #define API_OSS 2 | |
204 #define API_MMIO 3 | |
205 #define API_PORTAUDIO 4 | |
206 #define API_JACK 5 | |
207 #define API_SGI 6 /* gone */ | |
208 #define API_AUDIOUNIT 7 | |
209 #define API_ESD 8 /* no idea what this was, probably gone now */ | |
210 #define API_DUMMY 9 | |
211 | |
212 /* figure out which API should be the default. The one we judge most | |
213 likely to offer a working device takes precedence so that if you | |
214 start up Pd for the first time there's a reasonable chance you'll have | |
215 sound. (You'd think portaudio would be best but it seems to default | |
216 to jack on linux, and and on Windows we only use it for ASIO). | |
217 If nobody shows up, define DUMMY and make it the default.*/ | |
218 #if defined(USEAPI_MMIO) | |
219 # define API_DEFAULT API_MMIO | |
220 # define API_DEFSTRING "MMIO" | |
221 #elif defined(USEAPI_ALSA) | |
222 # define API_DEFAULT API_ALSA | |
223 # define API_DEFSTRING "ALSA" | |
224 #elif defined(USEAPI_OSS) | |
225 # define API_DEFAULT API_OSS | |
226 # define API_DEFSTRING "OSS" | |
227 #elif defined(USEAPI_AUDIOUNIT) | |
228 # define API_DEFAULT API_AUDIOUNIT | |
229 # define API_DEFSTRING "AudioUnit" | |
230 #elif defined(USEAPI_ESD) | |
231 # define API_DEFAULT API_ESD | |
232 # define API_DEFSTRING "ESD (?)" | |
233 #elif defined(USEAPI_PORTAUDIO) | |
234 # define API_DEFAULT API_PORTAUDIO | |
235 # define API_DEFSTRING "portaudio" | |
236 #elif defined(USEAPI_JACK) | |
237 # define API_DEFAULT API_JACK | |
238 # define API_DEFSTRING "Jack audio connection kit" | |
239 #else | |
240 # ifndef USEAPI_DUMMY /* we need at least one so bring in the dummy */ | |
241 # define USEAPI_DUMMY | |
242 # endif /* USEAPI_DUMMY */ | |
243 # define API_DEFAULT API_DUMMY | |
244 # define API_DEFSTRING "dummy audio" | |
245 #endif | |
246 | |
247 #define DEFAULTAUDIODEV 0 | |
248 | |
249 #define MAXAUDIOINDEV 4 | |
250 #define MAXAUDIOOUTDEV 4 | |
251 | |
252 #define DEFMIDIDEV 0 | |
253 | |
254 #define DEFAULTSRATE 44100 | |
255 #ifdef _WIN32 | |
256 #define DEFAULTADVANCE 80 | |
257 #else | |
258 #ifdef __APPLE__ | |
259 #define DEFAULTADVANCE 5 /* this is in addition to their own delay */ | |
260 #else | |
261 #define DEFAULTADVANCE 25 | |
262 #endif | |
263 #endif | |
264 | |
265 typedef void (*t_audiocallback)(void); | |
266 | |
267 int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin, | |
268 t_sample *soundout, int framesperbuf, int nbuffers, | |
269 int indeviceno, int outdeviceno, t_audiocallback callback); | |
270 void pa_close_audio(void); | |
271 int pa_send_dacs(void); | |
272 void sys_reportidle(void); | |
273 void pa_listdevs(void); | |
274 void pa_getdevs(char *indevlist, int *nindevs, | |
275 char *outdevlist, int *noutdevs, int *canmulti, | |
276 int maxndev, int devdescsize); | |
277 | |
278 int oss_open_audio(int naudioindev, int *audioindev, int nchindev, | |
279 int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, | |
280 int *choutdev, int rate, int blocksize); | |
281 void oss_close_audio(void); | |
282 int oss_send_dacs(void); | |
283 void oss_reportidle(void); | |
284 void oss_getdevs(char *indevlist, int *nindevs, | |
285 char *outdevlist, int *noutdevs, int *canmulti, | |
286 int maxndev, int devdescsize); | |
287 | |
288 int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, | |
289 int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, | |
290 int *choutdev, int rate, int blocksize); | |
291 void alsa_close_audio(void); | |
292 int alsa_send_dacs(void); | |
293 void alsa_reportidle(void); | |
294 void alsa_getdevs(char *indevlist, int *nindevs, | |
295 char *outdevlist, int *noutdevs, int *canmulti, | |
296 int maxndev, int devdescsize); | |
297 | |
298 int jack_open_audio(int wantinchans, int wantoutchans, int srate, | |
299 t_audiocallback callback); | |
300 void jack_close_audio(void); | |
301 int jack_send_dacs(void); | |
302 void jack_reportidle(void); | |
303 void jack_getdevs(char *indevlist, int *nindevs, | |
304 char *outdevlist, int *noutdevs, int *canmulti, | |
305 int maxndev, int devdescsize); | |
306 void jack_listdevs(void); | |
307 | |
308 int mmio_open_audio(int naudioindev, int *audioindev, | |
309 int nchindev, int *chindev, int naudiooutdev, int *audiooutdev, | |
310 int nchoutdev, int *choutdev, int rate, int blocksize); | |
311 void mmio_close_audio( void); | |
312 void mmio_reportidle(void); | |
313 int mmio_send_dacs(void); | |
314 void mmio_getdevs(char *indevlist, int *nindevs, | |
315 char *outdevlist, int *noutdevs, int *canmulti, | |
316 int maxndev, int devdescsize); | |
317 | |
318 int audiounit_open_audio(int naudioindev, int *audioindev, int nchindev, | |
319 int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, | |
320 int *choutdev, int rate); | |
321 void audiounit_close_audio(void); | |
322 int audiounit_send_dacs(void); | |
323 void audiounit_listdevs(void); | |
324 void audiounit_getdevs(char *indevlist, int *nindevs, | |
325 char *outdevlist, int *noutdevs, int *canmulti, | |
326 int maxndev, int devdescsize); | |
327 | |
328 int esd_open_audio(int naudioindev, int *audioindev, int nchindev, | |
329 int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, | |
330 int *choutdev, int rate); | |
331 void esd_close_audio(void); | |
332 int esd_send_dacs(void); | |
333 void esd_listdevs(void); | |
334 void esd_getdevs(char *indevlist, int *nindevs, | |
335 char *outdevlist, int *noutdevs, int *canmulti, | |
336 int maxndev, int devdescsize); | |
337 | |
338 int dummy_open_audio(int nin, int nout, int sr); | |
339 int dummy_close_audio( void); | |
340 int dummy_send_dacs( void); | |
341 void dummy_getdevs(char *indevlist, int *nindevs, char *outdevlist, | |
342 int *noutdevs, int *canmulti, int maxndev, int devdescsize); | |
343 void dummy_listdevs( void); | |
344 | |
345 void sys_listmididevs(void); | |
346 EXTERN void sys_set_midi_api(int whichapi); | |
347 EXTERN void sys_set_audio_api(int whichapi); | |
348 EXTERN int sys_audioapi; | |
349 EXTERN void sys_set_audio_state(int onoff); | |
350 | |
351 /* API dependent audio flags and settings */ | |
352 void oss_set32bit( void); | |
353 void linux_alsa_devname(char *devname); | |
354 | |
355 EXTERN void sys_get_audio_params( | |
356 int *pnaudioindev, int *paudioindev, int *chindev, | |
357 int *pnaudiooutdev, int *paudiooutdev, int *choutdev, | |
358 int *prate, int *padvance, int *callback, int *blocksize); | |
359 void sys_save_audio_params( | |
360 int naudioindev, int *audioindev, int *chindev, | |
361 int naudiooutdev, int *audiooutdev, int *choutdev, | |
362 int rate, int advance, int callback, int blocksize); | |
363 | |
364 /* s_file.c */ | |
365 | |
366 typedef void (*t_printhook)(const char *s); | |
367 extern t_printhook sys_printhook; /* set this to override printing */ | |
368 extern int sys_printtostderr; | |
369 | |
370 /* jsarlo { */ | |
371 | |
372 EXTERN double sys_time; | |
373 EXTERN double sys_time_per_dsp_tick; | |
374 EXTERN int sys_externalschedlib; | |
375 | |
376 EXTERN t_sample* get_sys_soundout(void ) ; | |
377 EXTERN t_sample* get_sys_soundin(void ) ; | |
378 EXTERN int* get_sys_main_advance(void ) ; | |
379 EXTERN double* get_sys_time_per_dsp_tick(void ) ; | |
380 EXTERN int* get_sys_schedblocksize(void ) ; | |
381 EXTERN double* get_sys_time(void ) ; | |
382 EXTERN t_float* get_sys_dacsr(void ) ; | |
383 EXTERN int* get_sys_sleepgrain(void ) ; | |
384 EXTERN int* get_sys_schedadvance(void ) ; | |
385 | |
386 EXTERN void sys_clearhist(void ); | |
387 EXTERN void sys_initmidiqueue(void ); | |
388 EXTERN int sys_addhist(int phase); | |
389 EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime); | |
390 EXTERN void sched_tick( void); | |
391 EXTERN void sys_pollmidiqueue(void ); | |
392 EXTERN int sys_pollgui(void ); | |
393 EXTERN void sys_setchsr(int chin, int chout, int sr); | |
394 | |
395 EXTERN void inmidi_realtimein(int portno, int cmd); | |
396 EXTERN void inmidi_byte(int portno, int byte); | |
397 EXTERN void inmidi_sysex(int portno, int byte); | |
398 EXTERN void inmidi_noteon(int portno, int channel, int pitch, int velo); | |
399 EXTERN void inmidi_controlchange(int portno, | |
400 int channel, | |
401 int ctlnumber, | |
402 int value); | |
403 EXTERN void inmidi_programchange(int portno, int channel, int value); | |
404 EXTERN void inmidi_pitchbend(int portno, int channel, int value); | |
405 EXTERN void inmidi_aftertouch(int portno, int channel, int value); | |
406 EXTERN void inmidi_polyaftertouch(int portno, | |
407 int channel, | |
408 int pitch, | |
409 int value); | |
410 /* } jsarlo */ | |
411 extern t_widgetbehavior text_widgetbehavior; |