Exemplo n.º 1
0
bool JukeBox::PlayMusic(const std::string& type)
{
  if (m_init == false || !Config::GetInstance()->GetSoundMusic())
    return false;

  PlayListMap::iterator it = playlist.find(type);

  if (it == playlist.end()) {
    std::cerr << "[Music] Unable to find " << type << " profile" << std::endl;
    if (type == "ingame") {
      return false;
    } else {
      return PlayMusic("ingame");
    }
  }


  MSG_DEBUG("jukebox", "Loading playlist %s", type.c_str());

  StopMusic();

  if (it->second.empty() || !Config::GetInstance()->GetSoundMusic())
    return false;

  playing_pl = it;

  int i, j = 0;
  do {
    i = RandomLocal().GetInt(0,it->second.size()-1);
    j++;
  } while(!PlayMusicSample(it->second.begin()+i) && j < 10); // After 10 times, we think there is a problem.

  if (j >= 10)
    playing_pl = playlist.end();

  return (j < 10);
}
Exemplo n.º 2
0
void MusicBannerWheel::SetScanMode(bool Scanmode)
{
	bScanning = Scanmode;
	if((PREVIEWMUSICMODE == 0 || PREVIEWMUSICMODE == 3) && !Scanmode)
		PlayMusicSample();	
}
Exemplo n.º 3
0
/****************************
void MusicBannerWheel::LoadSongData()

Loads the Song Data, based upon
its relative position. It's fairly
slow, so should only get used once
and once only.
*****************************/
void MusicBannerWheel::LoadSongData()
{
	Song* pSong = NULL;
	CStringArray asGraphicPaths;

	if(MAXSONGSINBUFFER >= arraySongs.size() && SingleLoad != 1)  // less than the MAXSONGSINBUFFER means we can get away with loading the lot in one go
	{
		SingleLoad=2;
		int difference=0;
		// find out just how short of a full buffer we are =)
		difference = MAXSONGSINBUFFER - arraySongs.size();
		for(int i=0; i<=difference; i++)
		{
			for(unsigned c=0; c<arraySongs.size(); c++)
			{
				pSong = arraySongs[c];

				if( pSong == NULL ) 
					asGraphicPaths.push_back(THEME->GetPathG("Common","fallback banner"));
				else if (pSong->HasBanner()) 
					asGraphicPaths.push_back(pSong->GetBannerPath());
				else 
					asGraphicPaths.push_back(THEME->GetPathG("Common","fallback banner"));	
			}
		}
	}
	
	if(SingleLoad==0)
	{
		for(int count=0; count<MAXSONGSINBUFFER; count++)
		{
			/* In essence, this element is the central one so we want the scrolling list
			to load in the song as specified by currentPos */
			if(count == scrlistPos)
			{	
				pSong = arraySongs[currentPos];
			}
			/* if it's the next element
			*/
			else if(count == scrlistPos+2 || (scrlistPos == MAXSONGSINBUFFER-2 && count == 0))
			{
				if((unsigned)currentPos+2 <= arraySongs.size()-1)
					pSong = arraySongs[currentPos+2];
				else
					pSong = arraySongs[0+2];
			}
			else if(count == scrlistPos-2 || (scrlistPos == 0 && count == MAXSONGSINBUFFER-2))
			{
				if(currentPos-2 >= 0)
					pSong = arraySongs[currentPos-2];
				else
					pSong = arraySongs[arraySongs.size()-2];			
			}
			else if(count == scrlistPos+1 || (scrlistPos == MAXSONGSINBUFFER-1 && count == 0))
			{
				if((unsigned)currentPos+1 <= arraySongs.size()-1)
					pSong = arraySongs[currentPos+1];
				else
					pSong = arraySongs[0];
			}
			/* if it's the previous element OR if we're at element 0..the 5th element (which will wrap to before element 0)
			will actually appear as 5 songs along and not the one immediately before it,, so pull a sneaky and make the 
			final element actually be the song before... */
			else if(count == scrlistPos-1 || (scrlistPos == 0 && count == MAXSONGSINBUFFER-1))
			{
				if(currentPos-1 >= 0)
					pSong = arraySongs[currentPos-1];
				else
					pSong = arraySongs[arraySongs.size()-1];
			}

			if( pSong == NULL ) 
				asGraphicPaths.push_back(THEME->GetPathG("Common","fallback banner"));
			else if (pSong->HasBanner()) 
				asGraphicPaths.push_back(pSong->GetBannerPath());
			else 
				asGraphicPaths.push_back(THEME->GetPathG("Common","fallback banner"));
		}
	}
	if(SingleLoad != 1)
		m_ScrollingList.Load( asGraphicPaths );
	if(SingleLoad == 2)
		SingleLoad = 1;
	if((PREVIEWMUSICMODE == 0 || PREVIEWMUSICMODE == 3) && !bScanning)
		PlayMusicSample();
}
Exemplo n.º 4
0
/********************************************
void MusicBannerWheel::InsertNewBanner(int direction)

Based upon the direction specified it will go off and 
figure out which banner went out of focus, (which is
now our NEW! banner) and replace it with something new...
works only if there are 5 banners in the scrolling list.
********************************************/
void MusicBannerWheel::InsertNewBanner(int direction)
{
	Song* pSong = NULL;
	CString sGraphicPath;
	int elementtoreplace=0;	

	if(	direction == GOINGLEFT)
	{
		/* Imagine this:
			[1][2][3][4][5]
			then they shift <-
			[?][1][2][3][4]
			gotta find out what ? is

		   scrlistpos = 0   0 1 2 [3] [4] [0] [1] [2] 3 4 0 1 2 3 4
		   scrlistpos = 4   4 0 1 [2] [3] [4] [0] [1] 2 3 4 0 1 2 3 // we lost 2 and got a new one
		   scrlistpos = 3   3 4 0 [1] [2] [3] [4] [0] 1 2 3 4 0 1 2 // we lost 1 and got a new one
		 */
		if(currentPos-2 >= 0)
			pSong = arraySongs[currentPos-2];
		else
			pSong = arraySongs[(arraySongs.size()-1) + (currentPos-2)];	// wrap around. (it does honestly!)		

		if( pSong == NULL ) 
			sGraphicPath = THEME->GetPathG("Common","fallback banner");
		else if (pSong->HasBanner()) 
			sGraphicPath = pSong->GetBannerPath();
		else 
			sGraphicPath = THEME->GetPathG("Common","fallback banner");

		elementtoreplace = scrlistPos - 2;
		if(elementtoreplace < 0) 
		{
			elementtoreplace = MAXSONGSINBUFFER + elementtoreplace;
		}
		m_ScrollingList.Replace(sGraphicPath, elementtoreplace);
	}
	else if( direction == GOINGRIGHT)
	{
		/* Imagine this:
			[1][2][3][4][5]
			then they shift ->
			[2][3][4][5][?]
			gotta find out what ? is
			scrlistpos = 0 1 2 [3] [4] [0] [1] [2] 3 4
			scrlistpos = 1 2 3 [4] [0] [1] [2] [3] 4 0 // we lost 3 and got a new one												
		 */
		if((unsigned)currentPos+2 <= arraySongs.size()-1)
			pSong = arraySongs[currentPos+2];
		else
			pSong = arraySongs[0+ (((currentPos+2) - (arraySongs.size()-1)) - 1)]; // wrap around. (it does honestly!)

		if( pSong == NULL ) 
			sGraphicPath = THEME->GetPathG("Common","fallback banner");
		else if (pSong->HasBanner()) 
			sGraphicPath = pSong->GetBannerPath();
		else 
			sGraphicPath = THEME->GetPathG("Common","fallback banner");

		elementtoreplace = scrlistPos + 2;
		if(elementtoreplace > MAXSONGSINBUFFER-1) 
		{
			elementtoreplace = elementtoreplace - MAXSONGSINBUFFER;
		}
		m_ScrollingList.Replace(sGraphicPath, elementtoreplace);
	}
	else
	{
		ASSERT(0); // we should be going in some sort of direction.
	}
	if((PREVIEWMUSICMODE == 0 || PREVIEWMUSICMODE == 3) && !bScanning)
		PlayMusicSample();
}