2006-05-01 23:22:59 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2007-09-24 15:57:32 +00:00
|
|
|
* $Id$
|
2006-05-01 23:22:59 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Karl Kurbjun based on midi2wav by Stepan Moskovchenko
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2006-05-01 23:22:59 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-09-24 15:57:32 +00:00
|
|
|
#include "plugin.h"
|
|
|
|
#include "guspat.h"
|
|
|
|
#include "midiutil.h"
|
|
|
|
#include "synth.h"
|
|
|
|
#include "sequencer.h"
|
|
|
|
#include "midifile.h"
|
2006-05-01 23:22:59 +00:00
|
|
|
|
|
|
|
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
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2008-01-02 06:35:59 +00:00
|
|
|
#define BTN_PLAY BUTTON_PLAY
|
2006-05-07 07:27:07 +00:00
|
|
|
|
|
|
|
#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
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2008-01-02 06:35:59 +00:00
|
|
|
#define BTN_PLAY (BUTTON_MENU | BUTTON_OFF)
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
|
|
|
|
#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
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2006-06-30 16:43:47 +00:00
|
|
|
#define BTN_RC_QUIT BUTTON_RC_STOP
|
2008-01-02 06:35:59 +00:00
|
|
|
#define BTN_PLAY BUTTON_ON
|
2006-06-30 16:43:47 +00:00
|
|
|
|
2007-07-27 09:57:27 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
|
2006-05-07 07:27:07 +00:00
|
|
|
#define BTN_QUIT (BUTTON_SELECT | BUTTON_MENU)
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2006-05-07 07:27:07 +00:00
|
|
|
#define BTN_UP BUTTON_SCROLL_FWD
|
|
|
|
#define BTN_DOWN BUTTON_SCROLL_BACK
|
2008-01-02 06:35:59 +00:00
|
|
|
#define BTN_PLAY BUTTON_PLAY
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2007-05-19 23:38:09 +00:00
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
2008-01-02 07:44:03 +00:00
|
|
|
#define BTN_PLAY BUTTON_A
|
2008-01-02 06:35:59 +00:00
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
|
2008-05-02 00:38:11 +00:00
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
|
|
|
#define BTN_PLAY BUTTON_PLAY
|
|
|
|
|
|
|
|
|
2008-01-10 08:08:31 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD)
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
|
|
|
#define BTN_UP BUTTON_SCROLL_FWD
|
|
|
|
#define BTN_DOWN BUTTON_SCROLL_BACK
|
|
|
|
#define BTN_PLAY BUTTON_UP
|
|
|
|
|
|
|
|
|
2008-11-28 00:37:28 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_C200_PAD) || (CONFIG_KEYPAD == SANSA_CLIP_PAD)
|
2006-10-26 13:38:09 +00:00
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2008-01-13 14:52:31 +00:00
|
|
|
#define BTN_UP BUTTON_VOL_UP
|
|
|
|
#define BTN_DOWN BUTTON_VOL_DOWN
|
|
|
|
#define BTN_PLAY BUTTON_UP
|
2008-01-02 06:35:59 +00:00
|
|
|
|
2006-10-26 13:38:09 +00:00
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
|
2006-05-07 07:27:07 +00:00
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2006-05-07 07:27:07 +00:00
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
2008-01-02 06:35:59 +00:00
|
|
|
#define BTN_PLAY BUTTON_PLAY
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2006-08-03 20:17:25 +00:00
|
|
|
#define BTN_UP BUTTON_SCROLL_UP
|
|
|
|
#define BTN_DOWN BUTTON_SCROLL_DOWN
|
2008-01-02 06:35:59 +00:00
|
|
|
#define BTN_PLAY BUTTON_PLAY
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
|
2007-10-25 07:44:56 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE500_PAD
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
2007-11-03 04:09:38 +00:00
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
2007-10-25 07:44:56 +00:00
|
|
|
#define BTN_UP BUTTON_RC_PLAY
|
|
|
|
#define BTN_DOWN BUTTON_RC_DOWN
|
2008-01-02 06:35:59 +00:00
|
|
|
#define BTN_PLAY BUTTON_RC_HEART
|
|
|
|
|
2007-10-25 07:44:56 +00:00
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == MROBE100_PAD)
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
|
|
|
#define BTN_UP BUTTON_UP
|
|
|
|
#define BTN_DOWN BUTTON_DOWN
|
|
|
|
#define BTN_PLAY BUTTON_DISPLAY
|
|
|
|
|
|
|
|
|
2008-03-22 14:20:04 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
#define BTN_QUIT BUTTON_RC_REC
|
|
|
|
#define BTN_RIGHT BUTTON_RC_FF
|
|
|
|
#define BTN_LEFT BUTTON_RC_REW
|
|
|
|
#define BTN_UP BUTTON_RC_VOL_UP
|
|
|
|
#define BTN_DOWN BUTTON_RC_VOL_DOWN
|
|
|
|
#define BTN_PLAY BUTTON_RC_PLAY
|
|
|
|
|
|
|
|
|
2008-03-22 22:03:34 +00:00
|
|
|
#elif CONFIG_KEYPAD == COWOND2_PAD
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
|
2008-10-07 16:38:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO67_PAD
|
|
|
|
#define BTN_QUIT BUTTON_POWER
|
|
|
|
#define BTN_RIGHT BUTTON_RIGHT
|
|
|
|
#define BTN_LEFT BUTTON_LEFT
|
|
|
|
#define BTN_UP BUTTON_STOP
|
|
|
|
#define BTN_DOWN BUTTON_PLAY
|
|
|
|
#define BTN_PLAY BUTTON_MENU
|
2008-03-22 22:03:34 +00:00
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#else
|
|
|
|
#error No keymap defined!
|
2006-05-07 07:27:07 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2008-04-27 15:30:19 +00:00
|
|
|
#ifndef BTN_QUIT
|
|
|
|
#define BTN_QUIT BUTTON_TOPLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef BTN_RIGHT
|
|
|
|
#define BTN_RIGHT BUTTON_MIDRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef BTN_LEFT
|
|
|
|
#define BTN_LEFT BUTTON_MIDLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef BTN_UP
|
|
|
|
#define BTN_UP BUTTON_TOPMIDDLE
|
|
|
|
#endif
|
|
|
|
#ifndef BTN_DOWN
|
|
|
|
#define BTN_DOWN BUTTON_BOTTOMMIDDLE
|
|
|
|
#endif
|
|
|
|
#ifndef BTN_PLAY
|
|
|
|
#define BTN_PLAY BUTTON_CENTER
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2006-05-01 23:22:59 +00:00
|
|
|
#undef SYNC
|
2007-01-11 20:13:15 +00:00
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
2008-01-13 14:52:31 +00:00
|
|
|
#define SYNC
|
2007-01-11 20:13:15 +00:00
|
|
|
#endif
|
|
|
|
|
2006-05-01 23:22:59 +00:00
|
|
|
struct MIDIfile * mf IBSS_ATTR;
|
|
|
|
|
2007-10-23 15:00:45 +00:00
|
|
|
int numberOfSamples IBSS_ATTR; /* the number of samples in the current tick */
|
2007-11-03 04:09:38 +00:00
|
|
|
int playingTime IBSS_ATTR; /* How many seconds into the file have we been playing? */
|
|
|
|
int samplesThisSecond IBSS_ATTR; /* How many samples produced during this second so far? */
|
|
|
|
|
2006-05-01 23:22:59 +00:00
|
|
|
long bpm IBSS_ATTR;
|
|
|
|
|
2007-09-24 16:47:34 +00:00
|
|
|
int32_t gmbuf[BUF_SIZE*NBUF];
|
2007-10-15 05:11:37 +00:00
|
|
|
static unsigned int samples_in_buf;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
|
|
|
int quit=0;
|
2008-05-13 09:57:56 +00:00
|
|
|
const struct plugin_api * rb;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
static int midimain(const void * filename);
|
2007-09-30 11:21:25 +00:00
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
|
2006-05-01 23:22:59 +00:00
|
|
|
{
|
2006-05-03 05:18:18 +00:00
|
|
|
int retval = 0;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2007-11-05 05:35:10 +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
|
|
|
|
|
2007-04-21 05:35:17 +00:00
|
|
|
printf("%s", parameter);
|
2006-05-03 05:18:18 +00:00
|
|
|
/* 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;
|
|
|
|
|
2007-09-29 16:06:16 +00:00
|
|
|
static inline void synthbuf(void)
|
2006-05-01 23:22:59 +00:00
|
|
|
{
|
2007-10-08 19:28:41 +00:00
|
|
|
int32_t *outptr;
|
2007-10-23 15:00:45 +00:00
|
|
|
int i=BUF_SIZE;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
|
|
|
#ifndef SYNC
|
2007-10-08 19:28:41 +00:00
|
|
|
if(lastswap==swap) return;
|
|
|
|
lastswap=swap;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2007-10-08 19:28:41 +00:00
|
|
|
outptr=(swap ? gmbuf : gmbuf+BUF_SIZE);
|
2006-05-01 23:22:59 +00:00
|
|
|
#else
|
2007-10-08 19:28:41 +00:00
|
|
|
outptr=gmbuf;
|
2006-05-01 23:22:59 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-15 05:11:37 +00:00
|
|
|
/* synth samples for as many whole ticks as we can fit in the buffer */
|
2007-10-23 15:00:45 +00:00
|
|
|
for(; i >= numberOfSamples; i -= numberOfSamples)
|
2007-10-08 19:28:41 +00:00
|
|
|
{
|
|
|
|
synthSamples((int32_t*)outptr, numberOfSamples);
|
|
|
|
outptr += numberOfSamples;
|
|
|
|
if( tick() == 0 )
|
|
|
|
quit=1;
|
|
|
|
}
|
|
|
|
|
2007-10-15 05:11:37 +00:00
|
|
|
/* how many samples did we write to the buffer? */
|
2007-10-23 15:00:45 +00:00
|
|
|
samples_in_buf = BUF_SIZE-i;
|
2007-10-15 05:11:37 +00:00
|
|
|
|
2006-05-01 23:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-10-15 05:11:37 +00:00
|
|
|
*size = samples_in_buf*sizeof(int32_t);
|
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
|
|
|
|
}
|
|
|
|
|
2008-05-13 09:57:56 +00:00
|
|
|
static int midimain(const void * filename)
|
2006-05-01 23:22:59 +00:00
|
|
|
{
|
2006-05-07 07:12:07 +00:00
|
|
|
int notesUsed = 0;
|
|
|
|
int a=0;
|
2007-04-21 05:35:17 +00:00
|
|
|
printf("Loading file");
|
2006-05-03 05:18:18 +00:00
|
|
|
mf= loadFile(filename);
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-08 02:43:29 +00:00
|
|
|
if(mf == NULL)
|
|
|
|
{
|
2007-04-21 05:35:17 +00:00
|
|
|
printf("Error loading file.");
|
2006-05-08 02:43:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2006-05-07 07:12:07 +00:00
|
|
|
|
2007-09-10 09:46:36 +00:00
|
|
|
if (initSynth(mf, ROCKBOX_DIR "/patchset/patchset.cfg",
|
|
|
|
ROCKBOX_DIR "/patchset/drums.cfg") == -1)
|
2006-05-03 05:18:18 +00:00
|
|
|
return -1;
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->pcm_play_stop();
|
2007-06-10 02:10:47 +00:00
|
|
|
#if INPUT_SRC_CAPS != 0
|
|
|
|
/* Select playback */
|
|
|
|
rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
|
|
|
|
rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);
|
|
|
|
#endif
|
2006-05-03 05:18:18 +00:00
|
|
|
rb->pcm_set_frequency(SAMPLE_RATE); // 44100 22050 11025
|
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
|
|
|
|
2007-04-21 05:35:17 +00:00
|
|
|
printf("Okay, 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++)
|
2007-11-11 01:02:45 +00:00
|
|
|
if(voices[a].isUsed)
|
2006-05-07 07:12:07 +00:00
|
|
|
notesUsed++;
|
|
|
|
tick();
|
|
|
|
} while(notesUsed == 0);
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2007-11-03 04:09:38 +00:00
|
|
|
playingTime = 0;
|
|
|
|
samplesThisSecond = 0;
|
|
|
|
|
2006-05-03 05:18:18 +00:00
|
|
|
synthbuf();
|
|
|
|
rb->pcm_play_data(&get_more, NULL, 0);
|
2006-05-01 23:22:59 +00:00
|
|
|
|
2008-01-02 06:35:59 +00:00
|
|
|
int isPlaying = 1; /* 0 = paused */
|
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
|
|
|
|
2007-05-19 20:37:02 +00:00
|
|
|
/* Prevent idle poweroff */
|
|
|
|
rb->reset_poweroff_timer();
|
|
|
|
|
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;
|
|
|
|
|
2007-11-03 04:09:38 +00:00
|
|
|
|
|
|
|
case BTN_LEFT:
|
|
|
|
{
|
|
|
|
/* Rewinding is tricky. Basically start the file over */
|
|
|
|
/* but run through the tracks without the synth running */
|
2007-11-03 06:31:33 +00:00
|
|
|
rb->pcm_play_stop();
|
2007-11-05 05:35:10 +00:00
|
|
|
seekBackward(5);
|
2008-01-02 06:35:59 +00:00
|
|
|
printf("Rewind to %d:%02d\n", playingTime/60, playingTime%60);
|
2007-11-05 05:35:10 +00:00
|
|
|
|
2008-01-02 06:35:59 +00:00
|
|
|
if(isPlaying)
|
|
|
|
rb->pcm_play_data(&get_more, NULL, 0);
|
2007-11-03 04:09:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-05-07 07:27:07 +00:00
|
|
|
case BTN_RIGHT:
|
2006-05-07 07:12:07 +00:00
|
|
|
{
|
2007-11-03 06:31:33 +00:00
|
|
|
rb->pcm_play_stop();
|
2007-11-05 05:35:10 +00:00
|
|
|
seekForward(5);
|
2008-01-02 06:35:59 +00:00
|
|
|
printf("Skip to %d:%02d\n", playingTime/60, playingTime%60);
|
|
|
|
|
|
|
|
if(isPlaying)
|
|
|
|
rb->pcm_play_data(&get_more, NULL, 0);
|
2006-05-07 07:12:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-11-03 04:09:38 +00:00
|
|
|
|
2008-01-02 06:35:59 +00:00
|
|
|
case BTN_PLAY:
|
|
|
|
{
|
|
|
|
if(isPlaying == 1)
|
|
|
|
{
|
|
|
|
printf("Paused at %d:%02d\n", playingTime/60, playingTime%60);
|
|
|
|
isPlaying = 0;
|
|
|
|
rb->pcm_play_stop();
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
printf("Playing from %d:%02d\n", playingTime/60, playingTime%60);
|
|
|
|
isPlaying = 1;
|
|
|
|
rb->pcm_play_data(&get_more, NULL, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-11-03 04:09:38 +00:00
|
|
|
|
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
|
|
|
}
|