Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Music Struct Reference

#include <music.h>

Public Types

enum  Playlist {
  NOLIST =-1, BATTLELIST =0, PEACELIST, PANICLIST,
  VICTORYLIST, LOSSLIST, MAXLIST
}
 

Public Member Functions

 Music (Unit *parent=NULL)
 
void Listen ()
 
 ~Music ()
 
void SetParent (Unit *parent)
 
void GotoSong (int whichlist, int whichsong, bool skip, int layer=-1)
 
 Music ()
 
bool Load (const char *file)
 
bool Play (float fadeout, float fadein, Music &oldmusic)
 
void Stop ()
 
void Free ()
 
void SetVolume (float vol)
 
 Music ()
 
bool Load (const char *file)
 
bool Play (float fadeout, float fadein, Music &oldmusic)
 
void Stop ()
 
void Free ()
 
void SetVolume (float vol)
 
void SetMasterVolume (float vol)
 

Static Public Member Functions

static int Addlist (std::string listfile)
 
static void SetLoops (int numloops, int layer=-1)
 
static void ChangeVolume (float inc=0, int layer=-1)
 
static void Skip (int layer=-1)
 
static void Stop (int layer=-1)
 
static void SkipRandSong (int whichlist, int layer=-1)
 
static void SkipRandList (int layer=-1)
 
static void GotoSong (std::string mus, int layer=-1)
 
static void InitMuzak ()
 
static void CleanupMuzak ()
 
static void MuzakCycle ()
 
static void SetVolume (float vol, int layer=-1, bool hardware=false, float latency_override=-1)
 
static void Mute (bool mute=true, int layer=-1)
 

Public Attributes

int loopsleft
 
std::vector< intsounds_to_stop
 
Mix_Musicm
 

Friends

void * Muzak::readerThread (void *input)
 

Detailed Description

Definition at line 20 of file music.h.

Member Enumeration Documentation

Enumerator
NOLIST 
BATTLELIST 
PEACELIST 
PANICLIST 
VICTORYLIST 
LOSSLIST 
MAXLIST 

Definition at line 87 of file music.h.

Constructor & Destructor Documentation

Music::Music ( Unit parent = NULL)

ERRORCHECK_MUTEX

_WIN32 USE_SOUNDSERVER

Definition at line 64 of file music.cpp.

References checkerr, VSFileSystem::datadir, fclose, fNET_startup(), fNET_Write(), fopen, g_game, Unit::GetHull(), VegaConfig::getVariable(), i, INET_ConnectTo(), INET_startup(), INET_Write(), loopsleft, MAXLIST, game_data_t::music_enabled, XMLSupport::parse_float(), PEACELIST, VsnetOSS::socket(), soundServerPipes(), TRUE, vs_config, and VSFileSystem::vs_fprintf().

