Skip to content

Commit

Permalink
Implement remaining MML translator methods in TranslatorUtil
Browse files Browse the repository at this point in the history
Also clean up some reg ex related FIXMEs
Flags "g" and "m" are safe to use, only "s"
still requires further investigation.
  • Loading branch information
YuriSizov committed May 24, 2024
1 parent 9e0a442 commit 1133adf
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 11 deletions.
16 changes: 16 additions & 0 deletions src/chip/siopm_channel_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ SiOPMOperatorParams *SiOPMChannelParams::get_operator_params(int p_index) {
return operator_params[p_index];
}

bool SiOPMChannelParams::has_amplitude_modulation() const {
return amplitude_modulation_depth > 0;
}

bool SiOPMChannelParams::has_pitch_modulation() const {
return pitch_modulation_depth > 0;
}

double SiOPMChannelParams::get_master_volume(int p_index) const {
ERR_FAIL_INDEX_V(p_index, master_volumes.size(), 0);

Expand All @@ -34,6 +42,14 @@ void SiOPMChannelParams::set_master_volume(int p_index, double p_value) {
master_volumes.write[p_index] = p_value;
}

bool SiOPMChannelParams::has_filter() const {
return filter_cutoff < 128 || filter_resonance > 0;
}

bool SiOPMChannelParams::has_filter_advanced() const {
return filter_attack_rate > 0 || filter_release_rate > 0;
}

int SiOPMChannelParams::get_lfo_frame() const {
return (int)(SiOPMRefTable::LFO_TIMER_INITIAL * 0.346938775510204 / lfo_frequency_step);
}
Expand Down
5 changes: 5 additions & 0 deletions src/chip/siopm_channel_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ class SiOPMChannelParams : public Object {

int get_amplitude_modulation_depth() const { return amplitude_modulation_depth; }
void set_amplitude_modulation_depth(int p_value) { amplitude_modulation_depth = p_value; }
bool has_amplitude_modulation() const;
int get_pitch_modulation_depth() const { return pitch_modulation_depth; }
void set_pitch_modulation_depth(int p_value) { pitch_modulation_depth = p_value; }
bool has_pitch_modulation() const;

double get_master_volume(int p_index) const;
void set_master_volume(int p_index, double p_value);
Expand Down Expand Up @@ -112,6 +114,9 @@ class SiOPMChannelParams : public Object {
int get_filter_release_offset() const { return filter_release_offset; }
void set_filter_release_offset(int p_value) { filter_release_offset = p_value; }

bool has_filter() const;
bool has_filter_advanced() const;

int get_lfo_frame() const;
void set_lfo_frame(int p_fps);

Expand Down
1 change: 0 additions & 1 deletion src/effector/si_effect_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ void SiEffectStream::parse_mml(int p_slot, String p_mml, String p_postfix) {

String command;

// FIXME: Godot's RegEx implementation doesn't support passing global flags. These patterns originally used "g". Behavioral implications require investigation.
Ref<RegEx> re_mml = RegEx::create_from_string("([a-zA-Z_]+|,)\\s*([.\\-\\d]+)?");
Ref<RegEx> re_postfix = RegEx::create_from_string("(p|@p|@v|,)\\s*([.\\-\\d]+)?");

Expand Down
8 changes: 8 additions & 0 deletions src/sequencer/simml_voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ void SiMMLVoice::set_module_type(SiONModuleType p_module_type, int p_channel_num
}
}

bool SiMMLVoice::has_amplitude_modulation() const {
return amplitude_modulation_depth > 0 || amplitude_modulation_depth_end > 0;
}

bool SiMMLVoice::has_pitch_modulation() const {
return pitch_modulation_depth > 0 || pitch_modulation_depth_end > 0;
}

void SiMMLVoice::update_track_voice(SiMMLTrack *p_track) {
switch (module_type) {
case MT_FM: { // Registered FM voice (%6)
Expand Down
5 changes: 5 additions & 0 deletions src/sequencer/simml_voice.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum SiONModuleType : unsigned int;
class SiMMLVoice : public RefCounted {
GDCLASS(SiMMLVoice, RefCounted)

friend class TranslatorUtil;

// Set to true to update track params alongside channel params.
bool update_track_parameters = false;
// Set to true to update volume, velocity, expression, and panning when the voice is set.
Expand Down Expand Up @@ -128,6 +130,9 @@ class SiMMLVoice : public RefCounted {
int get_expression_mode() const { return expression_mode; }
void set_expression_mode(int p_value) { expression_mode = p_value; }

bool has_amplitude_modulation() const;
bool has_pitch_modulation() const;

void update_track_voice(SiMMLTrack *p_track);

virtual void reset();
Expand Down
Loading

0 comments on commit 1133adf

Please sign in to comment.