music.c
changeset 481 286c27f54ea1
parent 479 3d8a5a7b1249
child 483 685cb4a41b92
equal deleted inserted replaced
480:30976a327fd3 481:286c27f54ea1
    35 #ifdef CMD_MUSIC
    35 #ifdef CMD_MUSIC
    36 #include "music_cmd.h"
    36 #include "music_cmd.h"
    37 #endif
    37 #endif
    38 #ifdef WAV_MUSIC
    38 #ifdef WAV_MUSIC
    39 #include "wavestream.h"
    39 #include "wavestream.h"
       
    40 #endif
       
    41 #ifdef MODPLUG_MUSIC
       
    42 #include "music_modplug.h"
    40 #endif
    43 #endif
    41 #ifdef MOD_MUSIC
    44 #ifdef MOD_MUSIC
    42 #include "music_mod.h"
    45 #include "music_mod.h"
    43 #endif
    46 #endif
    44 #ifdef MID_MUSIC
    47 #ifdef MID_MUSIC
    85 #ifdef CMD_MUSIC
    88 #ifdef CMD_MUSIC
    86 		MusicCMD *cmd;
    89 		MusicCMD *cmd;
    87 #endif
    90 #endif
    88 #ifdef WAV_MUSIC
    91 #ifdef WAV_MUSIC
    89 		WAVStream *wave;
    92 		WAVStream *wave;
       
    93 #endif
       
    94 #ifdef MODPLUG_MUSIC
       
    95 		modplug_data *modplug;
    90 #endif
    96 #endif
    91 #ifdef MOD_MUSIC
    97 #ifdef MOD_MUSIC
    92 		struct MODULE *module;
    98 		struct MODULE *module;
    93 #endif
    99 #endif
    94 #ifdef MID_MUSIC
   100 #ifdef MID_MUSIC
   251 #ifdef WAV_MUSIC
   257 #ifdef WAV_MUSIC
   252 			case MUS_WAV:
   258 			case MUS_WAV:
   253 				left = WAVStream_PlaySome(stream, len);
   259 				left = WAVStream_PlaySome(stream, len);
   254 				break;
   260 				break;
   255 #endif
   261 #endif
       
   262 #ifdef MODPLUG_MUSIC
       
   263 			case MUS_MODPLUG:
       
   264 				left = modplug_playAudio(music_playing->data.modplug, stream, len);
       
   265 				break;
       
   266 #endif
   256 #ifdef MOD_MUSIC
   267 #ifdef MOD_MUSIC
   257 			case MUS_MOD:
   268 			case MUS_MOD:
   258 				left = MOD_playAudio(music_playing->data.module, stream, len);
   269 				left = MOD_playAudio(music_playing->data.module, stream, len);
   259 				break;
   270 				break;
   260 #endif
   271 #endif
   305 int open_music(SDL_AudioSpec *mixer)
   316 int open_music(SDL_AudioSpec *mixer)
   306 {
   317 {
   307 #ifdef WAV_MUSIC
   318 #ifdef WAV_MUSIC
   308 	if ( WAVStream_Init(mixer) == 0 ) {
   319 	if ( WAVStream_Init(mixer) == 0 ) {
   309 		add_music_decoder("WAVE");
   320 		add_music_decoder("WAVE");
       
   321 	}
       
   322 #endif
       
   323 #ifdef MODPLUG_MUSIC
       
   324 	if ( modplug_init(mixer) < 0 ) {
       
   325 		++music_error;
       
   326 	} else {
       
   327 		add_music_decoder("MODPLUG");
   310 	}
   328 	}
   311 #endif
   329 #endif
   312 #ifdef MOD_MUSIC
   330 #ifdef MOD_MUSIC
   313 	if ( MOD_init(mixer) == 0 ) {
   331 	if ( MOD_init(mixer) == 0 ) {
   314 		add_music_decoder("MIKMOD");
   332 		add_music_decoder("MIKMOD");
   525 		    Mix_SetError("Could not initialize MPEG stream.");
   543 		    Mix_SetError("Could not initialize MPEG stream.");
   526 			music->error = 1;
   544 			music->error = 1;
   527 		}
   545 		}
   528 	} else
   546 	} else
   529 #endif
   547 #endif
       
   548 #ifdef MODPLUG_MUSIC
       
   549 	if ( 1 ) {
       
   550 		music->type = MUS_MODPLUG;
       
   551 		music->data.modplug = modplug_new(file);
       
   552 		if ( music->data.modplug == NULL ) {
       
   553 			music->error = 1;
       
   554 		}
       
   555 	} else
       
   556 #endif
   530 #ifdef MOD_MUSIC
   557 #ifdef MOD_MUSIC
   531 	if ( 1 ) {
   558 	if ( 1 ) {
   532 		music->type = MUS_MOD;
   559 		music->type = MUS_MOD;
   533 		music->data.module = MOD_new(file);
   560 		music->data.module = MOD_new(file);
   534 		if ( music->data.module == NULL ) {
   561 		if ( music->data.module == NULL ) {
   574 #ifdef WAV_MUSIC
   601 #ifdef WAV_MUSIC
   575 			case MUS_WAV:
   602 			case MUS_WAV:
   576 				WAVStream_FreeSong(music->data.wave);
   603 				WAVStream_FreeSong(music->data.wave);
   577 				break;
   604 				break;
   578 #endif
   605 #endif
       
   606 #ifdef MODPLUG_MUSIC
       
   607 			case MUS_MODPLUG:
       
   608 				modplug_delete(music->data.modplug);
       
   609 				break;
       
   610 #endif
   579 #ifdef MOD_MUSIC
   611 #ifdef MOD_MUSIC
   580 			case MUS_MOD:
   612 			case MUS_MOD:
   581 				MOD_delete(music->data.module);
   613 				MOD_delete(music->data.module);
   582 				break;
   614 				break;
   583 #endif
   615 #endif
   667 		break;
   699 		break;
   668 #endif
   700 #endif
   669 #ifdef WAV_MUSIC
   701 #ifdef WAV_MUSIC
   670 	    case MUS_WAV:
   702 	    case MUS_WAV:
   671 		WAVStream_Start(music->data.wave);
   703 		WAVStream_Start(music->data.wave);
       
   704 		break;
       
   705 #endif
       
   706 #ifdef MODPLUG_MUSIC
       
   707 	    case MUS_MODPLUG:
       
   708 		/* can't set volume until file is loaded, so finally set it now */
       
   709 		music_internal_initialize_volume();
       
   710 		modplug_play(music->data.modplug);
   672 		break;
   711 		break;
   673 #endif
   712 #endif
   674 #ifdef MOD_MUSIC
   713 #ifdef MOD_MUSIC
   675 	    case MUS_MOD:
   714 	    case MUS_MOD:
   676 		MOD_play(music->data.module);
   715 		MOD_play(music->data.module);
   785 int music_internal_position(double position)
   824 int music_internal_position(double position)
   786 {
   825 {
   787 	int retval = 0;
   826 	int retval = 0;
   788 
   827 
   789 	switch (music_playing->type) {
   828 	switch (music_playing->type) {
       
   829 #ifdef MODPLUG_MUSIC
       
   830 	    case MUS_MODPLUG:
       
   831 		modplug_jump_to_time(music_playing->data.modplug, position);
       
   832 		break;
       
   833 #endif
   790 #ifdef MOD_MUSIC
   834 #ifdef MOD_MUSIC
   791 	    case MUS_MOD:
   835 	    case MUS_MOD:
   792 		MOD_jump_to_time(music_playing->data.module, position);
   836 		MOD_jump_to_time(music_playing->data.module, position);
   793 		break;
   837 		break;
   794 #endif
   838 #endif
   865 #ifdef WAV_MUSIC
   909 #ifdef WAV_MUSIC
   866 	    case MUS_WAV:
   910 	    case MUS_WAV:
   867 		WAVStream_SetVolume(volume);
   911 		WAVStream_SetVolume(volume);
   868 		break;
   912 		break;
   869 #endif
   913 #endif
       
   914 #ifdef MODPLUG_MUSIC
       
   915 	    case MUS_MODPLUG:
       
   916 		modplug_setvolume(music_playing->data.modplug, volume);
       
   917 		break;
       
   918 #endif
   870 #ifdef MOD_MUSIC
   919 #ifdef MOD_MUSIC
   871 	    case MUS_MOD:
   920 	    case MUS_MOD:
   872 		MOD_setvolume(music_playing->data.module, volume);
   921 		MOD_setvolume(music_playing->data.module, volume);
   873 		break;
   922 		break;
   874 #endif
   923 #endif
   941 		break;
   990 		break;
   942 #endif
   991 #endif
   943 #ifdef WAV_MUSIC
   992 #ifdef WAV_MUSIC
   944 	    case MUS_WAV:
   993 	    case MUS_WAV:
   945 		WAVStream_Stop();
   994 		WAVStream_Stop();
       
   995 		break;
       
   996 #endif
       
   997 #ifdef MODPLUG_MUSIC
       
   998 	    case MUS_MODPLUG:
       
   999 		modplug_stop(music_playing->data.modplug);
   946 		break;
  1000 		break;
   947 #endif
  1001 #endif
   948 #ifdef MOD_MUSIC
  1002 #ifdef MOD_MUSIC
   949 	    case MUS_MOD:
  1003 	    case MUS_MOD:
   950 		MOD_stop(music_playing->data.module);
  1004 		MOD_stop(music_playing->data.module);
  1089 		if ( ! WAVStream_Active() ) {
  1143 		if ( ! WAVStream_Active() ) {
  1090 			playing = 0;
  1144 			playing = 0;
  1091 		}
  1145 		}
  1092 		break;
  1146 		break;
  1093 #endif
  1147 #endif
       
  1148 #ifdef MODPLUG_MUSIC
       
  1149 	    case MUS_MODPLUG:
       
  1150 		if ( ! modplug_playing(music_playing->data.modplug) ) {
       
  1151 			playing = 0;
       
  1152 		}
       
  1153 		break;
       
  1154 #endif
  1094 #ifdef MOD_MUSIC
  1155 #ifdef MOD_MUSIC
  1095 	    case MUS_MOD:
  1156 	    case MUS_MOD:
  1096 		if ( ! MOD_playing(music_playing->data.module) ) {
  1157 		if ( ! MOD_playing(music_playing->data.module) ) {
  1097 			playing = 0;
  1158 			playing = 0;
  1098 		}
  1159 		}
  1195 void close_music(void)
  1256 void close_music(void)
  1196 {
  1257 {
  1197 	Mix_HaltMusic();
  1258 	Mix_HaltMusic();
  1198 #ifdef CMD_MUSIC
  1259 #ifdef CMD_MUSIC
  1199 	Mix_SetMusicCMD(NULL);
  1260 	Mix_SetMusicCMD(NULL);
       
  1261 #endif
       
  1262 #ifdef MODPLUG_MUSIC
       
  1263 	modplug_exit();
  1200 #endif
  1264 #endif
  1201 #ifdef MOD_MUSIC
  1265 #ifdef MOD_MUSIC
  1202 	MOD_exit();
  1266 	MOD_exit();
  1203 #endif
  1267 #endif
  1204 #ifdef MID_MUSIC
  1268 #ifdef MID_MUSIC
  1333 			music->error = 1;
  1397 			music->error = 1;
  1334 		}
  1398 		}
  1335 #endif
  1399 #endif
  1336 	} else
  1400 	} else
  1337 #endif
  1401 #endif
       
  1402 #if defined(MODPLUG_MUSIC) || defined(MODPLUG_MUSIC)
       
  1403 	if (1) {
       
  1404 		music->error = 1;
       
  1405 #ifdef MODPLUG_MUSIC
       
  1406 		if ( music->error ) {
       
  1407 			music->type = MUS_MODPLUG;
       
  1408 			music->data.modplug = modplug_new_RW(rw);
       
  1409 			if ( music->data.modplug ) {
       
  1410 				music->error = 0;
       
  1411 			}
       
  1412 		}
       
  1413 #endif
  1338 #ifdef MOD_MUSIC
  1414 #ifdef MOD_MUSIC
  1339 	if (1) {
  1415 		if ( music->error ) {
  1340 		music->type=MUS_MOD;
  1416 			music->type = MUS_MOD;
  1341 		music->data.module = MOD_new_RW(rw);
  1417 			music->data.module = MOD_new_RW(rw);
  1342 		if ( music->data.module == NULL ) {
  1418 			if ( music->data.module ) {
  1343 			music->error = 1;
  1419 				music->error = 0;
  1344 		}
  1420 			}
  1345 	} else
  1421 		}
  1346 #endif
  1422 #endif
       
  1423 	} else
       
  1424 #endif /* MODPLUG_MUSIC || MOD_MUSIC */
  1347 	{
  1425 	{
  1348 		Mix_SetError("Unrecognized music format");
  1426 		Mix_SetError("Unrecognized music format");
  1349 		music->error=1;
  1427 		music->error=1;
  1350 	}
  1428 	}
  1351 	if (music->error) {
  1429 	if (music->error) {