summaryrefslogtreecommitdiff
path: root/src/music/dmusic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/music/dmusic.cpp')
-rw-r--r--src/music/dmusic.cpp58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp
index bf8657ef4..41ccd6102 100644
--- a/src/music/dmusic.cpp
+++ b/src/music/dmusic.cpp
@@ -141,16 +141,16 @@ static struct {
/** Handle to our worker thread. */
static std::thread _dmusic_thread;
/** Event to signal the thread that it should look at a state change. */
-static HANDLE _thread_event = NULL;
+static HANDLE _thread_event = nullptr;
/** Lock access to playback data that is not thread-safe. */
static std::mutex _thread_mutex;
/** The direct music object manages buffers and ports. */
-static IDirectMusic *_music = NULL;
+static IDirectMusic *_music = nullptr;
/** The port object lets us send MIDI data to the synthesizer. */
-static IDirectMusicPort *_port = NULL;
+static IDirectMusicPort *_port = nullptr;
/** The buffer object collects the data to sent. */
-static IDirectMusicBuffer *_buffer = NULL;
+static IDirectMusicBuffer *_buffer = nullptr;
/** List of downloaded DLS instruments. */
static std::vector<IDirectMusicDownload *> _dls_downloads;
@@ -438,7 +438,7 @@ bool DLSFile::LoadFile(const TCHAR *file)
DEBUG(driver, 2, "DMusic: Try to load DLS file %s", FS2OTTD(file));
FILE *f = _tfopen(file, _T("rb"));
- if (f == NULL) return false;
+ if (f == nullptr) return false;
FileCloser f_scope(f);
@@ -879,13 +879,13 @@ static const char *LoadDefaultDLSFile(const char *user_dls)
if ((caps.dwFlags & (DMUS_PC_DLS | DMUS_PC_DLS2)) != 0 && (caps.dwFlags & DMUS_PC_GMINHARDWARE) == 0) {
DLSFile dls_file;
- if (user_dls == NULL) {
+ if (user_dls == nullptr) {
/* Try loading the default GM DLS file stored in the registry. */
HKEY hkDM;
if (SUCCEEDED(RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\DirectMusic"), 0, KEY_READ, &hkDM))) {
TCHAR dls_path[MAX_PATH];
DWORD buf_size = sizeof(dls_path); // Buffer size as to be given in bytes!
- if (SUCCEEDED(RegQueryValueEx(hkDM, _T("GMFilePath"), NULL, NULL, (LPBYTE)dls_path, &buf_size))) {
+ if (SUCCEEDED(RegQueryValueEx(hkDM, _T("GMFilePath"), nullptr, nullptr, (LPBYTE)dls_path, &buf_size))) {
TCHAR expand_path[MAX_PATH * 2];
ExpandEnvironmentStrings(dls_path, expand_path, lengthof(expand_path));
if (!dls_file.LoadFile(expand_path)) DEBUG(driver, 1, "Failed to load default GM DLS file from registry");
@@ -906,7 +906,7 @@ static const char *LoadDefaultDLSFile(const char *user_dls)
}
/* Get download port and allocate download IDs. */
- IDirectMusicPortDownload *download_port = NULL;
+ IDirectMusicPortDownload *download_port = nullptr;
if (FAILED(_port->QueryInterface(IID_IDirectMusicPortDownload, (LPVOID *)&download_port))) return "Can't get download port";
DWORD dlid_wave = 0, dlid_inst = 0;
@@ -920,7 +920,7 @@ static const char *LoadDefaultDLSFile(const char *user_dls)
/* Download wave data. */
for (DWORD i = 0; i < dls_file.waves.size(); i++) {
- IDirectMusicDownload *dl_wave = NULL;
+ IDirectMusicDownload *dl_wave = nullptr;
if (FAILED(download_port->AllocateBuffer((DWORD)(sizeof(WAVE_DOWNLOAD) + dwAppend * dls_file.waves[i].fmt.wf.nBlockAlign + dls_file.waves[i].data.size()), &dl_wave))) {
download_port->Release();
return "Can't allocate wave download buffer";
@@ -984,7 +984,7 @@ static const char *LoadDefaultDLSFile(const char *user_dls)
i_size += offsets * sizeof(ULONG);
/* Allocate download buffer. */
- IDirectMusicDownload *dl_inst = NULL;
+ IDirectMusicDownload *dl_inst = nullptr;
if (FAILED(download_port->AllocateBuffer((DWORD)i_size, &dl_inst))) {
download_port->Release();
return "Can't allocate instrument download buffer";
@@ -1085,19 +1085,19 @@ static const char *LoadDefaultDLSFile(const char *user_dls)
download_port->Release();
}
- return NULL;
+ return nullptr;
}
const char *MusicDriver_DMusic::Start(const char * const *parm)
{
/* Initialize COM */
- if (FAILED(CoInitializeEx(NULL, COINITBASE_MULTITHREADED))) return "COM initialization failed";
+ if (FAILED(CoInitializeEx(nullptr, COINITBASE_MULTITHREADED))) return "COM initialization failed";
/* Create the DirectMusic object */
if (FAILED(CoCreateInstance(
CLSID_DirectMusic,
- NULL,
+ nullptr,
CLSCTX_INPROC,
IID_IDirectMusic,
(LPVOID*)&_music
@@ -1106,7 +1106,7 @@ const char *MusicDriver_DMusic::Start(const char * const *parm)
}
/* Assign sound output device. */
- if (FAILED(_music->SetDirectSound(NULL, NULL))) return "Can't set DirectSound interface";
+ if (FAILED(_music->SetDirectSound(nullptr, nullptr))) return "Can't set DirectSound interface";
/* MIDI events need to be send to the synth in time before their playback time
* has come. By default, we try send any events at least 50 ms before playback. */
@@ -1149,7 +1149,7 @@ const char *MusicDriver_DMusic::Start(const char * const *parm)
params.dwSize = sizeof(DMUS_PORTPARAMS);
params.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
params.dwChannelGroups = 1;
- if (FAILED(_music->CreatePort(guidPort, &params, &_port, NULL))) return "Failed to create port";
+ if (FAILED(_music->CreatePort(guidPort, &params, &_port, nullptr))) return "Failed to create port";
/* Activate port. */
if (FAILED(_port->Activate(TRUE))) return "Failed to activate port";
@@ -1159,19 +1159,19 @@ const char *MusicDriver_DMusic::Start(const char * const *parm)
desc.dwSize = sizeof(DMUS_BUFFERDESC);
desc.guidBufferFormat = KSDATAFORMAT_SUBTYPE_DIRECTMUSIC;
desc.cbBuffer = 1024;
- if (FAILED(_music->CreateMusicBuffer(&desc, &_buffer, NULL))) return "Failed to create music buffer";
+ if (FAILED(_music->CreateMusicBuffer(&desc, &_buffer, nullptr))) return "Failed to create music buffer";
/* On soft-synths (e.g. the default DirectMusic one), we might need to load a wavetable set to get music. */
const char *dls = LoadDefaultDLSFile(GetDriverParam(parm, "dls"));
- if (dls != NULL) return dls;
+ if (dls != nullptr) return dls;
/* Create playback thread and synchronization primitives. */
- _thread_event = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (_thread_event == NULL) return "Can't create thread shutdown event";
+ _thread_event = CreateEvent(nullptr, FALSE, FALSE, nullptr);
+ if (_thread_event == nullptr) return "Can't create thread shutdown event";
if (!StartNewThread(&_dmusic_thread, "ottd:dmusic", &MidiThreadProc)) return "Can't create MIDI output thread";
- return NULL;
+ return nullptr;
}
@@ -1191,34 +1191,34 @@ void MusicDriver_DMusic::Stop()
/* Unloaded any instruments we loaded. */
if (_dls_downloads.size() > 0) {
- IDirectMusicPortDownload *download_port = NULL;
+ IDirectMusicPortDownload *download_port = nullptr;
_port->QueryInterface(IID_IDirectMusicPortDownload, (LPVOID *)&download_port);
/* Instruments refer to waves. As the waves are at the beginning of the download list,
* do the unload from the back so that references are cleared properly. */
- for (std::vector<IDirectMusicDownload *>::reverse_iterator i = _dls_downloads.rbegin(); download_port != NULL && i != _dls_downloads.rend(); i++) {
+ for (std::vector<IDirectMusicDownload *>::reverse_iterator i = _dls_downloads.rbegin(); download_port != nullptr && i != _dls_downloads.rend(); i++) {
download_port->Unload(*i);
(*i)->Release();
}
_dls_downloads.clear();
- if (download_port != NULL) download_port->Release();
+ if (download_port != nullptr) download_port->Release();
}
- if (_buffer != NULL) {
+ if (_buffer != nullptr) {
_buffer->Release();
- _buffer = NULL;
+ _buffer = nullptr;
}
- if (_port != NULL) {
+ if (_port != nullptr) {
_port->Activate(FALSE);
_port->Release();
- _port = NULL;
+ _port = nullptr;
}
- if (_music != NULL) {
+ if (_music != nullptr) {
_music->Release();
- _music = NULL;
+ _music = nullptr;
}
CloseHandle(_thread_event);