64  : random( false )
65  , p( parent )
66  , song( -1 )
67  , thread_initialized( false )
68 {
69  loopsleft = 0;
70  socketw = socketr = -1;
71  music_load_info = NULL;
72  music_loaded = false;
73  music_loading = false;
74  killthread = 0;
75  threadalive = 0;
76  freeWav = true;
77 #ifdef HAVE_AL
78  music_load_info = new AUDSoundProperties;
79 #endif
80 
81 #ifndef USE_SOUNDSERVER
82 #ifdef _WIN32
83  musicinfo_mutex = CreateMutex( NULL, TRUE, NULL );
84 #else //_WIN32
85 #ifdef ERRORCHECK_MUTEX
86  pthread_mutexattr_t checkme;
87  pthread_mutexattr_init( &checkme );
88  pthread_mutexattr_settype( &checkme, PTHREAD_MUTEX_ERRORCHECK );
89  checkerr( pthread_mutex_init( &musicinfo_mutex, &checkme ) );
90 #else //ERRORCHECK_MUTEX
91  checkerr( pthread_mutex_init( &musicinfo_mutex, NULL ) );
92 #endif
93 
94  //Lock it immediately, since the loader will want to wait for its first data upon creation.
95  checkerr( pthread_mutex_lock( &musicinfo_mutex ) );
96 #endif
97 #endif
98  if (!g_game.music_enabled)
99  return;
100  lastlist = PEACELIST;
101  if (parent)
102  maxhull = parent->GetHull();
103  else
104  maxhull = 1;
105  int i;
106  const char *listvars[MAXLIST] = {"battleplaylist", "peaceplaylist", "panicplaylist", "victoryplaylist", "lossplaylist"};
107  const char *deflistvars[MAXLIST] = {"battle.m3u", "peace.m3u", "panic.m3u", "victory.m3u", "loss.m3u"};
108  for (i = 0; i < MAXLIST; i++)
109  LoadMusic( vs_config->getVariable( "audio", listvars[i], deflistvars[i] ).c_str() );
110 #ifdef USE_SOUNDSERVER
111 #if !defined (_WIN32)
112  if ( g_game.music_enabled && !soundServerPipes() ) {
113  int pid = fork();
114  if (!pid) {
115  string soundserver_path = VSFileSystem::datadir+"/bin/soundserver";
116  pid = execlp( soundserver_path.c_str(), soundserver_path.c_str(), NULL );
117  soundserver_path = VSFileSystem::datadir+"/soundserver";
118  pid = execlp( soundserver_path.c_str(), soundserver_path.c_str(), NULL );
119  g_game.music_enabled = false;
120  VSFileSystem::vs_fprintf( stderr, "Unable to spawn music player server\n" );
121  exit( 0 );
122  } else if (pid == -1) {
123  g_game.music_enabled = false;
124  }
125  }
126 #endif
127 #if defined (_WIN32) && !defined (__CYGWIN__)
128  if ( g_game.music_enabled && !soundServerPipes() ) {
129  string ss_path = VSFileSystem::datadir+"/soundserver.exe";
130  int pid = spawnl( P_NOWAIT, ss_path.c_str(), ss_path.c_str(), NULL );
131  if (pid == -1) {
132  ss_path = VSFileSystem::datadir+"/bin/soundserver.exe";
133  chdir( "bin" );
134  int pid = spawnl( P_NOWAIT, ss_path.c_str(), ss_path.c_str(), NULL );
135  if (pid == -1) {
136  g_game.music_enabled = false;
137  VSFileSystem::vs_fprintf( stderr, "Unable to spawn music player server Error (%d)\n", pid );
138  }
139  }
140  }
141 #endif
142  if ( soundServerPipes() ) {
143  fNET_startup();
144  int pipesw[2];
145  int pipesr[2];
146  socketw = socketr = -1; //FIXME --"How?" --chuck_starchaser
147 #ifdef _WIN32
148 #define pipe _pipe
149 #endif
150  if ( 0 == pipe( pipesw
151 #ifdef _WIN32
152  , 32, O_BINARY
153 #endif
154  )
155  && 0 == pipe( pipesr
156 #ifdef _WIN32
157  , 32, O_BINARY
158 #endif
159  ) ) {
160  socketw = pipesw[1];
161  socketr = pipesr[0];
162  char buffer1[32];
163  char buffer2[32];
164  sprintf( buffer1, "%d", pipesw[0] );
165  sprintf( buffer2, "%d", pipesr[1] );
166 
167 #if defined (_WIN32) && !defined (__CYGWIN__)
168  string ss_path = VSFileSystem::datadir+"/soundserver.exe";
169  int pid = spawnl( P_NOWAIT, ss_path.c_str(), ss_path.c_str(), buffer1, buffer2, NULL );
170  if (pid == -1) {
171  ss_path = VSFileSystem::datadir+"/bin/soundserver.exe";
172  bool chsuccess = (chdir( "bin" ) == 0);
173  int pid = spawnl( P_NOWAIT, ss_path.c_str(), ss_path.c_str(), buffer1, buffer2, NULL );
174  if (chsuccess) chdir( ".." );
175  if (pid == -1) {
176  g_game.music_enabled = false;
177  VSFileSystem::vs_fprintf( stderr, "Unable to spawn music player server Error (%d)\n", pid );
178  }
179  }
180 #else
181  if (g_game.music_enabled) {
182  std::string tmp = VSFileSystem::datadir+"/bin/soundserver";
183  FILE *fp = fopen( tmp.c_str(), "rb" );
184  if (!fp) {
185  tmp = VSFileSystem::datadir+"/soundserver";
186  fp = fopen( tmp.c_str(), "rb" );
187  if (!fp) {
188  g_game.music_enabled = false;
189  socketw = -1;
190  socketr = -1;
191  } else {fclose( fp ); }} else {fclose( fp ); }}
192  if (g_game.music_enabled) {
193  int pid = fork();
194  if (!pid) {
195  string soundserver_path = VSFileSystem::datadir+"/bin/soundserver";
196  pid = execlp( soundserver_path.c_str(), soundserver_path.c_str(), buffer1, buffer2, NULL );
197  soundserver_path = VSFileSystem::datadir+"/soundserver";
198  pid = execlp( soundserver_path.c_str(), soundserver_path.c_str(), buffer1, buffer2, NULL );
199  g_game.music_enabled = false;
200  VSFileSystem::vs_fprintf( stderr, "Unable to spawn music player server\n" );
201  close( atoi( buffer1 ) );
202  close( atoi( buffer2 ) );
203  exit( 0 );
204  } else if (pid == -1) {
205  g_game.music_enabled = false;
206  }
207  }
208 #endif
209  }
210  } else {
211  int socket = -1;
212  INET_startup();
213  for (i = 0; (i < 10) && (socket == -1); i++)
214  socket = INET_ConnectTo( "localhost", 4364 );
215  socketw = socketr = socket;
216  }
217  if (socketw == -1 || socketr == -1) {
218  g_game.music_enabled = false;
219  } else {
220  string data = string( "i" )+vs_config->getVariable( "audio", "music_fadein", "0" )+"\n"
221  "o"+vs_config->getVariable( "audio", "music_fadeout", "0" )+"\n";
222  if ( soundServerPipes() )
223  fNET_Write( socketw, data.size(), data.c_str() );
224  else
225  INET_Write( socketw, data.size(), data.c_str() );
226  }
227 #endif /* USE_SOUNDSERVER */
228  soft_vol_up_latency = XMLSupport::parse_float( vs_config->getVariable( "audio", "music_volume_up_latency", "15" ) );
229  soft_vol_down_latency = XMLSupport::parse_float( vs_config->getVariable( "audio", "music_volume_down_latency", "2" ) );
230  //Hardware volume = 1
231  _SetVolume( 1, true );
232  //Software volume = from config
233  _SetVolume( XMLSupport::parse_float( vs_config->getVariable( "audio", "music_volume", ".5" ) ), false );
234 }
Music::~Music ( )

