Commit cdfbceec authored by Richard Gobeille's avatar Richard Gobeille
Browse files

Duke3d/audiolib: restore MUSIC_GetSongPosition() and MUSIC_SetSongPosition()...

Duke3d/audiolib: restore MUSIC_GetSongPosition() and MUSIC_SetSongPosition() and use them in the menu when switching MIDI renderers
parent 042f102e
......@@ -112,6 +112,8 @@ void MUSIC_Pause(void);
int MUSIC_StopSong(void);
int MUSIC_PlaySong(char *song, int songsize, int loopflag, const char *fn = nullptr);
void MUSIC_Update(void);
void MUSIC_SetSongPosition(int measure, int beat, int tick);
void MUSIC_GetSongPosition(songposition *pos);
/* returns true only after program startup */
static FORCE_INLINE int MUSIC_WarmedUp(void)
......
......@@ -783,6 +783,169 @@ void MIDI_SetTempo(int tempo)
_MIDI_FPSecondsPerTick = tabledivide32_noinline(1 << TIME_PRECISION, tickspersecond);
}
static int _MIDI_ProcessNextTick(void)
{
if (_MIDI_TrackPtr == nullptr)
return 0;
int TimeSet = FALSE;
int tracknum = 0;
track *Track = _MIDI_TrackPtr;
while (tracknum < _MIDI_NumTracks)
{
while ((Track->active) && (Track->delay == 0))
{
int event;
GET_NEXT_EVENT(Track, event);
if (GET_MIDI_COMMAND(event) == MIDI_SPECIAL)
{
switch (event)
{
case MIDI_SYSEX:
case MIDI_SYSEX_CONTINUE:
_MIDI_SysEx(Track);
break;
case MIDI_META_EVENT:
_MIDI_MetaEvent(Track);
break;
}
if (Track->active)
Track->delay = _MIDI_ReadDelta(Track);
continue;
}
if (event & MIDI_RUNNING_STATUS)
Track->RunningStatus = event;
else
{
event = Track->RunningStatus;
Track->pos--;
}
int channel = GET_MIDI_CHANNEL(event);
int command = GET_MIDI_COMMAND(event);
int c1 = 0;
int c2 = 0;
if (_MIDI_CommandLengths[command] > 0)
{
GET_NEXT_EVENT(Track, c1);
if (_MIDI_CommandLengths[command] > 1)
GET_NEXT_EVENT(Track, c2);
}
switch (command)
{
case MIDI_NOTE_OFF:
break;
case MIDI_NOTE_ON:
break;
case MIDI_POLY_AFTER_TCH:
if (_MIDI_Funcs->PolyAftertouch)
_MIDI_Funcs->PolyAftertouch(channel, c1, c2);
break;
case MIDI_CONTROL_CHANGE:
TimeSet = _MIDI_InterpretControllerInfo(Track, TimeSet, channel, c1, c2);
break;
case MIDI_PROGRAM_CHANGE:
if ((_MIDI_Funcs->ProgramChange) && (!Track->EMIDI_ProgramChange))
_MIDI_Funcs->ProgramChange(channel, c1);
break;
case MIDI_AFTER_TOUCH:
if (_MIDI_Funcs->ChannelAftertouch)
_MIDI_Funcs->ChannelAftertouch(channel, c1);
break;
case MIDI_PITCH_BEND:
if (_MIDI_Funcs->PitchBend)
_MIDI_Funcs->PitchBend(channel, c1, c2);
break;
default:
break;
}
Track->delay = _MIDI_ReadDelta(Track);
}
Track->delay--;
Track++;
tracknum++;
if (_MIDI_ActiveTracks == 0)
break;
}
_MIDI_AdvanceTick();
return TimeSet;
}
void MIDI_SetSongPosition(int measure, int beat, int tick)
{
if (!_MIDI_SongLoaded)
return;
MIDI_PauseSong();
int32_t pos = RELATIVE_BEAT(measure, beat, tick);
if (pos < RELATIVE_BEAT(_MIDI_Measure, _MIDI_Beat, _MIDI_Tick))
{
SoundDriver_MIDI_Lock();
_MIDI_ResetTracks();
SoundDriver_MIDI_Unlock();
MIDI_Reset();
}
SoundDriver_MIDI_Lock();
while (RELATIVE_BEAT(_MIDI_Measure, _MIDI_Beat, _MIDI_Tick) < pos)
{
if (_MIDI_ProcessNextTick())
break;
if (_MIDI_ActiveTracks == 0)
{
_MIDI_ResetTracks();
if (!_MIDI_Loop)
{
SoundDriver_MIDI_Unlock();
return;
}
break;
}
}
SoundDriver_MIDI_Unlock();
MIDI_SetVolume(_MIDI_TotalVolume);
MIDI_ContinueSong();
}
void MIDI_GetSongPosition(songposition *pos)
{
uint32_t mil = (_MIDI_Time & ((1 << TIME_PRECISION) - 1)) * 1000;
uint32_t sec = _MIDI_Time >> TIME_PRECISION;
pos->milliseconds = (mil >> TIME_PRECISION) + (sec * 1000);
pos->tickposition = _MIDI_PositionInTicks;
pos->measure = _MIDI_Measure;
pos->beat = _MIDI_Beat;
pos->tick = _MIDI_Tick;
}
static void _MIDI_InitEMIDI(void)
{
int const type = (ASS_EMIDICard != -1) ? ASS_EMIDICard : SoundDriver_MIDI_GetCardType();
......
......@@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "compat.h"
#include "midifuncs.h"
#include "music.h"
enum MIDI_Errors
{
......@@ -64,5 +65,7 @@ int MIDI_PlaySong(char *song, int loopflag);
void MIDI_SetTempo(int tempo);
void MIDI_Restart(void);
void MIDI_ServiceRoutine(void);
void MIDI_SetSongPosition(int measure, int beat, int tick);
void MIDI_GetSongPosition(songposition *pos);
#endif
......@@ -138,5 +138,7 @@ int MUSIC_PlaySong(char *song, int songsize, int loopflag, const char *fn /*= nu
return MUSIC_Ok;
}
void MUSIC_SetSongPosition(int measure, int beat, int tick) { MIDI_SetSongPosition(measure, beat, tick); }
void MUSIC_GetSongPosition(songposition *pos) { MIDI_GetSongPosition(pos); }
void MUSIC_Update(void) {}
......@@ -3532,6 +3532,13 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry)
}
else if (entry == &ME_SOUND_RESTART)
{
songposition pos = {};
if (MusicIsWaveform)
FX_GetPosition(MusicVoice, (int *)&pos.tick);
else
MUSIC_GetSongPosition(&pos);
if (ud.config.MixRate != soundrate || ud.config.NumVoices != soundvoices
#ifdef __linux__
|| (musicdevice == ASS_ALSA && (size_t)alsadevice < alsadevices.size() &&
......@@ -3575,6 +3582,11 @@ static void Menu_EntryLinkActivate(MenuEntry_t *entry)
}
S_RestartMusic();
if (MusicIsWaveform)
FX_SetPosition(MusicVoice, (int)pos.tick);
else
MUSIC_SetSongPosition(pos.measure, pos.beat, pos.tick);
}
Menu_RefreshSoundProperties();
......
......@@ -1400,6 +1400,12 @@ static int osdcmd_cvar_set_game(osdcmdptr_t parm)
if (ASS_MIDISoundDriver == ASS_OPL3 || ASS_MIDISoundDriver == ASS_SF2 || MusicIsWaveform)
{
// music that we generate and send through sound
songposition pos = {};
if (MusicIsWaveform)
FX_GetPosition(MusicVoice, (int *)&pos.tick);
else
MUSIC_GetSongPosition(&pos);
S_MusicShutdown();
S_SoundShutdown();
......@@ -1410,7 +1416,14 @@ static int osdcmd_cvar_set_game(osdcmdptr_t parm)
S_ClearSoundLocks();
if (ud.config.MusicToggle)
{
S_RestartMusic();
if (MusicIsWaveform)
FX_SetPosition(MusicVoice, (int)pos.tick);
else
MUSIC_SetSongPosition(pos.measure, pos.beat, pos.tick);
}
}
else
{
......@@ -1420,16 +1433,32 @@ static int osdcmd_cvar_set_game(osdcmdptr_t parm)
S_ClearSoundLocks();
}
}
else if (!Bstrcasecmp(parm->name, "mus_volume"))
S_MusicVolume(Batol(parm->parms[0]));
else if (!Bstrncasecmp(parm->name, prefix_mus, ARRAY_SIZE(prefix_mus)-1))
{
if (!MUSIC_WarmedUp())
return r;
songposition pos = {};
if (MusicIsWaveform)
FX_GetPosition(MusicVoice, (int *)&pos.tick);
else
MUSIC_GetSongPosition(&pos);
S_MusicShutdown();
S_MusicStartup();
if (ud.config.MusicToggle)
{
S_RestartMusic();
if (MusicIsWaveform)
FX_SetPosition(MusicVoice, (int)pos.tick);
else
MUSIC_SetSongPosition(pos.measure, pos.beat, pos.tick);
}
}
else if (!Bstrcasecmp(parm->name, "hud_scale")
|| !Bstrcasecmp(parm->name, "hud_statusbarmode")
......@@ -1644,7 +1673,7 @@ int32_t registerosdcommands(void)
{ "mus_enabled", "music subsystem" CVAR_BOOL_OPTSTR, (void *)&ud.config.MusicToggle, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
{ "mus_device", "music device", (void*)& ud.config.MusicDevice, CVAR_INT|CVAR_FUNCPTR, 0, ASS_NumSoundCards },
{ "mus_volume", "controls music volume", (void *)&ud.config.MusicVolume, CVAR_INT, 0, 255 },
{ "mus_volume", "controls music volume", (void *)&ud.config.MusicVolume, CVAR_INT|CVAR_FUNCPTR, 0, 255 },
{ "osdhightile", "use content pack assets for console text if available" CVAR_BOOL_OPTSTR, (void *)&osdhightile, CVAR_BOOL, 0, 1 },
{ "osdscale", "console text size", (void *)&osdscale, CVAR_FLOAT|CVAR_FUNCPTR, 1, 4 },
......
......@@ -34,7 +34,7 @@ int32_t g_numEnvSoundsPlaying, g_highestSoundIdx;
static char *MusicPtr;
int32_t MusicIsWaveform;
static int32_t MusicVoice = -1;
int32_t MusicVoice = -1;
static bool MusicPaused;
static bool SoundPaused;
......
......@@ -63,7 +63,7 @@ extern char g_soundlocks[MAXSOUNDS];
extern sound_t g_sounds[MAXSOUNDS];
extern int32_t g_numEnvSoundsPlaying,g_highestSoundIdx;
extern int32_t MusicIsWaveform;
extern int32_t MusicIsWaveform, MusicVoice;
int A_CheckSoundPlaying(int spriteNum,int soundNum);
int A_PlaySound(int soundNum, int spriteNum);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment