Index: apps/plugins/beatbox/beatbox.c =================================================================== --- apps/plugins/beatbox/beatbox.c (revision 20325) +++ apps/plugins/beatbox/beatbox.c (working copy) @@ -17,110 +17,160 @@ * KIND, either express or implied. * ****************************************************************************/ - #include "plugin.h" -#include "midi/guspat.h" -#include "midi/midiutil.h" -#include "midi/synth.h" -#include "midi/sequencer.h" -#include "midi/midifile.h" - +#include "../midi/guspat.h" +#include "../midi/midiutil.h" +#include "../midi/synth.h" +#include "../midi/sequencer.h" +#include "../midi/midifile.h" PLUGIN_HEADER PLUGIN_IRAM_DECLARE - -/* 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 - -#define BTN_RC_QUIT BUTTON_RC_STOP - -#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ - (CONFIG_KEYPAD == IPOD_1G2G_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_UP -#define BTN_DOWN BUTTON_DOWN - -#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ -(CONFIG_KEYPAD == SANSA_C200_PAD) -#define BTN_QUIT BUTTON_POWER -#define BTN_RIGHT BUTTON_RIGHT -#define BTN_UP BUTTON_UP -#define BTN_DOWN BUTTON_DOWN - - -#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD -#define BTN_QUIT BUTTON_POWER -#define BTN_RIGHT BUTTON_RIGHT -#define BTN_UP BUTTON_UP -#define BTN_DOWN BUTTON_DOWN - -#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 - +/*------------------------------------------------------------------------------ + insanepotato's magical button guess-mapper thing. =D + This will try automatically define keymappings. The mappings defined + by this can be overridden (for comfort or other reasons) bellow. + An example partial mapping overide is done bellow (c200 override) +------------------------------------------------------------------------------*/ +/* attempt to set the directional buttons */ +#ifdef BUTTON_UP + #define BEATBOX_UP BUTTON_UP +#else + #warning No key mapping: no up button #endif - - - +#ifdef BUTTON_DOWN + #define BEATBOX_DOWN BUTTON_DOWN +#else + #warning No key mapping: no down button +#endif +#ifdef BUTTON_LEFT + #define BEATBOX_LEFT BUTTON_LEFT +#else + #warning No key mapping: no left button +#endif +#ifdef BUTTON_RIGHT + #define BEATBOX_RIGHT BUTTON_RIGHT +#else + #warning No key mapping: no right button +#endif +/* attempt to set the select button */ +/* order: select, record, playlist, menu */ +#ifdef BUTTON_SELECT + #define BEATBOX_SELECT BUTTON_SELECT +#else + #ifdef BUTTON_REC + #define BEATBOX_SELECT BUTTON_REC + #else + #ifdef BUTTON_PLAYLIST + #define BEATBOX_SELECT BUTTON_PLAYLIST + #else + #ifdef BUTTON_MENU + #define BEATBOX_SELECT MENU + #else + #warning No key mapping: no select button + #endif + #endif + #endif +#endif +/* attempt to set the play button */ +/* order: play, on, vol_up, scroll_forward */ +#ifdef BUTTON_PLAY + #define BEATBOX_PLAY BUTTON_PLAY +#else + #ifdef BUTTON_ON + #define BEATBOX_PLAY BUTTON_ON + #else + #ifdef BUTTON_VOL_UP + #define BEATBOX_PLAY BUTTON_VOL_UP + #else + #ifdef BUTTON_SCROLL_FWD + #define BEATBOX_PLAY BUTTON_SCROLL_BACK + #else + #warning No key mapping: no play button + #endif + #endif + #endif +#endif +/* attempt to set the stop button */ +/* order: stop, off, vol_down, scroll_back, home,power */ +#ifdef BUTTON_STOP + #define BEATBOX_STOP BUTTON_STOP +#else + #ifdef BUTTON_OFF + #define BEATBOX_STOP BUTTON_OFF + #else + #ifdef BUTTON_VOL_DOWN + #define BEATBOX_STOP BUTTON_VOL_DOWN + #else + #ifdef BUTTON_SCROLL_BACK + #define BEATBOX_STOP BUTTON_SCROLL_BACK + #else + #ifdef BUTTON_POWER + #define BEATBOX_STOP BUTTON_POWER + #else + #ifdef BUTTON_HOME + #define BEATBOX_STOP BUTTON_HOME + #else + #warning No key mapping: no stop button + #endif + #endif + #endif + #endif + #endif +#endif +/*------------------------------------------ + Manual overides here +------------------------------------------*/ +#if (CONFIG_KEYPAD == CUSTOM_PAD_GOES_HERE) +#define BEATBOX_UP BUTTON_UP +#define BEATBOX_DOWN BUTTON_DOWN +#define BEATBOX_LEFT BUTTON_LEFT +#define BEATBOX_RIGHT BUTTON_RIGHT +#define BEATBOX_SELECT BUTTON_SELECT +#define BEATBOX_PLAY BUTTON_ON +#define BEATBOX_STOP BUTTON_OFF +/* partial override to the c200 keypad, for more intuitive use */ +#elif (CONFIG_KEYPAD == SANSA_C200_PAD) +#define BEATBOX_PLAY BUTTON_REC +#define BEATBOX_STOP BUTTON_POWER +/* partial override to the h10 keypad, h10 is missing some directional btns */ +#elif (CONFIG_KEYPAD == IRIVER_H10_PAD) +#define BEATBOX_UP BUTTON_SCROLL_UP +#define BEATBOX_DOWN BUTTON_SCROLL_DOWN +#define BEATBOX_SELECT BUTTON_REW +#define BEATBOX_STOP BUTTON_POWER +/* m3 keypad has weird pad */ +#elif CONFIG_KEYPAD == IAUDIO_M3_PAD +#define BEATBOX_LEFT BUTTON_RC_REW +#define BEATBOX_RIGHT BUTTON_RC_FF +#define BEATBOX_UP BUTTON_RC_VOL_UP +#define BEATBOX_DOWN BUTTON_RC_VOL_DOWN +#define BEATBOX_SELECT BUTTON_RC_REC +#define BEATBOX_PLAY BUTTON_RC_PLAY +#define BEATBOX_STOP BUTTON_RC_MENU +#endif #define FRACTSIZE 10 - #ifndef SIMULATOR - #if (HW_SAMPR_CAPS & SAMPR_CAP_22) -#define SAMPLE_RATE SAMPR_22 // 44100 22050 11025 +#define SAMPLE_RATE SAMPR_22 /* 44100 22050 11025 */ #else -#define SAMPLE_RATE SAMPR_44 // 44100 22050 11025 +#define SAMPLE_RATE SAMPR_44 /* 44100 22050 11025 */ #endif - -#define MAX_VOICES 20 // Note: 24 midi channels is the minimum general midi - // spec implementation - -#else // Simulator requires 44100, and we can afford to use more voices - +/* this value was 20 */ +#define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi */ + /* spec implementation */ +#else /* Simulator requires 44100, and we can afford to use more voices */ #define SAMPLE_RATE SAMPR_44 #define MAX_VOICES 48 - #endif - - #define BUF_SIZE 256 #define NBUF 2 - #undef SYNC - #ifdef SIMULATOR #define SYNC #endif - struct MIDIfile * mf IBSS_ATTR; - int numberOfSamples IBSS_ATTR; long bpm IBSS_ATTR; - const unsigned char * drumNames[]={ "Bass Drum 2 ", "Bass Drum 1 ", @@ -176,45 +226,23 @@ "Mute Surdo ", "Open Surdo " }; - long gmbuf[BUF_SIZE*NBUF]; - int quit=0; - #define STATE_STOPPED 0 #define STATE_PAUSED 1 #define STATE_PLAYING 2 - - -#define BEATBOX_UP BUTTON_UP -#define BEATBOX_DOWN BUTTON_DOWN -#define BEATBOX_LEFT BUTTON_LEFT -#define BEATBOX_RIGHT BUTTON_RIGHT -#define BEATBOX_SELECT BUTTON_SELECT - - -#define BEATBOX_PLAY BUTTON_ON -#define BEATBOX_STOP BUTTON_OFF - - #define VAL_NONE 0 #define VAL_ENABLED 1 #define VAL_LOOP 2 - #define H_NUMCELLS 24 -#define V_NUMCELLS 8 - +#define V_NUMCELLS 10 /* was 8, 2 cells added: cymbals and maraca thing */ #define HILIGHT_NONE 0 #define HILIGHT_PLAY 1 #define HILIGHT_USER 2 - -#define CELL_XSIZE 9 -#define CELL_YSIZE 9 - -#define GRID_XPOS 2 -#define GRID_YPOS 10 - - +#define CELL_XSIZE (LCD_WIDTH/H_NUMCELLS) /* was 9 */ +#define CELL_YSIZE (LCD_HEIGHT/V_NUMCELLS) /* was 9 */ +#define GRID_XPOS 0 /* was 2 */ +#define GRID_YPOS 0 /* was 10 */ #define COLOR_NAME_TEXT LCD_RGBPACK(0xFF,0xFF,0xFF) #define COLOR_NORMAL LCD_RGBPACK(0xFF,0xFF,0xFF) #define COLOR_PLAY LCD_RGBPACK(0xFF,0xFF,0x00) @@ -222,28 +250,20 @@ #define COLOR_LOOPCELL LCD_RGBPACK(0xC0,0xC0,0xC0) #define COLOR_EDIT LCD_RGBPACK(0x30,0x30,0xFF) #define COLOR_GRID LCD_RGBPACK(0xD0,0xD0,0xD0) - #define EDITSTATE_PATTERN 0 - int xCursor=0, yCursor=0; - int editState=EDITSTATE_PATTERN; - int playState=STATE_STOPPED, stepFlag=0; - - +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? */ enum plugin_status plugin_start(const void* parameter) { int retval = 0; - PLUGIN_IRAM_INIT(rb) - rb->lcd_setfont(0); - #if defined(HAVE_ADJUSTABLE_CPU_FREQ) rb->cpu_boost(true); #endif - #ifdef RB_PROFILE rb->profile_thread(); #endif @@ -253,57 +273,47 @@ printf("\nINIT ERROR\n"); return -1; } -//#ifndef SIMULATOR +/*#ifndef SIMULATOR */ rb->pcm_play_stop(); #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(SAMPLE_RATE); // 44100 22050 11025 - - + rb->pcm_set_frequency(SAMPLE_RATE); /* 44100 22050 11025 */ retval = beatboxmain(); - #ifdef RB_PROFILE rb->profstop(); #endif - rb->pcm_play_stop(); rb->pcm_set_frequency(HW_SAMPR_DEFAULT); - #if defined(HAVE_ADJUSTABLE_CPU_FREQ) rb->cpu_boost(false); #endif - - if(retval == -1) return PLUGIN_ERROR; return PLUGIN_OK; } - bool swap=0; bool lastswap=1; - inline void synthbuf(void) { long *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; ilcd_set_foreground(COLOR_NAME_TEXT); rb->lcd_putsxy(NAME_POSX, NAME_POSY, drumNames[trackMap[trackNum]-35]); } - void updateDisplay() { int i, j; int grayOut=0; - for(j=0; jlcd_set_foreground(COLOR_GRID); - for(i=0; ilcd_vline(i*CELL_XSIZE+GRID_XPOS, GRID_YPOS, GRID_YPOS+CELL_YSIZE*V_NUMCELLS); - for(i=0; ilcd_hline(GRID_XPOS, GRID_XPOS+CELL_XSIZE*H_NUMCELLS, GRID_YPOS+i*CELL_YSIZE); - - rb->lcd_update(); } - void drawCell(int i, int j) { int cellX, cellY; - cellX = GRID_XPOS + CELL_XSIZE*i+1; cellY = GRID_YPOS + CELL_YSIZE*j+1; - rb->lcd_set_foreground(pattern[i][j].color); rb->lcd_fillrect(cellX, cellY, CELL_XSIZE-1, CELL_YSIZE-1); - rb->lcd_set_foreground(0); - if(pattern[i][j].val == VAL_LOOP) { rb->lcd_drawline(cellX, cellY, cellX+CELL_XSIZE-2, cellY+CELL_YSIZE-2); } - if(pattern[i][j].val == VAL_ENABLED) { rb->lcd_fillrect(cellX+1, cellY+1, CELL_XSIZE-3, CELL_YSIZE-3); } - } - void redrawScreen(unsigned char force) { int i, j; - for(i=0; ilcd_update(); } - void get_more(unsigned char** start, size_t* size) { #ifndef SYNC if(lastswap!=swap) { -// printf("Buffer miss!"); // Comment out the printf to make missses less noticable. + /* Comment out the printf to make missses less noticable. */ + /* printf("Buffer miss!"); */ } - #else - synthbuf(); // For some reason midiplayer crashes when an update is forced + synthbuf(); /* For some reason midiplayer crashes when an update is forced */ #endif - *size = BUF_SIZE*sizeof(short); #ifndef SYNC *start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE)); @@ -502,58 +469,42 @@ *start = (unsigned char*)(gmbuf); #endif } - int beatboxmain() { int vol=0; - - numberOfSamples=44100/10; synthbuf(); rb->pcm_play_data(&get_more, NULL, 0); - rb->lcd_set_background(0x000000); rb->lcd_clear_display(); - resetPosition(); - int i, j; - /* Start at 16 cells/loop for now. User can un-loop if more are needed */ for(i=0; iyield(); - if(stepFlag) { advancePosition(); @@ -562,10 +513,8 @@ redrawScreen(0); stepFlag=0; } - /* Prevent idle poweroff */ rb->reset_poweroff_timer(); - /* Code taken from Oscilloscope plugin */ switch(rb->button_get(false)) { @@ -580,7 +529,6 @@ rb->global_settings->volume = vol; } break; - case BTN_DOWN: case BTN_DOWN | BUTTON_REPEAT: vol = rb->global_settings->volume; @@ -591,7 +539,6 @@ rb->global_settings->volume = vol; } break; - case BTN_RIGHT: { //pressNote(9, 40, 127); @@ -602,10 +549,8 @@ redrawScreen(0); break; } - case BUTTON_LEFT: { - // isPlaying=1; resetPosition(); updateDisplay(); @@ -614,7 +559,6 @@ break; } */ - case BEATBOX_UP: case BEATBOX_UP | BUTTON_REPEAT: { @@ -630,7 +574,6 @@ } break; } - case BEATBOX_DOWN: case BEATBOX_DOWN | BUTTON_REPEAT: { @@ -646,7 +589,6 @@ } break; } - case BEATBOX_LEFT: case BEATBOX_LEFT | BUTTON_REPEAT: { @@ -661,7 +603,6 @@ } break; } - case BEATBOX_RIGHT: case BEATBOX_RIGHT | BUTTON_REPEAT: { @@ -676,7 +617,6 @@ } break; } - case BEATBOX_SELECT: { if(editState == EDITSTATE_PATTERN) @@ -685,16 +625,12 @@ cv++; if(cv > VAL_LOOP) cv = VAL_NONE; - trackData[xCursor][yCursor] = cv; - updateDisplay(); redrawScreen(0); } break; } - - case BEATBOX_PLAY: { if(playState == STATE_PLAYING) @@ -708,7 +644,6 @@ } break; } - case BEATBOX_STOP: { if(playState == STATE_STOPPED) @@ -724,10 +659,6 @@ break; } } - - } - return 0; } - Index: apps/plugins/beatbox/beatbox.make =================================================================== --- apps/plugins/beatbox/beatbox.make (revision 0) +++ apps/plugins/beatbox/beatbox.make (revision 0) @@ -0,0 +1,21 @@ +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# + +BEATBOXSRCDIR := $(APPSDIR)/plugins/beatbox +BEATBOXBUILDDIR := $(BUILDDIR)/apps/plugins/beatbox + +ROCKS += $(BEATBOXBUILDDIR)/beatbox.rock + +BEATBOX_SRC := $(call preprocess, $(BEATBOXSRCDIR)/SOURCES) +BEATBOX_OBJ := $(call c2obj, $(BEATBOX_SRC)) + +# add source files to OTHER_SRC to get automatic dependencies +OTHER_SRC += $(BEATBOX_SRC) + + +$(BEATBOXBUILDDIR)/beatbox.rock: $(BEATBOX_OBJ) Property changes on: apps/plugins/beatbox/beatbox.make ___________________________________________________________________ Added: svn:executable + * Index: apps/plugins/SUBDIRS =================================================================== --- apps/plugins/SUBDIRS (revision 20325) +++ apps/plugins/SUBDIRS (working copy) @@ -4,8 +4,8 @@ shortcuts /* For various targets... */ +#if CONFIG_RTC -#if CONFIG_RTC clock #endif @@ -43,7 +43,7 @@ /* For all the swcodec targets */ #if CONFIG_CODEC == SWCODEC midi -/* beatbox */ +beatbox #ifndef RB_PROFILE mpegplayer #endif