Definition at line 813 of file music.cpp.

References checkerr, fNET_cleanup(), fNET_close(), fNET_Write(), INET_cleanup(), INET_close(), INET_Write(), micro_sleep, and soundServerPipes().

814 {
815 #ifdef USE_SOUNDSERVER
816  char send[2] = {'t', '\n'};
817  if (socketw != -1) {
818  if ( soundServerPipes() ) {
819  if (threadalive && thread_initialized) {
820  killthread = 1;
821  int spindown = 50; //Thread has 5 seconds to close down.
822  while ( threadalive && (spindown-- > 0) )
823  micro_sleep( 100000 );
824  }
825  fNET_Write( socketw, 2, send );
826  fNET_close( socketw );
827  //fNET_close(socketr);
828  fNET_cleanup();
829  } else {
830  INET_Write( socketw, 2, send );
831  INET_close( socketw );
832  INET_cleanup();
833  }
834  socketw = -1;
835  }
836 #else /* USE_SOUNDSERVER */
837  if (threadalive && thread_initialized) {
838  killthread = 1;
839 #ifdef _WIN32
840  ReleaseMutex( musicinfo_mutex );
841 #else
842  checkerr( pthread_mutex_unlock( &musicinfo_mutex ) );
843 #endif
844  int spindown = 50; //Thread has 5 seconds to close down.
845  while ( threadalive && (spindown-- > 0) )
846  micro_sleep( 100000 );
847  if (threadalive)
848  threadalive = false;
849  }
850  //Kill the thread.
851 #endif /* !USE_SOUNDSERVER */
852 }
Music::Music ( )
inline

