From f13491ed0c365c58714d229bf5dcbddd45d8395a Mon Sep 17 00:00:00 2001 From: EvanR Date: Fri, 12 Jun 2009 21:31:55 -0400 Subject: [PATCH] Added more smf decoding code. Do not use. It is not ready or working. --- constants.h | 19 ++++++++++++++ core.c | 17 +++++++++++++ sdlclient.c | 21 +++++++++++++++- smf.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 127 insertions(+), 14 deletions(-) diff --git a/constants.h b/constants.h index 5b44100..5bf0ce4 100644 --- a/constants.h +++ b/constants.h @@ -1,3 +1,22 @@ +/* +orgux - a just-for-fun real time synth +Copyright (C) 2009 Evan Rinehart + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + /* constants needed by core and precompute */ #define PI 3.141592653589 diff --git a/core.c b/core.c index ad51573..af47f05 100644 --- a/core.c +++ b/core.c @@ -466,3 +466,20 @@ void orgux_free(orgux_state* S){ free(S); } + + +void orgux_seq_append(orgux_state* S, int tick, int type, int chan, int val1, int val2){ + if(S->seq_len == SEQUENCE_MAX) return; + + S->sequence[S->seq_len][0] = tick; + S->sequence[S->seq_len][1] = type; + S->sequence[S->seq_len][2] = chan; + S->sequence[S->seq_len][3] = val1; + S->sequence[S->seq_len][4] = val2; + S->seq_len++; +} + +void orgux_seq_sort(orgux_state* S){ + +} + diff --git a/sdlclient.c b/sdlclient.c index 810f2a8..377203a 100644 --- a/sdlclient.c +++ b/sdlclient.c @@ -1,3 +1,22 @@ +/* +orgux - a just-for-fun real time synth +Copyright (C) 2009 Evan Rinehart + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + /* sdl test */ @@ -51,4 +70,4 @@ int main(int argc, char* argv[]){ while(1){ SDL_Delay(1000); } -} \ No newline at end of file +} diff --git a/smf.c b/smf.c index b70c4af..5f27884 100644 --- a/smf.c +++ b/smf.c @@ -1,3 +1,22 @@ +/* +orgux - a just-for-fun real time synth +Copyright (C) 2009 Evan Rinehart + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + /* smf */ #include "orgux.h" @@ -8,6 +27,9 @@ typedef unsigned char octet; typedef int (*reader)(octet* buf, int count); +extern void orgux_seq_append(orgux_state* S, int tick, int type, int chan, int val1, int val2); +extern void orgux_seq_sort(orgux_state* S); + int bytes2short(octet arr[2]){ return (arr[1]<<8) | arr[0]; } @@ -86,23 +108,59 @@ int orgux_load_song(orgux_state* S, int (*pull) (unsigned char* buf, int bytes)) int chunk_size = bytes2int(buf); int tick = 0; + int end_of_track = 0; + int last_type = 0x80; + int last_chan = 0; while(1){ int delta = get_delta(pull); - if(1) break; + if(delta < 0) return -1; + tick += delta; + + //type and channel + if(pull(buf,1)<0) return -1; + int type = buf[0] & 0xf0; + if(type >= 0x80 && type <= 0xe0){//normal event + last_type = type; + int chan = buf[0] & 0x0f; + last_chan = chan; + if(pull(buf,2)<0) return -1; + int val1 = buf[0]; + int val2 = buf[1]; + + orgux_seq_append(S,tick,type,chan,val1,val2); + } + else if(type < 0x80){//running status + int val1 = buf[0]; + if(pull(buf,1)<0) return -1; + int val2 = buf[0]; + + orgux_seq_append(S,tick,last_type,last_chan,val1,val2); + } + else if(type == 0xff){//meta event + if(pull(buf,1)<0) return -1; + type = buf[0]; + + int len = get_delta(pull); + if(len < 0) return -1; + + switch(type){ + case 0x2f: end_of_track = 1; break; + case 0x51: /*tempo change*/ break; + case 0x58: /*time signature*/ break; + case 0x01: /*text*/ break; + default: skip_ahead(pull,len); break; + } + } + else{// sysex and such... + + } + + if(end_of_track) break; } } - /* get ticks per beat */ - /* get time signature */ - /* get us per quarter note */ - /* get time format */ - + orgux_seq_sort(S); + return 0; - /* for each track, each event, append event */ - - /* check for LoopStart and LoopEnd */ - - /* sort queue */ - -} \ No newline at end of file +} -- 2.11.4.GIT