diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/midi/midifile.c | 2 | ||||
-rw-r--r-- | apps/plugins/midi/synth.c | 17 | ||||
-rw-r--r-- | apps/plugins/midiplay.c | 68 |
3 files changed, 69 insertions, 18 deletions
diff --git a/apps/plugins/midi/midifile.c b/apps/plugins/midi/midifile.c index 13887e4a98..11f81b1fd6 100644 --- a/apps/plugins/midi/midifile.c +++ b/apps/plugins/midi/midifile.c @@ -68,8 +68,6 @@ struct MIDIfile * loadFile(char * filename) int track=0; printf("\nFile has %d tracks.", mfload->numTracks); - printf("Time division=%d\n", mfload->div); - while(! eof(file) && track < mfload->numTracks) { diff --git a/apps/plugins/midi/synth.c b/apps/plugins/midi/synth.c index 2b70074158..2ec263da60 100644 --- a/apps/plugins/midi/synth.c +++ b/apps/plugins/midi/synth.c @@ -103,19 +103,20 @@ int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig) drumUsed[getEvent(mf->tracks[a], ts)->d1]=1; if( (getEvent(mf->tracks[a], ts)->status & 0xF0) == MIDI_PRGM) - { -/* if(patchUsed[getEvent(mf->tracks[a], ts)->d1]==0) - printf("\nI need to load patch %d.", getEvent(mf->tracks[a], ts)->d1); -*/ patchUsed[getEvent(mf->tracks[a], ts)->d1]=1; - } } } int file = rb->open(filename, O_RDONLY); - if(file == -1) + if(file < 0) { - rb->splash(HZ*2, true, "Bad patch config.\nDid you install the patchset?"); + printf("\n"); + printf("\nNo MIDI patchset found."); + printf("\nPlease install the instruments."); + printf("\nSee Rockbox page for more info."); + + rb->splash(HZ*2, true, "No Instruments"); + rb->splash(HZ*2, true, "No Instruments"); return -1; } @@ -148,7 +149,7 @@ int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig) rb->close(file); file = rb->open(drumConfig, O_RDONLY); - if(file == -1) + if(file < 0) { rb->splash(HZ*2, true, "Bad drum config.\nDid you install the patchset?"); return -1; diff --git a/apps/plugins/midiplay.c b/apps/plugins/midiplay.c index d420508473..70ffaa7d92 100644 --- a/apps/plugins/midiplay.c +++ b/apps/plugins/midiplay.c @@ -22,7 +22,7 @@ PLUGIN_HEADER #define FRACTSIZE 10 #define SAMPLE_RATE 22050 // 44100 22050 11025 -#define MAX_VOICES 13 // Note: 24 midi channels is the minimum general midi +#define MAX_VOICES 14 // Note: 24 midi channels is the minimum general midi // spec implementation #define BUF_SIZE 512 #define NBUF 2 @@ -161,13 +161,12 @@ void get_more(unsigned char** start, size_t* size) int midimain(void * filename) { - int button; - - /* rb->splash(HZ/5, true, "LOADING MIDI"); */ + int notesUsed = 0; + int a=0; printf("\nLoading file"); mf= loadFile(filename); - /* rb->splash(HZ/5, true, "LOADING PATCHES"); */ + if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1) return -1; @@ -191,14 +190,25 @@ int midimain(void * filename) bpm=mf->div*1000000/tempo; numberOfSamples=SAMPLE_RATE/bpm; - tick(); + + + /* Skip over any junk in the beginning of the file, so start playing */ + /* after the first note event */ + do + { + notesUsed = 0; + for(a=0; a<MAX_VOICES; a++) + if(voices[a].isUsed == 1) + notesUsed++; + tick(); + } while(notesUsed == 0); synthbuf(); #ifndef SIMULATOR rb->pcm_play_data(&get_more, NULL, 0); #endif - button=rb->button_status(); + int vol=0; while(!quit) { @@ -206,7 +216,49 @@ int midimain(void * filename) synthbuf(); #endif rb->yield(); - if(rb->button_status()!=button) quit=1; + + /* Code taken from Oscilloscope plugin */ + switch(rb->button_get(false)) + { + case BUTTON_UP: + case BUTTON_UP | BUTTON_REPEAT: + vol = rb->global_settings->volume; + if (vol < rb->sound_max(SOUND_VOLUME)) + { + vol++; + rb->sound_set(SOUND_VOLUME, vol); + rb->global_settings->volume = vol; + } + break; + + case BUTTON_DOWN: + case BUTTON_DOWN | BUTTON_REPEAT: + vol = rb->global_settings->volume; + if (vol > rb->sound_min(SOUND_VOLUME)) + { + vol--; + rb->sound_set(SOUND_VOLUME, vol); + rb->global_settings->volume = vol; + } + break; + + case BUTTON_RIGHT: + { + /* Skip 3 seconds */ + /* Should skip length be retrieved from the RB settings? */ + int samp = 3*SAMPLE_RATE; + int tickCount = samp / numberOfSamples; + int a=0; + for(a=0; a<tickCount; a++) + tick(); + break; + } + + case BUTTON_OFF: + quit=1; + } + + } return 0; |