Skip to content

Commit 54cc67f

Browse files
committed
mod: Allow mods to start at specific "order".
Fixes #826. (cherry picked from commit b004875)
1 parent deba6e4 commit 54cc67f

22 files changed

Lines changed: 50 additions & 8 deletions

docs/README-migration.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ think that once you move to them, you'll be quite happy you did.
1717
There are a lot of things that don't have simple replacements that can be
1818
changed mechanically to migrate to SDL3_mixer. The new API is in many ways
1919
more powerful, but also much simpler. For example, there's no equivalent of
20-
Mix_ModMusicJumpToOrder(), because messing with the specifics
21-
of MOD files in the public API is both uncommon and generally pretty messy.
20+
Mix_GetNumTracks(), because messing with the specifics of MOD files in the
21+
public API is both uncommon and generally pretty messy.
2222

2323
This migration guide will attempt to walk through the important details but
2424
it's possible that some things can't be done the same way. Feel free to open
@@ -34,10 +34,8 @@ function name and a brief explanation about what to do with it.
3434
and packaged it as a separate library that can be used alongside SDL3_mixer,
3535
or without SDL_mixer at all: https://github.com/libsdl-org/SDL_native_midi
3636

37-
- Mix_GetNumTracks(), Mix_StartTrack(), and Mix_ModMusicJumpToOrder() have
38-
been removed; these were decoder-specific APIs.
39-
40-
- Mix_SetSoundFonts(), Mix_GetSoundFonts(), Mix_EachSoundFont(),
37+
- Mix_GetNumTracks(), Mix_StartTrack(), Mix_ModMusicJumpToOrder(),
38+
Mix_SetSoundFonts(), Mix_GetSoundFonts(), Mix_EachSoundFont(),
4139
Mix_SetTimidityCfg(), Mix_GetTimidityCfg(): these have been removed, but
4240
decoder-specific settings can be passed on in a generic way in SDL3_mixer,
4341
using SDL properties.
@@ -392,7 +390,7 @@ can discuss it!
392390
- Mix_ResumeMusic => MIX_ResumeTrack
393391
- Mix_RewindMusic => MIX_SetTrackPlaybackPosition(track, 0)
394392
- Mix_PausedMusic => MIX_TrackPaused
395-
- Mix_ModMusicJumpToOrder => no equivalent in SDL3_mixer.
393+
- Mix_ModMusicJumpToOrder => MIX_PlayTrack with MIX_PROP_PLAY_START_ORDER_NUMBER property set.
396394
- Mix_StartTrack => no equivalent in SDL3_mixer.
397395
- Mix_GetNumTracks => no equivalent in SDL3_mixer.
398396
- Mix_SetMusicPosition => MIX_SetTrackPlaybackPosition

