1 /* play.c -- Play ZZM music
2 * $Id: play.c,v 1.3 2005/06/29 03:20:34 kvance Exp $
3 * Copyright (C) 2001 Kev Vance <kvance@kvance.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place Suite 330; Boston, MA 02111-1307, USA.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "notes.h"
25 #include "zzm.h"
26 #include "synth.h"
27
28 #include <stdio.h>
29 #include <stdlib.h>
30
printNoteData(musicalNote note,musicSettings settings)31 void printNoteData(musicalNote note, musicSettings settings)
32 {
33 #if 0
34 printf("index: %d, len: %d, dots: %d, freq: %f, len: %f\n",
35 note.index, note.length, note.dots,
36 noteFrequency(note, settings),
37 noteDuration(note, settings));
38 #endif
39 }
40
41 #ifdef SDL
42 SDL_AudioSpec spec;
43 #endif
44
start()45 void start() {
46 #ifdef SDL
47 SDL_Init(SDL_INIT_AUDIO);
48
49 atexit(SDL_Quit);
50
51 OpenSynth(&spec);
52 #endif
53 }
54
end()55 void end() {
56 #ifdef SDL
57 while (!IsSynthBufferEmpty())
58 ;
59 CloseSynth();
60 SDL_Quit();
61 #elif defined DOS
62 pcSpeakerFinish();
63 #endif
64 }
65
playSong(musicalNote * song,musicSettings settings)66 void playSong(musicalNote* song, musicSettings settings)
67 {
68 if (song == NULL)
69 return;
70
71 printf("Playing note\n");
72 #ifdef DOS
73 pcSpeakerPlayNote(*song, settings);
74 #elif defined SDL
75 SynthPlayNote(spec, *song, settings);
76 #endif
77
78 playSong(song->next, settings);
79 }
80
play(char * tune)81 void play(char* tune)
82 {
83 musicalNote* song = zzmGetNoteChain(tune, zzmGetDefaultNote());
84
85 playSong(song, zzmGetDefaultSettings());
86
87 deleteNoteChain(song);
88 }
89
main(int argc,char * argv[])90 int main(int argc, char* argv[])
91 {
92 int i;
93
94 start();
95
96 /* Default tune */
97 if (argc <= 1)
98 play("icdefgab+c");
99
100 /* Play all the arguments as seperate lines */
101 for (i = 1; i < argc; i++)
102 play(argv[i]);
103
104 end();
105
106 return 0;
107 }
108
109