robert@464: /* Copyright (c) 1997-1999 Miller Puckette. robert@464: * For information on usage and redistribution, and for a DISCLAIMER OF ALL robert@464: * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ robert@464: robert@464: /* Audio and MIDI I/O, and other scheduling and system stuff. */ robert@464: robert@464: /* NOTE: this file describes Pd implementation details which may change robert@464: in future releases. The public (stable) API is in m_pd.h. */ robert@464: robert@464: /* in s_path.c */ robert@464: robert@464: typedef struct _namelist /* element in a linked list of stored strings */ robert@464: { robert@464: struct _namelist *nl_next; /* next in list */ robert@464: char *nl_string; /* the string */ robert@464: } t_namelist; robert@464: robert@464: t_namelist *namelist_append(t_namelist *listwas, const char *s, int allowdup); robert@464: t_namelist *namelist_append_files(t_namelist *listwas, const char *s); robert@464: void namelist_free(t_namelist *listwas); robert@464: char *namelist_get(t_namelist *namelist, int n); robert@464: void sys_setextrapath(const char *p); robert@464: extern int sys_usestdpath; robert@464: extern t_namelist *sys_externlist; robert@464: extern t_namelist *sys_searchpath; robert@464: extern t_namelist *sys_helppath; robert@464: int sys_open_absolute(const char *name, const char* ext, robert@464: char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp); robert@464: int sys_trytoopenone(const char *dir, const char *name, const char* ext, robert@464: char *dirresult, char **nameresult, unsigned int size, int bin); robert@464: t_symbol *sys_decodedialog(t_symbol *s); robert@464: robert@464: /* s_file.c */ robert@464: robert@464: void sys_loadpreferences( void); robert@464: void sys_savepreferences( void); robert@464: extern int sys_defeatrt; robert@464: extern t_symbol *sys_flags; robert@464: robert@464: /* s_main.c */ robert@464: extern int sys_debuglevel; robert@464: extern int sys_verbose; robert@464: extern int sys_noloadbang; robert@464: extern int sys_nogui; robert@464: extern char *sys_guicmd; robert@464: robert@464: EXTERN int sys_nearestfontsize(int fontsize); robert@464: EXTERN int sys_hostfontsize(int fontsize); robert@464: robert@464: extern int sys_defaultfont; robert@464: EXTERN t_symbol *sys_libdir; /* library directory for auxilliary files */ robert@464: extern t_symbol *sys_guidir; /* directory holding pd_gui, u_pdsend, etc */ robert@464: robert@464: /* s_loader.c */ robert@464: robert@464: typedef int (*loader_t)(t_canvas *canvas, char *classname); /* callback type */ robert@464: EXTERN int sys_load_lib(t_canvas *canvas, char *filename); robert@464: EXTERN void sys_register_loader(loader_t loader); robert@464: robert@464: /* s_audio.c */ robert@464: robert@464: #define SENDDACS_NO 0 /* return values for sys_send_dacs() */ robert@464: #define SENDDACS_YES 1 robert@464: #define SENDDACS_SLEPT 2 robert@464: robert@464: #define DEFDACBLKSIZE 8 robert@464: extern int sys_schedblocksize; /* audio block size for scheduler */ robert@464: extern int sys_hipriority; /* real-time flag, true if priority boosted */ robert@464: EXTERN t_sample *sys_soundout; robert@464: EXTERN t_sample *sys_soundin; robert@464: extern int sys_inchannels; robert@464: extern int sys_outchannels; robert@464: extern int sys_advance_samples; /* scheduler advance in samples */ robert@464: extern int sys_blocksize; /* audio I/O block size in sample frames */ robert@464: extern t_float sys_dacsr; robert@464: extern int sys_schedadvance; robert@464: extern int sys_sleepgrain; robert@464: EXTERN void sys_set_audio_settings(int naudioindev, int *audioindev, robert@464: int nchindev, int *chindev, robert@464: int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev, robert@464: int srate, int advance, int callback, int blocksize); robert@464: /* the same as above, but reopens the audio subsystem if needed */ robert@464: EXTERN void sys_set_audio_settings_reopen(int naudioindev, int *audioindev, robert@464: int nchindev, int *chindev, robert@464: int naudiooutdev, int *audiooutdev, int nchoutdev, int *choutdev, robert@464: int srate, int advance, int callback, int blocksize); robert@464: EXTERN void sys_reopen_audio( void); robert@464: EXTERN void sys_close_audio(void); robert@464: /* return true if the interface prefers always being open (ala jack) : */ robert@464: EXTERN int audio_shouldkeepopen( void); robert@464: EXTERN int audio_isopen( void); /* true if audio interface is open */ robert@464: EXTERN int sys_audiodevnametonumber(int output, const char *name); robert@464: EXTERN void sys_audiodevnumbertoname(int output, int devno, char *name, robert@464: int namesize); robert@464: robert@464: int sys_send_dacs(void); robert@464: void sys_reportidle(void); robert@464: void sys_set_priority(int higher); robert@464: void sys_audiobuf(int nbufs); robert@464: void sys_getmeters(t_sample *inmax, t_sample *outmax); robert@464: void sys_listdevs(void); robert@464: void sys_setblocksize(int n); robert@464: robert@464: EXTERN void sys_get_audio_devs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int *canmulti, int *cancallback, robert@464: int maxndev, int devdescsize); robert@464: EXTERN void sys_get_audio_apis(char *buf); robert@464: robert@464: /* s_midi.c */ robert@464: #define MAXMIDIINDEV 16 /* max. number of input ports */ robert@464: #define MAXMIDIOUTDEV 16 /* max. number of output ports */ robert@464: extern int sys_midiapi; robert@464: extern int sys_nmidiin; robert@464: extern int sys_nmidiout; robert@464: extern int sys_midiindevlist[]; robert@464: extern int sys_midioutdevlist[]; robert@464: robert@464: EXTERN void sys_open_midi(int nmidiin, int *midiinvec, robert@464: int nmidiout, int *midioutvec, int enable); robert@464: robert@464: EXTERN void sys_get_midi_apis(char *buf); robert@464: EXTERN void sys_get_midi_devs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, robert@464: int maxndev, int devdescsize); robert@464: EXTERN void sys_get_midi_params(int *pnmidiindev, int *pmidiindev, robert@464: int *pnmidioutdev, int *pmidioutdev); robert@464: EXTERN int sys_mididevnametonumber(int output, const char *name); robert@464: EXTERN void sys_mididevnumbertoname(int output, int devno, char *name, robert@464: int namesize); robert@464: robert@464: EXTERN void sys_reopen_midi( void); robert@464: EXTERN void sys_close_midi( void); robert@464: EXTERN void sys_putmidimess(int portno, int a, int b, int c); robert@464: EXTERN void sys_putmidibyte(int portno, int a); robert@464: EXTERN void sys_poll_midi(void); robert@464: EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime); robert@464: EXTERN void sys_midibytein(int portno, int byte); robert@464: robert@464: /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */ robert@464: void midi_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int maxndev, int devdescsize); robert@464: void sys_do_open_midi(int nmidiindev, int *midiindev, robert@464: int nmidioutdev, int *midioutdev); robert@464: robert@464: #ifdef USEAPI_ALSA robert@464: EXTERN void sys_alsa_putmidimess(int portno, int a, int b, int c); robert@464: EXTERN void sys_alsa_putmidibyte(int portno, int a); robert@464: EXTERN void sys_alsa_poll_midi(void); robert@464: EXTERN void sys_alsa_setmiditimediff(double inbuftime, double outbuftime); robert@464: EXTERN void sys_alsa_midibytein(int portno, int byte); robert@464: EXTERN void sys_alsa_close_midi( void); robert@464: robert@464: robert@464: /* implemented in the system dependent MIDI code (s_midi_pm.c, etc. ) */ robert@464: void midi_alsa_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int maxndev, int devdescsize); robert@464: void sys_alsa_do_open_midi(int nmidiindev, int *midiindev, robert@464: int nmidioutdev, int *midioutdev); robert@464: #endif robert@464: robert@464: /* m_sched.c */ robert@464: EXTERN void sys_log_error(int type); robert@464: #define ERR_NOTHING 0 robert@464: #define ERR_ADCSLEPT 1 robert@464: #define ERR_DACSLEPT 2 robert@464: #define ERR_RESYNC 3 robert@464: #define ERR_DATALATE 4 robert@464: robert@464: #define SCHED_AUDIO_NONE 0 robert@464: #define SCHED_AUDIO_POLL 1 robert@464: #define SCHED_AUDIO_CALLBACK 2 robert@464: void sched_set_using_audio(int flag); robert@464: robert@464: /* s_inter.c */ robert@464: robert@464: EXTERN void sys_microsleep(int microsec); robert@464: EXTERN void sys_init_fdpoll(void); robert@464: robert@464: EXTERN void sys_bail(int exitcode); robert@464: EXTERN int sys_pollgui(void); robert@464: robert@464: EXTERN_STRUCT _socketreceiver; robert@464: #define t_socketreceiver struct _socketreceiver robert@464: robert@464: typedef void (*t_socketnotifier)(void *x, int n); robert@464: typedef void (*t_socketreceivefn)(void *x, t_binbuf *b); robert@464: robert@464: EXTERN t_socketreceiver *socketreceiver_new(void *owner, robert@464: t_socketnotifier notifier, t_socketreceivefn socketreceivefn, int udp); robert@464: EXTERN void socketreceiver_read(t_socketreceiver *x, int fd); robert@464: EXTERN void sys_sockerror(char *s); robert@464: EXTERN void sys_closesocket(int fd); robert@464: robert@464: typedef void (*t_fdpollfn)(void *ptr, int fd); robert@464: EXTERN void sys_addpollfn(int fd, t_fdpollfn fn, void *ptr); robert@464: EXTERN void sys_rmpollfn(int fd); robert@464: #if defined(USEAPI_OSS) || defined(USEAPI_ALSA) robert@464: void sys_setalarm(int microsec); robert@464: #endif robert@464: robert@464: #define API_NONE 0 robert@464: #define API_ALSA 1 robert@464: #define API_OSS 2 robert@464: #define API_MMIO 3 robert@464: #define API_PORTAUDIO 4 robert@464: #define API_JACK 5 robert@464: #define API_SGI 6 /* gone */ robert@464: #define API_AUDIOUNIT 7 robert@464: #define API_ESD 8 /* no idea what this was, probably gone now */ robert@464: #define API_DUMMY 9 robert@464: robert@464: /* figure out which API should be the default. The one we judge most robert@464: likely to offer a working device takes precedence so that if you robert@464: start up Pd for the first time there's a reasonable chance you'll have robert@464: sound. (You'd think portaudio would be best but it seems to default robert@464: to jack on linux, and and on Windows we only use it for ASIO). robert@464: If nobody shows up, define DUMMY and make it the default.*/ robert@464: #if defined(USEAPI_MMIO) robert@464: # define API_DEFAULT API_MMIO robert@464: # define API_DEFSTRING "MMIO" robert@464: #elif defined(USEAPI_ALSA) robert@464: # define API_DEFAULT API_ALSA robert@464: # define API_DEFSTRING "ALSA" robert@464: #elif defined(USEAPI_OSS) robert@464: # define API_DEFAULT API_OSS robert@464: # define API_DEFSTRING "OSS" robert@464: #elif defined(USEAPI_AUDIOUNIT) robert@464: # define API_DEFAULT API_AUDIOUNIT robert@464: # define API_DEFSTRING "AudioUnit" robert@464: #elif defined(USEAPI_ESD) robert@464: # define API_DEFAULT API_ESD robert@464: # define API_DEFSTRING "ESD (?)" robert@464: #elif defined(USEAPI_PORTAUDIO) robert@464: # define API_DEFAULT API_PORTAUDIO robert@464: # define API_DEFSTRING "portaudio" robert@464: #elif defined(USEAPI_JACK) robert@464: # define API_DEFAULT API_JACK robert@464: # define API_DEFSTRING "Jack audio connection kit" robert@464: #else robert@464: # ifndef USEAPI_DUMMY /* we need at least one so bring in the dummy */ robert@464: # define USEAPI_DUMMY robert@464: # endif /* USEAPI_DUMMY */ robert@464: # define API_DEFAULT API_DUMMY robert@464: # define API_DEFSTRING "dummy audio" robert@464: #endif robert@464: robert@464: #define DEFAULTAUDIODEV 0 robert@464: robert@464: #define MAXAUDIOINDEV 4 robert@464: #define MAXAUDIOOUTDEV 4 robert@464: robert@464: #define DEFMIDIDEV 0 robert@464: robert@464: #define DEFAULTSRATE 44100 robert@464: #ifdef _WIN32 robert@464: #define DEFAULTADVANCE 80 robert@464: #else robert@464: #ifdef __APPLE__ robert@464: #define DEFAULTADVANCE 5 /* this is in addition to their own delay */ robert@464: #else robert@464: #define DEFAULTADVANCE 25 robert@464: #endif robert@464: #endif robert@464: robert@464: typedef void (*t_audiocallback)(void); robert@464: robert@464: int pa_open_audio(int inchans, int outchans, int rate, t_sample *soundin, robert@464: t_sample *soundout, int framesperbuf, int nbuffers, robert@464: int indeviceno, int outdeviceno, t_audiocallback callback); robert@464: void pa_close_audio(void); robert@464: int pa_send_dacs(void); robert@464: void sys_reportidle(void); robert@464: void pa_listdevs(void); robert@464: void pa_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int *canmulti, robert@464: int maxndev, int devdescsize); robert@464: robert@464: int oss_open_audio(int naudioindev, int *audioindev, int nchindev, robert@464: int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, robert@464: int *choutdev, int rate, int blocksize); robert@464: void oss_close_audio(void); robert@464: int oss_send_dacs(void); robert@464: void oss_reportidle(void); robert@464: void oss_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int *canmulti, robert@464: int maxndev, int devdescsize); robert@464: robert@464: int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, robert@464: int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, robert@464: int *choutdev, int rate, int blocksize); robert@464: void alsa_close_audio(void); robert@464: int alsa_send_dacs(void); robert@464: void alsa_reportidle(void); robert@464: void alsa_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int *canmulti, robert@464: int maxndev, int devdescsize); robert@464: robert@464: int jack_open_audio(int wantinchans, int wantoutchans, int srate, robert@464: t_audiocallback callback); robert@464: void jack_close_audio(void); robert@464: int jack_send_dacs(void); robert@464: void jack_reportidle(void); robert@464: void jack_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int *canmulti, robert@464: int maxndev, int devdescsize); robert@464: void jack_listdevs(void); robert@464: robert@464: int mmio_open_audio(int naudioindev, int *audioindev, robert@464: int nchindev, int *chindev, int naudiooutdev, int *audiooutdev, robert@464: int nchoutdev, int *choutdev, int rate, int blocksize); robert@464: void mmio_close_audio( void); robert@464: void mmio_reportidle(void); robert@464: int mmio_send_dacs(void); robert@464: void mmio_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int *canmulti, robert@464: int maxndev, int devdescsize); robert@464: robert@464: int audiounit_open_audio(int naudioindev, int *audioindev, int nchindev, robert@464: int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, robert@464: int *choutdev, int rate); robert@464: void audiounit_close_audio(void); robert@464: int audiounit_send_dacs(void); robert@464: void audiounit_listdevs(void); robert@464: void audiounit_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int *canmulti, robert@464: int maxndev, int devdescsize); robert@464: robert@464: int esd_open_audio(int naudioindev, int *audioindev, int nchindev, robert@464: int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, robert@464: int *choutdev, int rate); robert@464: void esd_close_audio(void); robert@464: int esd_send_dacs(void); robert@464: void esd_listdevs(void); robert@464: void esd_getdevs(char *indevlist, int *nindevs, robert@464: char *outdevlist, int *noutdevs, int *canmulti, robert@464: int maxndev, int devdescsize); robert@464: robert@464: int dummy_open_audio(int nin, int nout, int sr); robert@464: int dummy_close_audio( void); robert@464: int dummy_send_dacs( void); robert@464: void dummy_getdevs(char *indevlist, int *nindevs, char *outdevlist, robert@464: int *noutdevs, int *canmulti, int maxndev, int devdescsize); robert@464: void dummy_listdevs( void); robert@464: robert@464: void sys_listmididevs(void); robert@464: EXTERN void sys_set_midi_api(int whichapi); robert@464: EXTERN void sys_set_audio_api(int whichapi); robert@464: EXTERN int sys_audioapi; robert@464: EXTERN void sys_set_audio_state(int onoff); robert@464: robert@464: /* API dependent audio flags and settings */ robert@464: void oss_set32bit( void); robert@464: void linux_alsa_devname(char *devname); robert@464: robert@464: EXTERN void sys_get_audio_params( robert@464: int *pnaudioindev, int *paudioindev, int *chindev, robert@464: int *pnaudiooutdev, int *paudiooutdev, int *choutdev, robert@464: int *prate, int *padvance, int *callback, int *blocksize); robert@464: void sys_save_audio_params( robert@464: int naudioindev, int *audioindev, int *chindev, robert@464: int naudiooutdev, int *audiooutdev, int *choutdev, robert@464: int rate, int advance, int callback, int blocksize); robert@464: robert@464: /* s_file.c */ robert@464: robert@464: typedef void (*t_printhook)(const char *s); robert@464: extern t_printhook sys_printhook; /* set this to override printing */ robert@464: extern int sys_printtostderr; robert@464: robert@464: /* jsarlo { */ robert@464: robert@464: EXTERN double sys_time; robert@464: EXTERN double sys_time_per_dsp_tick; robert@464: EXTERN int sys_externalschedlib; robert@464: robert@464: EXTERN t_sample* get_sys_soundout(void ) ; robert@464: EXTERN t_sample* get_sys_soundin(void ) ; robert@464: EXTERN int* get_sys_main_advance(void ) ; robert@464: EXTERN double* get_sys_time_per_dsp_tick(void ) ; robert@464: EXTERN int* get_sys_schedblocksize(void ) ; robert@464: EXTERN double* get_sys_time(void ) ; robert@464: EXTERN t_float* get_sys_dacsr(void ) ; robert@464: EXTERN int* get_sys_sleepgrain(void ) ; robert@464: EXTERN int* get_sys_schedadvance(void ) ; robert@464: robert@464: EXTERN void sys_clearhist(void ); robert@464: EXTERN void sys_initmidiqueue(void ); robert@464: EXTERN int sys_addhist(int phase); robert@464: EXTERN void sys_setmiditimediff(double inbuftime, double outbuftime); robert@464: EXTERN void sched_tick( void); robert@464: EXTERN void sys_pollmidiqueue(void ); robert@464: EXTERN int sys_pollgui(void ); robert@464: EXTERN void sys_setchsr(int chin, int chout, int sr); robert@464: robert@464: EXTERN void inmidi_realtimein(int portno, int cmd); robert@464: EXTERN void inmidi_byte(int portno, int byte); robert@464: EXTERN void inmidi_sysex(int portno, int byte); robert@464: EXTERN void inmidi_noteon(int portno, int channel, int pitch, int velo); robert@464: EXTERN void inmidi_controlchange(int portno, robert@464: int channel, robert@464: int ctlnumber, robert@464: int value); robert@464: EXTERN void inmidi_programchange(int portno, int channel, int value); robert@464: EXTERN void inmidi_pitchbend(int portno, int channel, int value); robert@464: EXTERN void inmidi_aftertouch(int portno, int channel, int value); robert@464: EXTERN void inmidi_polyaftertouch(int portno, robert@464: int channel, robert@464: int pitch, robert@464: int value); robert@464: /* } jsarlo */ robert@464: extern t_widgetbehavior text_widgetbehavior;