From 5966a68a64e193a924c62364a2ef93a19cc3dccd Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Sat, 28 Sep 2024 16:35:26 +0200 Subject: [PATCH] Better control access to the next element in SLL This is a part of a rework that should make it safer to use and properly managed. The next pointer is no longer public. Instead a getter was introduced for reading, and several specialized setters were introduced for writing. --- src/chip/channels/siopm_channel_base.cpp | 10 +-- src/chip/channels/siopm_channel_fm.cpp | 72 +++++++++---------- src/chip/channels/siopm_channel_ks.cpp | 2 +- src/chip/channels/siopm_channel_pcm.cpp | 30 ++++---- src/chip/siopm_stream.cpp | 12 ++-- src/chip/wave/siopm_wave_sampler_data.cpp | 4 +- src/effector/effects/si_effect_autopan.cpp | 12 ++-- src/effector/effects/si_effect_compressor.cpp | 2 +- .../filters/si_controllable_filter_base.cpp | 8 +-- src/sequencer/base/mml_executor.cpp | 6 +- src/sequencer/simml_envelope_table.cpp | 16 ++--- src/sequencer/simml_track.cpp | 18 ++--- src/sion_driver.cpp | 4 +- src/templates/singly_linked_list.h | 54 +++++++++----- src/utils/translator_util.cpp | 22 +++--- 15 files changed, 143 insertions(+), 129 deletions(-) diff --git a/src/chip/channels/siopm_channel_base.cpp b/src/chip/channels/siopm_channel_base.cpp index a13b0f1..50ff168 100644 --- a/src/chip/channels/siopm_channel_base.cpp +++ b/src/chip/channels/siopm_channel_base.cpp @@ -264,7 +264,7 @@ void SiOPMChannelBase::note_off() { SinglyLinkedList *SiOPMChannelBase::_rotate_pipe(SinglyLinkedList *p_pipe, int p_length) { SinglyLinkedList *pipe = p_pipe; for (int i = 0; i < p_length; i++) { - pipe = pipe->next; + pipe = pipe->next(); } return pipe; } @@ -302,8 +302,8 @@ void SiOPMChannelBase::_apply_ring_modulation(SinglyLinkedList *p_target, i for (int i = 0; i < p_length; i++) { target->value *= pipe->value * _ringmod_level; - pipe = pipe->next; - target = target->next; + pipe = pipe->next(); + target = target->next(); } _ring_pipe = pipe; @@ -327,7 +327,7 @@ void SiOPMChannelBase::_apply_sv_filter(SinglyLinkedList *p_target, int p_l r_variables[0] += r_variables[1] * cutoff_value; target->value = (int)r_variables[_filter_type]; - target = target->next; + target = target->next(); } length -= step; @@ -352,7 +352,7 @@ void SiOPMChannelBase::_apply_sv_filter(SinglyLinkedList *p_target, int p_l r_variables[0] += r_variables[1] * cutoff_value; target->value = (int)r_variables[_filter_type]; - target = target->next; + target = target->next(); } // Next setting. diff --git a/src/chip/channels/siopm_channel_fm.cpp b/src/chip/channels/siopm_channel_fm.cpp index 99b00d6..9f18d3d 100644 --- a/src/chip/channels/siopm_channel_fm.cpp +++ b/src/chip/channels/siopm_channel_fm.cpp @@ -818,9 +818,9 @@ void SiOPMChannelFM::_process_operator1_lfo_off(int p_length) { { out_pipe->value = output + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -860,9 +860,9 @@ void SiOPMChannelFM::_process_operator1_lfo_on(int p_length) { // Output and increment pointers. { out_pipe->value = output + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -927,9 +927,9 @@ void SiOPMChannelFM::_process_operator2(int p_length) { // Output and increment pointers. { out_pipe->value = _pipe0->value + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -1016,9 +1016,9 @@ void SiOPMChannelFM::_process_operator3(int p_length) { // Output and increment pointers. { out_pipe->value = _pipe0->value + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -1125,9 +1125,9 @@ void SiOPMChannelFM::_process_operator4(int p_length) { // Output and increment pointers. { out_pipe->value = _pipe0->value + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -1162,9 +1162,9 @@ void SiOPMChannelFM::_process_pcm_lfo_off(int p_length) { // Fast forward. for (; i < p_length; i++) { out_pipe->value = base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } break; } else { @@ -1184,9 +1184,9 @@ void SiOPMChannelFM::_process_pcm_lfo_off(int p_length) { // Output and increment pointers. { out_pipe->value = output + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -1224,9 +1224,9 @@ void SiOPMChannelFM::_process_pcm_lfo_on(int p_length) { // Fast forward. for (; i < p_length; i++) { out_pipe->value = base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } break; } else { @@ -1246,9 +1246,9 @@ void SiOPMChannelFM::_process_pcm_lfo_on(int p_length) { // Output and increment pointers. { out_pipe->value = output + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -1304,9 +1304,9 @@ void SiOPMChannelFM::_process_analog_like(int p_length) { // Output and increment pointers. { out_pipe->value = output0 + output1 + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -1360,9 +1360,9 @@ void SiOPMChannelFM::_process_ring(int p_length) { // Output and increment pointers. { out_pipe->value = output + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } @@ -1417,9 +1417,9 @@ void SiOPMChannelFM::_process_sync(int p_length) { // Output and increment pointers. { out_pipe->value = output + base_pipe->value; - in_pipe = in_pipe->next; - base_pipe = base_pipe->next; - out_pipe = out_pipe->next; + in_pipe = in_pipe->next(); + base_pipe = base_pipe->next(); + out_pipe = out_pipe->next(); } } diff --git a/src/chip/channels/siopm_channel_ks.cpp b/src/chip/channels/siopm_channel_ks.cpp index aaf8d27..297e87b 100644 --- a/src/chip/channels/siopm_channel_ks.cpp +++ b/src/chip/channels/siopm_channel_ks.cpp @@ -167,7 +167,7 @@ void SiOPMChannelKS::_apply_karplus_strong(SinglyLinkedList *p_target, int _ks_delay_buffer.write[buffer_index] = _output; target->value = (int)_output; - target = target->next; + target = target->next(); } } diff --git a/src/chip/channels/siopm_channel_pcm.cpp b/src/chip/channels/siopm_channel_pcm.cpp index f2f1b93..9f0ecef 100644 --- a/src/chip/channels/siopm_channel_pcm.cpp +++ b/src/chip/channels/siopm_channel_pcm.cpp @@ -304,8 +304,8 @@ void SiOPMChannelPCM::_process_operator_mono(int p_length, bool p_mix) { if (_operator->get_pcm_end_point() <= 0) { for (int i = 0; i < p_length; i++) { out_pipe->value = base_pipe->value; - out_pipe = out_pipe->next; - base_pipe = base_pipe->next; + out_pipe = out_pipe->next(); + base_pipe = base_pipe->next(); } _out_pipe = out_pipe; @@ -337,7 +337,7 @@ void SiOPMChannelPCM::_process_operator_mono(int p_length, bool p_mix) { // Fast forward. for (; i < p_length; i++) { out_pipe->value = 0; - out_pipe = out_pipe->next; + out_pipe = out_pipe->next(); } break; } else { @@ -355,8 +355,8 @@ void SiOPMChannelPCM::_process_operator_mono(int p_length, bool p_mix) { // Output and increment pointers. { out_pipe->value = output + base_pipe->value; - out_pipe = out_pipe->next; - base_pipe = base_pipe->next; + out_pipe = out_pipe->next(); + base_pipe = base_pipe->next(); } } @@ -373,12 +373,12 @@ void SiOPMChannelPCM::_process_operator_stereo(int p_length, bool p_mix) { if (_operator->get_pcm_end_point() <= 0) { for (int i = 0; i < p_length; i++) { out_pipe->value = base_pipe->value; - out_pipe = out_pipe->next; - base_pipe = base_pipe->next; + out_pipe = out_pipe->next(); + base_pipe = base_pipe->next(); out_pipe2->value = base_pipe2->value; - out_pipe2 = out_pipe2->next; - base_pipe2 = base_pipe2->next; + out_pipe2 = out_pipe2->next(); + base_pipe2 = base_pipe2->next(); } _out_pipe = out_pipe; @@ -412,9 +412,9 @@ void SiOPMChannelPCM::_process_operator_stereo(int p_length, bool p_mix) { // Fast forward. for (; i < p_length; i++) { out_pipe->value = 0; - out_pipe = out_pipe->next; + out_pipe = out_pipe->next(); out_pipe2->value = 0; - out_pipe2 = out_pipe2->next; + out_pipe2 = out_pipe2->next(); } break; } else { @@ -444,12 +444,12 @@ void SiOPMChannelPCM::_process_operator_stereo(int p_length, bool p_mix) { // Output and increment pointers. { out_pipe->value = output_left + base_pipe->value; - out_pipe = out_pipe->next; - base_pipe = base_pipe->next; + out_pipe = out_pipe->next(); + base_pipe = base_pipe->next(); out_pipe2->value = output_right + base_pipe2->value; - out_pipe2 = out_pipe2->next; - base_pipe2 = base_pipe2->next; + out_pipe2 = out_pipe2->next(); + base_pipe2 = base_pipe2->next(); } } diff --git a/src/chip/siopm_stream.cpp b/src/chip/siopm_stream.cpp index 61fd41b..70535ef 100644 --- a/src/chip/siopm_stream.cpp +++ b/src/chip/siopm_stream.cpp @@ -50,7 +50,7 @@ void SiOPMStream::write(SinglyLinkedList *p_data, int p_start, int p_length buffer.write[i] += current->value * volume_right; i++; - current = current->next; + current = current->next(); } } else if (channels == 1) { // mono SinglyLinkedList *current = p_data; @@ -60,7 +60,7 @@ void SiOPMStream::write(SinglyLinkedList *p_data, int p_start, int p_length buffer.write[i] += current->value * volume; i++; - current = current->next; + current = current->next(); } } } @@ -83,8 +83,8 @@ void SiOPMStream::write_stereo(SinglyLinkedList *p_left, SinglyLinkedListvalue * volume_right; i++; - current_left = current_left->next; - current_right = current_right->next; + current_left = current_left->next(); + current_right = current_right->next(); } } else if (channels == 1) { // mono volume *= 0.5; @@ -98,8 +98,8 @@ void SiOPMStream::write_stereo(SinglyLinkedList *p_left, SinglyLinkedListvalue + current_right->value) * volume; i++; - current_left = current_left->next; - current_right = current_right->next; + current_left = current_left->next(); + current_right = current_right->next(); } } } diff --git a/src/chip/wave/siopm_wave_sampler_data.cpp b/src/chip/wave/siopm_wave_sampler_data.cpp index 6ee345d..f694177 100644 --- a/src/chip/wave/siopm_wave_sampler_data.cpp +++ b/src/chip/wave/siopm_wave_sampler_data.cpp @@ -45,7 +45,7 @@ int SiOPMWaveSamplerData::_seek_head_silence() { for (; i < _wave_data.size(); i++) { ms -= ms_window->value; - ms_window = ms_window->next; + ms_window = ms_window->next(); ms_window->value = _wave_data[i] * _wave_data[i]; ms += ms_window->value; @@ -64,7 +64,7 @@ int SiOPMWaveSamplerData::_seek_head_silence() { // Here we would increment and then break. This is inconsistent and needs to be validated. // Keeping as in the original implementation for now. - ms_window = ms_window->next; + ms_window = ms_window->next(); ms_window->value = _wave_data[i] * _wave_data[i]; i++; ms_window->value += _wave_data[i] * _wave_data[i]; diff --git a/src/effector/effects/si_effect_autopan.cpp b/src/effector/effects/si_effect_autopan.cpp index bd8a797..29019cd 100644 --- a/src/effector/effects/si_effect_autopan.cpp +++ b/src/effector/effects/si_effect_autopan.cpp @@ -23,13 +23,13 @@ void SiEffectAutopan::set_params(double p_frequency, double p_stereo_width) { // Volume table. for (int i = -128; i < 128; i++) { _p_left->value = Math::sin(1.5707963267948965 + i * width); - _p_left = _p_left->next; + _p_left = _p_left->next(); } // Right phase shift. _p_right = _p_left; for (int i = 0; i < 128; i++) { - _p_right = _p_right->next; + _p_right = _p_right->next(); } } @@ -45,8 +45,8 @@ void SiEffectAutopan::_process_lfo_mono(Vector *r_buffer, int p_start_in r_buffer->write[i + 1] = value * _p_right->value; } - _p_left = _p_left->next; - _p_right = _p_right->next; + _p_left = _p_left->next(); + _p_right = _p_right->next(); } void SiEffectAutopan::_process_lfo_stereo(Vector *r_buffer, int p_start_index, int p_length) { @@ -58,8 +58,8 @@ void SiEffectAutopan::_process_lfo_stereo(Vector *r_buffer, int p_start_ r_buffer->write[i + 1] = value_left * _p_right->value + value_right * _p_left->value; } - _p_left = _p_left->next; - _p_right = _p_right->next; + _p_left = _p_left->next(); + _p_right = _p_right->next(); } int SiEffectAutopan::process(int p_channels, Vector *r_buffer, int p_start_index, int p_length) { diff --git a/src/effector/effects/si_effect_compressor.cpp b/src/effector/effects/si_effect_compressor.cpp index 0aead52..a0329d3 100644 --- a/src/effector/effects/si_effect_compressor.cpp +++ b/src/effector/effects/si_effect_compressor.cpp @@ -45,7 +45,7 @@ int SiEffectCompressor::process(int p_channels, Vector *r_buffer, int p_ double value_left = (*r_buffer)[i]; double value_right = (*r_buffer)[i + 1]; - _window_rms_list = _window_rms_list->next; + _window_rms_list = _window_rms_list->next(); _window_rms_total -= _window_rms_list->value; _window_rms_list->value = value_left * value_left + value_right * value_right; _window_rms_total += _window_rms_list->value; diff --git a/src/effector/filters/si_controllable_filter_base.cpp b/src/effector/filters/si_controllable_filter_base.cpp index 05a9d18..83869a6 100644 --- a/src/effector/filters/si_controllable_filter_base.cpp +++ b/src/effector/filters/si_controllable_filter_base.cpp @@ -83,12 +83,12 @@ int SiControllableFilterBase::process(int p_channels, Vector *r_buffer, _process_lfo(r_buffer, i, step); if (_cutoff_ptr) { - _cutoff_ptr = _cutoff_ptr->next; + _cutoff_ptr = _cutoff_ptr->next(); _cutoff_index = (_cutoff_ptr ? _cutoff_ptr->value : 128); } if (_resonance_ptr) { - _resonance_ptr = _resonance_ptr->next; + _resonance_ptr = _resonance_ptr->next(); _resonance = (_resonance_ptr ? _resonance_ptr->value * 0.007751937984496124 : 0); } @@ -132,8 +132,8 @@ SiControllableFilterBase::SiControllableFilterBase() : inc_ptr->value = i; dec_ptr->value = 128 - i; - inc_ptr = inc_ptr->next; - dec_ptr = dec_ptr->next; + inc_ptr = inc_ptr->next(); + dec_ptr = dec_ptr->next(); } } } diff --git a/src/sequencer/base/mml_executor.cpp b/src/sequencer/base/mml_executor.cpp index 8b73337..b0dcc37 100644 --- a/src/sequencer/base/mml_executor.cpp +++ b/src/sequencer/base/mml_executor.cpp @@ -126,7 +126,7 @@ MMLEvent *MMLExecutor::on_repeat_all(MMLEvent *p_event) { MMLEvent *MMLExecutor::on_repeat_begin(MMLEvent *p_event) { SinglyLinkedList *counter = SinglyLinkedList::alloc(p_event->get_data()); - counter->next = _repeat_counters; + counter->link(_repeat_counters); _repeat_counters = counter; return p_event->get_next(); @@ -134,7 +134,7 @@ MMLEvent *MMLExecutor::on_repeat_begin(MMLEvent *p_event) { MMLEvent *MMLExecutor::on_repeat_break(MMLEvent *p_event) { if (_repeat_counters->value == 1) { - SinglyLinkedList *counter = _repeat_counters->next; + SinglyLinkedList *counter = _repeat_counters->next(); SinglyLinkedList::free(_repeat_counters); _repeat_counters = counter; @@ -148,7 +148,7 @@ MMLEvent *MMLExecutor::on_repeat_break(MMLEvent *p_event) { MMLEvent *MMLExecutor::on_repeat_end(MMLEvent *p_event) { _repeat_counters->value -= 1; if (_repeat_counters->value == 0) { - SinglyLinkedList *counter = _repeat_counters->next; + SinglyLinkedList *counter = _repeat_counters->next(); SinglyLinkedList::free(_repeat_counters); _repeat_counters = counter; diff --git a/src/sequencer/simml_envelope_table.cpp b/src/sequencer/simml_envelope_table.cpp index 5d906b2..37b540b 100644 --- a/src/sequencer/simml_envelope_table.cpp +++ b/src/sequencer/simml_envelope_table.cpp @@ -23,7 +23,7 @@ void SiMMLEnvelopeTable::to_vector(int p_length, Vector *r_destination, int int value = 0; if (current) { value = current->value; - current = current->next; + current = current->next(); } CLAMP(value, p_min, p_max); @@ -40,10 +40,10 @@ void SiMMLEnvelopeTable::copy_from(const Ref &p_source) { SinglyLinkedList *curr_source = p_source->head; SinglyLinkedList *curr_destination = nullptr; - for (; curr_source != p_source->tail; curr_source = curr_source->next) { + for (; curr_source != p_source->tail; curr_source = curr_source->next()) { SinglyLinkedList *sll_value = SinglyLinkedList::alloc(curr_source->value); if (curr_destination) { - curr_destination->next = sll_value; + curr_destination->link(sll_value); curr_destination = sll_value; } else { head = sll_value; @@ -57,14 +57,14 @@ void SiMMLEnvelopeTable::_initialize(SinglyLinkedList *p_head, SinglyLinked tail = p_tail; // Looping last data. - if (tail->next == nullptr) { - tail->next = tail; + if (tail->next() == nullptr) { + tail->link(tail); } } void SiMMLEnvelopeTable::free() { if (head) { - tail->next = nullptr; + tail->unlink(); SinglyLinkedList::free_list(head); head = nullptr; @@ -90,9 +90,9 @@ SiMMLEnvelopeTable::SiMMLEnvelopeTable(Vector p_table, int p_loop_point) { } tail->value = p_table[i]; - tail = tail->next; + tail = tail->next(); } tail->value = p_table[i]; - tail->next = loop; + tail->link(loop); } diff --git a/src/sequencer/simml_track.cpp b/src/sequencer/simml_track.cpp index dc204bf..31434e8 100644 --- a/src/sequencer/simml_track.cpp +++ b/src/sequencer/simml_track.cpp @@ -217,7 +217,7 @@ SinglyLinkedList *SiMMLTrack::_make_modulation_table(int p_depth, int p_end if (p_delay != 0) { for (int i = 0; i < p_delay; i++) { element->value = p_depth; - element = element->next; + element = element->next(); } } @@ -228,7 +228,7 @@ SinglyLinkedList *SiMMLTrack::_make_modulation_table(int p_depth, int p_end for (int i = 0; i < p_term; i++) { element->value = depth >> FIXED_BITS; depth += step; - element = element->next; + element = element->next(); } } @@ -534,7 +534,7 @@ int SiMMLTrack::_buffer_envelope(int p_length, int p_step) { int expression = CLAMP(_envelope_exp_offset + _envelope_exp->value, 0, 128); _channel->offset_volume(expression, _velocity); - _envelope_exp = _envelope_exp->next; + _envelope_exp = _envelope_exp->next(); _counter_exp = _max_counter_exp; } @@ -545,14 +545,14 @@ int SiMMLTrack::_buffer_envelope(int p_length, int p_step) { if (_counter_pitch == 1) { _counter_pitch--; - _envelope_pitch = _envelope_pitch->next; + _envelope_pitch = _envelope_pitch->next(); _counter_pitch = _max_counter_pitch; } if (_counter_note == 1) { _counter_note--; - _envelope_note = _envelope_note->next; + _envelope_note = _envelope_note->next(); _counter_note = _max_counter_note; } @@ -572,7 +572,7 @@ int SiMMLTrack::_buffer_envelope(int p_length, int p_step) { _channel->offset_filter(_envelope_filter->value); - _envelope_filter = _envelope_filter->next; + _envelope_filter = _envelope_filter->next(); _counter_filter = _max_counter_filter; } @@ -582,18 +582,18 @@ int SiMMLTrack::_buffer_envelope(int p_length, int p_step) { _channel_settings->select_tone(this, _envelope_voice->value); - _envelope_voice = _envelope_voice->next; + _envelope_voice = _envelope_voice->next(); _counter_voice = _max_counter_voice; } // Update modulations. if (_envelope_mod_amp) { _channel->set_amplitude_modulation(_envelope_mod_amp->value); - _envelope_mod_amp =_envelope_mod_amp->next; + _envelope_mod_amp =_envelope_mod_amp->next(); } if (_envelope_mod_pitch) { _channel->set_pitch_modulation(_envelope_mod_pitch->value); - _envelope_mod_pitch = _envelope_mod_pitch->next; + _envelope_mod_pitch = _envelope_mod_pitch->next(); } remaining_length -= current_step; diff --git a/src/sion_driver.cpp b/src/sion_driver.cpp index ff9db82..1d27ac0 100644 --- a/src/sion_driver.cpp +++ b/src/sion_driver.cpp @@ -447,7 +447,7 @@ void SiONDriver::_streaming() { _performance_stats.total_processing_time -= _performance_stats.processing_time_data->value; _performance_stats.processing_time_data->value = Time::get_singleton()->get_ticks_msec() - start_time; _performance_stats.total_processing_time += _performance_stats.processing_time_data->value; - _performance_stats.processing_time_data = _performance_stats.processing_time_data->next; + _performance_stats.processing_time_data = _performance_stats.processing_time_data->next(); _performance_stats.average_processing_time = _performance_stats.total_processing_time * _performance_stats.total_processing_time_ratio; // Write samples. @@ -607,7 +607,7 @@ void SiONDriver::play(const Variant &p_data, bool p_reset_effector) { _performance_stats.total_processing_time = 0; for (int i = 0; i < TIME_AVERAGING_COUNT; i++) { _performance_stats.processing_time_data->value = 0; - _performance_stats.processing_time_data = _performance_stats.processing_time_data->next; + _performance_stats.processing_time_data = _performance_stats.processing_time_data->next(); } _is_paused = false; diff --git a/src/templates/singly_linked_list.h b/src/templates/singly_linked_list.h index 98ee57b..17433fe 100644 --- a/src/templates/singly_linked_list.h +++ b/src/templates/singly_linked_list.h @@ -26,20 +26,21 @@ class SinglyLinkedList { // In other words, this is going to leak on exit, unless memory is properly managed. static SinglyLinkedList *_free_list; + SinglyLinkedList *_next = nullptr; + public: // NOTE: Original code called it `i`. There is no special accessor, so we opt for a better public name. T value = 0; - SinglyLinkedList *next = nullptr; static SinglyLinkedList *alloc(int p_value = 0) { SinglyLinkedList *ret; if (_free_list) { ret = _free_list; - _free_list = _free_list->next; + _free_list = _free_list->_next; ret->value = p_value; - ret->next = nullptr; + ret->_next = nullptr; } else { ret = memnew(SinglyLinkedList(p_value)); } @@ -52,8 +53,7 @@ class SinglyLinkedList { SinglyLinkedList *elem = ret; for (int i = 1; i < p_size; i++) { - elem->next = alloc(p_default_value); - elem = elem->next; + elem = elem->append(p_default_value); } return ret; @@ -64,10 +64,9 @@ class SinglyLinkedList { SinglyLinkedList *elem = ret; for (int i = 1; i < p_size; i++) { - elem->next = alloc(p_default_value); - elem = elem->next; + elem = elem->append(p_default_value); } - elem->next = ret; + elem->_next = ret; return ret; } @@ -75,7 +74,7 @@ class SinglyLinkedList { static void free(SinglyLinkedList *p_first_element) { // Append the current allocated free list and then assume its position. // The argument MUST be the first element in any list, otherwise we leave bad pointers. - p_first_element->next = _free_list; + p_first_element->_next = _free_list; _free_list = p_first_element; } @@ -86,12 +85,12 @@ class SinglyLinkedList { // The argument MUST be the first element in any list, otherwise we leave bad pointers. SinglyLinkedList *elem = p_first_element; - while (elem->next) { - elem = elem->next; + while (elem->_next) { + elem = elem->_next; } // Append the current allocated free list and then assume its position. - elem->next = _free_list; + elem->_next = _free_list; _free_list = p_first_element; } @@ -102,12 +101,12 @@ class SinglyLinkedList { // The argument MUST be the first element in any list, otherwise we leave bad pointers. SinglyLinkedList *elem = p_first_element; - while (elem->next != p_first_element) { - elem = elem->next; + while (elem->_next != p_first_element) { + elem = elem->_next; } // Append the current allocated free list and then assume its position. - elem->next = _free_list; + elem->_next = _free_list; _free_list = p_first_element; } @@ -120,16 +119,35 @@ class SinglyLinkedList { List *> pager; pager.push_back(p_first_element); - SinglyLinkedList *elem = p_first_element->next; + SinglyLinkedList *elem = p_first_element->_next; while (elem != p_first_element) { pager.push_back(elem); - elem = elem->next; + elem = elem->_next; } return pager; } - SinglyLinkedList(int p_value = 0) { + // + + SinglyLinkedList *next() const { + return _next; + } + + SinglyLinkedList *append(T p_value) { + _next = alloc(p_value); + return _next; + } + + void link(SinglyLinkedList *p_element) { + _next = p_element; + } + + void unlink() { + _next = nullptr; + } + + SinglyLinkedList(T p_value) { value = p_value; } }; diff --git a/src/utils/translator_util.cpp b/src/utils/translator_util.cpp index 8071ff9..1f6e4df 100644 --- a/src/utils/translator_util.cpp +++ b/src/utils/translator_util.cpp @@ -1505,8 +1505,7 @@ TranslatorUtil::MMLTableNumbers TranslatorUtil::parse_table_numbers(String p_tab value = (int)(value * postfix_coef + postfix_offset + 0.5); for (int j = 0; j < postfix_size; j++) { - last->next = SinglyLinkedList::alloc(value); - last = last->next; + last = last->append(value); } index += postfix_size; @@ -1517,8 +1516,7 @@ TranslatorUtil::MMLTableNumbers TranslatorUtil::parse_table_numbers(String p_tab for (int i = 0; i < inter_size && index < p_max_index; i++) { for (int j = 0; j < postfix_size; j++) { - last->next = SinglyLinkedList::alloc(value); - last = last->next; + last = last->append(value); } index += postfix_size; } @@ -1529,8 +1527,7 @@ TranslatorUtil::MMLTableNumbers TranslatorUtil::parse_table_numbers(String p_tab value = (int)(value * postfix_coef + postfix_offset + 0.5); for (int j = 0; j < postfix_size; j++) { - last->next = SinglyLinkedList::alloc(value); - last = last->next; + last = last->append(value); } index++; } else if (!parsed_number->get_string(5).is_empty()) { @@ -1546,7 +1543,7 @@ TranslatorUtil::MMLTableNumbers TranslatorUtil::parse_table_numbers(String p_tab } else { // End loop. ERR_FAIL_COND_V_MSG(loop_stack.is_empty(), parsed_table, "Translator: Failed to parse provided MML table, loop data is invalid."); - loop_head = loop_stack.back()->get()->next; + loop_head = loop_stack.back()->get()->next(); loop_stack.pop_back(); ERR_FAIL_COND_V_MSG(!loop_head, parsed_table, "Translator: Failed to parse provided MML table, loop data is invalid."); @@ -1556,9 +1553,8 @@ TranslatorUtil::MMLTableNumbers TranslatorUtil::parse_table_numbers(String p_tab loop_count = parsed_number->get_string(6).to_int(); } for (int j = loop_count; j > 0; j--) { - for (SinglyLinkedList *l = loop_head; l != loop_tail->next; l = l->next) { - last->next = SinglyLinkedList::alloc(l->value); - last = last->next; + for (SinglyLinkedList *l = loop_head; l != loop_tail->next(); l = l->next()) { + last = last->append(l->value); } } } @@ -1568,10 +1564,10 @@ TranslatorUtil::MMLTableNumbers TranslatorUtil::parse_table_numbers(String p_tab } if (repeat) { - last->next = repeat->next; + last->link(repeat->next()); } - parsed_table.head = head->next; + parsed_table.head = head->next(); parsed_table.tail = last; parsed_table.length = index; parsed_table.repeated = (repeat != nullptr); @@ -1593,7 +1589,7 @@ void TranslatorUtil::parse_wav(String p_table_numbers, String p_postfix, Vector< double value = (value_base->value + 0.5) * 0.0078125; r_data->write[i] = CLAMP(value, -1, 1); - value_base = value_base->next; + value_base = value_base->next(); } for (; i < data_length; i++) {