From 98329311b465a8cf3ece7a8d7c8b3f1bb17e3fd1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 23 Sep 2019 13:58:16 +0200 Subject: [PATCH] - moved the CVars out of the Timidity++ backend. --- .../music_timiditypp_mididevice.cpp | 134 +++++++++++++++++ src/sound/timiditypp/playmidi.cpp | 138 ------------------ src/sound/timiditypp/timidity.h | 4 + 3 files changed, 138 insertions(+), 138 deletions(-) diff --git a/src/sound/mididevices/music_timiditypp_mididevice.cpp b/src/sound/mididevices/music_timiditypp_mididevice.cpp index 16aad4974..76b3d76bc 100644 --- a/src/sound/mididevices/music_timiditypp_mididevice.cpp +++ b/src/sound/mididevices/music_timiditypp_mididevice.cpp @@ -43,6 +43,140 @@ #include "timiditypp/instrum.h" #include "timiditypp/playmidi.h" + + +template void ChangeVarSync(T& var, T value) +{ + std::lock_guard lock(TimidityPlus::CvarCritSec); + var = value; +} + +CUSTOM_CVAR(Bool, timidity_modulation_wheel, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_modulation_wheel, *self); +} + +CUSTOM_CVAR(Bool, timidity_portamento, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_portamento, *self); +} +/* +* reverb=0 no reverb 0 +* reverb=1 old reverb 1 +* reverb=1,n set reverb level to n (-1 to -127) +* reverb=2 "global" old reverb 2 +* reverb=2,n set reverb level to n (-1 to -127) - 128 +* reverb=3 new reverb 3 +* reverb=3,n set reverb level to n (-1 to -127) - 256 +* reverb=4 "global" new reverb 4 +* reverb=4,n set reverb level to n (-1 to -127) - 384 +*/ +EXTERN_CVAR(Int, timidity_reverb_level) +EXTERN_CVAR(Int, timidity_reverb) + +static void SetReverb() +{ + int value = 0; + int mode = timidity_reverb; + int level = timidity_reverb_level; + + if (mode == 0 || level == 0) value = mode; + else value = (mode - 1) * -128 - level; + ChangeVarSync(TimidityPlus::timidity_reverb, value); +} + +CUSTOM_CVAR(Int, timidity_reverb, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + if (self < 0 || self > 4) self = 0; + else SetReverb(); +} + +CUSTOM_CVAR(Int, timidity_reverb_level, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + if (self < 0 || self > 127) self = 0; + else SetReverb(); +} + +CUSTOM_CVAR(Int, timidity_chorus, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_chorus, *self); +} + +CUSTOM_CVAR(Bool, timidity_surround_chorus, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + if (currSong != nullptr && currSong->GetDeviceType() == MDEV_TIMIDITY) + { + MIDIDeviceChanged(-1, true); + } + ChangeVarSync(TimidityPlus::timidity_surround_chorus, *self); +} + +CUSTOM_CVAR(Bool, timidity_channel_pressure, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_channel_pressure, *self); +} + +CUSTOM_CVAR(Int, timidity_lpf_def, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_lpf_def, *self); +} + +CUSTOM_CVAR(Bool, timidity_temper_control, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_temper_control, *self); +} + +CUSTOM_CVAR(Bool, timidity_modulation_envelope, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_modulation_envelope, *self); + if (currSong != nullptr && currSong->GetDeviceType() == MDEV_TIMIDITY) + { + MIDIDeviceChanged(-1, true); + } +} + +CUSTOM_CVAR(Bool, timidity_overlap_voice_allow, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_overlap_voice_allow, *self); +} + +CUSTOM_CVAR(Bool, timidity_drum_effect, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_drum_effect, *self); +} + +CUSTOM_CVAR(Bool, timidity_pan_delay, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + ChangeVarSync(TimidityPlus::timidity_pan_delay, *self); +} + +CUSTOM_CVAR(Float, timidity_drum_power, 1.0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) /* coef. of drum amplitude */ +{ + if (self < 0) self = 0; + else if (self > MAX_AMPLIFICATION / 100.f) self = MAX_AMPLIFICATION / 100.f; + ChangeVarSync(TimidityPlus::timidity_drum_power, *self); +} +CUSTOM_CVAR(Int, timidity_key_adjust, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + if (self < -24) self = -24; + else if (self > 24) self = 24; + ChangeVarSync(TimidityPlus::timidity_key_adjust, *self); +} +// For testing mainly. +CUSTOM_CVAR(Float, timidity_tempo_adjust, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + if (self < 0.25) self = 0.25; + else if (self > 10) self = 10; + ChangeVarSync(TimidityPlus::timidity_tempo_adjust, *self); +} + +CUSTOM_CVAR(Float, min_sustain_time, 5000, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +{ + if (self < 0) self = 0; + ChangeVarSync(TimidityPlus::min_sustain_time, *self); +} + + class TimidityPPMIDIDevice : public SoftSynthMIDIDevice { static TimidityPlus::Instruments *instruments; diff --git a/src/sound/timiditypp/playmidi.cpp b/src/sound/timiditypp/playmidi.cpp index 2f134c13b..4f0297f66 100644 --- a/src/sound/timiditypp/playmidi.cpp +++ b/src/sound/timiditypp/playmidi.cpp @@ -25,7 +25,6 @@ #include #include -#include #include "timidity.h" #include "common.h" #include "instrum.h" @@ -35,10 +34,8 @@ #include "reverb.h" #include "freq.h" #include "quantity.h" -#include "c_cvars.h" #include "tables.h" #include "effect.h" -#include "i_musicinterns.h" namespace TimidityPlus @@ -70,142 +67,7 @@ namespace TimidityPlus static bool opt_tva_release = false; static bool opt_insertion_effect = false; static bool opt_delay_control = false; -} -template void ChangeVarSync(T&var, T value) -{ - std::lock_guard lock(TimidityPlus::CvarCritSec); - var = value; -} - -CUSTOM_CVAR(Bool, timidity_modulation_wheel, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_modulation_wheel, *self); -} - -CUSTOM_CVAR(Bool, timidity_portamento, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_portamento, *self); -} -/* -* reverb=0 no reverb 0 -* reverb=1 old reverb 1 -* reverb=1,n set reverb level to n (-1 to -127) -* reverb=2 "global" old reverb 2 -* reverb=2,n set reverb level to n (-1 to -127) - 128 -* reverb=3 new reverb 3 -* reverb=3,n set reverb level to n (-1 to -127) - 256 -* reverb=4 "global" new reverb 4 -* reverb=4,n set reverb level to n (-1 to -127) - 384 -*/ -EXTERN_CVAR(Int, timidity_reverb_level) -EXTERN_CVAR(Int, timidity_reverb) - -static void SetReverb() -{ - int value = 0; - int mode = timidity_reverb; - int level = timidity_reverb_level; - - if (mode == 0 || level == 0) value = mode; - else value = (mode - 1) * -128 - level; - ChangeVarSync(TimidityPlus::timidity_reverb, value); -} - -CUSTOM_CVAR(Int, timidity_reverb, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - if (self < 0 || self > 4) self = 0; - else SetReverb(); -} - -CUSTOM_CVAR(Int, timidity_reverb_level, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - if (self < 0 || self > 127) self = 0; - else SetReverb(); -} - -CUSTOM_CVAR(Int, timidity_chorus, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_chorus, *self); -} - -CUSTOM_CVAR(Bool, timidity_surround_chorus, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - if (currSong != nullptr && currSong->GetDeviceType() == MDEV_TIMIDITY) - { - MIDIDeviceChanged(-1, true); - } - ChangeVarSync(TimidityPlus::timidity_surround_chorus, *self); -} - -CUSTOM_CVAR(Bool, timidity_channel_pressure, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_channel_pressure, *self); -} - -CUSTOM_CVAR(Int, timidity_lpf_def, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_lpf_def, *self); -} - -CUSTOM_CVAR(Bool, timidity_temper_control, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_temper_control, *self); -} - -CUSTOM_CVAR(Bool, timidity_modulation_envelope, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_modulation_envelope, *self); - if (currSong != nullptr && currSong->GetDeviceType() == MDEV_TIMIDITY) - { - MIDIDeviceChanged(-1, true); - } -} - -CUSTOM_CVAR(Bool, timidity_overlap_voice_allow, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_overlap_voice_allow, *self); -} - -CUSTOM_CVAR(Bool, timidity_drum_effect, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_drum_effect, *self); -} - -CUSTOM_CVAR(Bool, timidity_pan_delay, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - ChangeVarSync(TimidityPlus::timidity_pan_delay, *self); -} - -CUSTOM_CVAR(Float, timidity_drum_power, 1.0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) /* coef. of drum amplitude */ -{ - if (self < 0) self = 0; - else if (self > MAX_AMPLIFICATION/100.f) self = MAX_AMPLIFICATION/100.f; - ChangeVarSync(TimidityPlus::timidity_drum_power, *self); -} -CUSTOM_CVAR(Int, timidity_key_adjust, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - if (self < -24) self = -24; - else if (self > 24) self = 24; - ChangeVarSync(TimidityPlus::timidity_key_adjust, *self); -} -// For testing mainly. -CUSTOM_CVAR(Float, timidity_tempo_adjust, 1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - if (self < 0.25) self = 0.25; - else if (self > 10) self = 10; - ChangeVarSync(TimidityPlus::timidity_tempo_adjust, *self); -} - -CUSTOM_CVAR(Float, min_sustain_time, 5000, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) -{ - if (self < 0) self = 0; - ChangeVarSync(TimidityPlus::min_sustain_time, *self); -} - - -namespace TimidityPlus -{ // These two variables need to remain global or things will get messy because they get accessed from non-class code. int32_t control_ratio = 22; diff --git a/src/sound/timiditypp/timidity.h b/src/sound/timiditypp/timidity.h index ce528d46e..59f8f529e 100644 --- a/src/sound/timiditypp/timidity.h +++ b/src/sound/timiditypp/timidity.h @@ -30,6 +30,7 @@ #include "controls.h" #include "mblock.h" +#include #include #ifdef _MSC_VER @@ -124,6 +125,7 @@ namespace TimidityPlus { +extern std::mutex CvarCritSec; extern bool timidity_modulation_wheel; extern bool timidity_portamento; extern int timidity_reverb; @@ -139,6 +141,8 @@ extern bool timidity_pan_delay; extern float timidity_drum_power; extern int timidity_key_adjust; extern float timidity_tempo_adjust; +extern float min_sustain_time; +extern int timidity_lpf_def; extern int32_t playback_rate; extern int32_t control_ratio; // derived from playback_rate