void BGM_PlayCDtrack (byte track, qboolean looping) { /* instead of searching by the order of music_handlers, do so by * the order of searchpath priority: the file from the searchpath * with the highest path_id is most likely from our own gamedir * itself. This way, if a mod has track02 as a *.mp3 file, which * is below *.ogg in the music_handler order, the mp3 will still * have priority over track02.ogg from, say, data1. */ char tmp[MAX_QPATH]; const char *ext; unsigned int path_id, prev_id, type; music_handler_t *handler; BGM_Stop(); if (CDAudio_Play(track, looping) == 0) return; /* success */ if (music_handlers == NULL) return; if (no_extmusic || !bgm_extmusic.value) return; prev_id = 0; type = 0; ext = NULL; handler = music_handlers; while (handler) { if (! handler->is_available) goto _next; if (! CDRIPTYPE(handler->type)) goto _next; q_snprintf(tmp, sizeof(tmp), "%s/track%02d.%s", MUSIC_DIRNAME, (int)track, handler->ext); if (! FS_FileExists(tmp, &path_id)) goto _next; if (path_id > prev_id) { prev_id = path_id; type = handler->type; ext = handler->ext; } _next: handler = handler->next; } if (ext == NULL) Con_Printf("Couldn't find a cdrip for track %d\n", (int)track); else { q_snprintf(tmp, sizeof(tmp), "%s/track%02d.%s", MUSIC_DIRNAME, (int)track, ext); bgmstream = S_CodecOpenStreamType(tmp, type); if (! bgmstream) Con_Printf("Couldn't handle music file %s\n", tmp); } }
void BGM_Play (const char *filename) { char tmp[MAX_QPATH]; const char *ext; music_handler_t *handler; BGM_Stop(); if (music_handlers == NULL) return; if (!filename || !*filename) { Con_DPrintf("null music file name\n"); return; } ext = COM_FileGetExtension(filename); if (! *ext) /* try all things */ { BGM_Play_noext(filename, ANY_CODECTYPE); return; } handler = music_handlers; while (handler) { if (handler->is_available && !q_strcasecmp(ext, handler->ext)) break; handler = handler->next; } if (!handler) { Con_Printf("Unhandled extension for %s\n", filename); return; } q_snprintf(tmp, sizeof(tmp), "%s/%s", handler->dir, filename); switch (handler->player) { case BGM_MIDIDRV: /* not supported in quake */ break; case BGM_STREAMER: bgmstream = S_CodecOpenStreamType(tmp, handler->type); if (bgmstream) return; /* success */ break; case BGM_NONE: default: break; } Con_Printf("Couldn't handle music file %s\n", filename); }
static void BGM_Play_noext (const char *filename, unsigned int allowed_types) { char tmp[MAX_QPATH]; music_handler_t *handler; handler = music_handlers; while (handler) { if (! (handler->type & allowed_types)) { handler = handler->next; continue; } if (!handler->is_available) { handler = handler->next; continue; } q_snprintf(tmp, sizeof(tmp), "%s/%s.%s", handler->dir, filename, handler->ext); switch (handler->player) { case BGM_MIDIDRV: if (BGM_Play_mididrv(tmp) == 0) return; /* success */ /* BGM_MIDIDRV is followed by CODECTYPE_MID streamer. * Even if the midi driver failed, we may still have * a chance with the streamer if it's available... */ if (! (handler->next && handler->next->is_available)) break; handler = handler->next; case BGM_STREAMER: bgmstream = S_CodecOpenStreamType(tmp, handler->type); if (bgmstream) return; /* success */ break; case BGM_NONE: default: break; } handler = handler->next; } Con_Printf("Couldn't handle music file %s\n", filename); }
static void BGM_Play_noext (const char *filename, unsigned int allowed_types) { char tmp[MAX_QPATH]; music_handler_t *handler; handler = music_handlers; while (handler) { if (! (handler->type & allowed_types)) { handler = handler->next; continue; } if (!handler->is_available) { handler = handler->next; continue; } q_snprintf(tmp, sizeof(tmp), "%s/%s.%s", handler->dir, filename, handler->ext); switch (handler->player) { case BGM_MIDIDRV: /* not supported in quake */ break; case BGM_STREAMER: bgmstream = S_CodecOpenStreamType(tmp, handler->type); if (bgmstream) return; /* success */ break; case BGM_NONE: default: break; } handler = handler->next; } Con_Printf("Couldn't handle music file %s\n", filename); }
void BGM_PlayMIDIorMusic (const char *filename) { /* instead of searching by the order of music_handlers, do so by * the order of searchpath priority: the file from the searchpath * with the highest path_id is most likely from our own gamedir * itself. this way, if a mod has egyp1 as a mp3 or a midi, which * is below *.ogg in the music_handler order, the mp3 or midi will * still have priority over egyp1.ogg from, say, data1. */ char tmp[MAX_QPATH]; const char *ext, *dir; unsigned int path_id, prev_id, type; qboolean try_midi_stream; music_handler_t *handler; if (music_handlers == NULL) return; BGM_Stop(); if (!filename || !*filename) { Con_DPrintf("null music file name\n"); return; } ext = COM_FileGetExtension(filename); if (*ext != '\0') { BGM_Play(filename); return; } prev_id = 0; type = 0; dir = ext = NULL; handler = music_handlers; try_midi_stream = false; while (handler) { if (! handler->is_available) goto _next; if (! MIDITYPE(handler->type) && (no_extmusic || !bgm_extmusic.value)) goto _next; q_snprintf(tmp, sizeof(tmp), "%s/%s.%s", handler->dir, filename, handler->ext); if (! FS_FileExists(tmp, &path_id)) { if (handler->type == MIDIDRIVER_MID) break; goto _next; } if (path_id > prev_id) { prev_id = path_id; type = handler->type; ext = handler->ext; dir = handler->dir; if (handler->type == MIDIDRIVER_MID) { if (handler->next && handler->next->is_available) try_midi_stream = true; break; } } _next: handler = handler->next; } if (ext == NULL) Con_Printf("Couldn't handle music file %s\n", filename); else { q_snprintf(tmp, sizeof(tmp), "%s/%s.%s", dir, filename, ext); switch (type) { case MIDIDRIVER_MID: if (BGM_Play_mididrv(tmp) == 0) return; /* success */ /* BGM_MIDIDRV is followed by CODECTYPE_MID streamer. * Even if the midi driver failed, we may still have * a chance with the streamer if it's available... */ if (!try_midi_stream) break; type = CODECTYPE_MID; default: bgmstream = S_CodecOpenStreamType(tmp, type); if (bgmstream) return; /* success */ } Con_Printf("Couldn't handle music file %s\n", tmp); } }
void BGM_Play (const char *filename) { char tmp[MAX_QPATH]; const char *ext; music_handler_t *handler; BGM_Stop(); if (music_handlers == NULL) return; if (!filename || !*filename) { Con_DPrintf("null music file name\n"); return; } ext = COM_FileGetExtension(filename); if (! *ext) /* try all things */ { BGM_Play_noext(filename, ANY_CODECTYPE); return; } /* use the filename as is */ handler = music_handlers; while (handler) { if (handler->is_available && !q_strcasecmp(ext, handler->ext)) break; handler = handler->next; } if (!handler) { Con_Printf("Unhandled extension for %s\n", filename); return; } q_snprintf(tmp, sizeof(tmp), "%s/%s", handler->dir, filename); switch (handler->player) { case BGM_MIDIDRV: if (BGM_Play_mididrv(tmp) == 0) return; /* success */ /* BGM_MIDIDRV is followed by CODECTYPE_MID streamer. * Even if the midi driver failed, we may still have * a chance with the streamer if it's available... */ if (! (handler->next && handler->next->is_available)) break; handler = handler->next; case BGM_STREAMER: bgmstream = S_CodecOpenStreamType(tmp, handler->type); if (bgmstream) return; /* success */ break; case BGM_NONE: default: break; } Con_Printf("Couldn't handle music file %s\n", filename); }