From 9f21b22cc5768177761baefa763cd427a8cfbe40 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 3 Aug 2008 03:54:48 +0000 Subject: [PATCH] - Fixed spurious warnings on 32-bit VC++ debug builds. - Made the subsong (order) number a proper parameter to MusInfo::Play() instead of requiring a separate SetPosition() call to do it. SVN r1104 (trunk) --- docs/rh-log.txt | 5 ++++ src/s_sound.cpp | 18 ++++++------ src/sound/fmodsound.cpp | 21 ++++++-------- src/sound/i_music.cpp | 21 ++++++++------ src/sound/i_music.h | 43 ++++++++++++++++++++++++++--- src/sound/i_musicinterns.h | 46 ++++++------------------------- src/sound/i_sound.cpp | 7 ++++- src/sound/i_sound.h | 3 +- src/sound/music_cd.cpp | 2 +- src/sound/music_dumb.cpp | 16 +++++------ src/sound/music_midi_timidity.cpp | 2 +- src/sound/music_midistream.cpp | 2 +- src/sound/music_mus_opl.cpp | 2 +- src/sound/music_stream.cpp | 25 +++++++++++++---- src/zstring.h | 9 ++++++ zdoom.vcproj | 4 +-- 16 files changed, 133 insertions(+), 93 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index e5a3d839d..c4bc33aa8 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,8 @@ +August 2, 2008 +- Fixed spurious warnings on 32-bit VC++ debug builds. +- Made the subsong (order) number a proper parameter to MusInfo::Play() + instead of requiring a separate SetPosition() call to do it. + August 2, 2008 (Changes by Graf Zahl) - Added Gez's submission for custom bridge things. - Fixed: ASpecialSpot must check the array's size before dividing by it. diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 8cbad20aa..25834b331 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -78,7 +78,7 @@ struct MusPlayingInfo { FString name; - void *handle; + MusInfo *handle; int baseorder; bool loop; }; @@ -1838,8 +1838,10 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) { if (order != mus_playing.baseorder) { - mus_playing.baseorder = - (I_SetSongPosition (mus_playing.handle, order) ? order : 0); + if (mus_playing.handle->SetSubsong(order)) + { + mus_playing.baseorder = order; + } } return true; } @@ -1862,7 +1864,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) int lumpnum = -1; int offset = 0, length = 0; int device = MDEV_DEFAULT; - void *handle = NULL; + MusInfo *handle = NULL; int *devp = MidiDevices.CheckKey(FName(musicname)); if (devp != NULL) device = *devp; @@ -1932,7 +1934,7 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) { mus_playing.loop = looping; mus_playing.name = ""; - mus_playing.baseorder = 0; + mus_playing.baseorder = order; LastSong = musicname; return true; } @@ -1956,13 +1958,13 @@ bool S_ChangeMusic (const char *musicname, int order, bool looping, bool force) mus_playing.loop = looping; mus_playing.name = musicname; + mus_playing.baseorder = 0; LastSong = ""; if (mus_playing.handle != 0) { // play it - I_PlaySong (mus_playing.handle, looping, S_GetMusicVolume (musicname)); - mus_playing.baseorder = - (I_SetSongPosition (mus_playing.handle, order) ? order : 0); + I_PlaySong (mus_playing.handle, looping, S_GetMusicVolume (musicname), order); + mus_playing.baseorder = order; return true; } return false; diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index e886ecabb..505e96422 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -454,21 +454,16 @@ public: Volume = volume; } - // Sets the current order number for a MOD-type song, or the position in ms - // for anything else. - bool SetPosition(int pos) + // Sets the position in ms. + bool SetPosition(unsigned int ms_pos) { - FMOD_SOUND_TYPE type; + return FMOD_OK == Channel->setPosition(ms_pos, FMOD_TIMEUNIT_MS); + } - if (FMOD_OK == Stream->getFormat(&type, NULL, NULL, NULL) && - (type == FMOD_SOUND_TYPE_IT || - type == FMOD_SOUND_TYPE_MOD || - type == FMOD_SOUND_TYPE_S3M || - type == FMOD_SOUND_TYPE_XM)) - { - return FMOD_OK == Channel->setPosition(pos, FMOD_TIMEUNIT_MODORDER); - } - return FMOD_OK == Channel->setPosition(pos, FMOD_TIMEUNIT_MS); + // Sets the order number for MOD formats. + bool SetOrder(int order_pos) + { + return FMOD_OK == Channel->setPosition(order_pos, FMOD_TIMEUNIT_MODORDER); } FString GetStats() diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index b99f0600b..55038cb91 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -121,7 +121,12 @@ MusInfo::~MusInfo () { } -bool MusInfo::SetPosition (int order) +bool MusInfo::SetPosition (unsigned int ms) +{ + return false; +} + +bool MusInfo::SetSubsong (int subsong) { return false; } @@ -197,7 +202,7 @@ void I_ShutdownMusic(void) } -void I_PlaySong (void *handle, int _looping, float rel_vol) +void I_PlaySong (void *handle, int _looping, float rel_vol, int subsong) { MusInfo *info = (MusInfo *)handle; @@ -206,7 +211,7 @@ void I_PlaySong (void *handle, int _looping, float rel_vol) saved_relative_volume = relative_volume = rel_vol; info->Stop (); - info->Play (_looping ? true : false); + info->Play (!!_looping, subsong); info->m_NotStartedYet = false; if (info->m_Status == MusInfo::STATE_Playing) @@ -256,7 +261,7 @@ void I_UnRegisterSong (void *handle) } } -void *I_RegisterURLSong (const char *url) +MusInfo *I_RegisterURLSong (const char *url) { StreamSong *song; @@ -269,7 +274,7 @@ void *I_RegisterURLSong (const char *url) return NULL; } -void *I_RegisterSong (const char *filename, char *musiccache, int offset, int len, int device) +MusInfo *I_RegisterSong (const char *filename, char *musiccache, int offset, int len, int device) { FILE *file; MusInfo *info = NULL; @@ -539,7 +544,7 @@ void *I_RegisterSong (const char *filename, char *musiccache, int offset, int le return info; } -void *I_RegisterCDSong (int track, int id) +MusInfo *I_RegisterCDSong (int track, int id) { MusInfo *info = new CDSong (track, id); @@ -635,7 +640,7 @@ CCMD (writeopl) } else { - dumper->Play(false); + dumper->Play(false, 0); // FIXME: Remember subsong. delete dumper; } } @@ -673,7 +678,7 @@ CCMD (writewave) } else { - dumper->Play(false); + dumper->Play(false, 0); // FIXME: Remember subsong delete dumper; } } diff --git a/src/sound/i_music.h b/src/sound/i_music.h index d517bd566..4c4dc4218 100644 --- a/src/sound/i_music.h +++ b/src/sound/i_music.h @@ -54,14 +54,15 @@ void I_PauseSong (void *handle); void I_ResumeSong (void *handle); // Registers a song handle to song data. -void *I_RegisterSong (const char *file, char * musiccache, int offset, int length, int device); -void *I_RegisterCDSong (int track, int cdid = 0); -void *I_RegisterURLSong (const char *url); +class MusInfo; +MusInfo *I_RegisterSong (const char *file, char * musiccache, int offset, int length, int device); +MusInfo *I_RegisterCDSong (int track, int cdid = 0); +MusInfo *I_RegisterURLSong (const char *url); // Called by anything that wishes to start music. // Plays a song, and when the song is done, // starts playing it again in an endless loop. -void I_PlaySong (void *handle, int looping, float relative_vol=1.f); +void I_PlaySong (void *handle, int looping, float relative_vol=1.f, int subsong=0); // Stops a song. void I_StopSong (void *handle); @@ -75,4 +76,38 @@ bool I_SetSongPosition (void *handle, int order); // Is the song still playing? bool I_QrySongPlaying (void *handle); +// The base music class. Everything is derived from this -------------------- + +class MusInfo +{ +public: + MusInfo (); + virtual ~MusInfo (); + virtual void MusicVolumeChanged(); // snd_musicvolume changed + virtual void TimidityVolumeChanged(); // timidity_mastervolume changed + virtual void Play (bool looping, int subsong) = 0; + virtual void Pause () = 0; + virtual void Resume () = 0; + virtual void Stop () = 0; + virtual bool IsPlaying () = 0; + virtual bool IsMIDI () const = 0; + virtual bool IsValid () const = 0; + virtual bool SetPosition (unsigned int ms); + virtual bool SetSubsong (int subsong); + virtual void Update(); + virtual FString GetStats(); + virtual MusInfo *GetOPLDumper(const char *filename); + virtual MusInfo *GetWaveDumper(const char *filename, int rate); + + enum EState + { + STATE_Stopped, + STATE_Playing, + STATE_Paused + } m_Status; + bool m_Looping; + bool m_NotStartedYet; // Song has been created but not yet played +}; + + #endif //__I_MUSIC_H__ diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 151db22cf..ec1829bf8 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -20,6 +20,7 @@ #include "c_cvars.h" #include "mus2midi.h" #include "i_sound.h" +#include "i_music.h" void I_InitMusicWin32 (); void I_ShutdownMusicWin32 (); @@ -29,38 +30,6 @@ extern float relative_volume; EXTERN_CVAR (Float, timidity_mastervolume) -// The base music class. Everything is derived from this -------------------- - -class MusInfo -{ -public: - MusInfo (); - virtual ~MusInfo (); - virtual void MusicVolumeChanged(); // snd_musicvolume changed - virtual void TimidityVolumeChanged(); // timidity_mastervolume changed - virtual void Play (bool looping) = 0; - virtual void Pause () = 0; - virtual void Resume () = 0; - virtual void Stop () = 0; - virtual bool IsPlaying () = 0; - virtual bool IsMIDI () const = 0; - virtual bool IsValid () const = 0; - virtual bool SetPosition (int order); - virtual void Update(); - virtual FString GetStats(); - virtual MusInfo *GetOPLDumper(const char *filename); - virtual MusInfo *GetWaveDumper(const char *filename, int rate); - - enum EState - { - STATE_Stopped, - STATE_Playing, - STATE_Paused - } m_Status; - bool m_Looping; - bool m_NotStartedYet; // Song has been created but not yet played -}; - // A device that provides a WinMM-like MIDI streaming interface ------------- #ifndef _WIN32 @@ -302,7 +271,7 @@ public: void MusicVolumeChanged(); void TimidityVolumeChanged(); - void Play(bool looping); + void Play(bool looping, int subsong); void Pause(); void Resume(); void Stop(); @@ -441,14 +410,15 @@ class StreamSong : public MusInfo public: StreamSong (const char *file, int offset, int length); ~StreamSong (); - void Play (bool looping); + void Play (bool looping, int subsong); void Pause (); void Resume (); void Stop (); bool IsPlaying (); bool IsMIDI () const { return false; } bool IsValid () const { return m_Stream != NULL; } - bool SetPosition (int order); + bool SetPosition (unsigned int pos); + bool SetSubsong (int subsong); FString GetStats(); protected: @@ -464,7 +434,7 @@ class TimiditySong : public StreamSong public: TimiditySong (FILE *file, char * musiccache, int length); ~TimiditySong (); - void Play (bool looping); + void Play (bool looping, int subsong); void Stop (); bool IsPlaying (); bool IsValid () const { return CommandLine.Len() > 0; } @@ -502,7 +472,7 @@ class OPLMUSSong : public StreamSong public: OPLMUSSong (FILE *file, char *musiccache, int length); ~OPLMUSSong (); - void Play (bool looping); + void Play (bool looping, int subsong); bool IsPlaying (); bool IsValid () const; void ResetChips (); @@ -530,7 +500,7 @@ class CDSong : public MusInfo public: CDSong (int track, int id); ~CDSong (); - void Play (bool looping); + void Play (bool looping, int subsong); void Pause (); void Resume (); void Stop (); diff --git a/src/sound/i_sound.cpp b/src/sound/i_sound.cpp index 1d6931970..affbe0895 100644 --- a/src/sound/i_sound.cpp +++ b/src/sound/i_sound.cpp @@ -302,7 +302,12 @@ SoundStream::~SoundStream () { } -bool SoundStream::SetPosition(int pos) +bool SoundStream::SetPosition(unsigned int pos) +{ + return false; +} + +bool SoundStream::SetOrder(int order) { return false; } diff --git a/src/sound/i_sound.h b/src/sound/i_sound.h index 8be689bd0..ec8633c9f 100644 --- a/src/sound/i_sound.h +++ b/src/sound/i_sound.h @@ -65,7 +65,8 @@ public: virtual bool SetPaused(bool paused) = 0; virtual unsigned int GetPosition() = 0; virtual bool IsEnded() = 0; - virtual bool SetPosition(int pos); + virtual bool SetPosition(unsigned int pos); + virtual bool SetOrder(int order); virtual FString GetStats(); }; diff --git a/src/sound/music_cd.cpp b/src/sound/music_cd.cpp index c6d6401c8..5b400ba82 100644 --- a/src/sound/music_cd.cpp +++ b/src/sound/music_cd.cpp @@ -1,7 +1,7 @@ #include "i_musicinterns.h" #include "i_cd.h" -void CDSong::Play (bool looping) +void CDSong::Play (bool looping, int subsong) { m_Status = STATE_Stopped; m_Looping = looping; diff --git a/src/sound/music_dumb.cpp b/src/sound/music_dumb.cpp index 21a80fe23..9382f80bb 100644 --- a/src/sound/music_dumb.cpp +++ b/src/sound/music_dumb.cpp @@ -45,8 +45,9 @@ class input_mod : public StreamSong public: input_mod(DUH *myduh); ~input_mod(); - bool SetPosition(int order); - void Play(bool looping); + //bool SetPosition(int ms); + bool SetSubsong(int subsong); + void Play(bool looping, int subsong); FString GetStats(); FString Codec; @@ -1153,11 +1154,12 @@ input_mod::~input_mod() // //========================================================================== -void input_mod::Play(bool looping) +void input_mod::Play(bool looping, int order) { m_Status = STATE_Stopped; m_Looping = looping; + start_order = order; if (open2(0) && m_Stream->Play(m_Looping, 1)) { m_Status = STATE_Playing; @@ -1166,15 +1168,11 @@ void input_mod::Play(bool looping) //========================================================================== // -// input_mod :: SetPosition -// -// FIXME: Pass the order number as a subsong parameter to Play, so we don't -// need to start playback at one position and then immediately throw that -// playback structure away and create a new one to go to the new order. +// input_mod :: SetSubsong // //========================================================================== -bool input_mod::SetPosition(int order) +bool input_mod::SetSubsong(int order) { if (order == start_order) { diff --git a/src/sound/music_midi_timidity.cpp b/src/sound/music_midi_timidity.cpp index c16e5a084..5483645dd 100644 --- a/src/sound/music_midi_timidity.cpp +++ b/src/sound/music_midi_timidity.cpp @@ -85,7 +85,7 @@ CUSTOM_CVAR (Int, timidity_frequency, 22050, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) self = 65000; } -void TimiditySong::Play (bool looping) +void TimiditySong::Play (bool looping, int subsong) { m_Status = STATE_Stopped; m_Looping = looping; diff --git a/src/sound/music_midistream.cpp b/src/sound/music_midistream.cpp index f411ab127..8a73217d7 100644 --- a/src/sound/music_midistream.cpp +++ b/src/sound/music_midistream.cpp @@ -182,7 +182,7 @@ void MIDIStreamer::CheckCaps() // //========================================================================== -void MIDIStreamer::Play(bool looping) +void MIDIStreamer::Play(bool looping, int subsong) { DWORD tid; diff --git a/src/sound/music_mus_opl.cpp b/src/sound/music_mus_opl.cpp index cc8bd5bf6..006b1a069 100644 --- a/src/sound/music_mus_opl.cpp +++ b/src/sound/music_mus_opl.cpp @@ -52,7 +52,7 @@ bool OPLMUSSong::IsPlaying () return m_Status == STATE_Playing; } -void OPLMUSSong::Play (bool looping) +void OPLMUSSong::Play (bool looping, int subsong) { m_Status = STATE_Stopped; m_Looping = looping; diff --git a/src/sound/music_stream.cpp b/src/sound/music_stream.cpp index 95cebc07f..72c825a28 100644 --- a/src/sound/music_stream.cpp +++ b/src/sound/music_stream.cpp @@ -1,12 +1,16 @@ #include "i_musicinterns.h" -void StreamSong::Play (bool looping) +void StreamSong::Play (bool looping, int subsong) { m_Status = STATE_Stopped; m_Looping = looping; if (m_Stream->Play (m_Looping, 1)) { + if (subsong != 0) + { + m_Stream->SetOrder (subsong); + } m_Status = STATE_Playing; } } @@ -70,14 +74,25 @@ bool StreamSong::IsPlaying () // // StreamSong :: SetPosition // -// Sets the current order number for a MOD-type song, or the position in ms -// for anything else. +// Sets the position in ms. -bool StreamSong::SetPosition(int order) +bool StreamSong::SetPosition(unsigned int pos) { if (m_Stream != NULL) { - return m_Stream->SetPosition(order); + return m_Stream->SetPosition(pos); + } + else + { + return false; + } +} + +bool StreamSong::SetSubsong(int subsong) +{ + if (m_Stream != NULL) + { + return m_Stream->SetOrder(subsong); } else { diff --git a/src/zstring.h b/src/zstring.h index 1cbc4aa56..db42b98e4 100644 --- a/src/zstring.h +++ b/src/zstring.h @@ -139,8 +139,17 @@ public: operator const char *() const { return Chars; } const char *GetChars() const { return Chars; } + const char &operator[] (int index) const { return Chars[index]; } +#if defined(_WIN32) && !defined(_WIN64) && defined(_MSC_VER) + // Compiling 32-bit Windows source with MSVC: size_t is typedefed to an + // unsigned int with the 64-bit portability warning attribute, so the + // prototype cannot substitute unsigned int for size_t, or you get + // spurious warnings. + const char &operator[] (size_t index) const { return Chars[index]; } +#else const char &operator[] (unsigned int index) const { return Chars[index]; } +#endif const char &operator[] (unsigned long index) const { return Chars[index]; } const char &operator[] (unsigned long long index) const { return Chars[index]; } diff --git a/zdoom.vcproj b/zdoom.vcproj index fe04e1ff6..36c27bd79 100644 --- a/zdoom.vcproj +++ b/zdoom.vcproj @@ -465,7 +465,7 @@