Skip to content

Commit

Permalink
Guillaume Cottenceau - Wed Dec 19 08:59:05 PST 2001
Browse files Browse the repository at this point in the history
 * Added an API for seeking in music files (implemented for MOD files)
        Mix_FadeInMusicPos(), Mix_SetMusicPosition()
 * Exposed the mikmod synchro value for music synchronization
        Mix_SetSynchroValue(), Mix_GetSynchroValue()
  • Loading branch information
slouken committed Dec 19, 2001
1 parent b67f7ca commit b11ca16
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGES
@@ -1,4 +1,11 @@

1.2.2:
Guillaume Cottenceau - Wed Dec 19 08:59:05 PST 2001
* Added an API for seeking in music files (implemented for MOD files)
Mix_FadeInMusicPos(), Mix_SetMusicPosition()
* Exposed the mikmod synchro value for music synchronization
Mix_SetSynchroValue(), Mix_GetSynchroValue()

1.2.1:
Yi-Huang Han - Wed Oct 24 21:55:47 PDT 2001
* Fixed MOD music volume when looping
Expand Down
13 changes: 12 additions & 1 deletion SDL_mixer.h
Expand Up @@ -41,7 +41,7 @@ extern "C" {
*/
#define MIX_MAJOR_VERSION 1
#define MIX_MINOR_VERSION 2
#define MIX_PATCHLEVEL 1
#define MIX_PATCHLEVEL 2

/* This macro can be used to fill a version structure with the compile-time
* version of the SDL_mixer library.
Expand Down Expand Up @@ -460,6 +460,7 @@ extern DECLSPEC int Mix_PlayMusic(Mix_Music *music, int loops);

/* Fade in music or a channel over "ms" milliseconds, same semantics as the "Play" functions */
extern DECLSPEC int Mix_FadeInMusic(Mix_Music *music, int loops, int ms);
extern DECLSPEC int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, int position);
#define Mix_FadeInChannel(channel,chunk,loops,ms) Mix_FadeInChannelTimed(channel,chunk,loops,ms,-1)
extern DECLSPEC int Mix_FadeInChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ms, int ticks);

Expand Down Expand Up @@ -506,6 +507,12 @@ extern DECLSPEC void Mix_ResumeMusic(void);
extern DECLSPEC void Mix_RewindMusic(void);
extern DECLSPEC int Mix_PausedMusic(void);

/* Set the current position in the music stream.
This returns 0 if successful, or -1 if it failed or isn't implemented.
This function is only implemented for MOD music formats at the moment.
*/
extern DECLSPEC int Mix_SetMusicPosition(int position);

/* Check the status of a specific channel.
If the specified channel is -1, check all channels.
*/
Expand All @@ -515,6 +522,10 @@ extern DECLSPEC int Mix_PlayingMusic(void);
/* Stop music and set external music playback command */
extern DECLSPEC int Mix_SetMusicCMD(const char *command);

/* Synchro value is set by MikMod from modules while playing */
extern DECLSPEC int Mix_SetSynchroValue(int value);
extern DECLSPEC int Mix_GetSynchroValue(void);

/* Get the Mix_Chunk currently associated with a mixer channel
Returns NULL if it's an invalid channel, or there's no chunk associated.
*/
Expand Down
6 changes: 3 additions & 3 deletions configure.in
Expand Up @@ -13,9 +13,9 @@ dnl Set various version strings - taken gratefully from the GTk sources

MAJOR_VERSION=1
MINOR_VERSION=2
MICRO_VERSION=1
INTERFACE_AGE=1
BINARY_AGE=1
MICRO_VERSION=2
INTERFACE_AGE=0
BINARY_AGE=2
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION

AC_SUBST(MAJOR_VERSION)
Expand Down
3 changes: 3 additions & 0 deletions mikmod/load_xm.c
Expand Up @@ -286,6 +286,9 @@ static UBYTE* XM_Convert(XMNOTE* xmtrack,UWORD rows)
break;
}
break;
case 'Z'-55: /* Z - synchro */
UniEffect(UNI_XMEFFECTZ,dat);
break;
default:
if(eff<=0xf) {
/* the pattern jump destination is written in decimal,
Expand Down
2 changes: 2 additions & 0 deletions mikmod/mikmod.h
Expand Up @@ -550,6 +550,8 @@ MIKMODAPI extern void Player_Mute(SLONG,...);
MIKMODAPI extern void Player_ToggleMute(SLONG,...);
MIKMODAPI extern int Player_GetChannelVoice(UBYTE);
MIKMODAPI extern UWORD Player_GetChannelPeriod(UBYTE);
MIKMODAPI extern void Player_SetSynchroValue(int);
MIKMODAPI extern int Player_GetSynchroValue(void);

typedef void (MikMod_player)(void);
typedef MikMod_player *MikMod_player_t;
Expand Down
1 change: 1 addition & 0 deletions mikmod/mikmod_internals.h
Expand Up @@ -336,6 +336,7 @@ enum {
UNI_MEDEFFECTF1, /* play note twice */
UNI_MEDEFFECTF2, /* delay note */
UNI_MEDEFFECTF3, /* play note three times */
UNI_XMEFFECTZ, /* XM Z synchro */

UNI_LAST
};
Expand Down
15 changes: 15 additions & 0 deletions mikmod/mplayer.c
Expand Up @@ -1806,6 +1806,9 @@ static void pt_playeffects(void)
case UNI_MEDEFFECTF3:
DoEEffects(0x90|(pf->sngspd/3));
break;
case UNI_XMEFFECTZ:
Player_SetSynchroValue(UniGetByte());
break;
default:
a->sliding=oldsliding;
UniSkipOpcode(c);
Expand Down Expand Up @@ -2897,4 +2900,16 @@ void Player_SetTempo(UWORD tempo)
MUTEX_UNLOCK(vars);
}

static int _pl_synchro_value;
void Player_SetSynchroValue(int i)
{
_pl_synchro_value = i;
}

int Player_GetSynchroValue(void)
{
return _pl_synchro_value;
}


/* ex:set ts=4: */
3 changes: 2 additions & 1 deletion mikmod/munitrk.c
Expand Up @@ -98,7 +98,8 @@ UWORD unioperands[UNI_LAST]={
2, /* UNI_MEDSPEED */
0, /* UNI_MEDEFFECTF1 */
0, /* UNI_MEDEFFECTF2 */
0 /* UNI_MEDEFFECTF3 */
0, /* UNI_MEDEFFECTF3 */
1 /* UNI_XMEFFECTZ */
};

/* Sparse description of the internal module format
Expand Down
75 changes: 74 additions & 1 deletion music.c
Expand Up @@ -679,22 +679,51 @@ int Mix_PlayMusic(Mix_Music *music, int loops)
return(0);
}

int Mix_SetMusicPosition(int position)
{
if ( music_playing && !music_stopped ) {
switch ( music_playing->type ) {
#ifdef MOD_MUSIC
case MUS_MOD:
Player_SetPosition(position);
return(0);
break;
#endif
default:
/* TODO: Implement this for other music backends */
return(-1);
break;
}
}
}

/* Fade in a music over "ms" milliseconds */
int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)
int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, int position)
{
if ( music && music_volume > 0 ) { /* No need to fade if we can't hear it */
music->fade_volume = music_volume;
music_volume = 0;
if ( Mix_PlayMusic(music, loops) < 0 ) {
return(-1);
}
if ( position ) {
if ( Mix_SetMusicPosition(position) < 0 ) {
Mix_HaltMusic();
return(-1);
}
}
music_playing->fade_step = 0;
music_playing->fade_steps = ms/ms_per_step;
music_playing->fading = MIX_FADING_IN;
}
return(0);
}

int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)
{
return Mix_FadeInMusicPos(music, loops, ms, 0);
}

/* Set the music volume */
int Mix_VolumeMusic(int volume)
{
Expand Down Expand Up @@ -980,6 +1009,50 @@ int Mix_SetMusicCMD(const char *command)
return(0);
}

int Mix_SetSynchroValue(int i)
{
if ( music_playing && ! music_stopped ) {
switch (music_playing->type) {
#ifdef MOD_MUSIC
case MUS_MOD:
if ( ! Player_Active() ) {
return(-1);
}
Player_SetSynchroValue(i);
return 0;
break;
#endif
default:
return(-1);
break;
}
return(-1);
}
return(-1);
}

int Mix_GetSynchroValue(void)
{
if ( music_playing && ! music_stopped ) {
switch (music_playing->type) {
#ifdef MOD_MUSIC
case MUS_MOD:
if ( ! Player_Active() ) {
return(-1);
}
return Player_GetSynchroValue();
break;
#endif
default:
return(-1);
break;
}
return(-1);
}
return(-1);
}


/* Uninitialize the music players */
void close_music(void)
{
Expand Down

0 comments on commit b11ca16

Please sign in to comment.