Definition at line 104 of file soundserver.mac.notworking.cpp.

References m.

105  {
106  m = NULL;
107  }
Music::Music ( )
inline

Definition at line 144 of file soundserver.segfault.cpp.

References m.

145  {
146  m = NULL;
147  }

Member Function Documentation

int Music::Addlist ( std::string  listfile)
static

Definition at line 767 of file music.cpp.

References g_game, i, game_data_t::music_enabled, and muzak_count.

Referenced by FactionUtil::LoadFactionPlaylists(), and UniverseUtil::musicAddList().

768 {
769  if (!g_game.music_enabled)
770  return -1;
771  int res = -1;
772  if (muzak) res = muzak->_Addlist( listfile );
773  if (muzak)
774  for (int i = 1; i < muzak_count; i++)
775  muzak[i]._Addlist( listfile );
776  return res;
777 }
void Music::ChangeVolume ( float  inc = 0,
int  layer = -1 
)
static

Definition at line 236 of file music.cpp.

References g_game, i, game_data_t::music_enabled, and muzak_count.

Referenced by decmusicvol(), incmusicvol(), VolDown(), and VolUp().

237 {
238  if (!g_game.music_enabled)
239  return;
240  if (muzak) {
241  if (layer < 0)
242  for (int i = 0; i < muzak_count; i++)
243  muzak[i]._SetVolume( muzak[i].soft_vol+inc, false, 0.1 );
244  else if ( (layer >= 0) && (layer < muzak_count) )
245  muzak[layer]._SetVolume( muzak[layer].soft_vol+inc, false, 0.1 );
246  }
247 }
void Music::CleanupMuzak ( )
static

Definition at line 873 of file music.cpp.

References muzak, and muzak_count.

Referenced by cleanup(), and VSExit().

874 {
875  if (muzak) {
876 #ifdef USE_SOUNDSERVER
877  delete[] muzak;
878 #endif
879  //Multithreading issues... don't care to waste time here waiting to get the lock back.
880  //Let the OS clean up this mess!
881  muzak = NULL;
882  muzak_count = 0;
883  }
884 }
void Music::Free ( )
inline

Definition at line 133 of file soundserver.mac.notworking.cpp.

References m.

Referenced by ForkedProcess().

134  {
135  if (m) Mix_FreeMusic( m );
136  }
void Music::Free ( )
inline

Definition at line 173 of file soundserver.segfault.cpp.

References m.

174  {
175  if (m) Mix_FreeMusic( m );
176  }
void Music::GotoSong ( int  whichlist,
int  whichsong,
bool  skip,
int  layer = -1 
)

Definition at line 679 of file music.cpp.

References g_game, VegaConfig::getVariable(), int, game_data_t::music_enabled, muzak_count, NOLIST, XMLSupport::parse_bool(), size, and vs_config.

Referenced by bootstrap_first_loop(), UniverseUtil::musicLayerPlaySong(), BaseComputer::newsPickerChangedSelection(), and UniverseUtil::playVictoryTune().

680 {
681  if (g_game.music_enabled) {
682  if ( whichsong != NOLIST && whichlist != NOLIST && whichlist < (int) playlist.size() && whichsong
683  < (int) playlist[whichlist].size() ) {
684  if (muzak[(layer >= 0) ? layer : 0].lastlist != whichlist) {
685  static bool clear =
686  XMLSupport::parse_bool( vs_config->getVariable( "audio", "shuffle_songs.clear_history_on_list_change",
687  "true" ) );
688  if (clear) {
689  std::list< std::string > &recent = muzak[(layer >= 0) ? layer : 0].recent_songs;
690  recent.clear();
691  }
692  }
693  if ( (layer < 0) && (muzak_count >= 2) )
694  muzak[0].lastlist = muzak[1].lastlist = whichlist;
695 
696  else
697  lastlist = whichlist;
698  GotoSong( playlist[whichlist][whichsong], layer );
699  } else {
700  _SkipRandList( layer );
701  }
702  }
703 }
void Music::GotoSong ( std::string  mus,
int  layer = -1 
)
static

Definition at line 610 of file music.cpp.

References g_game, VegaConfig::getVariable(), game_data_t::music_enabled, muzak_count, muzak_cross_index, XMLSupport::parse_bool(), and vs_config.

611 {
612  if (!g_game.music_enabled)
613  return;
614  static bool cross = XMLSupport::parse_bool( vs_config->getVariable( "audio", "cross_fade_music", "true" ) );
615  if ( cross && (muzak_count >= 2) ) {
616  if (layer < 0) {
617  if (mus == muzak[muzak_cross_index].cur_song_file) return;
618  muzak[muzak_cross_index]._StopLater();
620  muzak[muzak_cross_index]._GotoSong( mus );
621  } else if ( (layer >= 0) && (layer < muzak_count) ) {
622  if (mus == muzak[layer].cur_song_file) return;
623  muzak[layer]._GotoSong( mus );
624  }
625  } else {
626  muzak->_GotoSong( mus );
627  }
628 }
void Music::InitMuzak ( )
static

Definition at line 867 of file music.cpp.

References VegaConfig::getVariable(), muzak_count, XMLSupport::parse_int(), and vs_config.

Referenced by main().

868 {
869  muzak_count = XMLSupport::parse_int( vs_config->getVariable( "audio", "music_layers", "1" ) );
870  muzak = new Music[muzak_count];
871 }
void Music::Listen ( )

Definition at line 511 of file music.cpp.

References AUDBufferSound(), AUDDeleteSound(), AUDIsPlaying(), AUDSoundGain(), AUDStartPlaying(), AUDStreamingSound(), checkerr, fprintf, g_game, INET_BytesToRead(), INET_fgetc(), game_data_t::music_enabled, muzak_cross_index, Muzak::readerThread(), and soundServerPipes().

Referenced by MuzakCycle().

