void SdlAudio::BGM_Play(std::string const& file, int volume, int /* pitch */, int fadein) { if (file.empty() || file == "(OFF)") { BGM_Stop(); return; } std::string const path = FileFinder::FindMusic(file); if (path.empty()) { //HACK: Polish RTP translation replaced (OFF) reserved string with (Brak) if (file != "(Brak)") Output::Warning("Music not found: %s", file.c_str()); BGM_Stop(); return; } SDL_RWops *rw = SDL_RWFromFile(path.c_str(), "rb"); #if SDL_MIXER_MAJOR_VERSION>1 bgm.reset(Mix_LoadMUS_RW(rw, 1), &Mix_FreeMusic); #else bgm.reset(Mix_LoadMUS_RW(rw), &Mix_FreeMusic); #endif if (!bgm) { Output::Warning("Couldn't load %s BGM.\n%s\n", file.c_str(), Mix_GetError()); return; } #if SDL_MAJOR_VERSION>1 // SDL2_mixer produces noise when playing wav. // Workaround: Use Mix_LoadWAV // https://bugzilla.libsdl.org/show_bug.cgi?id=2094 if (bgs_playing) { BGS_Stop(); } if (Mix_GetMusicType(bgm.get()) == MUS_WAV) { BGM_Stop(); BGS_Play(file, volume, 0, fadein); return; } #endif BGM_Volume(volume); if (!me_stopped_bgm && #ifdef _WIN32 (Mix_GetMusicType(bgm.get()) == MUS_MID && WindowsUtils::GetWindowsVersion() >= 6 ? Mix_PlayMusic(bgm.get(), -1) : Mix_FadeInMusic(bgm.get(), -1, fadein)) #else Mix_FadeInMusic(bgm.get(), -1, fadein) #endif == -1) { Output::Warning("Couldn't play %s BGM.\n%s\n", file.c_str(), Mix_GetError()); return; } }
/** * Play the intro. */ void IntroState::init() { State::init(); Options::keepAspectRatio = _wasLetterBoxed; if (CrossPlatform::fileExists(_introFile) && (CrossPlatform::fileExists(_introSoundFileDOS) || CrossPlatform::fileExists(_introSoundFileWin))) { audioSequence = new AudioSequence(_game->getResourcePack()); Flc::flc.realscreen = _game->getScreen(); Flc::FlcInit(_introFile.c_str()); Flc::flc.dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2; Flc::flc.dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2; Flc::flc.loop = 0; // just the one time, please Flc::FlcMain(&audioHandler); Flc::FlcDeInit(); delete audioSequence; #ifndef __NO_MUSIC // fade out! Mix_FadeOutChannel(-1, 45 * 20); if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(45 * 20); func_fade(); } // SDL_Mixer has trouble with native midi and volume on windows, which is the most likely use case, so f@%# it. else { Mix_HaltMusic(); } #endif SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = 20; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; pal2[color].unused = pal[color].unused; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(45); } _game->getScreen()->clear(); _game->getScreen()->flip(); Options::musicVolume = _oldMusic; Options::soundVolume = _oldSound; _game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume); #ifndef __NO_MUSIC Sound::stop(); Music::stop(); #endif } Screen::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true); _game->getScreen()->resetDisplay(false); _game->setState(new MainMenuState); }
void SdlAudio::BGM_Resume() { #if SDL_MAJOR_VERSION>1 // SDL2_mixer bug, see above if (Mix_GetMusicType(bgm.get()) == MUS_WAV) { BGS_Resume(); return; } #endif Mix_ResumeMusic(); }
void PGE_MusPlayer::MUS_openFile(QString musFile) { if(current==musFile) { #ifdef USE_SDL_MIXER if(Mix_PlayingMusic()==1) return; #endif } #ifdef USE_QMEDIAPLAYER if(musicPlayer!=NULL) { musicPlayer->stop(); delete musicPlayer; delete playList; isMediaPlayer=false; } musicPlayer = new QMediaPlayer(); playList = new QMediaPlaylist(); playList->clear(); playList->addMedia(QUrl::fromLocalFile( musFile )); playList->setPlaybackMode(QMediaPlaylist::Loop); musicPlayer->setPlaylist(playList); current = musFile; #elif USE_SDL_MIXER if(play_mus!=NULL) { Mix_HaltMusic(); Mix_FreeMusic(play_mus); play_mus=NULL; } play_mus = Mix_LoadMUS( musFile.toUtf8() ); if(!play_mus) qDebug() << QString("Mix_LoadMUS(\"%1\"): %2").arg(musFile).arg(Mix_GetError()); else current = musFile; Mix_MusicType type=Mix_GetMusicType(play_mus); qDebug() << QString("Music type: %1").arg( type==MUS_NONE?"MUS_NONE": type==MUS_CMD?"MUS_CMD": type==MUS_WAV?"MUS_WAV": /*type==MUS_MOD_MODPLUG?"MUS_MOD_MODPLUG":*/ type==MUS_MOD?"MUS_MOD": type==MUS_MID?"MUS_MID": type==MUS_OGG?"MUS_OGG": type==MUS_MP3?"MUS_MP3": type==MUS_MP3_MAD?"MUS_MP3_MAD": type==MUS_FLAC?"MUS_FLAC": type==9?"MUS_SPC": "Unknown"); #endif }
void SdlAudio::BGM_Pause() { // Midi pause is not supported... (for some systems -.-) #if SDL_MAJOR_VERSION>1 // SDL2_mixer bug, see above if (Mix_GetMusicType(bgm.get()) == MUS_WAV) { BGS_Pause(); return; } #endif Mix_PauseMusic(); }
/** * Pauses music playback when game loses focus. */ void Music::pause() { #ifndef __NO_MUSIC if (!Options::mute) { Mix_PauseMusic(); if (Mix_GetMusicType(0) == MUS_NONE) Mix_HookMusic(NULL, NULL); } #endif }
/** * Resumes music playback when game gains focus. */ void Music::resume() { #ifndef __NO_MUSIC if (!Options::mute) { Mix_ResumeMusic(); if (Mix_GetMusicType(0) == MUS_NONE) Mix_HookMusic(AdlibMusic::player, NULL); } #endif }
void SdlAudio::BGM_Stop() { #if SDL_MAJOR_VERSION>1 // SDL2_mixer bug, see above if (Mix_GetMusicType(bgm.get()) == MUS_WAV) { BGS_Stop(); return; } #endif Mix_HaltMusic(); me_stopped_bgm = false; }
void snd_free_mus(mus_t mus) { int to_close = 0; if (!sound_on) return; if (!mus) return; Mix_HaltMusic(); if (mus->mus) { #ifdef _SDL_MOD_BUG if ((Mix_GetMusicType(mus->mus) == MUS_MOD) && !MIXER_VERSION_ATLEAST(1, 2, 12)) SDL_RWclose(mus->rw); #endif if (MIXER_VERSION_ATLEAST(1, 2, 12) && Mix_GetMusicType(mus->mus) != MUS_MP3) { to_close = 1; } Mix_FreeMusic((Mix_Music*) mus->mus); if (to_close) SDL_RWclose(mus->rw); } free(mus); }
void SdlAudio::BGM_Fade(int fade) { #ifdef _WIN32 // FIXME: Because of design change in Vista and higher reducing Midi volume // alters volume of whole application and mutes it forever when restarted. // Fading out midi music was disabled for Windows. if (Mix_GetMusicType(bgm.get()) == MUS_MID && WindowsUtils::GetWindowsVersion() >= 6) { BGM_Stop(); return; } #endif Mix_FadeOutMusic(fade); me_stopped_bgm = false; }
void MUS_openFile(QString musFile) { if(play_mus!=NULL) {Mix_FreeMusic(play_mus);play_mus=NULL;} play_mus = Mix_LoadMUS( musFile.toUtf8() ); if(!play_mus) { error(QString("Mix_LoadMUS(\"%1\"): %2").arg(musFile).arg(Mix_GetError())); } Mix_MusicType type=Mix_GetMusicType(play_mus); qDebug() << QString("Music type: %1").arg( type==MUS_NONE?"MUS_NONE": type==MUS_CMD?"MUS_CMD": type==MUS_WAV?"MUS_WAV": /*type==MUS_MOD_MODPLUG?"MUS_MOD_MODPLUG":*/ type==MUS_MOD?"MUS_MOD": type==MUS_MID?"MUS_MID": type==MUS_OGG?"MUS_OGG": type==MUS_MP3?"MUS_MP3": type==MUS_MP3_MAD?"MUS_MP3_MAD": type==MUS_FLAC?"MUS_FLAC": "Unknown"); }
/** * Play the intro. */ void IntroState::init() { State::init(); Options::keepAspectRatio = _wasLetterBoxed; if (CrossPlatform::fileExists(_introFile) && (CrossPlatform::fileExists(_introSoundFileDOS) || CrossPlatform::fileExists(_introSoundFileWin))) { audioSequence = new AudioSequence(_game->getResourcePack()); Flc::flc.realscreen = _game->getScreen(); Flc::FlcInit(_introFile.c_str()); Flc::flc.dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2; Flc::flc.dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2; Flc::flc.loop = 0; // just the one time, please Flc::FlcMain(&audioHandler); Flc::FlcDeInit(); delete audioSequence; #ifndef __NO_MUSIC // fade out! Mix_FadeOutChannel(-1, 45 * 20); if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(45 * 20); func_fade(); } // SDL_Mixer has trouble with native midi and volume on windows, which is the most likely use case, so f@%# it. else { Mix_HaltMusic(); } #endif SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = 20; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; pal2[color].a = 255; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(45); } _game->getScreen()->clear(); _game->getScreen()->flip(); Options::musicVolume = _oldMusic; Options::soundVolume = _oldSound; _game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume); #ifndef __NO_MUSIC Sound::stop(); Music::stop(); #endif } // FIXME: This should go to the Game.cpp probably #ifdef __ANDROID__ // We don't need to process mouse events, so we can probably save some cycles on it SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); SDL_EventState(SDL_MOUSEBUTTONDOWN, SDL_IGNORE); SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE); SDL_EventState(SDL_MOUSEWHEEL, SDL_IGNORE); // We're not really using the Dollar Gesture events either SDL_EventState(SDL_DOLLARGESTURE, SDL_IGNORE); SDL_EventState(SDL_DOLLARRECORD, SDL_IGNORE); #endif Screen::updateScale(Options::geoscapeScale, Options::geoscapeScale, Options::baseXGeoscape, Options::baseYGeoscape, true); _game->getScreen()->resetDisplay(false); _game->setState(new MainMenuState); }
void VideoState::init() { State::init(); bool wasLetterboxed = CutsceneState::initDisplay(); bool ufoIntroSoundFileDosExists = false; bool ufoIntroSoundFileWinExists = false; int prevMusicVol = Options::musicVolume; int prevSoundVol = Options::soundVolume; if (_useUfoAudioSequence) { const std::set<std::string> &soundDir = FileMap::getVFolderContents("SOUND"); ufoIntroSoundFileDosExists = soundDir.end() != soundDir.find("intro.cat"); ufoIntroSoundFileWinExists = soundDir.end() != soundDir.find("sample3.cat"); if (!ufoIntroSoundFileDosExists && !ufoIntroSoundFileWinExists) { _useUfoAudioSequence = false; } else { // ensure user can hear both music and sound effects for the // vanilla intro sequence Options::musicVolume = Options::soundVolume = std::max(prevMusicVol, prevSoundVol); _game->setVolume(Options::soundVolume, Options::musicVolume, -1); } } _game->getCursor()->setVisible(false); int dx = (Options::baseXResolution - Screen::ORIGINAL_WIDTH) / 2; int dy = (Options::baseYResolution - Screen::ORIGINAL_HEIGHT) / 2; FlcPlayer *flcPlayer = NULL; for (std::vector<std::string>::const_iterator it = _videos->begin(); it != _videos->end(); ++it) { std::string videoFileName = FileMap::getFilePath(*it); if (!CrossPlatform::fileExists(videoFileName)) { continue; } if (!flcPlayer) { flcPlayer = new FlcPlayer(); } if (_useUfoAudioSequence) { audioSequence = new AudioSequence(_game->getMod(), flcPlayer); } flcPlayer->init(videoFileName.c_str(), _useUfoAudioSequence ? &audioHandler : NULL, _game, dx, dy); flcPlayer->play(_useUfoAudioSequence); if (_useUfoAudioSequence) { flcPlayer->delay(10000); delete audioSequence; audioSequence = NULL; } flcPlayer->deInit(); if (flcPlayer->wasSkipped()) { break; } } if (flcPlayer) { delete flcPlayer; } // We can only do a fade out in 8bpp, otherwise instantly end it bool fade = (_game->getScreen()->getSurface()->getSurface()->format->BitsPerPixel == 8); const int FADE_DELAY = 45; const int FADE_STEPS = 20; #ifndef __NO_MUSIC // fade out! if (fade) { Mix_FadeOutChannel(-1, FADE_DELAY * FADE_STEPS); // SDL_Mixer has trouble with native midi and volume on windows, // which is the most likely use case, so f@%# it. if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(FADE_DELAY * FADE_STEPS); func_fade(); } else { Mix_HaltMusic(); } } else { Mix_HaltChannel(-1); Mix_HaltMusic(); } #endif if (fade) { SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = FADE_STEPS; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; pal2[color].unused = pal[color].unused; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(FADE_DELAY); } } _game->getScreen()->clear(); _game->getScreen()->flip(); if (_useUfoAudioSequence) { Options::musicVolume = prevMusicVol; Options::soundVolume = prevSoundVol; _game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume); } #ifndef __NO_MUSIC Sound::stop(); Music::stop(); #endif _game->getCursor()->setVisible(true); CutsceneState::resetDisplay(wasLetterboxed); _game->popState(); }
int main(int argc, char **argv) { int audio_rate,audio_channels; Uint16 audio_format; Uint32 t; Mix_Music *music; int volume=SDL_MIX_MAXVOLUME; /* initialize SDL for audio and video */ if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO)<0) cleanExit("SDL_Init"); atexit(SDL_Quit); int initted=Mix_Init(0); printf("Before Mix_Init SDL_mixer supported: "); print_init_flags(initted); initted=Mix_Init(~0); printf("After Mix_Init SDL_mixer supported: "); print_init_flags(initted); Mix_Quit(); if(argc<2 || argc>4) { fprintf(stderr,"Usage: %s filename [depth] [any 3rd argument...]\n" " filename is any music file supported by your SDL_mixer library\n" " depth is screen depth, default is 8bits\n" " if there is a third argument given, we go fullscreen for maximum fun!\n", *argv); return 1; } /* open a screen for the wav output */ if(!(s=SDL_SetVideoMode(W,H,(argc>2?atoi(argv[2]):8),(argc>3?SDL_FULLSCREEN:0)|SDL_HWSURFACE|SDL_DOUBLEBUF))) cleanExit("SDL_SetVideoMode"); SDL_WM_SetCaption("sdlwav - SDL_mixer demo","sdlwav"); /* hide the annoying mouse pointer */ SDL_ShowCursor(SDL_DISABLE); /* get the colors we use */ white=SDL_MapRGB(s->format,0xff,0xff,0xff); black=SDL_MapRGB(s->format,0,0,0); /* initialize sdl mixer, open up the audio device */ if(Mix_OpenAudio(44100,MIX_DEFAULT_FORMAT,2,BUFFER)<0) cleanExit("Mix_OpenAudio"); /* we play no samples, so deallocate the default 8 channels... */ Mix_AllocateChannels(0); /* print out some info on the formats this run of SDL_mixer supports */ { int i,n=Mix_GetNumChunkDecoders(); printf("There are %d available chunk(sample) decoders:\n",n); for(i=0; i<n; ++i) printf(" %s\n", Mix_GetChunkDecoder(i)); n = Mix_GetNumMusicDecoders(); printf("There are %d available music decoders:\n",n); for(i=0; i<n; ++i) printf(" %s\n", Mix_GetMusicDecoder(i)); } /* print out some info on the audio device and stream */ Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels); bits=audio_format&0xFF; sample_size=bits/8+audio_channels; rate=audio_rate; printf("Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate, bits, audio_channels>1?"stereo":"mono", BUFFER ); /* calculate some parameters for the wav display */ dy=s->h/2.0/(float)(0x1<<bits); /* load the song */ if(!(music=Mix_LoadMUS(argv[1]))) cleanExit("Mix_LoadMUS(\"%s\")",argv[1]); { Mix_MusicType type=Mix_GetMusicType(music); printf("Music type: %s\n", type==MUS_NONE?"MUS_NONE": type==MUS_CMD?"MUS_CMD": type==MUS_WAV?"MUS_WAV": /*type==MUS_MOD_MODPLUG?"MUS_MOD_MODPLUG":*/ type==MUS_MOD?"MUS_MOD": type==MUS_MID?"MUS_MID": type==MUS_OGG?"MUS_OGG": type==MUS_MP3?"MUS_MP3": type==MUS_MP3_MAD?"MUS_MP3_MAD": type==MUS_FLAC?"MUS_FLAC": "Unknown"); } /* set the post mix processor up */ Mix_SetPostMix(postmix,argv[1]); SDL_FillRect(s,NULL,black); SDL_Flip(s); SDL_FillRect(s,NULL,black); SDL_Flip(s); /* start playing and displaying the wav */ /* wait for escape key of the quit event to finish */ t=SDL_GetTicks(); if(Mix_PlayMusic(music, 1)==-1) cleanExit("Mix_PlayMusic(0x%p,1)",music); Mix_VolumeMusic(volume); while((Mix_PlayingMusic() || Mix_PausedMusic()) && !done) { SDL_Event e; while(SDL_PollEvent(&e)) { switch(e.type) { case SDL_KEYDOWN: switch(e.key.keysym.sym) { case SDLK_ESCAPE: done=1; break; case SDLK_LEFT: if(e.key.keysym.mod&KMOD_SHIFT) { Mix_RewindMusic(); position=0; } else { int pos=position/audio_rate-1; if(pos<0) pos=0; Mix_SetMusicPosition(pos); position=pos*audio_rate; } break; case SDLK_RIGHT: switch(Mix_GetMusicType(NULL)) { case MUS_MP3: Mix_SetMusicPosition(+5); position+=5*audio_rate; break; case MUS_OGG: case MUS_FLAC: case MUS_MP3_MAD: /*case MUS_MOD_MODPLUG:*/ Mix_SetMusicPosition(position/audio_rate+1); position+=audio_rate; break; default: printf("cannot fast-forward this type of music\n"); break; } break; case SDLK_UP: volume=(volume+1)<<1; if(volume>SDL_MIX_MAXVOLUME) volume=SDL_MIX_MAXVOLUME; Mix_VolumeMusic(volume); break; case SDLK_DOWN: volume>>=1; Mix_VolumeMusic(volume); break; case SDLK_SPACE: if(Mix_PausedMusic()) Mix_ResumeMusic(); else Mix_PauseMusic(); break; default: break; } break; case SDL_QUIT: done=1; break; default: break; } } /* the postmix processor tells us when there's new data to draw */ if(need_refresh) refresh(); SDL_Delay(0); } t=SDL_GetTicks()-t; /* free & close */ Mix_FreeMusic(music); Mix_CloseAudio(); SDL_Quit(); /* show a silly statistic */ printf("fps=%.2f\n",((float)flips)/(t/1000.0)); return(0); }
/** * Initializes all the elements in the Audio Options screen. * @param game Pointer to the core game. * @param origin Game section that originated this state. */ OptionsAudioState::OptionsAudioState(OptionsOrigin origin) : OptionsBaseState(origin) { setCategory(_btnAudio); // Create objects _txtMusicVolume = new Text(114, 9, 94, 8); _slrMusicVolume = new Slider(104, 16, 94, 18); _txtSoundVolume = new Text(114, 9, 206, 8); _slrSoundVolume = new Slider(104, 16, 206, 18); _txtUiVolume = new Text(114, 9, 94, 40); _slrUiVolume = new Slider(104, 16, 94, 50); _txtMusicFormat = new Text(114, 9, 94, 72); _cbxMusicFormat = new ComboBox(this, 104, 16, 94, 82); _txtCurrentMusic = new Text(114, 9, 94, 100); _txtSoundFormat = new Text(114, 9, 206, 72); _cbxSoundFormat = new ComboBox(this, 104, 16, 206, 82); _txtCurrentSound = new Text(114, 9, 206, 100); _txtVideoFormat = new Text(114, 9, 206, 40); _cbxVideoFormat = new ComboBox(this, 104, 16, 206, 50); add(_txtMusicVolume, "text", "audioMenu"); add(_slrMusicVolume, "button", "audioMenu"); add(_txtSoundVolume, "text", "audioMenu"); add(_slrSoundVolume, "button", "audioMenu"); add(_txtUiVolume, "text", "audioMenu"); add(_slrUiVolume, "button", "audioMenu"); add(_txtVideoFormat, "text", "audioMenu"); add(_txtMusicFormat, "text", "audioMenu"); add(_txtCurrentMusic, "text", "audioMenu"); add(_txtSoundFormat, "text", "audioMenu"); add(_txtCurrentSound, "text", "audioMenu"); add(_cbxMusicFormat, "button", "audioMenu"); add(_cbxSoundFormat, "button", "audioMenu"); add(_cbxVideoFormat, "button", "audioMenu"); centerAllSurfaces(); // Set up objects _txtMusicVolume->setText(tr("STR_MUSIC_VOLUME")); _slrMusicVolume->setRange(0, SDL_MIX_MAXVOLUME); _slrMusicVolume->setValue(Options::musicVolume); _slrMusicVolume->onChange((ActionHandler)&OptionsAudioState::slrMusicVolumeChange); _slrMusicVolume->setTooltip("STR_MUSIC_VOLUME_DESC"); _slrMusicVolume->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _slrMusicVolume->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); _txtSoundVolume->setText(tr("STR_SFX_VOLUME")); _slrSoundVolume->setRange(0, SDL_MIX_MAXVOLUME); _slrSoundVolume->setValue(Options::soundVolume); _slrSoundVolume->onChange((ActionHandler)&OptionsAudioState::slrSoundVolumeChange); _slrSoundVolume->onMouseRelease((ActionHandler)&OptionsAudioState::slrSoundVolumeRelease); _slrSoundVolume->setTooltip("STR_SFX_VOLUME_DESC"); _slrSoundVolume->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _slrSoundVolume->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); _txtUiVolume->setText(tr("STR_UI_VOLUME")); _slrUiVolume->setRange(0, SDL_MIX_MAXVOLUME); _slrUiVolume->setValue(Options::uiVolume); _slrUiVolume->onChange((ActionHandler)&OptionsAudioState::slrUiVolumeChange); _slrUiVolume->onMouseRelease((ActionHandler)&OptionsAudioState::slrUiVolumeRelease); _slrUiVolume->setTooltip("STR_UI_VOLUME_DESC"); _slrUiVolume->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _slrUiVolume->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); std::vector<std::string> musicText, soundText, videoText; /* MUSIC_AUTO, MUSIC_FLAC, MUSIC_OGG, MUSIC_MP3, MUSIC_MOD, MUSIC_WAV, MUSIC_ADLIB, MUSIC_GM, MUSIC_MIDI */ musicText.push_back(tr("STR_PREFERRED_FORMAT_AUTO")); musicText.push_back("FLAC"); musicText.push_back("OGG"); musicText.push_back("MP3"); musicText.push_back("MOD"); musicText.push_back("WAV"); musicText.push_back("Adlib"); musicText.push_back("GM"); musicText.push_back("MIDI"); soundText.push_back(tr("STR_PREFERRED_FORMAT_AUTO")); soundText.push_back("1.4"); soundText.push_back("1.0"); videoText.push_back(tr("STR_PREFERRED_VIDEO_ANIMATION")); videoText.push_back(tr("STR_PREFERRED_VIDEO_SLIDESHOW")); _txtMusicFormat->setText(tr("STR_PREFERRED_MUSIC_FORMAT")); _cbxMusicFormat->setOptions(musicText); _cbxMusicFormat->setSelected(Options::preferredMusic); _cbxMusicFormat->setTooltip("STR_PREFERRED_MUSIC_FORMAT_DESC"); _cbxMusicFormat->onChange((ActionHandler)&OptionsAudioState::cbxMusicFormatChange); _cbxMusicFormat->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _cbxMusicFormat->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); std::string curMusic = musFormats[Mix_GetMusicType(0)]; _txtCurrentMusic->setText(tr("STR_CURRENT_FORMAT").arg(curMusic)); _txtSoundFormat->setText(tr("STR_PREFERRED_SFX_FORMAT")); _cbxSoundFormat->setOptions(soundText); _cbxSoundFormat->setSelected(Options::preferredSound); _cbxSoundFormat->setTooltip("STR_PREFERRED_SFX_FORMAT_DESC"); _cbxSoundFormat->onChange((ActionHandler)&OptionsAudioState::cbxSoundFormatChange); _cbxSoundFormat->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _cbxSoundFormat->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); std::string curSound = sndFormats[Options::currentSound]; _txtCurrentSound->setText(tr("STR_CURRENT_FORMAT").arg(curSound)); _txtVideoFormat->setText(tr("STR_PREFERRED_VIDEO_FORMAT")); _cbxVideoFormat->setOptions(videoText); _cbxVideoFormat->setSelected(Options::preferredVideo); _cbxVideoFormat->setTooltip("STR_PREFERRED_VIDEO_FORMAT_DESC"); _cbxVideoFormat->onChange((ActionHandler)&OptionsAudioState::cbxVideoFormatChange); _cbxVideoFormat->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _cbxVideoFormat->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); // These options require a restart, so don't enable them in-game _txtMusicFormat->setVisible(_origin == OPT_MENU); _cbxMusicFormat->setVisible(_origin == OPT_MENU); _txtCurrentMusic->setVisible(_origin == OPT_MENU); // These options only apply to UFO _txtSoundFormat->setVisible(_origin == OPT_MENU && _game->getMod()->getSoundDefinitions()->empty()); _cbxSoundFormat->setVisible(_origin == OPT_MENU && _game->getMod()->getSoundDefinitions()->empty()); _txtCurrentSound->setVisible(_origin == OPT_MENU && _game->getMod()->getSoundDefinitions()->empty()); }
/** * Waits a cycle to load the resources so the screen is blitted first. * If the loading fails, it shows an error, otherwise moves on to the game. */ void StartState::think() { State::think(); switch (_load) { case LOADING_STARTED: try { Log(LOG_INFO) << "Loading ruleset..."; _game->loadRuleset(); Log(LOG_INFO) << "Ruleset loaded successfully."; Log(LOG_INFO) << "Loading resources..."; _game->setResourcePack(new XcomResourcePack(_game->getRuleset()->getExtraSprites(), _game->getRuleset()->getExtraSounds())); Log(LOG_INFO) << "Resources loaded successfully."; std::vector<std::string> langs = Language::getList(0); if (langs.empty()) { throw Exception("No languages available"); } _load = LOADING_SUCCESSFUL; // loading done? let's play intro! std::string introFile = CrossPlatform::getDataFile("UFOINTRO/UFOINT.FLI"); if (Options::getBool("playIntro") && CrossPlatform::fileExists(introFile)) { audioSequence = new AudioSequence(_game->getResourcePack()); Flc::flc.realscreen = _game->getScreen(); Flc::FlcInit(introFile.c_str()); Flc::flc.dx = (Options::getInt("baseXResolution") - 320) / 2; Flc::flc.dy = (Options::getInt("baseYResolution") - 200) / 2; Flc::flc.loop = 0; // just the one time, please Flc::FlcMain(&audioHandler); Flc::FlcDeInit(); delete audioSequence; // fade out! Mix_FadeOutChannel(-1, 45*20); if (Mix_GetMusicType(0) != MUS_MID) { Mix_FadeOutMusic(45*20); } // SDL_Mixer has trouble with native midi and volume on windows, which is the most likely use case, so f@%# it. else { Mix_HaltMusic(); } SDL_Color pal[256]; SDL_Color pal2[256]; memcpy(pal, _game->getScreen()->getPalette(), sizeof(SDL_Color) * 256); for (int i = 20; i > 0; --i) { SDL_Event event; if (SDL_PollEvent(&event) && event.type == SDL_KEYDOWN) break; for (int color = 0; color < 256; ++color) { pal2[color].r = (((int)pal[color].r) * i) / 20; pal2[color].g = (((int)pal[color].g) * i) / 20; pal2[color].b = (((int)pal[color].b) * i) / 20; } _game->getScreen()->setPalette(pal2, 0, 256, true); _game->getScreen()->flip(); SDL_Delay(45); } _game->getScreen()->clear(); _game->getScreen()->flip(); _game->setVolume(Options::getInt("soundVolume"), Options::getInt("musicVolume")); Mix_HaltChannel(-1); } } catch (Exception &e) { _load = LOADING_FAILED; _surface->clear(); _surface->drawString(1, 9, "ERROR:", 2); _surface->drawString(1, 17, e.what(), 2); _surface->drawString(1, 49, "Make sure you installed OpenXcom", 1); _surface->drawString(1, 57, "correctly.", 1); _surface->drawString(1, 73, "Check the requirements and", 1); _surface->drawString(1, 81, "documentation for more details.", 1); _surface->drawString(75, 183, "Press any key to quit", 1); Log(LOG_ERROR) << e.what(); } break; case LOADING_NONE: _load = LOADING_STARTED; break; case LOADING_SUCCESSFUL: Log(LOG_INFO) << "OpenXcom started successfully!"; if (Options::getString("language").empty()) { _game->setState(new LanguageState(_game)); } else { try { _game->loadLanguage(Options::getString("language")); _game->setState(new MainMenuState(_game)); } catch (Exception) { _game->setState(new LanguageState(_game)); } } break; default: break; } }
bool Music::IsMIDI() { return Mix_GetMusicType(mMusic) == MUS_MID; }
bool Music::IsMOD() { return Mix_GetMusicType(mMusic) == MUS_MOD; }
bool Music::IsWAV() { return Mix_GetMusicType(mMusic) == MUS_WAV; }
bool Music::IsOGG() { return Mix_GetMusicType(mMusic) == MUS_OGG; }
/** * Initializes all the elements in the Audio Options screen. * @param game Pointer to the core game. * @param origin Game section that originated this state. */ OptionsAudioState::OptionsAudioState(OptionsOrigin origin) : OptionsBaseState(origin) { setCategory(_btnAudio); // Create objects _txtMusicVolume = new Text(114, 9, 94, 8); _slrMusicVolume = new Slider(104, 16, 94, 18); _txtSoundVolume = new Text(114, 9, 206, 8); _slrSoundVolume = new Slider(104, 16, 206, 18); _txtUiVolume = new Text(114, 9, 94, 40); _slrUiVolume = new Slider(104, 16, 94, 50); _txtSampleRate = new Text(114, 9, 206, 40); _cbxSampleRate = new ComboBox(this, 104, 16, 206, 50); _txtMusicFormat = new Text(114, 9, 94, 72); _cbxMusicFormat = new ComboBox(this, 104, 16, 94, 82); _txtCurrentMusic = new Text(114, 9, 94, 100); _txtSoundFormat = new Text(114, 9, 206, 72); _cbxSoundFormat = new ComboBox(this, 104, 16, 206, 82); _txtCurrentSound = new Text(114, 9, 206, 100); add(_txtMusicVolume, "text", "audioMenu"); add(_slrMusicVolume, "button", "audioMenu"); add(_txtSoundVolume, "text", "audioMenu"); add(_slrSoundVolume, "button", "audioMenu"); add(_txtUiVolume, "text", "audioMenu"); add(_slrUiVolume, "button", "audioMenu"); add(_txtSampleRate, "text", "audioMenu"); add(_txtMusicFormat, "text", "audioMenu"); add(_txtCurrentMusic, "text", "audioMenu"); add(_txtSoundFormat, "text", "audioMenu"); add(_txtCurrentSound, "text", "audioMenu"); add(_cbxMusicFormat, "button", "audioMenu"); add(_cbxSoundFormat, "button", "audioMenu"); add(_cbxSampleRate, "button", "audioMenu"); centerAllSurfaces(); // Set up objects _txtMusicVolume->setText(tr("STR_MUSIC_VOLUME")); _slrMusicVolume->setRange(0, SDL_MIX_MAXVOLUME); _slrMusicVolume->setValue(Options::musicVolume); _slrMusicVolume->onChange((ActionHandler)&OptionsAudioState::slrMusicVolumeChange); _slrMusicVolume->setTooltip("STR_MUSIC_VOLUME_DESC"); _slrMusicVolume->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _slrMusicVolume->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); _txtSoundVolume->setText(tr("STR_SFX_VOLUME")); _slrSoundVolume->setRange(0, SDL_MIX_MAXVOLUME); _slrSoundVolume->setValue(Options::soundVolume); _slrSoundVolume->onChange((ActionHandler)&OptionsAudioState::slrSoundVolumeChange); _slrSoundVolume->onMouseRelease((ActionHandler)&OptionsAudioState::slrSoundVolumeRelease); _slrSoundVolume->setTooltip("STR_SFX_VOLUME_DESC"); _slrSoundVolume->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _slrSoundVolume->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); _txtUiVolume->setText(tr("STR_UI_VOLUME")); _slrUiVolume->setRange(0, SDL_MIX_MAXVOLUME); _slrUiVolume->setValue(Options::uiVolume); _slrUiVolume->onChange((ActionHandler)&OptionsAudioState::slrUiVolumeChange); _slrUiVolume->onMouseRelease((ActionHandler)&OptionsAudioState::slrUiVolumeRelease); _slrUiVolume->setTooltip("STR_UI_VOLUME_DESC"); _slrUiVolume->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _slrUiVolume->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); std::wostringstream ss; std::vector<std::wstring> samplesText; int samples[] = {8000, 11025, 16000, 22050, 32000, 44100, 48000}; for (unsigned int i = 0; i < sizeof(samples) / sizeof(samples[0]); ++i) { _sampleRates.push_back(samples[i]); ss << samples[i] << L" Hz"; samplesText.push_back(ss.str()); ss.str(L""); if (Options::audioSampleRate == samples[i]) { _cbxSampleRate->setSelected(i); } } _txtSampleRate->setText(tr("STR_AUDIO_SAMPLE_RATE")); _cbxSampleRate->setOptions(samplesText); _cbxSampleRate->setTooltip("STR_AUDIO_SAMPLE_RATE_DESC"); _cbxSampleRate->onChange((ActionHandler)&OptionsAudioState::cbxSampleRateChange); _cbxSampleRate->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _cbxSampleRate->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); std::vector<std::wstring> musicText, soundText; /* MUSIC_AUTO, MUSIC_FLAC, MUSIC_OGG, MUSIC_MP3, MUSIC_MOD, MUSIC_WAV, MUSIC_ADLIB, MUSIC_MIDI */ musicText.push_back(tr("STR_PREFERRED_FORMAT_AUTO")); musicText.push_back(L"FLAC"); musicText.push_back(L"OGG"); musicText.push_back(L"MP3"); musicText.push_back(L"MOD"); musicText.push_back(L"WAV"); musicText.push_back(L"Adlib"); musicText.push_back(L"MIDI"); soundText.push_back(tr("STR_PREFERRED_FORMAT_AUTO")); soundText.push_back(L"1.4"); soundText.push_back(L"1.0"); _txtMusicFormat->setText(tr("STR_PREFERRED_MUSIC_FORMAT")); _cbxMusicFormat->setOptions(musicText); _cbxMusicFormat->setSelected(Options::preferredMusic); _cbxMusicFormat->setTooltip("STR_PREFERRED_MUSIC_FORMAT_DESC"); _cbxMusicFormat->onChange((ActionHandler)&OptionsAudioState::cbxMusicFormatChange); _cbxMusicFormat->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _cbxMusicFormat->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); std::wstring curMusic = musFormats[Mix_GetMusicType(0)]; _txtCurrentMusic->setText(tr("STR_CURRENT_FORMAT").arg(curMusic)); _txtSoundFormat->setText(tr("STR_PREFERRED_SFX_FORMAT")); _cbxSoundFormat->setOptions(soundText); _cbxSoundFormat->setSelected(Options::preferredSound); _cbxSoundFormat->setTooltip("STR_PREFERRED_SFX_FORMAT_DESC"); _cbxSoundFormat->onChange((ActionHandler)&OptionsAudioState::cbxSoundFormatChange); _cbxSoundFormat->onMouseIn((ActionHandler)&OptionsAudioState::txtTooltipIn); _cbxSoundFormat->onMouseOut((ActionHandler)&OptionsAudioState::txtTooltipOut); std::wstring curSound = sndFormats[Options::currentSound]; _txtCurrentSound->setText(tr("STR_CURRENT_FORMAT").arg(curSound)); // These options require a restart, so don't enable them in-game _txtSampleRate->setVisible(_origin == OPT_MENU); _cbxSampleRate->setVisible(_origin == OPT_MENU); _txtMusicFormat->setVisible(_origin == OPT_MENU); _cbxMusicFormat->setVisible(_origin == OPT_MENU); _txtCurrentMusic->setVisible(_origin == OPT_MENU); _txtSoundFormat->setVisible(_origin == OPT_MENU); _cbxSoundFormat->setVisible(_origin == OPT_MENU); _txtCurrentSound->setVisible(_origin == OPT_MENU); }
static mrb_value mrb_sdl2_mixer_music_get_type(mrb_state *mrb, mrb_value self) { return mrb_fixnum_value(Mix_GetMusicType(mrb_sdl2_music_get_ptr(mrb, self))); }
bool Music::IsMP3() { return Mix_GetMusicType(mMusic) == MUS_MP3; }
VALUE MSPhysics::Music::get_type(VALUE self, VALUE v_address) { Mix_Music* music = c_value_to_music(v_address); return Util::to_value(Mix_GetMusicType(music)); }
bool Music::IsCMD() { return Mix_GetMusicType(mMusic) == MUS_CMD; }