From 90198b6e59d7c05d97b415b1fb7a953954023dd2 Mon Sep 17 00:00:00 2001 From: EvanR Date: Sat, 27 Feb 2010 12:29:31 -0600 Subject: [PATCH] Work on music, midi, and seq interfaces. --- audio.c | 2 -- midi.c | 4 +-- music.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- music.h | 2 ++ seq.c | 23 ++++++++++++- seq.h | 6 ++++ soundtest.c | 1 + synth.c | 4 ++- 8 files changed, 138 insertions(+), 10 deletions(-) diff --git a/audio.c b/audio.c index e3a7615..2cb960f 100644 --- a/audio.c +++ b/audio.c @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -97,7 +96,6 @@ void audio_init(){ org_init(); synth_init(); - seq_init(); printf(" sound on\n"); SDL_PauseAudio(0); diff --git a/midi.c b/midi.c index 82fc5c3..3d6a9b6 100644 --- a/midi.c +++ b/midi.c @@ -140,10 +140,10 @@ list* midi_load(char* filename){ loader_read(f,string,len); string[len] = '\0'; if(strncmp(string,"LoopStart",len)==0){ - push(events, make_event(tick, 0x100, 0, 1, 0)); + push(events, make_event(tick, 0x100, 0, 1, 0)); } else if(strncmp(string,"LoopEnd",len)==0){ - push(events, make_event(tick, 0x100, 0, 0, 0)); + push(events, make_event(tick, 0x100, 0, 0, 0)); } } break; diff --git a/music.c b/music.c index 0a10287..40323e3 100644 --- a/music.c +++ b/music.c @@ -22,16 +22,82 @@ evanrinehart@gmail.com */ +#include +#include + +#include #include +#include +#include +#include mus_id current_id = MUS_NOTHING; +list* songs[32] = { +NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, +}; + +int positions[32]; + +static char* mus_name(mus_id id){ + switch(id){ + case MUS_NOTHING: return "MUS_NOTHING"; + case MUS_COOL: return "MUS_COOL"; + default: return "?"; + } +} + +static int is_id_invalid(mus_id id){ + if(id >= 32) return 1; + else return 0; +} + + int music_load(char* filename, mus_id id){ - return -1; + list* events; + + if(id == MUS_NOTHING){ + //error_msg("music_load: you can't load a song into MUS_NOTHING\n"); + return -1; + } + + if(is_id_invalid(id)){ + //error_msg("music_load: music id out of range (%d)\n", id); + return -1; + } + + if(songs[id] != NULL){ + //error_msg("music_load: slot %s not empty\n", mus_name(id)); + return -1; + } + + events = midi_load(filename); + if(events == NULL){ + //error_msg("music_load: unable to load \"%s\"\n", filename); + return -1; + } + + songs[id] = events; + return 0; } void music_unload(mus_id id){ + if(is_id_invalid(id)) return; + if(songs[id] == NULL) return; + + if(music_current() == id) music_stop(id); + list* ptr = songs[id]->next; + while(ptr){ + free(ptr->item); + ptr = ptr->next; + } + + recycle(songs[id]->next); + songs[id] = NULL; } mus_id music_current(){ @@ -39,23 +105,55 @@ mus_id music_current(){ } void music_play(mus_id id){ + if(is_id_invalid(id)) return; + if(songs[id] == NULL) return; + if(music_current() == id) return; + + music_stop(id); + seq_load(songs[id]); + seq_seek(positions[id]); + seq_enable(); + current_id = id; } void music_stop(mus_id id){ + if(is_id_invalid(id)) return; + if(songs[id] == NULL) return; + if(music_current() == id) seq_disable(); + positions[id] = 0; } void music_pause(){ - + seq_disable(); + positions[music_current()] = seq_tell(); } -void music_volume(int precent){ - +void music_volume(int percent){ + /* somehow enqueue a special event */ } void music_fadeout(int seconds){ + /* somehow enqueue a special event */ +} + +void music_debug(){ + int i; + printf("music:\n"); + for(i=0; i<32; i++){ + char* name = mus_name(i); + int pos = positions[i]; + + if(songs[i]){ + int count = length(songs[i]); + printf("(%15s, %7de, %11d)\n", name, count, pos); + } + else{ + printf("(%15s, %7s, %11d)\n", name, "_", pos); + } + } } diff --git a/music.h b/music.h index ce278a3..3346e5a 100644 --- a/music.h +++ b/music.h @@ -38,6 +38,8 @@ void music_pause(); void music_volume(int precent); void music_fadeout(int seconds); +void music_debug(); + /* the music player diff --git a/seq.c b/seq.c index 8658c53..e5c4d72 100644 --- a/seq.c +++ b/seq.c @@ -24,9 +24,9 @@ #include #include +#include #include #include -#include #include #include @@ -203,3 +203,24 @@ void seq_init(){ next_event = sequence->next; printf("OK\n"); } + +void seq_load(list* events){ + +} + +void seq_seek(int tick){ + +} + +int seq_tell(){ + return 0; +} + +void seq_enable(){ + +} + +void seq_disable(){ + +} + diff --git a/seq.h b/seq.h index 8425b75..11751ba 100644 --- a/seq.h +++ b/seq.h @@ -43,4 +43,10 @@ event* seq_get_immediate(); /***/ void seq_instant(int type, int chan, int val1, int val2); void seq_clear(); +void seq_load(list* events); +void seq_seek(int tick); +int seq_tell(); +void seq_enable(); +void seq_disable(); void seq_append(event* e); + diff --git a/soundtest.c b/soundtest.c index 20c45c8..548d3ac 100644 --- a/soundtest.c +++ b/soundtest.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/synth.c b/synth.c index 5a9a45c..26bde53 100644 --- a/synth.c +++ b/synth.c @@ -26,10 +26,10 @@ #include #include +#include #include #include #include -#include /* timing stuff @@ -198,5 +198,7 @@ void synth_init(){ //srate = sample_rate; + seq_init(); + printf("OK\n"); } -- 2.11.4.GIT