music.c
changeset 561 87bdb4c81c0b
parent 547 a9a5f18ea123
child 565 64688955a7b2
equal deleted inserted replaced
560:0fc8dffb86c5 561:87bdb4c81c0b
   161 	return(music_decoders[index]);
   161 	return(music_decoders[index]);
   162 }
   162 }
   163 
   163 
   164 static void add_music_decoder(const char *decoder)
   164 static void add_music_decoder(const char *decoder)
   165 {
   165 {
   166 	void *ptr = realloc(music_decoders, (num_decoders + 1) * sizeof (const char **));
   166 	void *ptr = SDL_realloc(music_decoders, (num_decoders + 1) * sizeof (const char **));
   167 	if (ptr == NULL) {
   167 	if (ptr == NULL) {
   168 		return;  /* oh well, go on without it. */
   168 		return;  /* oh well, go on without it. */
   169 	}
   169 	}
   170 	music_decoders = (const char **) ptr;
   170 	music_decoders = (const char **) ptr;
   171 	music_decoders[num_decoders++] = decoder;
   171 	music_decoders[num_decoders++] = decoder;
   518 	char *ext = strrchr(file, '.');
   518 	char *ext = strrchr(file, '.');
   519 
   519 
   520 #ifdef CMD_MUSIC
   520 #ifdef CMD_MUSIC
   521 	if ( music_cmd ) {
   521 	if ( music_cmd ) {
   522 		/* Allocate memory for the music structure */
   522 		/* Allocate memory for the music structure */
   523 		music = (Mix_Music *)malloc(sizeof(Mix_Music));
   523 		music = (Mix_Music *)SDL_malloc(sizeof(Mix_Music));
   524 		if ( music == NULL ) {
   524 		if ( music == NULL ) {
   525 			Mix_SetError("Out of memory");
   525 			Mix_SetError("Out of memory");
   526 			return(NULL);
   526 			return(NULL);
   527 		}
   527 		}
   528 		music->error = 0;
   528 		music->error = 0;
   529 		music->type = MUS_CMD;
   529 		music->type = MUS_CMD;
   530 		music->data.cmd = MusicCMD_LoadSong(music_cmd, file);
   530 		music->data.cmd = MusicCMD_LoadSong(music_cmd, file);
   531 		if ( music->data.cmd == NULL ) {
   531 		if ( music->data.cmd == NULL ) {
   532 			free(music);
   532 			SDL_free(music);
   533 			music == NULL;
   533 			music == NULL;
   534 		}
   534 		}
   535 		return music;
   535 		return music;
   536 	}
   536 	}
   537 #endif
   537 #endif
   604 			return NULL;
   604 			return NULL;
   605 		}
   605 		}
   606 	}
   606 	}
   607 
   607 
   608 	/* Allocate memory for the music structure */
   608 	/* Allocate memory for the music structure */
   609 	music = (Mix_Music *)malloc(sizeof(Mix_Music));
   609 	music = (Mix_Music *)SDL_malloc(sizeof(Mix_Music));
   610 	if (music == NULL ) {
   610 	if (music == NULL ) {
   611 		Mix_SetError("Out of memory");
   611 		Mix_SetError("Out of memory");
   612 		return NULL;
   612 		return NULL;
   613 	}
   613 	}
   614 	music->error = 0;
   614 	music->error = 0;
   743 		music->error=1;
   743 		music->error=1;
   744 	} /* switch (want) */
   744 	} /* switch (want) */
   745 
   745 
   746 
   746 
   747 	if (music->error) {
   747 	if (music->error) {
   748 		free(music);
   748 		SDL_free(music);
   749 		music=NULL;
   749 		music=NULL;
   750 	}
   750 	}
   751 	return(music);
   751 	return(music);
   752 }
   752 }
   753 
   753 
   836 				/* Unknown music type?? */
   836 				/* Unknown music type?? */
   837 				break;
   837 				break;
   838 		}
   838 		}
   839 
   839 
   840     skip:
   840     skip:
   841 		free(music);
   841 		SDL_free(music);
   842 	}
   842 	}
   843 }
   843 }
   844 
   844 
   845 /* Find out the music format of a mixer music, or the currently playing
   845 /* Find out the music format of a mixer music, or the currently playing
   846    music, if 'music' is NULL.
   846    music, if 'music' is NULL.
  1479 /* Set the external music playback command */
  1479 /* Set the external music playback command */
  1480 int Mix_SetMusicCMD(const char *command)
  1480 int Mix_SetMusicCMD(const char *command)
  1481 {
  1481 {
  1482 	Mix_HaltMusic();
  1482 	Mix_HaltMusic();
  1483 	if ( music_cmd ) {
  1483 	if ( music_cmd ) {
  1484 		free(music_cmd);
  1484 		SDL_free(music_cmd);
  1485 		music_cmd = NULL;
  1485 		music_cmd = NULL;
  1486 	}
  1486 	}
  1487 	if ( command ) {
  1487 	if ( command ) {
  1488 		music_cmd = (char *)malloc(strlen(command)+1);
  1488 		music_cmd = (char *)SDL_malloc(strlen(command)+1);
  1489 		if ( music_cmd == NULL ) {
  1489 		if ( music_cmd == NULL ) {
  1490 			return(-1);
  1490 			return(-1);
  1491 		}
  1491 		}
  1492 		strcpy(music_cmd, command);
  1492 		strcpy(music_cmd, command);
  1493 	}
  1493 	}
  1525 	Timidity_Close();
  1525 	Timidity_Close();
  1526 # endif
  1526 # endif
  1527 #endif
  1527 #endif
  1528 
  1528 
  1529 	/* rcg06042009 report available decoders at runtime. */
  1529 	/* rcg06042009 report available decoders at runtime. */
  1530 	free(music_decoders);
  1530 	SDL_free(music_decoders);
  1531 	music_decoders = NULL;
  1531 	music_decoders = NULL;
  1532 	num_decoders = 0;
  1532 	num_decoders = 0;
  1533 
  1533 
  1534 	ms_per_step = 0;
  1534 	ms_per_step = 0;
  1535 }
  1535 }
  1536 
  1536 
  1537 int Mix_SetSoundFonts(const char *paths)
  1537 int Mix_SetSoundFonts(const char *paths)
  1538 {
  1538 {
  1539 #ifdef MID_MUSIC
  1539 #ifdef MID_MUSIC
  1540 	if (soundfont_paths) {
  1540 	if (soundfont_paths) {
  1541 		free(soundfont_paths);
  1541 		SDL_free(soundfont_paths);
  1542 		soundfont_paths = NULL;
  1542 		soundfont_paths = NULL;
  1543 	}
  1543 	}
  1544 
  1544 
  1545 	if (paths) {
  1545 	if (paths) {
  1546 		if (!(soundfont_paths = strdup(paths))) {
  1546 		if (!(soundfont_paths = SDL_strdup(paths))) {
  1547 			Mix_SetError("Insufficient memory to set SoundFonts");
  1547 			Mix_SetError("Insufficient memory to set SoundFonts");
  1548 			return 0;
  1548 			return 0;
  1549 		}
  1549 		}
  1550 	}
  1550 	}
  1551 #endif
  1551 #endif
  1572 	if (!cpaths) {
  1572 	if (!cpaths) {
  1573 		Mix_SetError("No SoundFonts have been requested");
  1573 		Mix_SetError("No SoundFonts have been requested");
  1574 		return 0;
  1574 		return 0;
  1575 	}
  1575 	}
  1576 
  1576 
  1577 	if (!(paths = strdup(cpaths))) {
  1577 	if (!(paths = SDL_strdup(cpaths))) {
  1578 		Mix_SetError("Insufficient memory to iterate over SoundFonts");
  1578 		Mix_SetError("Insufficient memory to iterate over SoundFonts");
  1579 		return 0;
  1579 		return 0;
  1580 	}
  1580 	}
  1581 
  1581 
  1582 #if defined(__MINGW32__) || defined(__MINGW64__)
  1582 #if defined(__MINGW32__) || defined(__MINGW64__)
  1585 	for (path = strtok_s(paths, ";", &context); path; path = strtok_s(NULL, ";", &context)) {
  1585 	for (path = strtok_s(paths, ";", &context); path; path = strtok_s(NULL, ";", &context)) {
  1586 #else
  1586 #else
  1587 	for (path = strtok_r(paths, ":;", &context); path; path = strtok_r(NULL, ":;", &context)) {
  1587 	for (path = strtok_r(paths, ":;", &context); path; path = strtok_r(NULL, ":;", &context)) {
  1588 #endif
  1588 #endif
  1589 		if (!function(path, data)) {
  1589 		if (!function(path, data)) {
  1590 			free(paths);
  1590 			SDL_free(paths);
  1591 			return 0;
  1591 			return 0;
  1592 		}
  1592 		}
  1593 	}
  1593 	}
  1594 
  1594 
  1595 	free(paths);
  1595 	SDL_free(paths);
  1596 	return 1;
  1596 	return 1;
  1597 }
  1597 }
  1598 #endif
  1598 #endif