512 {
513  if (g_game.music_enabled) {
514 #ifdef USE_SOUNDSERVER
515  if ( soundServerPipes() ) {
516  killthread = 0;
517  threadalive = 0;
518  if (!thread_initialized) {
519 #ifdef _WIN32
520  a_thread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) Muzak::readerThread, (PVOID) this, 0, NULL );
521 #else
522  int res = pthread_create( &a_thread, NULL, Muzak::readerThread, (void*) this );
523 #endif
524  thread_initialized = 1;
525  }
526  //int bytes=fNET_BytesToRead(socketr);
527  if (moredata) {
528  moredata = 0;
529  cur_song_file = "";
530  _Skip();
531  }
532  } else {
533  int bytes = INET_BytesToRead( socketr );
534  if (bytes) {
535  char data;
536  while (bytes) {
537  data = INET_fgetc( socketr );
538  bytes--;
539  }
540  if (data == 'e') {
541  cur_song_file = "";
542  _Skip();
543  } else {
544  g_game.music_enabled = false;
545  }
546  }
547  }
548 #else /* USE_SOUNDSERVER */
549  if ( !music_load_list.empty() ) {
550  if (music_loaded) {
551  //fprintf(stderr,"LOADED is true\n");
552 #ifdef _WIN32
553  int trylock_ret = 0;
554  if (WaitForSingleObject( musicinfo_mutex, 0 ) == WAIT_TIMEOUT) {
555 #else
556  int trylock_ret = pthread_mutex_trylock( &musicinfo_mutex );
557  if (trylock_ret == EBUSY) {
558 #endif
559  fprintf( stderr, "Failed to lock music loading mutex despite loaded flag being set...\n" );
560  return;
561  } else {
562  checkerr( trylock_ret );
563  }
564  music_loading = false;
565  music_loaded = false; //once the loading thread sees this, it will try to grab a lock and wait.
566  //The lock will only be achieved once the next song is put in the queue.
567 
568 #ifdef HAVE_AL
569  if (music_load_info->success && music_load_info->wave) {
570  int source = AUDBufferSound( music_load_info, true );
571  if (freeWav)
572  free( music_load_info->wave );
573  music_load_info->wave = NULL;
574  if (source != -1)
575  playingSource.push_back( source );
576  }
577 #endif
578  if (playingSource.size() == 1) {
579  //Start playing if first in list.
580  _StopNow();
581  AUDStartPlaying( playingSource.front() );
582  AUDStreamingSound( playingSource.front() );
583  AUDSoundGain( playingSource.front(), vol, true );
584  }
585  music_load_list.pop_back();
586  if ( !music_load_list.empty() )
587  _LoadLastSongAsync();
588  return; //Returns if finished loading, since the AUDIsPlaying() could fail right now.
589  }
590  }
591  if ( !playingSource.empty() )
592  if ( !AUDIsPlaying( playingSource.front() ) ) {
593  AUDDeleteSound( playingSource.front(), true );
594  playingSource.pop_front();
595  if ( !playingSource.empty() ) {
596  _StopNow();
597  AUDStartPlaying( playingSource.front() );
598  AUDSoundGain( playingSource.front(), vol, true );
599  }
600  }
601  if ( playingSource.empty() && muzak[muzak_cross_index].playingSource.empty()
602  && music_load_list.empty() && muzak[muzak_cross_index].music_load_list.empty() ) {
603  cur_song_file = "";
604  _Skip();
605  }
606 #endif /* !USE_SOUNDSERVER */
607  }
608 }
bool Music::Load ( const char *  file)
inline

Definition at line 108 of file soundserver.mac.notworking.cpp.

References m.

Referenced by ForkedProcess(), and PlayMusic().

109  {
110  m = Mix_LoadMUS( file );
111  return m != NULL;
112  }
bool Music::Load ( const char *  file)
inline

Definition at line 148 of file soundserver.segfault.cpp.

References m.

149  {
150  m = Mix_LoadMUS( file );
151  return m != NULL;
152  }
void Music::Mute ( bool  mute = true,
int  layer = -1 
)
static

Definition at line 977 of file music.cpp.

References g_game, VegaConfig::getVariable(), i, game_data_t::music_enabled, muzak_count, XMLSupport::parse_float(), and vs_config.

Referenced by UniverseUtil::musicMute().

978 {
979  static vector< float >saved_vol;
980  saved_vol.resize( muzak_count, -1 );
981  if (!g_game.music_enabled)
982  return;
983  if (muzak) {
984  static float muting_fadeout = XMLSupport::parse_float( vs_config->getVariable( "audio", "music_muting_fadeout", "0.2" ) );
985  static float muting_fadein = XMLSupport::parse_float( vs_config->getVariable( "audio", "music_muting_fadeout", "0.5" ) );
986  if (layer < 0) {
987  for (int i = 0; i < muzak_count; i++) {
988  if (mute) {
989  if (muzak[i].soft_vol != 0) {
990  saved_vol[i] = muzak[i].soft_vol;
991  muzak[i]._SetVolume( 0, false, muting_fadeout );
992  }
993  } else if (saved_vol[i] >= 0) {
994  muzak[i]._SetVolume( saved_vol[i], false, muting_fadein );
995  }
996  }
997  } else if ( (layer >= 0) && (layer < muzak_count) ) {
998  if (mute) {
999  if (muzak[layer].soft_vol != 0) {
1000  saved_vol[layer] = muzak[layer].soft_vol;
1001  muzak[layer]._SetVolume( 0, false, muting_fadeout );
1002  }
1003  } else if (saved_vol[layer] >= 0) {
1004  muzak[layer]._SetVolume( saved_vol[layer], false, muting_fadein );
1005  }
1006  }
1007  }
1008 }
void Music::MuzakCycle ( )
static

