From a2ab5492cc66f3d505d3aff58bc46edd2edb0709 Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 19 Oct 2019 23:48:31 +0000 Subject: [PATCH] Further small midi cleanup changes--nothing functional git-svn-id: https://svn.eduke32.com/eduke32@8221 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # source/audiolib/include/al_midi.h # source/audiolib/src/_al_midi.h --- source/audiolib/src/driver_adlib.cpp | 15 +++++++------- source/audiolib/src/drivers.cpp | 30 ++++++++++++++-------------- source/audiolib/src/fx_man.cpp | 6 +++++- source/audiolib/src/gmtimbre.cpp | 2 +- source/audiolib/src/midi.cpp | 21 ++++++++----------- 5 files changed, 36 insertions(+), 38 deletions(-) diff --git a/source/audiolib/src/driver_adlib.cpp b/source/audiolib/src/driver_adlib.cpp index c6c798c66..b5f1b508c 100644 --- a/source/audiolib/src/driver_adlib.cpp +++ b/source/audiolib/src/driver_adlib.cpp @@ -116,21 +116,21 @@ void AdLibDrv_MIDI_SetTempo(int tempo, int division) static opl3_chip chip; opl3_chip *AL_GetChip() { return &chip; } -static unsigned int OctavePitch[MAX_OCTAVE + 1] = { +static constexpr unsigned int OctavePitch[MAX_OCTAVE+1] = { OCTAVE_0, OCTAVE_1, OCTAVE_2, OCTAVE_3, OCTAVE_4, OCTAVE_5, OCTAVE_6, OCTAVE_7, }; -static unsigned int NoteMod12[MAX_NOTE + 1]; -static unsigned int NoteDiv12[MAX_NOTE + 1]; +static unsigned int NoteMod12[MAX_NOTE+1]; +static unsigned int NoteDiv12[MAX_NOTE+1]; // Pitch table -//static unsigned NotePitch[ FINETUNE_MAX + 1 ][ 12 ] = +//static unsigned NotePitch[ FINETUNE_MAX+1 ][ 12 ] = // { // { C, C_SHARP, D, D_SHARP, E, F, F_SHARP, G, G_SHARP, A, A_SHARP, B }, // }; -static unsigned int NotePitch[FINETUNE_MAX + 1][12] = { +static constexpr unsigned int NotePitch[FINETUNE_MAX+1][12] = { { 0x157, 0x16b, 0x181, 0x198, 0x1b0, 0x1ca, 0x1e5, 0x202, 0x220, 0x241, 0x263, 0x287 }, { 0x157, 0x16b, 0x181, 0x198, 0x1b0, 0x1ca, 0x1e5, 0x202, 0x220, 0x242, 0x264, 0x288 }, { 0x158, 0x16c, 0x182, 0x199, 0x1b1, 0x1cb, 0x1e6, 0x203, 0x221, 0x243, 0x265, 0x289 }, @@ -168,7 +168,7 @@ static unsigned int NotePitch[FINETUNE_MAX + 1][12] = { // Slot numbers as a function of the voice and the operator. // ( melodic only) -static int slotVoice[NUMADLIBVOICES][2] = { +static constexpr int slotVoice[NUMADLIBVOICES][2] = { { 0, 3 }, // voice 0 { 1, 4 }, // 1 { 2, 5 }, // 2 @@ -186,7 +186,7 @@ static int VoiceKsl[AL_NumChipSlots][2]; // This table gives the offset of each slot within the chip. // offset = fn( slot) -static int8_t offsetSlot[AL_NumChipSlots] = { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21 }; +static constexpr int8_t offsetSlot[AL_NumChipSlots] = { 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, 21 }; static int VoiceReserved[NUMADLIBVOICES * 2]; @@ -854,7 +854,6 @@ static void AL_SetPitchBend(int channel, int lsb, int msb) static void AL_Shutdown(void) { AL_StereoOff(); - AL_ResetVoices(); AL_Reset(); } diff --git a/source/audiolib/src/drivers.cpp b/source/audiolib/src/drivers.cpp index 1a49a6ad7..7e322dfa2 100644 --- a/source/audiolib/src/drivers.cpp +++ b/source/audiolib/src/drivers.cpp @@ -41,9 +41,9 @@ int ASS_PCMSoundDriver = ASS_AutoDetect; int ASS_MIDISoundDriver = ASS_AutoDetect; int ASS_EMIDICard = -1; -#define UNSUPPORTED_PCM 0,0,0,0,0,0 -#define UNSUPPORTED_MIDI 0,0,0,0,0,0,0 -#define UNSUPPORTED_COMPLETELY { 0,0, UNSUPPORTED_PCM, UNSUPPORTED_MIDI }, +#define UNSUPPORTED_PCM nullptr,nullptr,nullptr,nullptr,nullptr,nullptr +#define UNSUPPORTED_MIDI nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr +#define UNSUPPORTED_COMPLETELY { nullptr, nullptr, nullptr, UNSUPPORTED_PCM, UNSUPPORTED_MIDI }, static struct { const char * DriverName; @@ -169,39 +169,39 @@ const char *SoundDriver_GetName(int driver) { return SoundDrivers[driver].Drive int SoundDriver_PCM_GetError(void) { - if (!SoundDriver_IsPCMSupported(ASS_PCMSoundDriver)) { + if (!SoundDriver_IsPCMSupported(ASS_PCMSoundDriver)) return -1; - } + return SoundDrivers[ASS_PCMSoundDriver].GetError(); } const char * SoundDriver_PCM_ErrorString( int ErrorNumber ) { - if (ASS_PCMSoundDriver < 0 || ASS_PCMSoundDriver >= ASS_NumSoundCards) { + if (ASS_PCMSoundDriver < 0 || ASS_PCMSoundDriver >= ASS_NumSoundCards) return "No sound driver selected."; - } - if (!SoundDriver_IsPCMSupported(ASS_PCMSoundDriver)) { + + if (!SoundDriver_IsPCMSupported(ASS_PCMSoundDriver)) return "Unsupported sound driver selected."; - } + return SoundDrivers[ASS_PCMSoundDriver].ErrorString(ErrorNumber); } int SoundDriver_MIDI_GetError(void) { - if (!SoundDriver_IsMIDISupported(ASS_MIDISoundDriver)) { + if (!SoundDriver_IsMIDISupported(ASS_MIDISoundDriver)) return -1; - } + return SoundDrivers[ASS_MIDISoundDriver].GetError(); } const char * SoundDriver_MIDI_ErrorString( int ErrorNumber ) { - if (ASS_MIDISoundDriver < 0 || ASS_MIDISoundDriver >= ASS_NumSoundCards) { + if (ASS_MIDISoundDriver < 0 || ASS_MIDISoundDriver >= ASS_NumSoundCards) return "No sound driver selected."; - } - if (!SoundDriver_IsMIDISupported(ASS_MIDISoundDriver)) { + + if (!SoundDriver_IsMIDISupported(ASS_MIDISoundDriver)) return "Unsupported sound driver selected."; - } + return SoundDrivers[ASS_MIDISoundDriver].ErrorString(ErrorNumber); } diff --git a/source/audiolib/src/fx_man.cpp b/source/audiolib/src/fx_man.cpp index 245b66989..260dc3bea 100644 --- a/source/audiolib/src/fx_man.cpp +++ b/source/audiolib/src/fx_man.cpp @@ -20,10 +20,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ //------------------------------------------------------------------------- +#include "fx_man.h" + #include "compat.h" #include "drivers.h" +#include "driver_adlib.h" +#include "midi.h" #include "multivoc.h" -#include "fx_man.h" +#include "osd.h" int FX_ErrorCode = FX_Ok; int FX_Installed; diff --git a/source/audiolib/src/gmtimbre.cpp b/source/audiolib/src/gmtimbre.cpp index 809d65abc..a363e75e7 100644 --- a/source/audiolib/src/gmtimbre.cpp +++ b/source/audiolib/src/gmtimbre.cpp @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include -#include "_al_midi.h" +#include "al_midi.h" AdLibTimbre ADLIB_TimbreBank[256] = { diff --git a/source/audiolib/src/midi.cpp b/source/audiolib/src/midi.cpp index 9d89f72c0..03caa7dde 100644 --- a/source/audiolib/src/midi.cpp +++ b/source/audiolib/src/midi.cpp @@ -696,13 +696,6 @@ void MIDI_StopSong(void) int MIDI_PlaySong(char *song, int loopflag) { - int numtracks; - int format; - int headersize; - int tracklength; - track *CurrentTrack; - char *ptr; - if (_MIDI_Funcs == nullptr) return MIDI_NullMidiModule; @@ -710,11 +703,13 @@ int MIDI_PlaySong(char *song, int loopflag) return MIDI_InvalidMidiFile; song += 4; - headersize = _MIDI_ReadNumber(song, 4); + int const headersize = _MIDI_ReadNumber(song, 4); song += 4; - format = _MIDI_ReadNumber(song, 2); + int const format = _MIDI_ReadNumber(song, 2); + int My_MIDI_NumTracks = _MIDI_ReadNumber(song + 2, 2); int My_MIDI_Division = _MIDI_ReadNumber(song + 4, 2); + if (My_MIDI_Division < 0) { // If a SMPTE time division is given, just set to 96 so no errors occur @@ -724,7 +719,7 @@ int MIDI_PlaySong(char *song, int loopflag) if (format > MAX_FORMAT) return MIDI_UnknownMidiFormat; - ptr = song + headersize; + char *ptr = song + headersize; if (My_MIDI_NumTracks == 0) return MIDI_NoTracks; @@ -732,8 +727,8 @@ int MIDI_PlaySong(char *song, int loopflag) int My_MIDI_TrackMemSize = My_MIDI_NumTracks * sizeof(track); track * My_MIDI_TrackPtr = (track *)Xmalloc(My_MIDI_TrackMemSize); - CurrentTrack = My_MIDI_TrackPtr; - numtracks = My_MIDI_NumTracks; + auto CurrentTrack = My_MIDI_TrackPtr; + int numtracks = My_MIDI_NumTracks; while (numtracks--) { @@ -746,7 +741,7 @@ int MIDI_PlaySong(char *song, int loopflag) return MIDI_InvalidTrack; } - tracklength = _MIDI_ReadNumber(ptr + 4, 4); + int tracklength = _MIDI_ReadNumber(ptr + 4, 4); ptr += 8; CurrentTrack->start = ptr; ptr += tracklength;