Index: apps/plugins/CATEGORIES =================================================================== --- apps/plugins/CATEGORIES (revision 20874) +++ apps/plugins/CATEGORIES (working copy) @@ -19,6 +19,7 @@ dict,apps disktidy,apps doom,games +drumkit,apps euroconverter,apps fire,demos fireworks,demos Index: apps/plugins/SOURCES =================================================================== --- apps/plugins/SOURCES (revision 20874) +++ apps/plugins/SOURCES (working copy) @@ -127,6 +127,7 @@ #endif /* HAVE_LCD_CHARCELLS */ #if CONFIG_CODEC == SWCODEC /* software codec platforms */ +drumkit.c mp3_encoder.c wav2wv.c #else /* hardware codec platforms */ Index: apps/plugins/drumkit.c =================================================================== --- apps/plugins/drumkit.c (revision 0) +++ apps/plugins/drumkit.c (revision 0) @@ -0,0 +1,305 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2009 Marc Guay + * + * 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. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "plugin.h" + +PLUGIN_HEADER + +#if (HW_SAMPR_CAPS & SAMPR_CAP_22) + #define SAMPLE_RATE SAMPR_22 /* 44100 22050 11025 */ +#else + #define SAMPLE_RATE SAMPR_44 /* 44100 22050 11025 */ +#endif + +#define SAMPLE_1 BUTTON_UP +#define SAMPLE_2 BUTTON_DOWN +#define SAMPLE_3 BUTTON_LEFT +#define SAMPLE_4 BUTTON_RIGHT +#define SAMPLE_5 BUTTON_SELECT +#define QUIT BUTTON_POWER + +#if CONFIG_KEYPAD == SANSA_E200_PAD + + #define VOLUME_UP BUTTON_SCROLL_FWD + #define VOLUME_DOWN BUTTON_SCROLL_BACK + +#elif CONFIG_KEYPAD == SANSA_C200_PAD + + #define VOLUME_UP BUTTON_VOL_UP + #define VOLUME_DOWN BUTTON_VOL_DOWN + +#endif + /*#define BUTTON_REC */ + + + +int quit = 0; +int raw_file = 0; + +char audio_buffer[5][100000]; + +char str_buffer[255]; +char arr_filenames[5][255]; + +char *drum_dir = "/.rockbox/rocks/apps/drumkit/"; + +/* Function Prototypes */ +int drumkit_main(void); +bool find_raw_files(void); +void change_volume(int delta); +void draw_display(void); +void drumkit_draw(struct screen* display); +bool is_raw_file(const char* file); +void load_to_mem(void); + +/* Plugin entry point */ +enum plugin_status plugin_start(const void* file){ + + (void)file; + int retval = 0; + + /* Prevent idle poweroff */ + rb->reset_poweroff_timer(); + +#if defined(HAVE_ADJUSTABLE_CPU_FREQ) + rb->cpu_boost(true); +#endif + + rb->pcm_play_stop(); + +#if INPUT_SRC_CAPS != 0 + /* Select playback */ + rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); + /* Recordable targets can play back from other sources */ + rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); +#endif + rb->pcm_set_frequency(SAMPLE_RATE); /* 44100 22050 11025 */ + + if (!find_raw_files()){ + rb->splash(200, "Dir not found"); + return PLUGIN_OK; + } + + load_to_mem(); + + draw_display(); + + /* Main program loop */ + retval = drumkit_main(); + + /* Wind down */ + 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; /* End */ +} + + +bool find_raw_files(){ + + DIR* dir = NULL; + struct dirent* entry = NULL; + int i = 0; + + dir = rb->opendir(drum_dir); + + if(!dir) /* Directory doesn't exist -> TODO: create it otherwise? */ + return false; + + /* loop all files in the dir */ + while((entry = rb->readdir(dir)) != 0){ + + if (is_raw_file(entry->d_name)){ + + /* Store the filenames in an array */ + rb->strcpy(arr_filenames[i], entry->d_name); + i++; + } + } + + rb->closedir(dir); + return true; +} + +bool is_raw_file(const char* file) { + + char *extension = rb->strrchr(file, '.'); + + if (!rb->strcasecmp(extension, ".raw")) + return true; + else + return false; +} + +void load_to_mem(){ + + int j; + + for (j = 0; j < 5; j++){ + + // Write the drum_dir & filename to the str_buffer string + rb->snprintf(str_buffer, sizeof(str_buffer), "%s/%s", + drum_dir, arr_filenames[j]); + + // Open the file + raw_file = rb->open(str_buffer, O_RDONLY); + + rb->read(raw_file, audio_buffer[j], sizeof(audio_buffer[j])); + + rb->close(raw_file); + } +} + +void play_sample(int i){ + + rb->pcm_play_data(NULL,audio_buffer[i],sizeof(audio_buffer[i])); + +} + +/* helper function to change the volume by a certain amount, +/- + ripped from video.c */ +void change_volume(int delta){ + + int minvol = rb->sound_min(SOUND_VOLUME); + int maxvol = rb->sound_max(SOUND_VOLUME); + int vol = rb->global_settings->volume + delta; + + if (vol > maxvol) + vol = maxvol; + else if (vol < minvol) + vol = minvol; + + if (vol != rb->global_settings->volume) { + + rb->sound_set(SOUND_VOLUME, vol); + rb->global_settings->volume = vol; + draw_display(); + } +} + +void draw_display(void) +{ + int i; + FOR_NB_SCREENS(i) + drumkit_draw(rb->screens[i]); +} + +void drumkit_draw(struct screen* display){ + + display->clear_display(); + display->puts(0, 0, "Drumkit"); + rb->snprintf(str_buffer, sizeof(str_buffer), "Vol: %d", + rb->global_settings->volume); + display->puts(0, 1, str_buffer); + + // SAMPLE_1 -> UP + rb->snprintf(str_buffer, sizeof(str_buffer), "Up: %s", arr_filenames[0]); + display->puts(0, 3, str_buffer); + + // SAMPLE_2 -> DOWN + rb->snprintf(str_buffer, sizeof(str_buffer), "Down: %s", arr_filenames[1]); + display->puts(0, 4, str_buffer); + + // SAMPLE_3 -> LEFT + rb->snprintf(str_buffer, sizeof(str_buffer), "Left: %s", arr_filenames[2]); + display->puts(0, 5, str_buffer); + + // SAMPLE_4 -> RIGHT + rb->snprintf(str_buffer, sizeof(str_buffer), "Right: %s", arr_filenames[3]); + display->puts(0, 6, str_buffer); + + // SAMPLE_5 - > MIDDLE + rb->snprintf(str_buffer, sizeof(str_buffer), "Select: %s", arr_filenames[4]); + display->puts(0, 7, str_buffer); + + display->update(); +} + + +int drumkit_main(){ + + while(!quit){ + + rb->yield(); + + switch(rb->button_get(false)){ + + case SAMPLE_1: + case SAMPLE_1 | BUTTON_REPEAT: + { + play_sample(0); + break; + } + + case SAMPLE_2: + case SAMPLE_2 | BUTTON_REPEAT: + { + play_sample(1); + break; + } + + case SAMPLE_3: + case SAMPLE_3 | BUTTON_REPEAT: + { + play_sample(2); + break; + } + + case SAMPLE_4: + case SAMPLE_4 | BUTTON_REPEAT: + { + play_sample(3); + break; + } + + case SAMPLE_5: + { + play_sample(4); + break; + } + + case VOLUME_UP: + case VOLUME_UP | BUTTON_REPEAT: + { + change_volume(1); + break; + } + case VOLUME_DOWN: + case VOLUME_DOWN | BUTTON_REPEAT: + { + change_volume(-1); + break; + } + + case QUIT: + { + quit = 1; + break; + } + } + } + return 0; +} Property changes on: apps/plugins/drumkit.c ___________________________________________________________________ Added: svn:executable + * Added: svn:keywords + Author Id Date Revision