include/SDL3_mixer/SDL_mixer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,14 @@ extern SDL_DECLSPEC Sint64 SDLCALL MIX_FramesToMS(int sample_rate, Sint64 frames
18851885
* possible. Note that a track is not consider exhausted until all its loops
18861886
* and appended silence have been mixed (and also, that loops don't mean
18871887
* anything when the input is an AudioStream). Default true.
1888+
* - `MIX_PROP_PLAY_START_ORDER_NUMBER`: This is a special-case property
1889+
* that most apps can ignore. For mod file formats, start mixing from a
1890+
* specific "order" index instead of the start of the file. A value < 0 will
1891+
* cause this property to be ignored. If the decoder doesn't support this
1892+
* property, it will also be ignored. If this property is _not_ ignored,
1893+
* the MIX_PROP_PLAY_START_FRAME_NUMBER and
1894+
* MIX_PROP_PLAY_START_MILLISECOND_NUMBER properties will be ignored instead.
1895+
* Default -1. Since SDL_mixer 3.2.2.
18881896
*
18891897
* If this function fails, mixing of this track will not start (or restart, if
18901898
* it was already started).
@@ -1910,6 +1918,7 @@ extern SDL_DECLSPEC bool SDLCALL MIX_PlayTrack(MIX_Track *track, SDL_PropertiesI
19101918
#define MIX_PROP_PLAY_MAX_MILLISECONDS_NUMBER "SDL_mixer.play.max_milliseconds"
19111919
#define MIX_PROP_PLAY_START_FRAME_NUMBER "SDL_mixer.play.start_frame"
19121920
#define MIX_PROP_PLAY_START_MILLISECOND_NUMBER "SDL_mixer.play.start_millisecond"
1921+
#define MIX_PROP_PLAY_START_ORDER_NUMBER "SDL_mixer.play.start_order"
19131922
#define MIX_PROP_PLAY_LOOP_START_FRAME_NUMBER "SDL_mixer.play.loop_start_frame"
19141923
#define MIX_PROP_PLAY_LOOP_START_MILLISECOND_NUMBER "SDL_mixer.play.loop_start_millisecond"
19151924
#define MIX_PROP_PLAY_FADE_IN_FRAMES_NUMBER "SDL_mixer.play.fade_in_frames"

src/SDL_mixer.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,7 @@ bool MIX_PlayTrack(MIX_Track *track, SDL_PropertiesID options)
22422242
Sint64 loop_start = 0;
22432243
Sint64 fade_in = 0;
22442244
Sint64 append_silence_frames = 0;
2245+
int start_order = -1;
22452246
float fade_start_gain = 0.0f;
22462247
bool halt_when_exhausted = true;
22472248

@@ -2255,6 +2256,7 @@ bool MIX_PlayTrack(MIX_Track *track, SDL_PropertiesID options)
22552256
fade_start_gain = SDL_GetFloatProperty(options, MIX_PROP_PLAY_FADE_IN_START_GAIN_FLOAT, fade_start_gain);
22562257
append_silence_frames = GetTrackOptionFramesOrTicks(track, options, MIX_PROP_PLAY_APPEND_SILENCE_FRAMES_NUMBER, MIX_PROP_PLAY_APPEND_SILENCE_MILLISECONDS_NUMBER, append_silence_frames);
22572258
halt_when_exhausted = SDL_GetBooleanProperty(options, MIX_PROP_PLAY_HALT_WHEN_EXHAUSTED_BOOLEAN, halt_when_exhausted);
2259+
start_order = (int) SDL_GetNumberProperty(options, MIX_PROP_PLAY_START_ORDER_NUMBER, start_order);
22582260

22592261
if (start_pos < 0) {
22602262
start_pos = 0;
@@ -2271,7 +2273,14 @@ bool MIX_PlayTrack(MIX_Track *track, SDL_PropertiesID options)
22712273
fade_start_gain = SDL_clamp(fade_start_gain, 0.0f, 1.0f);
22722274
}
22732275

2274-
if (track->input_audio && (!track->input_audio->decoder->seek(track->decoder_userdata, start_pos))) {
2276+
if ((start_order >= 0) && (!track->input_audio || !track->input_audio->decoder->jump_to_order)) {
2277+
start_order = -1; // ignore this option, it doesn't mean anything on this decoder.
2278+
}
2279+
2280+
if ((start_order >= 0) && !track->input_audio->decoder->jump_to_order(track->decoder_userdata, start_order)) {
2281+
UnlockTrack(track);
2282+
return false;
2283+
} else if (track->input_audio && (!track->input_audio->decoder->seek(track->decoder_userdata, start_pos))) {
22752284
UnlockTrack(track);
22762285
return false;
22772286
} else if (!track->input_audio && (start_pos != 0)) {

src/SDL_mixer_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ typedef struct MIX_Decoder
105105
bool (SDLCALL *init_track)(void *audio_userdata, SDL_IOStream *io, const SDL_AudioSpec *spec, SDL_PropertiesID props, void **track_userdata); // init decoder instance data for a single track.
106106
bool (SDLCALL *decode)(void *track_userdata, SDL_AudioStream *stream);
107107
bool (SDLCALL *seek)(void *track_userdata, Uint64 frame);
108+
bool (SDLCALL *jump_to_order)(void *track_userdata, int order);
108109
void (SDLCALL *quit_track)(void *track_userdata);
109110
void (SDLCALL *quit_audio)(void *audio_userdata);
110111
void (SDLCALL *quit)(void); // deinitialize the decoder (unload external libraries, etc).

src/decoder_aiff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ const MIX_Decoder MIX_Decoder_AIFF = {
581581
AIFF_init_track,
582582
AIFF_decode,
583583
AIFF_seek,
584+
NULL, // jump_to_order
584585
AIFF_quit_track,
585586
AIFF_quit_audio,
586587
NULL // quit

src/decoder_au.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ const MIX_Decoder MIX_Decoder_AU = {
269269
AU_init_track,
270270
AU_decode,
271271
AU_seek,
272+
NULL, // jump_to_order
272273
AU_quit_track,
273274
AU_quit_audio,
274275
NULL // quit

src/decoder_drflac.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ const MIX_Decoder MIX_Decoder_DRFLAC = {
331331
DRFLAC_init_track,
332332
DRFLAC_decode,
333333
DRFLAC_seek,
334+
NULL, // jump_to_order
334335
DRFLAC_quit_track,
335336
DRFLAC_quit_audio,
336337
NULL // quit

src/decoder_drmp3.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ const MIX_Decoder MIX_Decoder_DRMP3 = {
195195
DRMP3_init_track,
196196
DRMP3_decode,
197197
DRMP3_seek,
198+
NULL, // jump_to_order
198199
DRMP3_quit_track,
199200
DRMP3_quit_audio,
200201
NULL // quit

src/decoder_flac.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ const MIX_Decoder MIX_Decoder_FLAC = {
507507
FLAC_init_track,
508508
FLAC_decode,
509509
FLAC_seek,
510+
NULL, // jump_to_order
510511
FLAC_quit_track,
511512
FLAC_quit_audio,
512513
FLAC_quit

src/decoder_fluidsynth.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ const MIX_Decoder MIX_Decoder_FLUIDSYNTH = {
451451
FLUIDSYNTH_init_track,
452452
FLUIDSYNTH_decode,
453453
FLUIDSYNTH_seek,
454+
NULL, // jump_to_order
454455
FLUIDSYNTH_quit_track,
455456
FLUIDSYNTH_quit_audio,
456457
FLUIDSYNTH_quit

0 commit comments

Comments
 (0)