diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f273bb4b..22ea7df91 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1143,14 +1143,15 @@ set (PCH_SOURCES sound/mididevices/music_softsynth_mididevice.cpp sound/mididevices/music_timidity_mididevice.cpp sound/mididevices/music_wildmidi_mididevice.cpp + sound/midisources/midisource.cpp + sound/midisources/midisource_mus.cpp + sound/midisources/midisource_smf.cpp + sound/midisources/midisource_hmi.cpp + sound/midisources/midisource_xmi.cpp sound/musicformats/music_cd.cpp sound/musicformats/music_dumb.cpp sound/musicformats/music_gme.cpp sound/musicformats/music_libsndfile.cpp - sound/musicformats/music_mus_midiout.cpp - sound/musicformats/music_smf_midiout.cpp - sound/musicformats/music_hmi_midiout.cpp - sound/musicformats/music_xmi_midiout.cpp sound/musicformats/music_midistream.cpp sound/musicformats/music_opl.cpp sound/musicformats/music_stream.cpp @@ -1354,6 +1355,7 @@ source_group("Audio Files\\Timidity" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE source_group("Audio Files\\Timiditypp" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/timiditypp/.+") source_group("Audio Files\\WildMidi" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/wildmidi/.+") source_group("Audio Files\\MIDI Devices" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/mididevices/.+") +source_group("Audio Files\\MIDI Sources" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/midisources/.+") source_group("Audio Files\\Music formats" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/sound/musicformats/.+") source_group("External\\Math" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/math/.+") source_group("External\\RapidJSON" REGULAR_EXPRESSION "^${CMAKE_CURRENT_SOURCE_DIR}/rapidjson/.+") diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index fe307f614..47fdcc04a 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -117,13 +117,13 @@ CUSTOM_CVAR (Float, snd_musicvolume, 0.5f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) else { // Set general music volume. - if (GSnd != NULL) + if (GSnd != nullptr) { GSnd->SetMusicVolume(clamp(self * relative_volume, 0, 1)); } // For music not implemented through the digital sound system, // let them know about the change. - if (currSong != NULL) + if (currSong != nullptr) { currSong->MusicVolumeChanged(); } @@ -178,7 +178,7 @@ void I_ShutdownMusic(bool onexit) if (currSong) { S_StopMusic (true); - assert (currSong == NULL); + assert (currSong == nullptr); } Timidity::FreeAll(); if (onexit) @@ -207,7 +207,7 @@ MusInfo::MusInfo() MusInfo::~MusInfo () { - if (currSong == this) currSong = NULL; + if (currSong == this) currSong = nullptr; } //========================================================================== @@ -233,7 +233,7 @@ void MusInfo::Start(bool loop, float rel_vol, int subsong) if (m_Status == MusInfo::STATE_Playing) currSong = this; else - currSong = NULL; + currSong = nullptr; // Notify the sound system of the changed relative volume snd_musicvolume.Callback(); @@ -299,12 +299,12 @@ FString MusInfo::GetStats() MusInfo *MusInfo::GetOPLDumper(const char *filename) { - return NULL; + return nullptr; } MusInfo *MusInfo::GetWaveDumper(const char *filename, int rate) { - return NULL; + return nullptr; } //========================================================================== @@ -331,7 +331,7 @@ static MIDISource *CreateMIDISource(FileReader &reader, EMIDIType miditype) return new XMISong(reader); default: - return NULL; + return nullptr; } } @@ -404,7 +404,7 @@ static EMIDIType IdentifyMIDIType(uint32_t *id, int size) MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) { - MusInfo *info = NULL; + MusInfo *info = nullptr; const char *fmt; uint32_t id[32/4]; @@ -431,11 +431,11 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) { delete[] gzipped; delete reader; - return NULL; + return nullptr; } delete reader; - MemoryArrayReader *memreader = new MemoryArrayReader(NULL, 0); + MemoryArrayReader *memreader = new MemoryArrayReader(nullptr, 0); if (!ungzip(gzipped, len, memreader->GetArray())) { delete[] gzipped; @@ -460,32 +460,41 @@ MusInfo *I_RegisterSong (FileReader *reader, MidiDeviceSetting *device) if (source == nullptr) return 0; if (!source->isValid()) { + delete reader; delete source; return 0; } // fixme: device and streamer need to be handled individually. - EMidiDevice devtype = device == NULL? MDEV_DEFAULT : (EMidiDevice)device->device; + EMidiDevice devtype = device == nullptr? MDEV_DEFAULT : (EMidiDevice)device->device; #ifndef _WIN32 // non-Windows platforms don't support MDEV_MMAPI so map to MDEV_SNDSYS if (devtype == MDEV_MMAPI) devtype = MDEV_SNDSYS; #endif + MIDIStreamer *streamer = nullptr; retry_as_sndsys: - info = CreateMIDIStreamer(devtype, device != NULL? device->args.GetChars() : ""); + streamer = CreateMIDIStreamer(devtype, device != nullptr? device->args.GetChars() : ""); - if (info == NULL && devtype != MDEV_SNDSYS && snd_mididevice < 0) + if (streamer == nullptr && devtype != MDEV_SNDSYS && snd_mididevice < 0) { devtype = MDEV_SNDSYS; goto retry_as_sndsys; } #ifdef _WIN32 - if (info == NULL && devtype != MDEV_MMAPI && snd_mididevice >= 0) + if (streamer == nullptr && devtype != MDEV_MMAPI && snd_mididevice >= 0) { - info = CreateMIDIStreamer(MDEV_MMAPI, ""); + streamer = CreateMIDIStreamer(MDEV_MMAPI, ""); } #endif + if (streamer == nullptr) + { + delete reader; + return 0; + } + streamer->SetMIDISource(source); + info = streamer; } // Check for various raw OPL formats @@ -494,10 +503,10 @@ retry_as_sndsys: (id[0] == MAKE_ID('D','B','R','A') && id[1] == MAKE_ID('W','O','P','L')) || // DosBox Raw OPL (id[0] == MAKE_ID('A','D','L','I') && *((uint8_t *)id + 4) == 'B')) // Martin Fernandez's modified IMF { - info = new OPLMUSSong (*reader, device != NULL? device->args.GetChars() : ""); + info = new OPLMUSSong (*reader, device != nullptr? device->args.GetChars() : ""); } // Check for game music - else if ((fmt = GME_CheckFormat(id[0])) != NULL && fmt[0] != '\0') + else if ((fmt = GME_CheckFormat(id[0])) != nullptr && fmt[0] != '\0') { info = GME_OpenSong(*reader, fmt); } @@ -512,7 +521,7 @@ retry_as_sndsys: if (info != nullptr) reader = nullptr; } - if (info == NULL) + if (info == nullptr) { // Check for CDDA "format" if (id[0] == (('R')|(('I')<<8)|(('F')<<16)|(('F')<<24))) @@ -535,12 +544,12 @@ retry_as_sndsys: } } - if (reader != NULL) delete reader; + if (reader != nullptr) delete reader; if (info && !info->IsValid ()) { delete info; - info = NULL; + info = nullptr; } return info; @@ -559,7 +568,7 @@ MusInfo *I_RegisterCDSong (int track, int id) if (info && !info->IsValid ()) { delete info; - info = NULL; + info = nullptr; } return info; @@ -649,7 +658,7 @@ static bool ungzip(uint8_t *data, int complen, TArray &newdata) void I_UpdateMusic() { - if (currSong != NULL) + if (currSong != nullptr) { currSong->Update(); } @@ -686,7 +695,7 @@ CCMD(testmusicvol) { if (argv.argc() > 1) { - relative_volume = (float)strtod(argv[1], NULL); + relative_volume = (float)strtod(argv[1], nullptr); snd_musicvolume.Callback(); } else @@ -701,7 +710,7 @@ CCMD(testmusicvol) ADD_STAT(music) { - if (currSong != NULL) + if (currSong != nullptr) { return currSong->GetStats(); } @@ -721,14 +730,14 @@ UNSAFE_CCMD (writeopl) { if (argv.argc() == 2) { - if (currSong == NULL) + if (currSong == nullptr) { Printf ("No song is currently playing.\n"); } else { MusInfo *dumper = currSong->GetOPLDumper(argv[1]); - if (dumper == NULL) + if (dumper == nullptr) { Printf ("Current song cannot be saved as OPL data.\n"); } @@ -759,14 +768,14 @@ UNSAFE_CCMD (writewave) { if (argv.argc() >= 2 && argv.argc() <= 3) { - if (currSong == NULL) + if (currSong == nullptr) { Printf ("No song is currently playing.\n"); } else { MusInfo *dumper = currSong->GetWaveDumper(argv[1], argv.argc() == 3 ? atoi(argv[2]) : 0); - if (dumper == NULL) + if (dumper == nullptr) { Printf ("Current song cannot be saved as wave data.\n"); } @@ -835,7 +844,7 @@ UNSAFE_CCMD (writemidi) source->CreateSMF(midi, 1); auto f = FileWriter::Open(argv[2]); - if (f == NULL) + if (f == nullptr) { Printf("Could not open %s.\n", argv[2]); return; diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index f6c247b57..b0b4c297a 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -7,7 +7,7 @@ #include "s_sound.h" #include "files.h" #include "wildmidi/wildmidi_lib.h" -#include "midisources.h" +#include "midisources/midisource.h" void I_InitMusicWin32 (); diff --git a/src/sound/midisource.cpp b/src/sound/midisources/midisource.cpp similarity index 99% rename from src/sound/midisource.cpp rename to src/sound/midisources/midisource.cpp index 6c639709a..acb09fd56 100644 --- a/src/sound/midisource.cpp +++ b/src/sound/midisources/midisource.cpp @@ -35,7 +35,7 @@ #include "i_musicinterns.h" -#include "midisources.h" +#include "midisource.h" char MIDI_EventLengths[7] = { 2, 2, 2, 2, 1, 1, 2 }; diff --git a/src/sound/midisources.h b/src/sound/midisources/midisource.h similarity index 100% rename from src/sound/midisources.h rename to src/sound/midisources/midisource.h diff --git a/src/sound/musicformats/music_hmi_midiout.cpp b/src/sound/midisources/midisource_hmi.cpp similarity index 99% rename from src/sound/musicformats/music_hmi_midiout.cpp rename to src/sound/midisources/midisource_hmi.cpp index d961c29c1..c2ce9b1fc 100644 --- a/src/sound/musicformats/music_hmi_midiout.cpp +++ b/src/sound/midisources/midisource_hmi.cpp @@ -39,7 +39,7 @@ #include "doomdef.h" #include "m_swap.h" #include "files.h" -#include "midisources.h" +#include "midisource.h" // MACROS ------------------------------------------------------------------ diff --git a/src/sound/musicformats/music_mus_midiout.cpp b/src/sound/midisources/midisource_mus.cpp similarity index 100% rename from src/sound/musicformats/music_mus_midiout.cpp rename to src/sound/midisources/midisource_mus.cpp diff --git a/src/sound/musicformats/music_smf_midiout.cpp b/src/sound/midisources/midisource_smf.cpp similarity index 100% rename from src/sound/musicformats/music_smf_midiout.cpp rename to src/sound/midisources/midisource_smf.cpp diff --git a/src/sound/musicformats/music_xmi_midiout.cpp b/src/sound/midisources/midisource_xmi.cpp similarity index 100% rename from src/sound/musicformats/music_xmi_midiout.cpp rename to src/sound/midisources/midisource_xmi.cpp diff --git a/src/sound/music_midi_base.cpp b/src/sound/music_midi_base.cpp index 810dd7e12..33c36842a 100644 --- a/src/sound/music_midi_base.cpp +++ b/src/sound/music_midi_base.cpp @@ -54,7 +54,6 @@ static bool nummididevicesset; static void AddDefaultMidiDevices(FOptionValues *opt) { - int p; FOptionValues::Pair *pair = &opt->mValues[opt->mValues.Reserve(NUM_DEF_DEVICES)]; pair[0].Text = "FluidSynth"; pair[0].Value = -5.0;