/* Luna Music Box v 1.0 (surely no one else is using that name right?) I made this program so my infant daughter could play music on my RetroGame 300. It plays music and says the names of the button colors as I have it set up. You should change out the sounds to play whatever you want. They are currently blank dummy files. If you try running the game with the dummy files, best case: it does nothing, worst case: it crashes? Program use instructions: First change out all the dummy sound files with your original sound files. That's the whole point of a customizeable music box player right? The sound files are all standard WAVs. The program mixes it to 22khz, but I don't think it matters much what the source music file is saved as. I haven't noticed any file length problems. Some songs I have are a couple of minutes long and some are 30 seconds are so. The menu sound effects are all a couple of seconds long as well as the welcome sound. MP3s are not supported in this version. Then put all that and the luna.dge file into a folder and put it on your SD card. Make a new program icon on your RetroGame or compatible system, and point it to the included luna.dge file. That's the actual compiled program that can be run by your hardware. This program will play sound effects when the ABXY buttons are pressed. They also change the screen color and open a new "menu" for the music that plays when the D-Pad is pressed. Press the same direction again on the D-Pad to stop the music. Since there are 4 direction buttons (for songs) and 4 action buttons (playing sound effects/changing menus), there are 16 different songs that can be played and 4 different sound effects plus the welcome sound. Those are the only buttons that function (besides screen brightness which is controlled by the hardware as I understand it) so that children won't accidentally close the program. It currently has no support for going to sleep, but I have considered adding that in. If I do, I'll release that code, too. When the program first starts, the screen will be black, and the menu will default to the blue menu. Playing a song will select something from the bluemusic files and pressing the ABXY buttons will light up the screen and change to the corresponding menu. This was a design decision to encourage my daughter to press both sets of buttons. Source code and licensing information (programming stuff): The libraries are standard C and Simple DirectMedia Layer 1.2 (SDL) which is available here: https://www.libsdl.org/ From what I found of the licensing for SDL 1.2, it's GPL and doesn't require any acknowledgements, but let's acknowledge it anyway for being nice software. My code is all released as Public Domain, you don't have to acknowledge me or my code either. Do whatever you want/can with it. I couldn't get SDL2 to work and had a hell of a time with SDL1. The toolchain for the RetroGame 300 is extremely fickle and my Linux VM had trouble linking libraries properly if not in the project source directory. I'm no pro, so you might get better results, but it works. Most of my linking troubles probably came from my poor makefile-fu. Additional info on my makefile (complaining about programming stuff): I HATE makefiles. I managed to get one put together that works, but I think the whole concept of makefiles is convoluted garbage. Why make a batchfile that requires learning a whole new programming language just to compile your program written in some other language. Did I mention I hate makefiles? */ // Library files #include "SDL.h" #include "SDL_mixer.h" #include #include #include #include // variables for tracking states of the menu etc. static bool running = true; int red; int green; int blue; int lastpress=0; int menucolor=1; // keeps track of which color menu is currently selected 1=blue 2=yellow 3=red 4=green //The music that will be played Mix_Music *bluemusic1 = NULL; Mix_Music *bluemusic2 = NULL; Mix_Music *bluemusic3 = NULL; Mix_Music *bluemusic4 = NULL; Mix_Music *redmusic1 = NULL; Mix_Music *redmusic2 = NULL; Mix_Music *redmusic3 = NULL; Mix_Music *redmusic4 = NULL; Mix_Music *greenmusic1 = NULL; Mix_Music *greenmusic2 = NULL; Mix_Music *greenmusic3 = NULL; Mix_Music *greenmusic4 = NULL; Mix_Music *yellowmusic1 = NULL; Mix_Music *yellowmusic2 = NULL; Mix_Music *yellowmusic3 = NULL; Mix_Music *yellowmusic4 = NULL; //The sound effects that will be used Mix_Chunk *bluesound = NULL; Mix_Chunk *redsound = NULL; Mix_Chunk *yellowsound = NULL; Mix_Chunk *greensound = NULL; Mix_Chunk *welcomesound = NULL; void clean_up() // This is basically here for if you decide to include a way to close the game. I just turn off the game and haven't had any problems yet. Nothing writes to the SD, only reads. These two sections below are the filenames with the ".wav" omitted. Just name your files "bluesound.wav", "bluemusic1.wav", etc. { Mix_FreeChunk( bluesound ); Mix_FreeChunk( redsound ); Mix_FreeChunk( yellowsound ); Mix_FreeChunk( greensound ); Mix_FreeChunk( welcomesound ); //Free the music Mix_FreeMusic( bluemusic1 ); Mix_FreeMusic( bluemusic2 ); Mix_FreeMusic( bluemusic3 ); Mix_FreeMusic( bluemusic4 ); Mix_FreeMusic( redmusic1 ); Mix_FreeMusic( redmusic2 ); Mix_FreeMusic( redmusic3 ); Mix_FreeMusic( redmusic4 ); Mix_FreeMusic( greenmusic1 ); Mix_FreeMusic( greenmusic2 ); Mix_FreeMusic( greenmusic3 ); Mix_FreeMusic( greenmusic4 ); Mix_FreeMusic( yellowmusic1 ); Mix_FreeMusic( yellowmusic2 ); Mix_FreeMusic( yellowmusic3 ); Mix_FreeMusic( yellowmusic4 ); //Quit SDL_mixer Mix_CloseAudio(); //Quit SDL SDL_Quit(); } int main(int argc, char **argv) // main loop as far as C is concerned { (void)argv; (void)argc; SDL_Surface *screen = SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE); // setting up the screen SDL_Init(SDL_INIT_VIDEO); // using the set up screen SDL_ShowCursor(SDL_DISABLE); Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096); // setting up audio atexit(clean_up); // again, just for in case you want to provide a button for exiting the game //Load the music bluemusic1 = Mix_LoadMUS( "bluemusic1.wav" ); bluemusic2 = Mix_LoadMUS( "bluemusic2.wav" ); bluemusic3 = Mix_LoadMUS( "bluemusic3.wav" ); bluemusic4 = Mix_LoadMUS( "bluemusic4.wav" ); redmusic1 = Mix_LoadMUS( "redmusic1.wav" ); redmusic2 = Mix_LoadMUS( "redmusic2.wav" ); redmusic3 = Mix_LoadMUS( "redmusic3.wav" ); redmusic4 = Mix_LoadMUS( "redmusic4.wav" ); greenmusic1 = Mix_LoadMUS( "greenmusic1.wav" ); greenmusic2 = Mix_LoadMUS( "greenmusic2.wav" ); greenmusic3 = Mix_LoadMUS( "greenmusic3.wav" ); greenmusic4 = Mix_LoadMUS( "greenmusic4.wav" ); yellowmusic1 = Mix_LoadMUS( "yellowmusic1.wav" ); yellowmusic2 = Mix_LoadMUS( "yellowmusic2.wav" ); yellowmusic3 = Mix_LoadMUS( "yellowmusic3.wav" ); yellowmusic4 = Mix_LoadMUS( "yellowmusic4.wav" ); //Load the sound effects redsound = Mix_LoadWAV( "redsound.wav" ); bluesound = Mix_LoadWAV( "bluesound.wav" ); yellowsound = Mix_LoadWAV( "yellowsound.wav" ); greensound = Mix_LoadWAV( "greensound.wav" ); welcomesound = Mix_LoadWAV( "welcomesound.wav" ); Mix_PlayChannel(-1, welcomesound, 0); // play the welcome sound once at game load while (running) { // my actual main loop for checking buttons and playing music SDL_Event event; // checking for button presses while (SDL_PollEvent(&event)) { SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, red, green, blue)); SDL_UpdateRect(screen, 0,0,0,0); switch(event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_LEFT: // dpad left //If there is no music playing if( Mix_PlayingMusic() == 1 && lastpress == 1 ) { Mix_HaltMusic(); lastpress=0; } else if( Mix_PlayingMusic() == 0 ) { switch(menucolor){ // play the correct song number 1 depending on the color of the menu. The default menu at the black inital startup screen is the blue menu case 1: //Play the music Mix_PlayMusic(bluemusic1, 0); break; case 2: Mix_PlayMusic(yellowmusic1, 0); break; case 3: Mix_PlayMusic(redmusic1, 0); break; case 4: Mix_PlayMusic(greenmusic1, 0); break; } lastpress=1; } break; case SDLK_RIGHT: // dpad right //If there is no music playing if( Mix_PlayingMusic() == 1 && lastpress == 2 ) { Mix_HaltMusic(); lastpress=0; } else if( Mix_PlayingMusic() == 0 ) { //Play the music switch(menucolor){ case 1: //Play the music #2 depending on menu color Mix_PlayMusic(bluemusic2, 0); break; case 2: Mix_PlayMusic(yellowmusic2, 0); break; case 3: Mix_PlayMusic(redmusic2, 0); break; case 4: Mix_PlayMusic(greenmusic2, 0); break; } lastpress=2; } break; case SDLK_UP: // dpad up //If there is no music playing if( Mix_PlayingMusic() == 1 && lastpress == 3 ) { Mix_HaltMusic(); lastpress=0; } else if( Mix_PlayingMusic() == 0 ) { //Play the music switch(menucolor){ case 1: //Play the music Mix_PlayMusic(bluemusic3, 0); break; case 2: Mix_PlayMusic(yellowmusic3, 0); break; case 3: Mix_PlayMusic(redmusic3, 0); break; case 4: Mix_PlayMusic(greenmusic3, 0); break; } lastpress=3; } break; case SDLK_DOWN: // dpad down //If there is no music playing if( Mix_PlayingMusic() == 1 && lastpress == 4 ) { Mix_HaltMusic(); lastpress=0; } else if( Mix_PlayingMusic() == 0 ) { //Play the music switch(menucolor){ case 1: //Play the music Mix_PlayMusic(bluemusic4, 0); break; case 2: Mix_PlayMusic(yellowmusic4, 0); break; case 3: Mix_PlayMusic(redmusic4, 0); break; case 4: Mix_PlayMusic(greenmusic4, 0); break; } lastpress=4; } break; case SDLK_SPACE: // x button menucolor=1; // 1=blue ... If you have different color buttons or just want different color menus, change these RGB values to the colors you want. red=0; green=0; blue=255; Mix_PlayChannel(-1, bluesound, 0); break; case SDLK_ESCAPE: // select button // exit(1); break; case SDLK_TAB: // left shoulder button break; case SDLK_BACKSPACE: // right shoulder button break; case SDLK_RETURN: // start button break; case SDLK_LALT: // b button menucolor=2; //2=yellow red=255; green=255; blue=0; Mix_PlayChannel(-1, yellowsound, 0); break; case SDLK_LCTRL: // a button menucolor=3; //3=red red=255; green=0; blue=0; Mix_PlayChannel(-1, redsound, 0); break; case SDLK_LSHIFT: // y button menucolor=4; //4=green red=0; green=255; blue=25; Mix_PlayChannel(-1, greensound, 0); break; default: break; } break; case SDL_QUIT: // last case of an exit scheme that just needs to be programmed to a button running = false; break; default: break; } } } return 0; } // That's it. Very simple. Play a sound, set the screen to a color, and change to a different menu. It's just a music box after all.