2004-03-12 08:21:26 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Matthias Wientapper
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2006-11-16 02:53:44 +00:00
|
|
|
#include "pluginlib_actions.h"
|
2007-07-29 03:43:37 +00:00
|
|
|
#include "metronome.h"
|
2004-03-12 08:21:26 +00:00
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
2007-07-29 03:43:37 +00:00
|
|
|
#define METRONOME_QUIT PLA_QUIT
|
2008-01-23 08:25:04 +00:00
|
|
|
#define METRONOME_VOL_UP PLA_INC
|
|
|
|
#define METRONOME_VOL_DOWN PLA_DEC
|
|
|
|
#define METRONOME_VOL_UP_REP PLA_INC_REPEAT
|
|
|
|
#define METRONOME_VOL_DOWN_REP PLA_DEC_REPEAT
|
2007-07-29 03:43:37 +00:00
|
|
|
#define METRONOME_LEFT PLA_LEFT
|
|
|
|
#define METRONOME_RIGHT PLA_RIGHT
|
2006-11-17 00:50:35 +00:00
|
|
|
#define METRONOME_LEFT_REP PLA_LEFT_REPEAT
|
|
|
|
#define METRONOME_RIGHT_REP PLA_RIGHT_REPEAT
|
2006-11-16 02:53:44 +00:00
|
|
|
enum {
|
|
|
|
METRONOME_PLAY_TAP = LAST_PLUGINLIB_ACTION+1,
|
2006-11-26 07:20:04 +00:00
|
|
|
#if CONFIG_KEYPAD == ONDIO_PAD
|
2006-11-16 02:53:44 +00:00
|
|
|
METRONOME_PAUSE,
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* ONDIO_PAD */
|
2006-11-26 07:20:04 +00:00
|
|
|
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2006-11-16 02:53:44 +00:00
|
|
|
METRONOME_SYNC
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* IRIVER_H100_PAD||IRIVER_H300_PAD */
|
2006-11-16 02:53:44 +00:00
|
|
|
};
|
2004-10-12 23:45:25 +00:00
|
|
|
|
2006-11-16 02:53:44 +00:00
|
|
|
|
|
|
|
#if CONFIG_KEYPAD == ONDIO_PAD
|
2006-11-26 07:20:04 +00:00
|
|
|
#define METRONOME_TAP PLA_START
|
2004-12-26 14:56:05 +00:00
|
|
|
#define METRONOME_MSG_START "start: mode"
|
|
|
|
#define METRONOME_MSG_STOP "pause: hold mode"
|
2006-11-16 02:53:44 +00:00
|
|
|
static const struct button_mapping ondio_action[] =
|
|
|
|
{
|
2006-11-17 00:50:35 +00:00
|
|
|
{METRONOME_PLAY_TAP, BUTTON_MENU|BUTTON_REL, BUTTON_MENU },
|
2006-11-26 07:20:04 +00:00
|
|
|
{METRONOME_PAUSE, BUTTON_MENU|BUTTON_REPEAT, BUTTON_NONE },
|
|
|
|
{CONTEXT_CUSTOM,BUTTON_NONE,BUTTON_NONE}
|
2006-11-16 02:53:44 +00:00
|
|
|
};
|
2007-07-29 05:30:04 +00:00
|
|
|
#else /* !ONDIO_PAD */
|
2006-11-26 07:20:04 +00:00
|
|
|
#define METRONOME_TAP PLA_FIRE
|
|
|
|
#define METRONOME_PLAYPAUSE PLA_START
|
2006-03-30 21:17:19 +00:00
|
|
|
#define METRONOME_MSG_START "press play"
|
|
|
|
#define METRONOME_MSG_STOP "press pause"
|
|
|
|
|
2006-11-16 02:53:44 +00:00
|
|
|
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2006-12-04 01:04:14 +00:00
|
|
|
#define MET_SYNC
|
2006-12-03 16:49:36 +00:00
|
|
|
static const struct button_mapping iriver_syncaction[] =
|
2006-11-16 02:53:44 +00:00
|
|
|
{
|
|
|
|
{METRONOME_SYNC, BUTTON_REC, BUTTON_NONE },
|
2006-11-26 07:20:04 +00:00
|
|
|
{CONTEXT_CUSTOM,BUTTON_NONE,BUTTON_NONE}
|
2006-11-16 02:53:44 +00:00
|
|
|
};
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* IRIVER_H100_PAD||IRIVER_H300_PAD */
|
2006-11-16 02:53:44 +00:00
|
|
|
#endif /* #if CONFIG_KEYPAD == ONDIO_PAD */
|
2006-01-10 02:51:50 +00:00
|
|
|
|
2007-07-29 05:30:04 +00:00
|
|
|
const struct button_mapping *plugin_contexts[]={
|
2008-01-23 08:25:04 +00:00
|
|
|
generic_increase_decrease,
|
2007-07-29 05:30:04 +00:00
|
|
|
generic_directions,
|
|
|
|
#if CONFIG_KEYPAD == ONDIO_PAD
|
|
|
|
ondio_action,
|
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
|
|
|
iriver_syncaction,
|
|
|
|
#endif
|
|
|
|
generic_actions
|
|
|
|
};
|
2008-01-23 08:25:04 +00:00
|
|
|
#define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
|
2006-01-10 02:51:50 +00:00
|
|
|
|
2004-03-12 08:21:26 +00:00
|
|
|
static struct plugin_api* rb;
|
|
|
|
|
2007-06-13 15:35:07 +00:00
|
|
|
MEM_FUNCTION_WRAPPERS(rb);
|
|
|
|
|
2004-05-26 06:56:18 +00:00
|
|
|
static int bpm = 120;
|
|
|
|
static int period = 0;
|
|
|
|
static int minitick = 0;
|
2004-03-12 08:21:26 +00:00
|
|
|
|
|
|
|
static bool sound_active = false;
|
|
|
|
static bool sound_paused = true;
|
2004-03-17 14:54:32 +00:00
|
|
|
|
2004-05-26 06:56:18 +00:00
|
|
|
static char buffer[30];
|
2004-03-12 08:21:26 +00:00
|
|
|
|
2007-07-29 05:30:04 +00:00
|
|
|
static bool reset_tap = false;
|
2004-11-26 13:31:40 +00:00
|
|
|
static int tap_count = 0;
|
|
|
|
static int tap_time = 0;
|
|
|
|
static int tap_timeout = 0;
|
|
|
|
|
2006-01-14 02:39:30 +00:00
|
|
|
int bpm_step_counter = 0;
|
|
|
|
|
2006-01-10 02:51:50 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
|
|
|
|
|
|
|
#define MET_IS_PLAYING rb->mp3_is_playing()
|
|
|
|
#define MET_PLAY_STOP rb->mp3_play_stop()
|
|
|
|
|
2007-06-13 15:35:07 +00:00
|
|
|
void callback(unsigned char** start, size_t* size){
|
2004-03-19 22:15:52 +00:00
|
|
|
(void)start; /* unused parameter, avoid warning */
|
2008-01-13 18:27:54 +00:00
|
|
|
*size = 0; /* end of data */
|
2004-03-12 08:21:26 +00:00
|
|
|
sound_active = false;
|
2007-07-29 03:43:37 +00:00
|
|
|
rb->led(0);
|
2004-03-12 08:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void play_tock(void){
|
|
|
|
sound_active = true;
|
2007-07-29 03:43:37 +00:00
|
|
|
rb->led(1);
|
2004-03-12 08:21:26 +00:00
|
|
|
rb->mp3_play_data(sound, sizeof(sound), callback);
|
|
|
|
rb->mp3_play_pause(true); /* kickoff audio */
|
|
|
|
}
|
|
|
|
|
2007-07-29 05:30:04 +00:00
|
|
|
#else /* CONFIG_CODEC == SWCODEC */
|
2006-01-10 02:51:50 +00:00
|
|
|
|
|
|
|
#define MET_IS_PLAYING rb->pcm_is_playing()
|
2006-01-14 02:39:30 +00:00
|
|
|
#define MET_PLAY_STOP rb->audio_stop()
|
2006-01-10 02:51:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
int tock;
|
2007-04-12 17:58:42 +00:00
|
|
|
bool need_to_play = false;
|
2004-03-12 08:21:26 +00:00
|
|
|
|
2006-01-10 22:22:19 +00:00
|
|
|
short sndbuf[sizeof(sound)*2];
|
|
|
|
|
|
|
|
/* Convert the mono "tock" sample to interleaved stereo */
|
|
|
|
void prepare_tock(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i = 0;i < (int)sizeof(sound)/2;i++) {
|
|
|
|
sndbuf[i*2] = sound[i];
|
|
|
|
sndbuf[i*2+1] = sound[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-10 02:51:50 +00:00
|
|
|
void play_tock(void) {
|
2006-02-07 20:38:55 +00:00
|
|
|
rb->pcm_play_data(NULL,(unsigned char *)sndbuf,sizeof(sndbuf));
|
2006-01-10 02:51:50 +00:00
|
|
|
tock++;
|
|
|
|
}
|
|
|
|
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* CONFIG_CODEC != SWCODEC */
|
2006-01-10 02:51:50 +00:00
|
|
|
|
|
|
|
void calc_period(void)
|
|
|
|
{
|
2006-03-03 08:14:44 +00:00
|
|
|
period = 61440/bpm-1; /* (60*1024)/bpm; */
|
2006-01-10 02:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-29 03:43:37 +00:00
|
|
|
void metronome_draw(struct screen* display)
|
2006-01-10 02:51:50 +00:00
|
|
|
{
|
2007-07-29 03:43:37 +00:00
|
|
|
display->clear_display();
|
2004-03-12 08:21:26 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-07-29 03:43:37 +00:00
|
|
|
display->setfont(FONT_SYSFIXED);
|
|
|
|
display->puts(0, 0, "Metronome");
|
|
|
|
if(display->screen_type==SCREEN_MAIN)
|
|
|
|
{
|
|
|
|
display->puts(0, 5, "Select to TAP");
|
|
|
|
display->puts(0, 6, "Rec to SYNC");
|
|
|
|
}
|
2006-01-10 02:51:50 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2007-07-29 03:43:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
display->puts(0, 5, "Rec to TAP");
|
|
|
|
display->puts(0, 6, "Mode to SYNC");
|
|
|
|
}
|
|
|
|
#endif
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
2004-03-17 14:54:32 +00:00
|
|
|
|
2004-03-12 08:21:26 +00:00
|
|
|
rb->snprintf(buffer, sizeof(buffer), "BPM: %d ",bpm);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-07-29 03:43:37 +00:00
|
|
|
display->puts(0,3, buffer);
|
2004-03-12 08:21:26 +00:00
|
|
|
#else
|
2007-07-29 03:43:37 +00:00
|
|
|
display->puts(0,0, buffer);
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
2006-01-10 02:51:50 +00:00
|
|
|
|
2004-03-12 08:21:26 +00:00
|
|
|
rb->snprintf(buffer, sizeof(buffer), "Vol: %d",
|
|
|
|
rb->global_settings->volume);
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-07-29 03:43:37 +00:00
|
|
|
display->puts(10, 3, buffer);
|
2004-03-12 08:21:26 +00:00
|
|
|
#else
|
2007-07-29 04:01:46 +00:00
|
|
|
display->puts(0,1, buffer);
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
2004-03-12 08:21:26 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-07-29 03:43:37 +00:00
|
|
|
display->drawline(0, 12, 111, 12);
|
2004-03-12 08:21:26 +00:00
|
|
|
if(sound_paused)
|
2007-07-29 03:43:37 +00:00
|
|
|
display->puts(0,2,METRONOME_MSG_START);
|
2004-03-12 08:21:26 +00:00
|
|
|
else
|
2007-07-29 03:43:37 +00:00
|
|
|
display->puts(0,2,METRONOME_MSG_STOP);
|
2008-03-09 02:36:17 +00:00
|
|
|
display->setfont(FONT_UI);
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* HAVE_LCD_BITMAP */
|
2007-07-29 03:43:37 +00:00
|
|
|
display->update();
|
2004-03-12 08:21:26 +00:00
|
|
|
}
|
|
|
|
|
2007-07-29 04:16:12 +00:00
|
|
|
void draw_display(void)
|
2007-07-29 03:43:37 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
metronome_draw(rb->screens[i]);
|
|
|
|
}
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-03-17 14:54:32 +00:00
|
|
|
/* helper function to change the volume by a certain amount, +/-
|
|
|
|
ripped from video.c */
|
2004-03-12 08:21:26 +00:00
|
|
|
void change_volume(int delta){
|
2005-12-17 21:13:30 +00:00
|
|
|
int minvol = rb->sound_min(SOUND_VOLUME);
|
|
|
|
int maxvol = rb->sound_max(SOUND_VOLUME);
|
2004-03-12 08:21:26 +00:00
|
|
|
int vol = rb->global_settings->volume + delta;
|
2005-12-17 21:13:30 +00:00
|
|
|
|
|
|
|
if (vol > maxvol) vol = maxvol;
|
|
|
|
else if (vol < minvol) vol = minvol;
|
2004-03-12 08:21:26 +00:00
|
|
|
if (vol != rb->global_settings->volume) {
|
2005-04-01 13:41:03 +00:00
|
|
|
rb->sound_set(SOUND_VOLUME, vol);
|
2004-03-12 08:21:26 +00:00
|
|
|
rb->global_settings->volume = vol;
|
2006-01-10 02:51:50 +00:00
|
|
|
draw_display();
|
2004-03-12 08:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-14 02:39:30 +00:00
|
|
|
/*function to accelerate bpm change*/
|
|
|
|
void change_bpm(int direction){
|
|
|
|
if((bpm_step_counter < 20)
|
|
|
|
|| (bpm > 389)
|
|
|
|
|| (bpm < 10))
|
|
|
|
bpm = bpm + direction;
|
|
|
|
else if (bpm_step_counter < 60)
|
|
|
|
bpm = bpm + direction * 2;
|
|
|
|
else
|
|
|
|
bpm = bpm + direction * 9;
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2006-01-14 02:39:30 +00:00
|
|
|
if (bpm > 400) bpm = 400;
|
|
|
|
if (bpm < 1) bpm = 1;
|
|
|
|
calc_period();
|
|
|
|
draw_display();
|
|
|
|
bpm_step_counter++;
|
2007-07-29 05:30:04 +00:00
|
|
|
}
|
2006-01-14 02:39:30 +00:00
|
|
|
|
2006-01-10 02:51:50 +00:00
|
|
|
void timer_callback(void)
|
|
|
|
{
|
|
|
|
if(minitick >= period){
|
|
|
|
minitick = 0;
|
|
|
|
if(!sound_active && !sound_paused && !tap_count) {
|
2007-04-12 17:58:42 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* On SWCODEC we can't call play_tock() directly from an ISR. */
|
|
|
|
need_to_play = true;
|
|
|
|
#else
|
2006-01-10 02:51:50 +00:00
|
|
|
play_tock();
|
2007-04-12 17:58:42 +00:00
|
|
|
#endif
|
2006-01-10 02:51:50 +00:00
|
|
|
rb->reset_poweroff_timer();
|
|
|
|
}
|
2004-08-28 09:07:21 +00:00
|
|
|
}
|
2004-05-26 06:56:18 +00:00
|
|
|
else {
|
2006-01-10 02:51:50 +00:00
|
|
|
minitick++;
|
2004-05-26 06:56:18 +00:00
|
|
|
}
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
if (tap_count) {
|
|
|
|
tap_time++;
|
|
|
|
if (tap_count > 1 && tap_time > tap_timeout)
|
|
|
|
tap_count = 0;
|
|
|
|
}
|
2004-05-26 06:56:18 +00:00
|
|
|
}
|
|
|
|
|
2004-10-12 23:45:25 +00:00
|
|
|
void cleanup(void *parameter)
|
|
|
|
{
|
|
|
|
(void)parameter;
|
|
|
|
|
2005-07-26 20:01:11 +00:00
|
|
|
rb->timer_unregister();
|
2006-01-10 02:51:50 +00:00
|
|
|
MET_PLAY_STOP; /* stop audio ISR */
|
2007-07-29 03:43:37 +00:00
|
|
|
rb->led(0);
|
2004-10-12 23:45:25 +00:00
|
|
|
}
|
2004-05-26 06:56:18 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
void tap(void)
|
|
|
|
{
|
2007-04-12 17:58:42 +00:00
|
|
|
if (tap_count == 0 || tap_time < tap_count) {
|
2004-11-26 13:31:40 +00:00
|
|
|
tap_time = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (tap_time > 0) {
|
|
|
|
bpm = 61440/(tap_time/tap_count);
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
if (bpm > 400)
|
|
|
|
bpm = 400;
|
|
|
|
}
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
calc_period();
|
|
|
|
draw_display();
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
tap_timeout = (tap_count+2)*tap_time/tap_count;
|
|
|
|
}
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
tap_count++;
|
|
|
|
minitick = 0; /* sync tock to tapping */
|
2006-01-10 02:51:50 +00:00
|
|
|
play_tock();
|
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
reset_tap = false;
|
|
|
|
}
|
2004-03-12 08:21:26 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
|
2004-10-12 23:45:25 +00:00
|
|
|
int button;
|
2007-06-10 02:10:47 +00:00
|
|
|
enum plugin_status status;
|
2004-10-12 23:45:25 +00:00
|
|
|
|
2004-03-12 08:21:26 +00:00
|
|
|
(void)parameter;
|
|
|
|
rb = api;
|
|
|
|
|
2006-01-10 02:51:50 +00:00
|
|
|
if (MET_IS_PLAYING)
|
2006-03-03 08:14:44 +00:00
|
|
|
MET_PLAY_STOP; /* stop audio IS */
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2006-01-10 02:51:50 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2004-03-12 08:21:26 +00:00
|
|
|
rb->bitswap(sound, sizeof(sound));
|
2006-01-10 02:51:50 +00:00
|
|
|
#else
|
2006-01-10 22:22:19 +00:00
|
|
|
prepare_tock();
|
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
|
|
|
|
rb->pcm_set_frequency(SAMPR_44);
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* CONFIG_CODEC != SWCODEC */
|
2004-03-12 08:21:26 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
calc_period();
|
2006-04-02 12:45:30 +00:00
|
|
|
rb->timer_register(1, NULL, TIMER_FREQ/1024, 1, timer_callback);
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
draw_display();
|
2004-03-12 08:21:26 +00:00
|
|
|
|
|
|
|
/* main loop */
|
|
|
|
while (true){
|
2004-11-26 13:31:40 +00:00
|
|
|
reset_tap = true;
|
2007-04-12 17:58:42 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
button = pluginlib_getaction(rb,1,plugin_contexts,PLA_ARRAY_COUNT);
|
|
|
|
if (need_to_play)
|
|
|
|
{
|
|
|
|
need_to_play = false;
|
|
|
|
play_tock();
|
|
|
|
}
|
|
|
|
#else
|
2006-11-16 02:53:44 +00:00
|
|
|
button = pluginlib_getaction(rb,TIMEOUT_BLOCK,
|
|
|
|
plugin_contexts,PLA_ARRAY_COUNT);
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* SWCODEC */
|
2004-11-26 13:31:40 +00:00
|
|
|
switch (button) {
|
|
|
|
|
|
|
|
case METRONOME_QUIT:
|
|
|
|
/* get out of here */
|
|
|
|
cleanup(NULL);
|
2007-06-10 02:10:47 +00:00
|
|
|
status = PLUGIN_OK;
|
|
|
|
goto metronome_exit;
|
2004-11-26 13:31:40 +00:00
|
|
|
|
|
|
|
#if CONFIG_KEYPAD == ONDIO_PAD
|
|
|
|
case METRONOME_PLAY_TAP:
|
|
|
|
if(sound_paused) {
|
|
|
|
sound_paused = false;
|
|
|
|
calc_period();
|
|
|
|
draw_display();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tap();
|
|
|
|
break;
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
case METRONOME_PAUSE:
|
2004-11-29 00:19:51 +00:00
|
|
|
if(!sound_paused) {
|
2004-11-26 13:31:40 +00:00
|
|
|
sound_paused = true;
|
2004-11-29 00:19:51 +00:00
|
|
|
draw_display();
|
2007-07-29 05:30:04 +00:00
|
|
|
}
|
2004-11-26 13:31:40 +00:00
|
|
|
break;
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
#else
|
|
|
|
case METRONOME_PLAYPAUSE:
|
|
|
|
if(sound_paused)
|
|
|
|
sound_paused = false;
|
|
|
|
else
|
|
|
|
sound_paused = true;
|
|
|
|
calc_period();
|
|
|
|
draw_display();
|
|
|
|
break;
|
2007-07-29 05:30:04 +00:00
|
|
|
#endif /* ONDIO_PAD */
|
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
case METRONOME_VOL_UP:
|
2006-11-16 02:53:44 +00:00
|
|
|
case METRONOME_VOL_UP_REP:
|
2004-11-26 13:31:40 +00:00
|
|
|
change_volume(1);
|
|
|
|
calc_period();
|
|
|
|
break;
|
2007-07-29 05:30:04 +00:00
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
case METRONOME_VOL_DOWN:
|
2006-11-16 02:53:44 +00:00
|
|
|
case METRONOME_VOL_DOWN_REP:
|
2004-11-26 13:31:40 +00:00
|
|
|
change_volume(-1);
|
|
|
|
calc_period();
|
|
|
|
break;
|
|
|
|
|
2006-11-17 00:50:35 +00:00
|
|
|
case METRONOME_LEFT:
|
2006-01-14 02:39:30 +00:00
|
|
|
bpm_step_counter = 0;
|
2006-11-17 00:50:35 +00:00
|
|
|
case METRONOME_LEFT_REP:
|
2006-01-14 02:39:30 +00:00
|
|
|
change_bpm(-1);
|
2004-11-26 13:31:40 +00:00
|
|
|
break;
|
|
|
|
|
2006-11-17 00:50:35 +00:00
|
|
|
case METRONOME_RIGHT:
|
2006-01-14 02:39:30 +00:00
|
|
|
bpm_step_counter = 0;
|
2006-11-17 00:50:35 +00:00
|
|
|
case METRONOME_RIGHT_REP:
|
2006-01-14 02:39:30 +00:00
|
|
|
change_bpm(1);
|
2004-11-26 13:31:40 +00:00
|
|
|
break;
|
|
|
|
|
2006-11-26 07:20:04 +00:00
|
|
|
#ifdef METRONOME_TAP
|
2004-11-26 13:31:40 +00:00
|
|
|
case METRONOME_TAP:
|
|
|
|
tap();
|
|
|
|
break;
|
|
|
|
#endif
|
2006-01-10 02:51:50 +00:00
|
|
|
|
2006-12-04 01:04:14 +00:00
|
|
|
#ifdef MET_SYNC
|
2006-01-10 02:51:50 +00:00
|
|
|
case METRONOME_SYNC:
|
|
|
|
minitick = period;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2004-11-26 13:31:40 +00:00
|
|
|
default:
|
|
|
|
if (rb->default_event_handler_ex(button, cleanup, NULL)
|
|
|
|
== SYS_USB_CONNECTED)
|
2007-06-10 02:10:47 +00:00
|
|
|
{
|
|
|
|
status = PLUGIN_USB_CONNECTED;
|
|
|
|
goto metronome_exit;
|
|
|
|
}
|
2004-11-26 13:31:40 +00:00
|
|
|
reset_tap = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (reset_tap) {
|
|
|
|
tap_count = 0;
|
|
|
|
}
|
2004-03-12 08:21:26 +00:00
|
|
|
}
|
2007-06-10 02:10:47 +00:00
|
|
|
|
|
|
|
metronome_exit:
|
2007-06-10 02:19:39 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-06-10 02:10:47 +00:00
|
|
|
rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
|
2007-06-10 02:19:39 +00:00
|
|
|
#endif
|
2007-06-10 02:10:47 +00:00
|
|
|
return status;
|
2004-03-12 08:21:26 +00:00
|
|
|
}
|