Definition at line 886 of file music.cpp.

References BaseInterface::CurrentBase, i, Listen(), and muzak_count.

Referenced by base_main_loop(), bootstrap_draw(), gamemenu_draw(), and main_loop().

887 {
888  if (muzak) {
889  if (BaseInterface::CurrentBase != NULL) {
890  if (!BaseInterface::CurrentBase->isDJEnabled()) {
891  // Bail out... they don't want us running
892  return;
893  }
894  }
895 
896  for (int i = 0; i < muzak_count; i++)
897  muzak[i].Listen();
898  }
899 }
bool Music::Play ( float  fadeout,
float  fadein,
Music oldmusic 
)
inline

Definition at line 113 of file soundserver.mac.notworking.cpp.

References i, m, micro_sleep, and SetVolume().

Referenced by ForkedProcess(), and PlayMusic().

114  {
115  if (m) {
116  int fadesteps = fadeout*100;
117  for (int i = fadesteps; i >= 0; i--) {
118  oldmusic.SetVolume( i/(float) fadesteps );
119  micro_sleep( 10000 );
120  }
121  Mix_FadeInMusic( m, 1, fadein ) != -1;
122  micro_sleep( fadein*1000000 );
123 
124  return true;
125  } else {
126  return false;
127  }
128  }
bool Music::Play ( float  fadeout,
float  fadein,
Music oldmusic 
)
inline

Definition at line 153 of file soundserver.segfault.cpp.

References i, m, micro_sleep, and SetVolume().

154  {
155  if (m) {
156  int fadesteps = fadeout*100;
157  for (int i = fadesteps; i >= 0; i--) {
158  oldmusic.SetVolume( i/(float) fadesteps );
159  micro_sleep( 10000 );
160  }
161  Mix_FadeInMusic( m, 1, fadein ) != -1;
162  micro_sleep( fadein*1000000 );
163 
164  return true;
165  } else {
166  return false;
167  }
168  }
void Music::SetLoops ( int  numloops,
int  layer = -1 
)
static

Definition at line 1010 of file music.cpp.

References g_game, loopsleft, game_data_t::music_enabled, and muzak_count.

Referenced by UniverseUtil::musicLayerLoopList().

1011 {
1012  if (!g_game.music_enabled)
1013  return;
1014  if (muzak) {
1015  if (layer < 0) {
1016  //This only will apply to the crossfading channel (layers 0 && 1)
1017  SetLoops( numloops, 0 );
1018  SetLoops( numloops, 1 );
1019  } else if ( (layer >= 0) && (layer < muzak_count) ) {
1020  //Specific channel
1021  muzak[layer].loopsleft = numloops;
1022  }
1023  }
1024 }
void Music::SetMasterVolume ( float  vol)
inline

Definition at line 182 of file soundserver.segfault.cpp.

References SetVolume().

Referenced by main().

183  {
184  SetVolume( vol );
185  }
void Music::SetParent ( Unit parent)

Definition at line 862 of file music.cpp.

863 {
864  p = parent;
865 }
void Music::SetVolume ( float  vol,
int  layer = -1,
bool  hardware = false,
float  latency_override = -1 
)
static

Definition at line 966 of file music.cpp.

References i, and muzak_count.

Referenced by main(), UniverseUtil::musicLayerSetHardVolume(), UniverseUtil::musicLayerSetSoftVolume(), Play(), and SetMasterVolume().

967 {
968  if (muzak) {
969  if (layer < 0)
970  for (int i = 0; i < muzak_count; i++)
971  muzak[i]._SetVolume( vol, hardware, latency_override );
972  else if ( (layer >= 0) && (layer < muzak_count) )
973  muzak[layer]._SetVolume( vol, hardware, latency_override );
974  }
975 }
void Music::SetVolume ( float  vol)
inline

