Add build time flag to choose whether to enable ADL MIDI support
Since ADL MIDI is not packaged on some distributions, default the option to off.
This commit is contained in:
parent
1b50c31f55
commit
1be414217c
35
SConstruct
35
SConstruct
|
@ -1160,6 +1160,22 @@ struct d_screenshot
|
||||||
successflags = self.pkgconfig.merge(context, self.msgprefix, self.user_settings, 'libpng', 'libpng', _guess_flags)
|
successflags = self.pkgconfig.merge(context, self.msgprefix, self.user_settings, 'libpng', 'libpng', _guess_flags)
|
||||||
return self._soft_check_system_library(context, header=_header, main=_main, lib='png', text=_text, successflags=successflags)
|
return self._soft_check_system_library(context, header=_header, main=_main, lib='png', text=_text, successflags=successflags)
|
||||||
|
|
||||||
|
@_custom_test
|
||||||
|
def _check_user_settings_adldmidi(self,context):
|
||||||
|
user_settings = self.user_settings
|
||||||
|
adlmidi = user_settings.adlmidi
|
||||||
|
if adlmidi == 'none':
|
||||||
|
adlmidi_load_type = 'disabled'
|
||||||
|
elif adlmidi == 'runtime':
|
||||||
|
adlmidi_load_type = 'load dynamically'
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
context.Result('%s: checking how to handle ADL MIDI...%s' % (self.msgprefix, adlmidi_load_type))
|
||||||
|
Define = context.sconf.Define
|
||||||
|
enable_adlmidi = int(adlmidi != 'none')
|
||||||
|
user_settings._enable_adlmidi = enable_adlmidi
|
||||||
|
Define('DXX_USE_ADLMIDI', enable_adlmidi)
|
||||||
|
|
||||||
@_custom_test
|
@_custom_test
|
||||||
def _check_user_settings_screenshot(self,context):
|
def _check_user_settings_screenshot(self,context):
|
||||||
user_settings = self.user_settings
|
user_settings = self.user_settings
|
||||||
|
@ -3440,6 +3456,8 @@ class DXXCommon(LazyObjectConstructor):
|
||||||
if self.raspberrypi == 'yes':
|
if self.raspberrypi == 'yes':
|
||||||
return 'brcmEGL'
|
return 'brcmEGL'
|
||||||
return self.default_EGL_LIB
|
return self.default_EGL_LIB
|
||||||
|
def need_dynamic_library_load(self):
|
||||||
|
return self.adlmidi == 'runtime'
|
||||||
|
|
||||||
def __default_DATA_DIR(self):
|
def __default_DATA_DIR(self):
|
||||||
platform_settings_type = self._program.get_platform_settings_type(self.host_platform)
|
platform_settings_type = self._program.get_platform_settings_type(self.host_platform)
|
||||||
|
@ -3634,6 +3652,7 @@ class DXXCommon(LazyObjectConstructor):
|
||||||
'variable': EnumVariable,
|
'variable': EnumVariable,
|
||||||
'arguments': (
|
'arguments': (
|
||||||
('host_endian', None, 'endianness of host platform', {'allowed_values' : ('little', 'big')}),
|
('host_endian', None, 'endianness of host platform', {'allowed_values' : ('little', 'big')}),
|
||||||
|
('adlmidi', 'none', 'include ADL MIDI support (none: disabled; runtime: dynamically load at runtime)', {'allowed_values' : ('none', 'runtime')}),
|
||||||
('screenshot', 'png', 'screenshot file format', {'allowed_values' : ('none', 'legacy', 'png')}),
|
('screenshot', 'png', 'screenshot file format', {'allowed_values' : ('none', 'legacy', 'png')}),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -4254,7 +4273,6 @@ class DXXArchive(DXXCommon):
|
||||||
'common/3d/points.cpp',
|
'common/3d/points.cpp',
|
||||||
'common/3d/rod.cpp',
|
'common/3d/rod.cpp',
|
||||||
'common/3d/setup.cpp',
|
'common/3d/setup.cpp',
|
||||||
'common/music/adlmidi_dynamic.cpp',
|
|
||||||
'common/arch/sdl/event.cpp',
|
'common/arch/sdl/event.cpp',
|
||||||
'common/arch/sdl/joy.cpp',
|
'common/arch/sdl/joy.cpp',
|
||||||
'common/arch/sdl/key.cpp',
|
'common/arch/sdl/key.cpp',
|
||||||
|
@ -4277,13 +4295,19 @@ class DXXArchive(DXXCommon):
|
||||||
'common/misc/vgrphys.cpp',
|
'common/misc/vgrphys.cpp',
|
||||||
'common/misc/vgwphys.cpp',
|
'common/misc/vgwphys.cpp',
|
||||||
)), \
|
)), \
|
||||||
|
__get_objects_use_adlmidi=DXXCommon.create_lazy_object_getter((
|
||||||
|
'common/music/adlmidi_dynamic.cpp',
|
||||||
|
)),
|
||||||
__get_objects_use_sdl1=DXXCommon.create_lazy_object_getter((
|
__get_objects_use_sdl1=DXXCommon.create_lazy_object_getter((
|
||||||
'common/arch/sdl/rbaudio.cpp',
|
'common/arch/sdl/rbaudio.cpp',
|
||||||
))
|
))
|
||||||
):
|
):
|
||||||
value = list(__get_objects_common(self))
|
value = list(__get_objects_common(self))
|
||||||
extend = value.extend
|
extend = value.extend
|
||||||
if not self.user_settings.sdl2:
|
user_settings = self.user_settings
|
||||||
|
if user_settings._enable_adlmidi:
|
||||||
|
extend(__get_objects_use_adlmidi(self))
|
||||||
|
if not user_settings.sdl2:
|
||||||
extend(__get_objects_use_sdl1(self))
|
extend(__get_objects_use_sdl1(self))
|
||||||
extend(self.platform_settings.get_platform_objects())
|
extend(self.platform_settings.get_platform_objects())
|
||||||
return value
|
return value
|
||||||
|
@ -4642,6 +4666,11 @@ class DXXProgram(DXXCommon):
|
||||||
DXXCommon.LinuxPlatformSettings.__init__(self,program,user_settings)
|
DXXCommon.LinuxPlatformSettings.__init__(self,program,user_settings)
|
||||||
if user_settings.sharepath and user_settings.sharepath[-1] != '/':
|
if user_settings.sharepath and user_settings.sharepath[-1] != '/':
|
||||||
user_settings.sharepath += '/'
|
user_settings.sharepath += '/'
|
||||||
|
def adjust_environment(self,program,env):
|
||||||
|
DXXCommon.LinuxPlatformSettings.adjust_environment(self,program,env)
|
||||||
|
user_settings = self.user_settings
|
||||||
|
if user_settings.need_dynamic_library_load():
|
||||||
|
env.Append(LIBS = ['dl'])
|
||||||
|
|
||||||
def get_objects_common(self,
|
def get_objects_common(self,
|
||||||
__get_objects_common=__get_objects_common,
|
__get_objects_common=__get_objects_common,
|
||||||
|
@ -4702,7 +4731,7 @@ class DXXProgram(DXXCommon):
|
||||||
('__STDC_FORMAT_MACROS',),
|
('__STDC_FORMAT_MACROS',),
|
||||||
],
|
],
|
||||||
CPPPATH = [os.path.join(self.srcdir, 'main')],
|
CPPPATH = [os.path.join(self.srcdir, 'main')],
|
||||||
LIBS = ['m', 'dl'],
|
LIBS = ['m'],
|
||||||
)
|
)
|
||||||
|
|
||||||
def register_program(self):
|
def register_program(self):
|
||||||
|
|
|
@ -91,9 +91,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
static current_music_t current_music;
|
static current_music_t current_music;
|
||||||
static ADL_MIDIPlayer_t current_adlmidi;
|
|
||||||
static std::vector<uint8_t> current_music_hndlbuf;
|
static std::vector<uint8_t> current_music_hndlbuf;
|
||||||
|
|
||||||
|
#if DXX_USE_ADLMIDI
|
||||||
|
static ADL_MIDIPlayer_t current_adlmidi;
|
||||||
static ADL_MIDIPlayer *get_adlmidi()
|
static ADL_MIDIPlayer *get_adlmidi()
|
||||||
{
|
{
|
||||||
ADL_MIDIPlayer *adlmidi = current_adlmidi.get();
|
ADL_MIDIPlayer *adlmidi = current_adlmidi.get();
|
||||||
|
@ -114,10 +115,15 @@ static ADL_MIDIPlayer *get_adlmidi()
|
||||||
return adlmidi;
|
return adlmidi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mix_adlmidi(void *udata, Uint8 *stream, int len);
|
||||||
|
#endif
|
||||||
|
|
||||||
enum class CurrentMusicType
|
enum class CurrentMusicType
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
|
#if DXX_USE_ADLMIDI
|
||||||
ADLMIDI,
|
ADLMIDI,
|
||||||
|
#endif
|
||||||
SDLMixer,
|
SDLMixer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,9 +132,6 @@ static CurrentMusicType current_music_type = CurrentMusicType::None;
|
||||||
static CurrentMusicType load_mus_data(const uint8_t *data, size_t size);
|
static CurrentMusicType load_mus_data(const uint8_t *data, size_t size);
|
||||||
static CurrentMusicType load_mus_file(const char *filename);
|
static CurrentMusicType load_mus_file(const char *filename);
|
||||||
|
|
||||||
static void mix_adlmidi(void *udata, Uint8 *stream, int len);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Plays a music file from an absolute path or a relative path
|
* Plays a music file from an absolute path or a relative path
|
||||||
*/
|
*/
|
||||||
|
@ -139,8 +142,6 @@ int mix_play_file(const char *filename, int loop, void (*hook_finished_track)())
|
||||||
const char *fptr;
|
const char *fptr;
|
||||||
unsigned int bufsize = 0;
|
unsigned int bufsize = 0;
|
||||||
|
|
||||||
// fprintf(stderr, "Load music: %s\n", filename);
|
|
||||||
|
|
||||||
mix_free_music(); // stop and free what we're already playing, if anything
|
mix_free_music(); // stop and free what we're already playing, if anything
|
||||||
|
|
||||||
fptr = strrchr(filename, '.');
|
fptr = strrchr(filename, '.');
|
||||||
|
@ -198,6 +199,7 @@ int mix_play_file(const char *filename, int loop, void (*hook_finished_track)())
|
||||||
switch (current_music_type)
|
switch (current_music_type)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if DXX_USE_ADLMIDI
|
||||||
case CurrentMusicType::ADLMIDI:
|
case CurrentMusicType::ADLMIDI:
|
||||||
{
|
{
|
||||||
ADL_MIDIPlayer *adlmidi = get_adlmidi();
|
ADL_MIDIPlayer *adlmidi = get_adlmidi();
|
||||||
|
@ -206,6 +208,7 @@ int mix_play_file(const char *filename, int loop, void (*hook_finished_track)())
|
||||||
Mix_HookMusicFinished(hook_finished_track ? hook_finished_track : mix_free_music);
|
Mix_HookMusicFinished(hook_finished_track ? hook_finished_track : mix_free_music);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
case CurrentMusicType::SDLMixer:
|
case CurrentMusicType::SDLMixer:
|
||||||
{
|
{
|
||||||
|
@ -229,7 +232,15 @@ int mix_play_file(const char *filename, int loop, void (*hook_finished_track)())
|
||||||
void mix_free_music()
|
void mix_free_music()
|
||||||
{
|
{
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
|
#if DXX_USE_ADLMIDI
|
||||||
|
/* Only ADLMIDI can set a hook, so if ADLMIDI is compiled out, there is no
|
||||||
|
* need to clear the hook.
|
||||||
|
*
|
||||||
|
* When ADLMIDI is supported, clear unconditionally, instead of checking
|
||||||
|
* whether the music type requires it.
|
||||||
|
*/
|
||||||
Mix_HookMusic(nullptr, nullptr);
|
Mix_HookMusic(nullptr, nullptr);
|
||||||
|
#endif
|
||||||
current_music.reset();
|
current_music.reset();
|
||||||
current_music_hndlbuf.clear();
|
current_music_hndlbuf.clear();
|
||||||
current_music_type = CurrentMusicType::None;
|
current_music_type = CurrentMusicType::None;
|
||||||
|
@ -268,14 +279,15 @@ void mix_pause_resume_music()
|
||||||
static CurrentMusicType load_mus_data(const uint8_t *data, size_t size)
|
static CurrentMusicType load_mus_data(const uint8_t *data, size_t size)
|
||||||
{
|
{
|
||||||
CurrentMusicType type = CurrentMusicType::None;
|
CurrentMusicType type = CurrentMusicType::None;
|
||||||
|
#if DXX_USE_ADLMIDI
|
||||||
ADL_MIDIPlayer *adlmidi = get_adlmidi();
|
ADL_MIDIPlayer *adlmidi = get_adlmidi();
|
||||||
SDL_RWops *rw = NULL;
|
|
||||||
|
|
||||||
if (adlmidi && adl_openData(adlmidi, data, size) == 0)
|
if (adlmidi && adl_openData(adlmidi, data, size) == 0)
|
||||||
type = CurrentMusicType::ADLMIDI;
|
type = CurrentMusicType::ADLMIDI;
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
rw = SDL_RWFromConstMem(data, size);
|
const auto rw = SDL_RWFromConstMem(data, size);
|
||||||
current_music.reset(Mix_LoadMUS_RW(rw DXX_SDL_MIXER_Mix_LoadMUS_MANAGE_RWOPS) DXX_SDL_MIXER_Mix_LoadMUS_PASS_RWOPS(rw));
|
current_music.reset(Mix_LoadMUS_RW(rw DXX_SDL_MIXER_Mix_LoadMUS_MANAGE_RWOPS) DXX_SDL_MIXER_Mix_LoadMUS_PASS_RWOPS(rw));
|
||||||
if (current_music)
|
if (current_music)
|
||||||
type = CurrentMusicType::SDLMixer;
|
type = CurrentMusicType::SDLMixer;
|
||||||
|
@ -287,11 +299,13 @@ static CurrentMusicType load_mus_data(const uint8_t *data, size_t size)
|
||||||
static CurrentMusicType load_mus_file(const char *filename)
|
static CurrentMusicType load_mus_file(const char *filename)
|
||||||
{
|
{
|
||||||
CurrentMusicType type = CurrentMusicType::None;
|
CurrentMusicType type = CurrentMusicType::None;
|
||||||
|
#if DXX_USE_ADLMIDI
|
||||||
ADL_MIDIPlayer *adlmidi = get_adlmidi();
|
ADL_MIDIPlayer *adlmidi = get_adlmidi();
|
||||||
|
|
||||||
if (adlmidi && adl_openFile(adlmidi, filename) == 0)
|
if (adlmidi && adl_openFile(adlmidi, filename) == 0)
|
||||||
type = CurrentMusicType::ADLMIDI;
|
type = CurrentMusicType::ADLMIDI;
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
current_music.reset(Mix_LoadMUS(filename));
|
current_music.reset(Mix_LoadMUS(filename));
|
||||||
if (current_music)
|
if (current_music)
|
||||||
|
@ -301,6 +315,7 @@ static CurrentMusicType load_mus_file(const char *filename)
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DXX_USE_ADLMIDI
|
||||||
static int16_t sat16(int32_t x)
|
static int16_t sat16(int32_t x)
|
||||||
{
|
{
|
||||||
x = (x < INT16_MIN) ? INT16_MIN : x;
|
x = (x < INT16_MIN) ? INT16_MIN : x;
|
||||||
|
@ -323,5 +338,6 @@ static void mix_adlmidi(void *, Uint8 *stream, int len)
|
||||||
const auto amplify = [](int16_t i) { return sat16(2 * i); };
|
const auto amplify = [](int16_t i) { return sat16(2 * i); };
|
||||||
std::transform(samples, samples + sampleCount, samples, amplify);
|
std::transform(samples, samples + sampleCount, samples, amplify);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "dxxsconf.h"
|
||||||
|
|
||||||
|
#if DXX_USE_ADLMIDI
|
||||||
struct ADL_MIDIPlayer;
|
struct ADL_MIDIPlayer;
|
||||||
|
|
||||||
enum ADLMIDI_SampleType
|
enum ADLMIDI_SampleType
|
||||||
|
@ -71,3 +73,4 @@ struct ADLMIDI_delete
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::unique_ptr<ADL_MIDIPlayer, ADLMIDI_delete> ADL_MIDIPlayer_t;
|
typedef std::unique_ptr<ADL_MIDIPlayer, ADLMIDI_delete> ADL_MIDIPlayer_t;
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue