/* * PlayMidiRsc: Play MIDI file associated with given resource number. */ void PlayMidiRsc(ID rsc) { debug(("PlayMidiRsc %d\n", rsc)); if (!config.play_music || !has_midi) return; if (playing_music) { PauseMusic(); playing_midi = True; /* Don't let music start */ #ifndef M59_MSS mciSendCommand(midi_element, MCI_CLOSE, 0, 0); #endif PostMessage(hMain, BK_NEWSOUND, SOUND_MIDI, rsc); return; } #ifndef M59_MSS /* If sound is already going, stop it and prepare to start new one */ if (playing_midi) { mciSendCommand(midi_element, MCI_CLOSE, 0, 0); PostMessage(hMain, BK_NEWSOUND, SOUND_MIDI, rsc); return; } #endif NewMusic(SOUND_MIDI, rsc); }
static void CheckCheats(void) { if ((NewJoyPadButtons & PadStart) && !(players.AutomapFlags & AF_OPTIONSACTIVE)) { /* Pressed pause? */ if (gamepaused || !(JoyPadButtons&PadUse)) { gamepaused ^= 1; /* Toggle the pause flag */ if (gamepaused) { PauseMusic(); } else { ResumeMusic(); } } } }
void Mixer::LoadMusic(std::string const & filename) { if (theBgMusic) { LOG_DEBUG() << "Changing BG music to:" << filename; if (1 == Mix_PlayingMusic()) { // Stop music that is already playing PauseMusic(); } } else { LOG_DEBUG() << "Loading BG music:" << filename; } std::map<std::string, Mix_Music*>::const_iterator cachedSong = theMusicCatalog.find(filename); if (cachedSong == theMusicCatalog.end()) { // Song has not been loaded before theBgMusic = Mix_LoadMUS(filename.c_str()); if (theBgMusic == nullptr) { LOG_WARNING() << "Error loading BG Music (" << filename << "): " << Mix_GetError(); } else { theMusicCatalog[filename] = theBgMusic; } } else { // We already had this song in our cache songs! LOG_DEBUG() << "Loading song from cache:" << filename; theBgMusic = (cachedSong->second); } }
int SDLU_EventFilter( const SDL_Event *event ) { switch( event->type ) { // Put keydowns in a buffer case SDL_KEYDOWN: if( s_interestedInTyping && event->key.keysym.sym < 300 && s_keyBufferFilled < sizeof(s_keyBufferASCII) ) { s_keyBufferFilled++; s_keyBufferASCII[s_keyBufferPutAt] = event->key.keysym.unicode; s_keyBufferSDL [s_keyBufferPutAt] = event->key.keysym.sym; s_keyBufferPutAt = (s_keyBufferPutAt + 1) % sizeof(s_keyBufferASCII); } if( ((event->key.keysym.sym == SDLK_F4) && (event->key.keysym.mod & (KMOD_LALT | KMOD_RALT))) || ((event->key.keysym.sym == SDLK_q) && (event->key.keysym.mod & (KMOD_LMETA | KMOD_RMETA))) ) { finished = true; } break; case SDL_MOUSEBUTTONDOWN: if( event->button.button == SDL_BUTTON_LEFT ) s_mouseButton = true; s_mousePosition.y = event->button.y; s_mousePosition.x = event->button.x; break; case SDL_MOUSEBUTTONUP: if( event->button.button == SDL_BUTTON_LEFT ) s_mouseButton = false; s_mousePosition.y = event->button.y; s_mousePosition.x = event->button.x; break; case SDL_MOUSEMOTION: s_mousePosition.y = event->motion.y; s_mousePosition.x = event->motion.x; s_mouseButton = event->motion.state & SDL_BUTTON(1); break; case SDL_QUIT: finished = true; break; // Handle gaining and losing focus (kind of cheesy) case SDL_ACTIVEEVENT: if( (event->active.state & SDL_APPINPUTFOCUS) ) { if( !event->active.gain && s_isForeground ) { FreezeGameTickCount(); PauseMusic(); s_isForeground = false; } else if( event->active.gain && !s_isForeground ) { UnfreezeGameTickCount(); ResumeMusic(); s_isForeground = true; DoFullRepaint(); } } break; } return 0; }
int main(int argc, char *argv[]) { // Initialize the SDL library // This is required to avoid _main errors at runtime. #ifdef UseSDLMixer if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { #else if ( SDL_Init(SDL_INIT_VIDEO ) < 0 ) { #endif fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } // Init SDL_Image - only applies above 1.2.7 // load support for the JPG and PNG image formats int IMGflags=IMG_INIT_JPG|IMG_INIT_PNG; int initted=IMG_Init(IMGflags); if(initted && IMGflags != IMGflags) { printf("IMG_Init: Failed to init required jpg and png support!\n"); printf("IMG_Init: %s\n", IMG_GetError()); // handle error } #ifdef UseSDLMixer // Initialize SDL mixer. if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) != 0) { fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError()); exit(1); } #endif // Retrieve display gamma for reference in fade in/fade out routines. SDL_GetGammaRamp(redGamma, greenGamma, blueGamma); // printf("%u", *redGamma); Initialize( ); LoadPrefs( ); ReserveMonitor( ); ShowTitle( ); ChooseMusic( 13 ); while( !finished ) { if( showStartMenu ) { GameStartMenu( ); showStartMenu = false; } if( !finished ) { DoFullRepaint = NeedRefresh; CheckKeys( ); HandlePlayers( ); UpdateOpponent( ); UpdateBalloon( ); UpdateSound( ); DoFullRepaint = NoPaint; if( needsRefresh ) { RefreshAll(); needsRefresh = false; } if( !showStartMenu && pauseKey ) { FreezeGameTickCount( ); PauseMusic( ); MaskRect( &playerWindowRect[0] ); MaskRect( &playerWindowRect[1] ); WaitForRelease( ); HandleDialog( kPauseDialog ); WaitForRelease( ); RefreshPlayerWindow( 0 ); RefreshPlayerWindow( 1 ); ResumeMusic( ); UnfreezeGameTickCount( ); } } } SavePrefs( ); ReleaseMonitor( ); return 0; } void NoPaint( void ) { } void MaskRect( MRect *r ) { SDL_Rect sdlRect; SDLU_MRectToSDLRect( r, &sdlRect ); SDLU_BlitFrontSurface( backdropSurface, &sdlRect, &sdlRect ); }
void CSoundManager::Pause(bool pauseIt) { PauseMusic(pauseIt); PauseAmbient(pauseIt); PauseAction(pauseIt); }