home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / SOUNDUTILS / mm1_tracker.lzh / TRACKER4.6 / extern.h < prev    next >
Text File  |  1994-11-24  |  15KB  |  502 lines

  1. /* extern.h 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: extern.h,v 4.4 1994/11/15 16:11:01 espie Exp espie $
  6.  * $Log: extern.h,v $
  7.  * Revision 4.4  1994/11/15  16:11:01  espie
  8.  * *** empty log message ***
  9.  *
  10.  *
  11.  * Revision 4.1  1994/02/04  14:54:08  espie
  12.  * Fixed up ansi C stupid bug.
  13.  * Lots of new proto for all functions.
  14.  * Generalized open.c.
  15.  * Comments.
  16.  * Added checkbrk.
  17.  * General cleanup.
  18.  * Suppressed some unused code.
  19.  * Better portability.
  20.  * Removed init_display.
  21.  * No more reentrency problems with INIT_ONCE.
  22.  * Protos for ui: notice, info, scroller, pattern display.
  23.  * Mostly working.
  24.  * Just dies with a guru.
  25.  * Plus timing problems at start.
  26.  * New prototypes.
  27.  * Initial revision
  28.  *
  29.  * Revision 3.15  1993/12/04  16:12:50  espie
  30.  * Amiga support.
  31.  * Added bg/fg test.
  32.  * stty_sane.
  33.  * New audio functions.
  34.  * Simplified delay_pattern.
  35.  * Protracker commands.
  36.  * New release.
  37.  *
  38.  * Revision 2.19  1992/11/17  17:06:25  espie
  39.  * Lots of new functions to account for new interface.
  40.  * open_file support.
  41.  * Separated mix/stereo stuff.
  42.  * Added possibility to get back to MONO for the sgi.
  43.  * Added stereo capabilities to the indigo version.
  44.  * Added some new song types to automatize the choice process.
  45.  * Moved resampling to audio, added prototype.
  46.  * Added SAMPLE_FAULT, for trying to play
  47.  * a note without a sample (not really an error).
  48.  *
  49.  * Revision 1.7  1991/11/08  14:25:55  espie
  50.  * Modified audio prototype so that you can change
  51.  * frequency.
  52.  * Added prototype for release_song.
  53.  * Added arpeggio effect.
  54.  * Added entries for new effects.
  55.  * Added entries for commands.c.
  56.  */
  57.  
  58.  
  59.  
  60. /* audio.c */
  61. #define ACCURACY 12
  62. #define fix_to_int(x) ((x) >> ACCURACY)
  63. #define int_to_fix(x) ((x) << ACCURACY)
  64. #define fractional_part(x) ((x) & (total_step - 1))
  65. #define total_step     (1 << ACCURACY)
  66.  
  67.  
  68. /* release_audio_channels:
  69.  * free every audio channel previously allocated
  70.  */
  71. XT void release_audio_channels P((void));
  72.  
  73. /* chan = new_channel_tag_list(prop):
  74.  * allocates a new channel for the current song
  75.  * No properties are currently defined.
  76.  */
  77. XT struct audio_channel *new_channel_tag_list P((struct tag *prop));
  78.  
  79. /* init_tables(oversample, frequency):
  80.  * precomputes the step_table and the pitch_table
  81.  * according to the desired oversample and frequency.
  82.  * This is static, you can call it again whenever you want.
  83.  * Adjust the currently used audio channels if needed.
  84.  */
  85. XT void init_tables P((int oversample, int frequency));
  86.  
  87. /* resample(oversample, number):
  88.  * send number samples out computed according
  89.  * to the current state of channels
  90.  * and oversample.
  91.  */
  92. XT void resample P((int oversample, int number));
  93.  
  94. /* play_note(au, samp, pitch)
  95.  * set audio channel au to play samp at pitch
  96.  */
  97. XT void play_note P((struct audio_channel *au, struct sample_info *samp, \
  98. int pitch));
  99.  
  100. /* set_play_pitch(au, pitch):
  101.  * set channel au to play at pitch pitch
  102.  */
  103. XT void set_play_pitch P((struct audio_channel *au, int pitch));
  104.  
  105. /* set_play_volume(au, volume):
  106.  * set channel au to play at volume volume
  107.  */
  108. XT void set_play_volume P((struct audio_channel *au, int volume));
  109.  
  110. /* set_play_position(au, pos):
  111.  * set position in sample for channel au at given offset
  112.  */
  113. XT void set_play_position P((struct audio_channel *au, int pos));
  114.  
  115.  
  116. /* automaton.c */
  117. /* init_automaton(a, song, start):
  118.  * put the automaton a in the right state to play song from pattern start.
  119.  */
  120. XT void init_automaton P((struct automaton *a, struct song *song, int start));
  121.  
  122. /* next_tick(a):
  123.  * set up everything for the next tick.
  124.  */
  125. XT void next_tick P((struct automaton *a));
  126.  
  127.  
  128. /* commands.c */
  129. /* init_effects(): sets up all data for the effects */
  130. /* (not set up as auto_init due to huge overhead) */
  131. XT void init_effects P((void (*table[])()));
  132.  
  133. /* do_nothing: this is the default behavior for an effect.
  134.  */
  135. XT void do_nothing P((struct channel *ch));
  136.  
  137.  
  138. /* dump_song.c */
  139. /* dump_song(s): 
  140.  * displays some information pertinent to the given 
  141.  * song s.
  142.  */
  143. XT void dump_song P((struct song *song));
  144.  
  145.  
  146. /* display.c */
  147.  
  148. /* dump_event(ch, e): dump event e as occuring on channel ch
  149.  */
  150. XT void dump_event P((struct channel *ch, struct event *e));
  151.  
  152.  
  153. /* main.c */
  154.  
  155. #define OLD 0
  156. #define NEW 1
  157. /* special new type: for when we try to read it as both types.
  158.  */
  159. #define BOTH 2
  160. /* special type: does not check the signature */
  161. #define NEW_NO_CHECK 3
  162.  
  163.  
  164. /* error types. Everything is centralized,
  165.  * and we check in some places (see st_read, player and main)
  166.  * that there was no error. Additionnally signal traps work
  167.  * that way too.
  168.  */
  169.  
  170. /* normal state */
  171. #define NONE 0  
  172. /* read error */
  173. #define FILE_TOO_SHORT 1
  174. #define CORRUPT_FILE 2
  175. /* trap error: goto next song right now */
  176. #define NEXT_SONG 3
  177. /* run time problem */
  178. #define FAULT 4
  179. /* the song has ended */
  180. #define ENDED 5
  181. /* unrecoverable problem: typically, trying to 
  182.  * jump to nowhere land.
  183.  */
  184. #define UNRECOVERABLE 6
  185. /* Missing sample. Very common error, not too serious. */
  186. #define SAMPLE_FAULT 7
  187. /* New */
  188. #define PREVIOUS_SONG 8
  189. #define OUT_OF_MEM 9
  190. XT int error;
  191.  
  192. /* notes.c */
  193. #define NUMBER_NOTES 120
  194. #define NUMBER_FINETUNES 17
  195. XT short pitch_table[NUMBER_NOTES][NUMBER_FINETUNES];    /* 120 * 17 = big ! */
  196.  
  197. /* note = find_note(pitch):
  198.  * find note corresponding to a given pitch. 
  199.  */
  200. XT int find_note P((int pitch));
  201.  
  202. /* oldtranspose = transpose_song(song, newtranspose):
  203.  * tranpose song to a new pitch
  204.  */
  205. XT int transpose_song P((struct song *song, int newtranspose));
  206.  
  207. /* name = name_of_note(note):
  208.  * name of the note. Warning! This name is only valid
  209.  * until a new call to name_of_note.
  210.  */
  211. XT char *name_of_note P((int note));
  212.  
  213.  
  214.  
  215.  
  216.  
  217. /* open.c */
  218. /* handle = open_file(filename, mode, path):
  219.  * transparently open a compressed file.
  220.  */
  221. XT struct exfile *open_file P((char *fname, char *fmode, char *path));
  222.  
  223. /* handle = file_handle(f):
  224.  * obtain the actual FILE handle from the private structure
  225.  */
  226. XT FILE *file_handle P((struct exfile *f));
  227.  
  228. /* close_file(handle):
  229.  * close a file that was opened with open_file.
  230.  */
  231. XT void close_file P((struct exfile *file));
  232.  
  233. XT int getc_file P((struct exfile *file));
  234. XT int tell_file P((struct exfile *file));
  235.  
  236.  
  237.  
  238.  
  239. /* player.c */
  240.  
  241. /* reset_note(ch, note, pitch):
  242.  * set channel ch to play note at pitch pitch
  243.  */
  244. XT void reset_note P((struct channel *ch, int note, int pitch));
  245.  
  246. /* set_current_pitch(ch, pitch):
  247.  * set ch to play at pitch pitch
  248.  */
  249. XT void set_current_pitch P((struct channel *ch, int pitch));
  250.  
  251. /* set_current_volume(ch, volume):
  252.  * set channel ch to play at volume volume
  253.  */
  254. XT void set_current_volume P((struct channel *ch, int volume));
  255.  
  256. /* set_position(ch, pos):
  257.  * set position in sample for current channel at given offset
  258.  */
  259. XT void set_position P((struct channel *ch, int pos));
  260.  
  261. /* init_player(oversample, frequency):
  262.  * sets up the player for a given oversample and
  263.  * output frequency.
  264.  * Note: we can call init_player again to change oversample and
  265.  * frequency.
  266.  */
  267. XT void init_player P((int o, int f));
  268.  
  269. /* play_song(song, start):
  270.  * play the song.
  271.  */
  272. XT struct tag *play_song P((struct song *song, int start));
  273. /* returns tags as shown further down in get_ui */
  274.  
  275.  
  276.  
  277. /* st_read.c */
  278. /* s = read_song(f, type):
  279.  * tries to read f as a song of type NEW/OLD.
  280.  * returns NULL (and an error) if it doesn't work.
  281.  * Returns a dynamic song structure if successful.
  282.  */
  283. XT struct song *read_song P((struct exfile *f, int type));
  284.  
  285. /* release_song(s):
  286.  * release all the memory song occupies.
  287.  */
  288. XT void release_song P((struct song *song));
  289.  
  290.  
  291.  
  292. /* setup_audio.c */
  293. /* setup_audio(ask_freq, stereo, oversample):
  294.  * setup the audio output with these values 
  295.  */
  296. XT void setup_audio P((int f, int s, int o));
  297. /* do_close_audio():
  298.  * close audio only if needed
  299.  */
  300. XT void do_close_audio P((void));
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308. /* xxx_audio.c */
  309. /* frequency = open_audio(f, s):
  310.  * try to open audio with a sampling rate of f, and eventually stereo.
  311.  * We get the real frequency back. If we ask for 0, we
  312.  * get the ``preferred'' frequency.
  313.  * Note: we have to close_audio() before we can open_audio() again.
  314.  * Note: even if we don't ask for stereo, we still have to give a
  315.  * right and left sample.
  316.  */
  317. XT int open_audio P((int f, int s));
  318. /* close_audio():
  319.  * returns the audio to the system control, doing necessary
  320.  * cleanup
  321.  */
  322. XT void close_audio P((void));
  323. /* set_mix(percent): set mix channels level.
  324.  * 0: spatial stereo. 100: mono.
  325.  */
  326. XT void set_mix P((int percent));
  327.  
  328. /* output_samples(l, r): outputs a pair of stereo samples.
  329.  * Samples are 15 bits signed.
  330.  */
  331. XT void output_samples P((int left, int right));
  332.  
  333. /* flush_buffer(): call from time to time, because buffering
  334.  * is done by the program to get better (?) performance.
  335.  */
  336. XT void flush_buffer P((void));
  337.  
  338. /* discard_buffer(): try to get rid of the buffer contents
  339.  */
  340. XT void discard_buffer P((void));
  341.  
  342. /* new_freq = update_frequency():
  343.  * if !0, frequency changed and playing should be updated accordingly
  344.  */
  345. XT int update_frequency P((void));
  346.  
  347. /* set_synchro(boolean):
  348.  * try to synchronize audio output by using a smaller buffer
  349.  */
  350. XT void set_synchro P((int s));
  351.  
  352. #ifdef SPECIAL_SAMPLE_MEMORY
  353. XT GENERIC alloc_sample P((int len));
  354. XT void free_sample P((GENERIC s));
  355. XT int obtain_sample P((GENERIC start, int l, FILE *f));
  356.  
  357. #else
  358. #define alloc_sample(len)        calloc(len, 1)
  359. #define free_sample(sample)        free(sample)
  360. #define obtain_sample(start, l, f)    fread(start, 1, l, f)
  361. #endif
  362.  
  363.  
  364.  
  365. /* tools.c */
  366. /* v = read_env(name, default):
  367.  * read a scalar value in the environment
  368.  */
  369. XT int read_env P((char *name, int def));
  370.  
  371.  
  372.  
  373.  
  374. /* autoinit.c */
  375. /* used for decentralizing initialization/termination of various
  376.  * system routines
  377.  */
  378.  
  379. /* end_all(s): the program must exit now, after displaying s to the user, usually 
  380.  * through notice and calling all stacked at_end() functions. s may be 0 for normal
  381.  * exit. DO NOT use exit() anywhere in tracker but end_all() instead.
  382.  */
  383. XT void end_all P((char *s));
  384.  
  385. /* at_end(cleanup): stack cleanup to be called at program's termination
  386.  */
  387. XT void at_end P((void (*cleanup)(void)));
  388.  
  389. /* INIT_ONCE: macro for autoinitialization of routines.
  390.  * modules that need an init routine should LOCAL void INIT = init_routine,
  391.  * and add INIT_ONCE; at EVERY possible first entry point for their routine.
  392.  * (I mean every, don't try to second-guess me !)
  393.  */
  394. #define INIT_ONCE        if (INIT)    {void (*func)P((void)) = INIT; INIT = 0; (*func)();}
  395.  
  396.  
  397. /* $(UI)/ui.c */
  398. /* see unix/ui.c for the general unix implementation.
  399.  * The old may_getchar() has been replaced by the tag-based
  400.  * get_ui
  401.  */
  402. /* get_ui(): returns an array of tags that reflect the current user-interface
  403.  * actions. Unknown tags WILL be ignored.
  404.  * Note that get_ui will be called about once every tick, providing a poor man's
  405.  * timer to the interface writer if needed to code multiple actions on the same
  406.  * user-input. See unix/termio.c for a good example.
  407.  * see amiga/ui.c for the correct way to do it when you have a real timer.
  408.  *
  409.  * VERY IMPORTANT: who do the tags belong to ?
  410.  *    as a general rule, result (and their values) MUST only be considered
  411.  *    valid between two calls to get_ui ! Be careful to call get_ui ONLY at
  412.  *    reasonable places.
  413.  *    One exception: structures that are dynamically allocated (like UI_LOAD_SONG
  414.  *    values) will ONLY get freed when you ask for it !
  415.  */
  416. XT struct tag *get_ui P((void));
  417. #define BASE_UI 10
  418. #define UI_NEXT_SONG    (BASE_UI)            /* load next song */
  419. #define UI_PREVIOUS_SONG (BASE_UI + 1)    /* load previous song */
  420. #define UI_LOAD_SONG (BASE_UI + 2)        /* load song. Name as value */
  421. #define UI_SET_BPM (BASE_UI + 3)          /* set beat per minute to value */
  422. #define UI_JUMP_TO_PATTERN (BASE_UI + 4)  /* jump to pattern #value. Use display_pattern to
  423.                                            * keep in sync with the player
  424.                                            */
  425. #define UI_RESTART (BASE_UI + 5)          /* restart current song. Not quite jump to 0 */
  426. #define UI_QUIT (BASE_UI + 6)             /* need I say more ? */
  427. #define UI_DISPLAY (BASE_UI + 7)          /* status of scrolling window: true or false */
  428.  
  429.  
  430. /* player.c translates the get_ui() tags in a standard way.
  431.  * Actually it doesn't translate anything right now...
  432.  */
  433. #define BASE_PLAY 20
  434. #define PLAY_NEXT_SONG UI_NEXT_SONG
  435. #define PLAY_PREVIOUS_SONG UI_PREVIOUS_SONG
  436. #define PLAY_LOAD_SONG UI_LOAD_SONG
  437.  
  438. #define PLAY_ERROR BASE_PLAY
  439.  
  440. /* Most of these functions are information display function.
  441.  * A correct implementation should heed run_in_fg() if needed
  442.  */
  443.  
  444. /* notice(s): important message for the user (terminal error maybe).
  445.  * take extra pain to make it apparent even if run in background
  446.  */
  447. XT void notice P((char *s));
  448.  
  449. /* status(s): some indication of the system current status... 
  450.  * Used for fleeing error messages too. 
  451.  * s = 0 is valid and indicates return to the default status.
  452.  */
  453. XT void status P((char *s));
  454.  
  455. /* begin_info: open a logical information window.
  456.  * returns 0 if the window couldn't be opened.
  457.  * A NULL window shouldn't be used, but don't count on it !
  458.  */
  459. XT GENERIC begin_info P((char *title));
  460. /* info(handle, line): add a line to the info window,
  461.  * completing the current line if applicable
  462.  */
  463. XT void info P((GENERIC handle, char *line));
  464. /* infos(handle, line): add to the current line of the info window
  465.  */
  466. XT void infos P((GENERIC handle, char *s));
  467. /* end_info(handle): this window is complete...
  468.  */
  469. XT void end_info P((GENERIC handle));
  470.  
  471. /* Scrolling score display:
  472.  * new_scroll() returns a writable buffer of 4*14-1 characters in
  473.  * which the program (usually display.c) will write what it wills.
  474.  * It can return 0 if not applicable.
  475.  */
  476. XT char *new_scroll P((void));
  477.  
  478. /* scroll: returns this scrolling line to the program. Note that
  479.  * scroll doesn't take any argument, and implies calls to new_scroll/scroll
  480.  * are paired. After a call to scroll, the last pointer returned by new_scroll
  481.  * should be considered invalid !
  482.  */
  483. XT void scroll P((void));
  484.  
  485. /* display_pattern(current, total, real): we are at current/total(real) 
  486.  * in the current song
  487.  * may be used as a poor man's timer.
  488.  */
  489. XT void display_pattern P((int current, int total, int real));
  490.  
  491. /* song_title(s): the current song title is s.
  492.  * ui implementors: Don't count on this pointer remaining valid AFTER the call,
  493.  * make a copy if needed
  494.  */
  495. XT void song_title P((char *s));
  496.  
  497. /* boolean checkbrk():
  498.  * check whether a break occured and we should end right now.
  499.  * Call it often enough (like when loading songs and stuff)
  500.  */
  501. XT int checkbrk P((void));
  502.