Skip to content

Commit

Permalink
Better control access to the next element in SLL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
YuriSizov committed Sep 28, 2024
1 parent e182385 commit 5966a68
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 129 deletions.
10 changes: 5 additions & 5 deletions src/chip/channels/siopm_channel_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void SiOPMChannelBase::note_off() {
SinglyLinkedList<int> *SiOPMChannelBase::_rotate_pipe(SinglyLinkedList<int> *p_pipe, int p_length) {
SinglyLinkedList<int> *pipe = p_pipe;
for (int i = 0; i < p_length; i++) {
pipe = pipe->next;
pipe = pipe->next();
}
return pipe;
}
Expand Down Expand Up @@ -302,8 +302,8 @@ void SiOPMChannelBase::_apply_ring_modulation(SinglyLinkedList<int> *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;
Expand All @@ -327,7 +327,7 @@ void SiOPMChannelBase::_apply_sv_filter(SinglyLinkedList<int> *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;

Expand All @@ -352,7 +352,7 @@ void SiOPMChannelBase::_apply_sv_filter(SinglyLinkedList<int> *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.
Expand Down
72 changes: 36 additions & 36 deletions src/chip/channels/siopm_channel_fm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/chip/channels/siopm_channel_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void SiOPMChannelKS::_apply_karplus_strong(SinglyLinkedList<int> *p_target, int

_ks_delay_buffer.write[buffer_index] = _output;
target->value = (int)_output;
target = target->next;
target = target->next();
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/chip/channels/siopm_channel_pcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/chip/siopm_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void SiOPMStream::write(SinglyLinkedList<int> *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<int> *current = p_data;
Expand All @@ -60,7 +60,7 @@ void SiOPMStream::write(SinglyLinkedList<int> *p_data, int p_start, int p_length
buffer.write[i] += current->value * volume;
i++;

current = current->next;
current = current->next();
}
}
}
Expand All @@ -83,8 +83,8 @@ void SiOPMStream::write_stereo(SinglyLinkedList<int> *p_left, SinglyLinkedList<i
buffer.write[i] += current_right->value * 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;
Expand All @@ -98,8 +98,8 @@ void SiOPMStream::write_stereo(SinglyLinkedList<int> *p_left, SinglyLinkedList<i
buffer.write[i] += (current_left->value + 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();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/chip/wave/siopm_wave_sampler_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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];
Expand Down
12 changes: 6 additions & 6 deletions src/effector/effects/si_effect_autopan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -45,8 +45,8 @@ void SiEffectAutopan::_process_lfo_mono(Vector<double> *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<double> *r_buffer, int p_start_index, int p_length) {
Expand All @@ -58,8 +58,8 @@ void SiEffectAutopan::_process_lfo_stereo(Vector<double> *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<double> *r_buffer, int p_start_index, int p_length) {
Expand Down
2 changes: 1 addition & 1 deletion src/effector/effects/si_effect_compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int SiEffectCompressor::process(int p_channels, Vector<double> *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;
Expand Down
Loading

0 comments on commit 5966a68

Please sign in to comment.