music.c
branchSDL-1.2
changeset 1081 119300487b73
parent 945 c606c85c8863
equal deleted inserted replaced
1080:dcccb70e568f 1081:119300487b73
   143 /* rcg06042009 report available decoders at runtime. */
   143 /* rcg06042009 report available decoders at runtime. */
   144 static const char **music_decoders = NULL;
   144 static const char **music_decoders = NULL;
   145 static int num_decoders = 0;
   145 static int num_decoders = 0;
   146 
   146 
   147 /* Semicolon-separated SoundFont paths */
   147 /* Semicolon-separated SoundFont paths */
   148 #ifdef MID_MUSIC
       
   149 char* soundfont_paths = NULL;
   148 char* soundfont_paths = NULL;
   150 #endif
       
   151 
   149 
   152 int Mix_GetNumMusicDecoders(void)
   150 int Mix_GetNumMusicDecoders(void)
   153 {
   151 {
   154 	return(num_decoders);
   152 	return(num_decoders);
   155 }
   153 }
  1525 	ms_per_step = 0;
  1523 	ms_per_step = 0;
  1526 }
  1524 }
  1527 
  1525 
  1528 int Mix_SetSoundFonts(const char *paths)
  1526 int Mix_SetSoundFonts(const char *paths)
  1529 {
  1527 {
  1530 #ifdef MID_MUSIC
       
  1531 	if (soundfont_paths) {
  1528 	if (soundfont_paths) {
  1532 		SDL_free(soundfont_paths);
  1529 		SDL_free(soundfont_paths);
  1533 		soundfont_paths = NULL;
  1530 		soundfont_paths = NULL;
  1534 	}
  1531 	}
  1535 
  1532 
  1537 		if (!(soundfont_paths = SDL_strdup(paths))) {
  1534 		if (!(soundfont_paths = SDL_strdup(paths))) {
  1538 			Mix_SetError("Insufficient memory to set SoundFonts");
  1535 			Mix_SetError("Insufficient memory to set SoundFonts");
  1539 			return 0;
  1536 			return 0;
  1540 		}
  1537 		}
  1541 	}
  1538 	}
  1542 #endif
       
  1543 	return 1;
  1539 	return 1;
  1544 }
  1540 }
  1545 
  1541 
  1546 #ifdef MID_MUSIC
       
  1547 const char* Mix_GetSoundFonts(void)
  1542 const char* Mix_GetSoundFonts(void)
  1548 {
  1543 {
  1549 	const char* force = getenv("SDL_FORCE_SOUNDFONTS");
  1544 	const char* force = getenv("SDL_FORCE_SOUNDFONTS");
  1550 
  1545 
  1551 	if (!soundfont_paths || (force && force[0] == '1')) {
  1546 	if (!soundfont_paths || (force && force[0] == '1')) {
  1552 		return getenv("SDL_SOUNDFONTS");
  1547 		return getenv("SDL_SOUNDFONTS");
  1553 	} else {
  1548 	}
  1554 		return soundfont_paths;
  1549 	return soundfont_paths;
  1555 	}
       
  1556 }
  1550 }
  1557 
  1551 
  1558 int Mix_EachSoundFont(int (SDLCALL *function)(const char*, void*), void *data)
  1552 int Mix_EachSoundFont(int (SDLCALL *function)(const char*, void*), void *data)
  1559 {
  1553 {
  1560 	char *context, *path, *paths;
  1554 	char *context, *path, *paths;
  1561 	const char* cpaths = Mix_GetSoundFonts();
  1555 	const char* cpaths = Mix_GetSoundFonts();
       
  1556 	int soundfonts_found = 0;
  1562 
  1557 
  1563 	if (!cpaths) {
  1558 	if (!cpaths) {
  1564 		Mix_SetError("No SoundFonts have been requested");
  1559 		Mix_SetError("No SoundFonts have been requested");
  1565 		return 0;
  1560 		return 0;
  1566 	}
  1561 	}
  1576 	for (path = strtok_s(paths, ";", &context); path; path = strtok_s(NULL, ";", &context)) {
  1571 	for (path = strtok_s(paths, ";", &context); path; path = strtok_s(NULL, ";", &context)) {
  1577 #else
  1572 #else
  1578 	for (path = strtok_r(paths, ":;", &context); path; path = strtok_r(NULL, ":;", &context)) {
  1573 	for (path = strtok_r(paths, ":;", &context); path; path = strtok_r(NULL, ":;", &context)) {
  1579 #endif
  1574 #endif
  1580 		if (!function(path, data)) {
  1575 		if (!function(path, data)) {
  1581 			SDL_free(paths);
  1576 			continue;
  1582 			return 0;
  1577 		}
  1583 		}
  1578 		soundfonts_found++;
  1584 	}
  1579 	}
  1585 
  1580 
  1586 	SDL_free(paths);
  1581 	SDL_free(paths);
  1587 	return 1;
  1582 	return (soundfonts_found > 0);
  1588 }
  1583 }
  1589 #endif