Definition at line 137 of file soundserver.mac.notworking.cpp.

References GetMaxVolume(), and m.

138  {
139  if (m)
140  Mix_VolumeMusic( vol*GetMaxVolume() );
141  }
void Music::SetVolume ( float  vol)
inline

Definition at line 177 of file soundserver.segfault.cpp.

References GetMaxVolume(), and m.

178  {
179  if (m)
180  Mix_VolumeMusic( vol*GetMaxVolume() );
181  }
void Music::Skip ( int  layer = -1)
static

Definition at line 790 of file music.cpp.

References g_game, game_data_t::music_enabled, muzak_count, and muzak_cross_index.

Referenced by UniverseUtil::musicLayerSkip(), CockpitKeys::SkipMusicTrack(), BaseComputer::switchToControls(), and BaseComputer::~BaseComputer().

791 {
792  if (!g_game.music_enabled)
793  return;
794  if (muzak) {
795  if (layer < 0) {
796  if (muzak_count >= 2)
797  muzak[muzak_cross_index]._Skip();
798 
799  else
800  muzak->_Skip();
801  } else if ( (layer >= 0) && (layer < muzak_count) ) {
802  muzak[layer]._Skip( layer );
803  }
804  }
805 }
void Music::SkipRandList ( int  layer = -1)
static

Definition at line 739 of file music.cpp.

References g_game, game_data_t::music_enabled, muzak_count, and muzak_cross_index.

740 {
741  if (!g_game.music_enabled)
742  return;
743  if (muzak) {
744  if (layer < 0) {
745  if (muzak_count >= 2)
746  muzak[muzak_cross_index]._SkipRandList();
747 
748  else
749  muzak->_SkipRandList();
750  } else if ( (layer >= 0) && (layer < muzak_count) ) {
751  muzak[layer]._SkipRandList( layer );
752  }
753  }
754 }
void Music::SkipRandSong ( int  whichlist,
int  layer = -1 
)
static

Definition at line 705 of file music.cpp.

References muzak_count, and muzak_cross_index.

Referenced by GameUnit< UnitType >::Explode(), and UniverseUtil::musicLayerPlayList().

706 {
707  if (muzak) {
708  if (layer < 0) {
709  if (muzak_count >= 2)
710  muzak[muzak_cross_index]._SkipRandSong( whichlist );
711 
712  else
713  muzak->_SkipRandSong( whichlist );
714  } else if ( (layer >= 0) && (layer < muzak_count) ) {
715  muzak[layer]._SkipRandSong( whichlist, layer );
716  }
717  }
718 }
void Music::Stop ( int  layer = -1)
static

Definition at line 901 of file music.cpp.

References muzak_count, and muzak_cross_index.

Referenced by ForkedProcess(), and UniverseUtil::musicLayerStop().

902 {
903  if (muzak) {
904  if (layer < 0) {
905  if (muzak_count >= 2)
906  muzak[muzak_cross_index]._Stop();
907 
908  else
909  muzak->_Stop();
910  } else if ( (layer >= 0) && (layer < muzak_count) ) {
911  muzak[layer]._Stop();
912  }
913  }
914 }
void Music::Stop ( )
inline

Definition at line 129 of file soundserver.mac.notworking.cpp.

References m.

Referenced by BaseUtil::SetDJEnabled().

130  {
131  if (m) Mix_StopMusic( m );
132  }
void Music::Stop ( )
inline

Definition at line 169 of file soundserver.segfault.cpp.

References m.

170  {
171  if (m) Mix_StopMusic( m );
172  }

Friends And Related Function Documentation

void* Muzak::readerThread ( void *  input)
friend

Member Data Documentation

int Music::loopsleft

Definition at line 89 of file music.h.

Referenced by Music(), and SetLoops().

Mix_Music * Music::m
std::vector< int > Music::sounds_to_stop

Definition at line 113 of file music.h.


The documentation for this struct was generated from the following files: