2006-05-01 23:22:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Karl Kurbjun based on midi2wav by Stepan Moskovchenko
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "../../plugin.h"
|
|
|
|
|
|
|
|
PLUGIN_HEADER
|
2006-11-18 02:18:29 +00:00
|
|
|
PLUGIN_IRAM_DECLARE
|
2006-05-07 07:27:07 +00:00
|
|
|
|
|
|
|
/* variable button definitions */
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
#define BTN_QUIT BUTTON_OFF
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
|
|
|
#define BTN_QUIT BUTTON_OFF
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
|
|
|
#define BTN_QUIT BUTTON_OFF
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
|
|
|
|
2006-06-30 16:43:47 +00:00
|
|
|
#define BTN_RC_QUIT BUTTON_RC_STOP
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD)
|
|
|
|
#define BTN_QUIT (BUTTON_SELECT | BUTTON_MENU)
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_UP BUTTON_SCROLL_FWD
|
|
|
|
#define BTN_DOWN BUTTON_SCROLL_BACK
|
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_UP BUTTON_VOL_UP
|
|
|
|
#define BTN_DOWN BUTTON_VOL_DOWN
|
|
|
|
|
2006-10-26 13:38:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD)
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
|
|
|
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_UP BUTTON_SCROLL_UP
|
|
|
|
#define BTN_DOWN BUTTON_SCROLL_DOWN
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
#define FRACTSIZE 10
|
2007-01-11 20:13:15 +00:00
|
|
|
|
|
|
|
#ifndef SIMULATOR
|
|
|
|
#define SAMPLE_RATE 22050 // 44100 22050 11025
|
|
|
|
#define MAX_VOICES 14 // Note: 24 midi channels is the minimum general midi
|
2006-05-01 23:22:59 +00:00
|
|
|
// spec implementation
|
2007-01-11 20:13:15 +00:00
|
|
|
#else // Simulator requires 44100, and we can afford to use more voices
|
|
|
|
#define SAMPLE_RATE 44100
|
|
|
|
#define MAX_VOICES 48
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-05-01 23:22:59 +00:00
|
|
|
#define BUF_SIZE 512
|
|
|
|
#define NBUF 2
|
|
|
|
|
|
|
|
#undef SYNC
|
2007-01-11 20:13:15 +00:00
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
#define SYNC
|
|
|
|
#endif
|
|
|
|
|
2006-05-01 23:22:59 +00:00
|
|
|
struct MIDIfile * mf IBSS_ATTR;
|
|
|
|
|
|
|
|
int numberOfSamples IBSS_ATTR;
|
|
|
|
long bpm IBSS_ATTR;
|
|
|
|
|
|
|
|
#include "midi/midiutil.c"
|
|
|
|
#include "midi/guspat.h"
|
|
|
|
#include "midi/guspat.c"
|
|
|
|
#include "midi/sequencer.c"
|
|
|
|
#include "midi/midifile.c"
|
|
|
|
#include "midi/synth.c"
|
|
|
|
|
|
|
|
short gmbuf[BUF_SIZE*NBUF] IBSS_ATTR;
|
|
|
|
|
|
|
|
int quit=0;
|
|
|
|
struct plugin_api * rb;
|
|
|
|
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|
|
|
{
|
2006-05-03 05:18:18 +00:00
|
|
|
int retval = 0;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-11-26 18:31:41 +00:00
|
|
|
PLUGIN_IRAM_INIT(api)
|
|
|
|
|
|
|
|
rb = api;
|
2006-05-03 05:18:18 +00:00
|
|
|
if(parameter == NULL)
|
|
|
|
{
|
2007-03-16 22:09:52 +00:00
|
|
|
rb->splash(HZ*2, " Play .MID file ");
|
2006-05-03 05:18:18 +00:00
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
rb->lcd_setfont(0);
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-06-12 00:13:00 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->cpu_boost(true);
|
2006-05-01 23:22:59 +00:00
|
|
|
#endif
|
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
printf("\n%s", parameter);
|
|
|
|
/* rb->splash(HZ, true, parameter); */
|
2006-05-01 23:22:59 +00:00
|
|
|
|
|
|
|
#ifdef RB_PROFILE
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->profile_thread();
|
2006-05-01 23:22:59 +00:00
|
|
|
#endif
|
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
retval = midimain(parameter);
|
2006-05-01 23:22:59 +00:00
|
|
|
|
|
|
|
#ifdef RB_PROFILE
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->profstop();
|
2006-05-01 23:22:59 +00:00
|
|
|
#endif
|
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->pcm_play_stop();
|
2007-03-14 16:43:21 +00:00
|
|
|
rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-06-12 00:13:00 +00:00
|
|
|
#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->cpu_boost(false);
|
2006-05-01 23:22:59 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-16 22:09:52 +00:00
|
|
|
rb->splash(HZ, "FINISHED PLAYING");
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
if(retval == -1)
|
|
|
|
return PLUGIN_ERROR;
|
|
|
|
return PLUGIN_OK;
|
2006-05-01 23:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool swap=0;
|
|
|
|
bool lastswap=1;
|
|
|
|
|
|
|
|
inline void synthbuf(void)
|
|
|
|
{
|
|
|
|
short *outptr;
|
|
|
|
register int i;
|
|
|
|
static int currentSample=0;
|
|
|
|
int synthtemp[2];
|
|
|
|
|
|
|
|
#ifndef SYNC
|
|
|
|
if(lastswap==swap) return;
|
|
|
|
lastswap=swap;
|
|
|
|
|
|
|
|
outptr=(swap ? gmbuf : gmbuf+BUF_SIZE);
|
|
|
|
#else
|
|
|
|
outptr=gmbuf;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for(i=0; i<BUF_SIZE/2; i++)
|
|
|
|
{
|
|
|
|
synthSample(&synthtemp[0], &synthtemp[1]);
|
|
|
|
currentSample++;
|
|
|
|
*outptr=synthtemp[0]&0xFFFF;
|
|
|
|
outptr++;
|
|
|
|
*outptr=synthtemp[1]&0xFFFF;
|
|
|
|
outptr++;
|
|
|
|
if(currentSample==numberOfSamples)
|
|
|
|
{
|
|
|
|
if( tick() == 0 ) quit=1;
|
|
|
|
currentSample=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void get_more(unsigned char** start, size_t* size)
|
|
|
|
{
|
|
|
|
#ifndef SYNC
|
2006-05-03 05:18:18 +00:00
|
|
|
if(lastswap!=swap)
|
|
|
|
{
|
|
|
|
printf("Buffer miss!"); // Comment out the printf to make missses less noticable.
|
2006-05-01 23:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2006-05-03 05:18:18 +00:00
|
|
|
synthbuf(); // For some reason midiplayer crashes when an update is forced
|
2006-05-01 23:22:59 +00:00
|
|
|
#endif
|
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
*size = BUF_SIZE*sizeof(short);
|
2006-05-01 23:22:59 +00:00
|
|
|
#ifndef SYNC
|
2006-05-03 05:18:18 +00:00
|
|
|
*start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE));
|
|
|
|
swap=!swap;
|
2006-05-01 23:22:59 +00:00
|
|
|
#else
|
2006-05-03 05:18:18 +00:00
|
|
|
*start = (unsigned char*)(gmbuf);
|
2006-05-01 23:22:59 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int midimain(void * filename)
|
|
|
|
{
|
2006-05-07 07:12:07 +00:00
|
|
|
int notesUsed = 0;
|
|
|
|
int a=0;
|
2006-05-03 05:18:18 +00:00
|
|
|
printf("\nLoading file");
|
|
|
|
mf= loadFile(filename);
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-08 02:43:29 +00:00
|
|
|
if(mf == NULL)
|
|
|
|
{
|
|
|
|
printf("\nError loading file.");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-05-07 07:12:07 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1)
|
|
|
|
return -1;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2007-01-11 20:13:15 +00:00
|
|
|
//#ifndef SIMULATOR
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->pcm_play_stop();
|
|
|
|
rb->pcm_set_frequency(SAMPLE_RATE); // 44100 22050 11025
|
2007-01-11 20:13:15 +00:00
|
|
|
//#endif
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
/*
|
|
|
|
* tick() will do one MIDI clock tick. Then, there's a loop here that
|
|
|
|
* will generate the right number of samples per MIDI tick. The whole
|
|
|
|
* MIDI playback is timed in terms of this value.. there are no forced
|
|
|
|
* delays or anything. It just produces enough samples for each tick, and
|
|
|
|
* the playback of these samples is what makes the timings right.
|
|
|
|
*
|
|
|
|
* This seems to work quite well. On a laptop, anyway.
|
|
|
|
*/
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
printf("\nOkay, starting sequencing");
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
bpm=mf->div*1000000/tempo;
|
|
|
|
numberOfSamples=SAMPLE_RATE/bpm;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-07 07:12:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* 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);
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
synthbuf();
|
2007-01-11 20:13:15 +00:00
|
|
|
//#ifndef SIMULATOR
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->pcm_play_data(&get_more, NULL, 0);
|
2007-01-11 20:13:15 +00:00
|
|
|
//#endif
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-07 07:12:07 +00:00
|
|
|
int vol=0;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
while(!quit)
|
|
|
|
{
|
|
|
|
#ifndef SYNC
|
|
|
|
synthbuf();
|
|
|
|
#endif
|
|
|
|
rb->yield();
|
2006-05-07 07:12:07 +00:00
|
|
|
|
|
|
|
/* Code taken from Oscilloscope plugin */
|
|
|
|
switch(rb->button_get(false))
|
|
|
|
{
|
2006-05-07 07:27:07 +00:00
|
|
|
case BTN_UP:
|
|
|
|
case BTN_UP | BUTTON_REPEAT:
|
2006-05-07 07:12:07 +00:00
|
|
|
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;
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
case BTN_DOWN:
|
|
|
|
case BTN_DOWN | BUTTON_REPEAT:
|
2006-05-07 07:12:07 +00:00
|
|
|
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;
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
case BTN_RIGHT:
|
2006-05-07 07:12:07 +00:00
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
}
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef BTN_RC_QUIT
|
|
|
|
case BTN_RC_QUIT:
|
|
|
|
#endif
|
2006-05-07 07:27:07 +00:00
|
|
|
case BTN_QUIT:
|
2006-05-07 07:12:07 +00:00
|
|
|
quit=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
}
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
return 0;
|
2006-05-01 23:22:59 +00:00
|
|
|
}
|