Exemplo n.º 1
0
int IsPlayWave( int no )
{
	switch ( s_iYGSSoundType[no] )
	{
	case YGS_SOUNDTYPE_WAV:
		/* なぜかここを実行すると落ちる… */
		return Mix_Playing(no);
		break;

	case YGS_SOUNDTYPE_MUS:
		return Mix_PlayingMusic();
		break;
	}
	return 0;
}
Exemplo n.º 2
0
void jhi_play_music(JHI_Music *music, int loop)
{

	if (Mix_PausedMusic() == 1)
	{
		Mix_ResumeMusic();
	}

	else if(Mix_PlayingMusic() == 0) {
		if(Mix_PlayMusic(music->mix_music, loop) == -1 )
		{
			printf("Error while playing music.\n");
		}
	}
}
Exemplo n.º 3
0
/*! 
  Updates audio status.  Must be called at every frame.

  \return  none
  \author  jfpatry
  \date    Created:  2000-08-14
  \date    Modified: 2000-09-02
*/
void 
update_audio()
{
    int volume;

    check_assertion( initialized_, "audio module not initialized" );

    if ( ! is_audio_open() ) {
	return;
    }

    if ( getparam_music_enabled() == False ) {
	Mix_HaltMusic();
    }

    /* Set sounds volume level */
    volume = getparam_sound_volume();
    if ( volume < 0 ) {
	volume = 0;
    }
    if ( volume > 128 ) {
	volume = 128;
    }
    setparam_sound_volume( volume );

    Mix_Volume( -1, volume ); /* channel of -1 sets volume for all channels */

    /* Set music volume level */
    volume = getparam_music_volume();
    if ( volume < 0 ) {
	volume = 0;
    }
    if ( volume > 128 ) {
	volume = 128;
    }
    setparam_music_volume( volume );
 
    Mix_VolumeMusic( volume );

    /* Update music status */

    if ( current_music_name_ != NULL && !Mix_PlayingMusic() ) {
	set_music_playing_status( current_music_name_, False );
	current_music_name_ = NULL;
	current_music_data_ = NULL;
    }

}
Exemplo n.º 4
0
void Audio::musicMute(bool bMute)
{
    if (bMute)  //turn mute on
    {
        _musicVolSave = getMusicVol();
        setMusicVol(0, false);
        if (Mix_PlayingMusic() && !Mix_Paused(-1))
            Mix_PauseMusic();
    }
    else    //unmute
    {
        setMusicVol(_musicVolSave, false);
        Mix_ResumeMusic();
    }
    _opt._bMusic = !bMute;
}
Exemplo n.º 5
0
// Might want to add a feature to add if we want repeat or not
void D2DMusic::play()
{
    if (Mix_PlayingMusic() == 0){
        Mix_PlayMusic(m_music, -1);
    }

    else {
        if (Mix_PausedMusic() == 1){
            Mix_ResumeMusic();
        }

        else {
            Mix_PauseMusic();
        }
    }
}
Exemplo n.º 6
0
//----------------------------------------------------------------------------------------------------------------------
void Game::gameover()
{
  // set playing flag to false and swap music
  m_playing=false;
  if(Mix_PlayingMusic()==1)
  {
    Mix_HaltMusic();
  }
  Mix_PlayMusic(m_menu, -1);
  // reset key counters and world
  m_level=0;
  m_world->m_score=0;
  m_world->resetWorld();
  // set menu clear color
  glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
}
Exemplo n.º 7
0
 void platform_support::play_music(unsigned idx)
 {
    printf("play music\n");
    if (idx >= max_images || !m_specific->m_music[idx])
    {
       return;
    }
    printf("play music\n");
    if (Mix_PlayingMusic())
    {
       Mix_HaltMusic();
    } 
    printf("play music\n");
    Mix_PlayMusic(m_specific->m_music[idx], -1);
    printf("play music\n");
 }
Exemplo n.º 8
0
 void platform_support::play_music(unsigned idx, unsigned vol)
 {
    if (idx >= max_images || !m_specific->m_music[idx])
    {
       return;
    }
    Mix_VolumeMusic(vol);
    if (Mix_PlayingMusic())
    {
       Mix_HaltMusic();
    } 
    if (vol)
    {
       Mix_PlayMusic(m_specific->m_music[idx], -1);
    }
 }
