mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 23:01:50 +00:00
- started cleanup work on WildMidi code.
This commit is contained in:
parent
7962bf189e
commit
d9e32eb207
4 changed files with 14 additions and 32 deletions
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include "i_musicinterns.h"
|
#include "i_musicinterns.h"
|
||||||
#include "doomerrors.h"
|
#include "doomerrors.h"
|
||||||
|
#include "i_soundfont.h"
|
||||||
|
|
||||||
// MACROS ------------------------------------------------------------------
|
// MACROS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -123,6 +124,13 @@ WildMIDIDevice::WildMIDIDevice(const char *args, int samplerate)
|
||||||
WildMidi_Shutdown();
|
WildMidi_Shutdown();
|
||||||
CurrentConfig = "";
|
CurrentConfig = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto reader = sfmanager.OpenSoundFont(CurrentConfig, SF_GUS);
|
||||||
|
if (reader == nullptr)
|
||||||
|
{
|
||||||
|
I_Error("WildMidi: Unable to open sound font %s\n", CurrentConfig.GetChars());
|
||||||
|
}
|
||||||
|
|
||||||
if (!WildMidi_Init(args, SampleRate, 0))
|
if (!WildMidi_Init(args, SampleRate, 0))
|
||||||
{
|
{
|
||||||
CurrentConfig = args;
|
CurrentConfig = args;
|
||||||
|
|
|
@ -42,20 +42,7 @@
|
||||||
#include "i_soundfont.h"
|
#include "i_soundfont.h"
|
||||||
|
|
||||||
std::unique_ptr<FSoundFontReader> wm_sfreader;
|
std::unique_ptr<FSoundFontReader> wm_sfreader;
|
||||||
static FString config_name;
|
|
||||||
|
|
||||||
bool _WM_InitReader(const char *config_file)
|
|
||||||
{
|
|
||||||
auto reader = sfmanager.OpenSoundFont(config_file, SF_GUS);
|
|
||||||
if (reader == nullptr)
|
|
||||||
{
|
|
||||||
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, errno);
|
|
||||||
return false; // No sound font could be opened.
|
|
||||||
}
|
|
||||||
wm_sfreader.reset(reader);
|
|
||||||
config_name = config_file;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size)
|
unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size)
|
||||||
{
|
{
|
||||||
|
@ -64,7 +51,7 @@ unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size)
|
||||||
if (filename == nullptr)
|
if (filename == nullptr)
|
||||||
{
|
{
|
||||||
fp = wm_sfreader->OpenMainConfigFile();
|
fp = wm_sfreader->OpenMainConfigFile();
|
||||||
filename = config_name;
|
filename = wm_sfreader->MainConfigFileName();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#include "reverb.h"
|
#include "reverb.h"
|
||||||
#include "gus_pat.h"
|
#include "gus_pat.h"
|
||||||
#include "wildmidi_lib.h"
|
#include "wildmidi_lib.h"
|
||||||
#include "files.h"
|
|
||||||
#include "i_soundfont.h"
|
#include "i_soundfont.h"
|
||||||
|
|
||||||
#define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\')
|
#define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\')
|
||||||
|
@ -663,21 +662,13 @@ static int WM_LoadConfig(const char *config_file, bool main) {
|
||||||
int token_count = 0;
|
int token_count = 0;
|
||||||
auto config_parm = config_file;
|
auto config_parm = config_file;
|
||||||
|
|
||||||
FileReader fr;
|
|
||||||
if (main)
|
|
||||||
{
|
|
||||||
if (!_WM_InitReader(config_file)) return -1; // unable to open this as a config file.
|
|
||||||
config_parm = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
config_buffer = (char *)_WM_BufferFile(config_parm, &config_size);
|
config_buffer = (char *)_WM_BufferFile(config_parm, &config_size);
|
||||||
if (!config_buffer) {
|
if (!config_buffer) {
|
||||||
WM_FreePatches();
|
WM_FreePatches();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
FString bp = wm_sfreader->basePath();
|
if (config_parm == nullptr) config_file = wm_sfreader->basePath().GetChars(); // Re-get the base path because for archives this is empty.
|
||||||
if (config_parm == nullptr) config_file = bp.GetChars(); // Re-get the base path because for archives this is empty.
|
|
||||||
|
|
||||||
// This part was rewritten because the original depended on a header that was GPL'd.
|
// This part was rewritten because the original depended on a header that was GPL'd.
|
||||||
dir_end = strrchr(config_file, '/');
|
dir_end = strrchr(config_file, '/');
|
||||||
|
@ -2502,20 +2493,16 @@ WildMidi_GetString(unsigned short int info) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
WM_SYMBOL int WildMidi_Init(const char * config_file, unsigned short int rate,
|
WM_SYMBOL int WildMidi_Init(FSoundFontReader *reader, unsigned short int rate,
|
||||||
unsigned short int options) {
|
unsigned short int options) {
|
||||||
if (WM_Initialized) {
|
if (WM_Initialized) {
|
||||||
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_ALR_INIT, NULL, 0);
|
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_ALR_INIT, NULL, 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_file == NULL) {
|
|
||||||
_WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG,
|
|
||||||
"(NULL config file pointer)", 0);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
WM_InitPatches();
|
WM_InitPatches();
|
||||||
if (WM_LoadConfig(config_file, true) == -1) {
|
wm_sfreader.reset(reader);
|
||||||
|
if (WM_LoadConfig(nullptr, true) == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ struct _WM_Info {
|
||||||
typedef void midi;
|
typedef void midi;
|
||||||
|
|
||||||
WM_SYMBOL const char * WildMidi_GetString (unsigned short int info);
|
WM_SYMBOL const char * WildMidi_GetString (unsigned short int info);
|
||||||
WM_SYMBOL int WildMidi_Init (const char * config_file, unsigned short int rate, unsigned short int options);
|
WM_SYMBOL int WildMidi_Init (FSoundFontReader *reader, unsigned short int rate, unsigned short int options);
|
||||||
WM_SYMBOL int WildMidi_MasterVolume (unsigned char master_volume);
|
WM_SYMBOL int WildMidi_MasterVolume (unsigned char master_volume);
|
||||||
WM_SYMBOL int WildMidi_SetOption (midi * handle, unsigned short int options, unsigned short int setting);
|
WM_SYMBOL int WildMidi_SetOption (midi * handle, unsigned short int options, unsigned short int setting);
|
||||||
WM_SYMBOL int WildMidi_Close (midi * handle);
|
WM_SYMBOL int WildMidi_Close (midi * handle);
|
||||||
|
|
Loading…
Reference in a new issue