#include "sound_control.h" /** \brief Handles input events */ void handleKey(SDL_KeyboardEvent key) { SoundControl* sound = SoundControl::getInstance(); switch(key.keysym.sym) { case SDLK_a: if(key.type == SDL_KEYDOWN) { if(sound->sfx_channel1 < 0) { sound->sfx_channel1 = 1; sound->playWav("sound1.wav"); } } else { Mix_HaltChannel(sound->sfx_channel1); sound->sfx_channel1 = -1; } break; case SDLK_s: if(key.type == SDL_KEYDOWN) { if(sound->sfx_channel2 < 0) { sound->sfx_channel2 = 1; sound->playWav("sound2.wav"); } } else { Mix_HaltChannel(sound->sfx_channel2); sound->sfx_channel2 = -1; } break; case SDLK_m: if(key.state == SDL_PRESSED) { sound->playOgg("music.ogg"); } break; case SDLK_q: sound->finished = 1; break; default: break; } } int main(int argc, char* argv[]) { SDL_Surface* screen; SDL_Event event; SoundControl* soundControl = SoundControl::getInstance(); SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO); screen = SDL_SetVideoMode(320, 240, 0, 0); while(!soundControl->finished) { while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: soundControl->finished = 1; break; case SDL_KEYDOWN: case SDL_KEYUP: handleKey(event.key); break; default: break; } } SDL_Delay(50); } delete SoundControl::getInstance(); SDL_Quit(); return 0; }