Exemplo n.º 9
0
void CleanUp(void)
{
	if( Mix_PlayingMusic() ) {
		Mix_FadeOutMusic(1500);
		SDL_Delay(1500);
	}
	if ( music ) {
		Mix_FreeMusic(music);
		music = NULL;
	}
	if ( audio_open ) {
		Mix_CloseAudio();
		audio_open = 0;
	}
	SDL_Quit();
}
Exemplo n.º 10
0
// Pauses music if playing, resume if pausing, return false if play() not called
bool AudioHandler::switch_pause_resume()
{
	if (!Mix_PlayingMusic())
	{
		return false;
	}
	if (Mix_PausedMusic())
	{
		Mix_ResumeMusic();
	}
	else
	{
		Mix_PauseMusic();
	}
	return true;
}
Exemplo n.º 11
0
void jhi_replay_music(JHI_Music *music, int loop)
{
	if (Mix_PausedMusic() == 1)
	{
		Mix_ResumeMusic();
	}

	if (Mix_PlayingMusic() != 0) 
	{
		jhi_stop_music();
	}

	jhi_free_music(music);
	jhi_load_music(music, music->filename);

	jhi_play_music(music, loop);
}
Exemplo n.º 12
0
bool I_QrySongPlaying (int handle)
{
	if(!music_initialized)
		return false;

#ifdef OSX

	Boolean result;
	MusicPlayerIsPlaying(player, &result);
	return result;

#else

	return Mix_PlayingMusic() ? true : false;

#endif
}
Exemplo n.º 13
0
void AudioController::play_music(int track,int loopnum) {
     stop_music(); //Stop music first.
     if (track<=0) track=1;
     if (track>NUM_TRACKS) track=NUM_TRACKS;
     if( Mix_PlayingMusic() == 0 ) {
         if (Mix_PlayMusic( music[track-1], loopnum ) == -1) {
            //Fail somehow
         };
     }
     
    //Play one of the MIDI tracks.
    //Specify which one in the documentation.
    //Only one music should be playable at a time.
    //Also it should automatically loop to a starting point.
    //All the songs that need to loop to a specific point will have
    // a midi cue at that point named "loopStart" when they're done.
}
Exemplo n.º 14
0
void InitMenuBG(S_scene_menu* sc,E_camera* camera){
	G_menuBG* menuBG = &sc->menuBG;

	menuBG->active = 1;
	InitT(&menuBG->transform,0,0,1,1);
	InitT(&menuBG->sprite.srce,0,0,512,512);
	InitT(&menuBG->sprite.dest,0,0,512,512);
	menuBG->sprite.texture = LoadTexture(camera,"./src/resources/BG.png");
	SetRectSprite(&menuBG->sprite,&menuBG->transform);

	menuBG->BGMusic = Mix_LoadMUS( "./src/resources/JourneyTitle.mp3" );
	if( Mix_PlayingMusic() == 0 )
	{
		//Play the music
		Mix_PlayMusic( menuBG->BGMusic, -1 );
	}
}
Exemplo n.º 15
0
int main( int argc, char* args[] ) {
    bool quit = false;
    imageManager = new ImageManager;
    soundManager = new SoundManager;
    timeManager = new TimeManager;
    

    //Kill the program if it didn't init successfully.
    if( !init_sdl() ) {
        return -1;
    }

    // Load the images 
    splash = imageManager->load_image( "splash.jpg" );
    background = imageManager->load_image( "background.jpg" );

    imageManager->draw_to_surface( splash, screen );
    // Start the Timer.
    timeManager->start();

    while( quit == false ) {
        while( SDL_PollEvent( &event ) ) {
            if( event.type == SDL_QUIT ) {
                quit = true;
            }

            if( Mix_PlayingMusic() == 0 ) {
                //Play the music
                soundManager->play_music( "titlemusic.wav" );
            }
        }

        if ( SDL_Flip( screen ) == -1 ) {
            return 1;
        }

        draw_relevent_surface();
        timeManager->check_fps();
    }

    // Apply the message to the screen
    //apply_surface( 180, 140, message, screen );

    clean_up();
    return 0;
}
Exemplo n.º 16
0
void music_muter::handle_window_event(const SDL_Event& event)
{
	if (preferences::stop_music_in_background() && preferences::music_on())
	{
		if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
		{
			Mix_ResumeMusic();
		}
		else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)
		{
			if (Mix_PlayingMusic())
			{
				Mix_PauseMusic();
			}
		}
	}
}
Exemplo n.º 17
0
void    music_play()
{
    //If there is no music playing
    if( Mix_PlayingMusic() == 0 )
    {
        music_choose_track(playlist[current_track_num]);

        LOG("Track %d is playing: %s\n", current_track_num, playlist[current_track_num]);

        if(current_track_num++ == playlist_length)
        {
            current_track_num = 0;
        }

        Mix_PlayMusic( music, 1 );
    }
}
Exemplo n.º 18
0
//*************************************************************************************************
void Game::initGame()
{
    m_board.m_direction = RIGHT;
    m_board.m_length = 3;
    int startPos = START_POS;
    for (int i = 0; i < m_board.m_length ; ++i)
    {
        m_board.m_x[i] = startPos - i;
        m_board.m_y[i] = startPos;
    }

    m_score = 0;
    addGoal();

    if (!Mix_PlayingMusic())
        Mix_PlayMusic(m_music, -1);
}
Exemplo n.º 19
0
void cMusicSDL2::Play(int _repeat, int fade){
	if(music != NULL){
		if(Mix_PlayingMusic() > 0){	//Music is already playing
			if(isPaused){
				Mix_ResumeMusic();
				isPaused = false;
				return;
			}else if(Mix_FadingMusic() == MIX_FADING_OUT){
				Mix_HaltMusic();
			}else{
				return;
			}
		}
		if(Mix_FadeInMusic(music, _repeat, fade) < 0){
			StormPrintLog(STORM_LOG_ERROR, "cMusicSDL2", "Error %s", Mix_GetError());
		}
	}
}
Exemplo n.º 20
0
void
Sound::enableMusic(bool enabled)
{
    if(getConfig()->musicEnabled == enabled)
        return;
    getConfig()->musicEnabled = enabled;

    if(!audioOpen)
        return;

    if(enabled) {
        playMusic(musicFile);
    } else {
        if(Mix_PlayingMusic()) {
            Mix_FadeOutMusic(1000);
        }
    }
}
Exemplo n.º 21
0
void music_stop(void)
{
#ifndef NOSOUND
#ifdef ARGS
	if (sound_arg)
	{
#endif
	while (Mix_PlayingMusic())
	{
		Mix_HaltMusic();

		SDL_Delay(100);
	}
#ifdef ARGS
	}
#endif
#endif
}
Exemplo n.º 22
0
/* function: Mix_PlayingMusic */
static int toluaI_sound_sound_is_playing_music00(lua_State* tolua_S)
{
 if (
 !tolua_isnoobj(tolua_S,1)
 )
 goto tolua_lerror;
 else
 {
 {
  bool toluaI_ret = (bool)  Mix_PlayingMusic();
 tolua_pushbool(tolua_S,(int)toluaI_ret);
 }
 }
 return 1;
tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'is_playing_music'.");
 return 0;
}
Exemplo n.º 23
0
// Play the loaded music loop times through from start to finish. The previous music will be
// halted, or if fading out it waits (blocking) for that to finish.
// Fade in is true, if want fade in effect, withing ms milliseconds
// Return 1 for success; -1 for error
int SDLAudio::play_music(int index, int loops, bool fadeIn, int ms) {
  Mix_Music *music = m_musics[index];

  if (fadeIn) {
    if (Mix_FadeInMusic(music, loops, ms) == -1) {
      logError(std::cout, "Fade in music");
      return -1;
    }
  } else {
    if (!Mix_PlayingMusic()) {
      if (Mix_PlayMusic(music, loops) == -1) {
	logError(std::cout, "Play Music");
	return -1;
      }
    }
  }
  return 1;
}
Exemplo n.º 24
0
void closeSound() {
  int i;
  if ( !useAudio ) return;
  if ( Mix_PlayingMusic() ) {
    Mix_HaltMusic();
  }
  for ( i=0 ; i<MUSIC_NUM ; i++ ) {
    if ( music[i] ) {
      Mix_FreeMusic(music[i]);
    }
  }
  for ( i=0 ; i<CHUNK_NUM ; i++ ) {
    if ( chunk[i] ) {
      Mix_FreeChunk(chunk[i]);
    }
  }
  Mix_CloseAudio();
}
Exemplo n.º 25
0
SE_music *SE_audio_loadmusic(char *filename)
{
	SE_music *music;

	if (Mix_PlayingMusic())
		Mix_HaltMusic();

	/*if (engine.music != NULL)
		Mix_FreeMusic(engine.music);*/

	music=Mix_LoadMUS(filename);
	if(!music){
		printf("error cargando música: %s\n",filename);
		return 0;
	}

	return music;
	
}
Exemplo n.º 26
0
void PGE_MusPlayer::postMixCallback(void *udata, Uint8 *stream, int len)
{
    if(!isLoaded) return;

    Q_UNUSED(udata);
    Q_UNUSED(stream);
	if (SDL_LockMutex(sampleCountMutex) == 0)
	{
		// This post mix callback has a simple purpose: count audio samples.
		sCount += len/4;

		// (Approximate) sample count for only when music is playing
		if ((Mix_PlayingMusic() == 1) && (Mix_PausedMusic() == 0))
		{
			musSCount += len/4;
		}
		SDL_UnlockMutex(sampleCountMutex);
	}
}
Exemplo n.º 27
0
//----------------------------------------------------------------------------------------------------------------------
void Game::keyPressEvent(const SDL_Keysym &_key)
{
  // in-game key control events
  // call attack method if "a" is pressed
  if(_key.sym==SDLK_a && m_playing)
  {
    m_combatSys.attack();
  }
  // call tether method if "space" is pressed
  else if(_key.sym==SDLK_SPACE && m_playing)
  {
    m_controlSys.tether();
  }
  // call slow toggle method if "s" is pressed
  else if(_key.sym==SDLK_s && m_playing)
  {
    m_controlSys.toggleSlow();
  }
  // call clear tethers method if "f" is pressed
  else if(_key.sym==SDLK_f && m_playing)
  {
    m_controlSys.clearTethers();
  }

  // menu key control event
  else if(_key.sym==SDLK_e && !m_playing)
  {
    // set all game beginning states, first swap music to in-game ambience
    m_playing=true;
    if(Mix_PlayingMusic()==1)
    {
      Mix_HaltMusic();
    }
    Mix_PlayMusic(m_wind, -1);
    // reset mouse movements in case carried over from previous playthrough
    m_rotX=0.0f;
    m_rotY=0.0f;
    // clear color to dark-blue for minimap
    glClearColor(0.31f, 0.37f, 0.406f, 1.0f);
    // load first level
    loadLevel("levels/lvl_1.txt");
  }
}
Exemplo n.º 28
0
void InitGame(void)
{
    if(!Mix_PlayingMusic())
    {
        Mix_PlayMusic(music, 0);
    }

    VG= 50;
    xpos=626;
    ypos=220;
    xpos1=2;
    ypos1=220;
    xpos2=50;
    ypos2= rand()%400+50;
    Win= 0;
    redraw= false;
    CloseThread= false;
    NewGame= false;
}
Exemplo n.º 29
0
void RUN()
{
/*RUN - this in the game control loop, it calls the Awake() function once to
	initialise all the modules and then calls the Update() function over and over
	until the game ends.*/

	//int gameOver = 0; // gameOver = 1
	GameState gameState = Awake ();

  while(OBJECTS->pauseMenu->exitGame == false && OBJECTS->titleMenu->exitGame == false){
    Update(gameState);
    if(Mix_PlayingMusic() == 0){
      Mix_PlayMusic(OBJECTS->gameSounds->music, -1);
    }
  }

  sleep(1);
  Free_Memory(OBJECTS);
}
Exemplo n.º 30
0
void Mixer::playMusic( std::string name )
{
    if( soundList_.size() < 1 )
    {
        return;
    }

    AudioData* data = NULL;
    bool foundData = false;

    for ( size_t i = 0; i < soundList_.size(); ++i )
    {
    	if( soundList_[i]->friendlyname.compare( name ) == 0 )
    	{
    	    data = soundList_[i];

    	    // check if the data exists
    	    if( data->data_p == NULL ) return;
    	    foundData = true;
    	}
    }

    if( !foundData ) return;

    Mix_Music* music = (Mix_Music*)data->data_p;

    // check if there already is music playing
    // if this is the case, fade out & in
    // else just start playing
    // TODO: real crossfading needs implementation of a multi-channel music mixer
    if( Mix_PlayingMusic() )
    {
        Mix_FadeOutMusic( 500 );
        while( Mix_FadingMusic() ) {}
        Mix_FadeInMusic( music, -1, 500 );
    }
    else
    {
        Mix_PlayMusic( music, -1 );
    }

    lastPlayed = name;
}