Skip to content

Commit

Permalink
Change the base type of SiOPMOperatorParams to RefCounted
Browse files Browse the repository at this point in the history
Just how it was meant to be, always.
  • Loading branch information
YuriSizov committed Nov 12, 2024
1 parent b3154eb commit 5cabcdf
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 57 deletions.
2 changes: 1 addition & 1 deletion doc_classes/SiOPMOperatorParams.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="SiOPMOperatorParams" inherits="Object" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<class name="SiOPMOperatorParams" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/godotengine/godot/master/doc/class.xsd">
<brief_description>
Container for processing operator parameters within [SiOPMChannelParams].
</brief_description>
Expand Down
4 changes: 2 additions & 2 deletions src/chip/channels/siopm_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ void SiOPMOperator::set_pipes(SinglyLinkedList<int> *p_out_pipe, SinglyLinkedLis

//

void SiOPMOperator::set_operator_params(SiOPMOperatorParams *p_params) {
void SiOPMOperator::set_operator_params(const Ref<SiOPMOperatorParams> &p_params) {
// Some code here is duplicated from respective setters to avoid calling them
// and triggering side effects. Modify with care.

Expand Down Expand Up @@ -480,7 +480,7 @@ void SiOPMOperator::set_operator_params(SiOPMOperatorParams *p_params) {
_update_pitch();
}

void SiOPMOperator::get_operator_params(SiOPMOperatorParams *r_params) {
void SiOPMOperator::get_operator_params(const Ref<SiOPMOperatorParams> &r_params) {
r_params->set_pulse_generator_type(_pg_type);
r_params->set_pitch_table_type(_pt_type);

Expand Down
4 changes: 2 additions & 2 deletions src/chip/channels/siopm_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ class SiOPMOperator : public Object {

//

void set_operator_params(SiOPMOperatorParams *p_params);
void get_operator_params(SiOPMOperatorParams *r_params);
void set_operator_params(const Ref<SiOPMOperatorParams> &p_params);
void get_operator_params(const Ref<SiOPMOperatorParams> &r_params);
void set_wave_table(const Ref<SiOPMWaveTable> &p_wave_table);
void set_pcm_data(const Ref<SiOPMWavePCMData> &p_pcm_data);

Expand Down
8 changes: 2 additions & 6 deletions src/chip/siopm_channel_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

using namespace godot;

SiOPMOperatorParams *SiOPMChannelParams::get_operator_params(int p_index) {
Ref<SiOPMOperatorParams> SiOPMChannelParams::get_operator_params(int p_index) {
ERR_FAIL_INDEX_V(p_index, operator_count, nullptr);

return operator_params[p_index];
Expand Down Expand Up @@ -109,7 +109,7 @@ void SiOPMChannelParams::set_by_opm_register(int p_channel, int p_address, int p
} else { // Operator parameter
int ops[4] = { 3, 1, 2, 0 };
int op_index = ops[(p_address >> 3) & 3];
SiOPMOperatorParams *op_params = operator_params[op_index];
Ref<SiOPMOperatorParams> op_params = operator_params[op_index];

switch ((p_address - 0x40) >> 5) {
case 0: { // DT1:6-4 MUL:3-0
Expand Down Expand Up @@ -361,9 +361,5 @@ SiOPMChannelParams::~SiOPMChannelParams() {
memdelete(init_sequence);
init_sequence = nullptr;

for (int i = 0; i < MAX_OPERATORS; i++) {
memdelete(operator_params[i]);
operator_params[i] = nullptr;
}
operator_params.clear();
}
4 changes: 2 additions & 2 deletions src/chip/siopm_channel_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SiOPMChannelParams : public RefCounted {
MMLSequence *init_sequence = nullptr;

// This list is exactly MAX_OPERATORS at all times, use operator_count to read only valid values.
List<SiOPMOperatorParams *> operator_params;
List<Ref<SiOPMOperatorParams>> operator_params;
int operator_count = 0;
bool analog_like = false;

Expand Down Expand Up @@ -69,7 +69,7 @@ class SiOPMChannelParams : public RefCounted {
public:
MMLSequence *get_init_sequence() const { return init_sequence; }

SiOPMOperatorParams *get_operator_params(int p_index);
Ref<SiOPMOperatorParams> get_operator_params(int p_index);
int get_operator_count() const { return operator_count; }
void set_operator_count(int p_value);
bool is_analog_like() const { return analog_like; }
Expand Down
6 changes: 5 additions & 1 deletion src/chip/siopm_operator_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void SiOPMOperatorParams::initialize() {
envelope_reset_on_attack = false;
}

void SiOPMOperatorParams::copy_from(SiOPMOperatorParams *p_params) {
void SiOPMOperatorParams::copy_from(const Ref<SiOPMOperatorParams> &p_params) {
pulse_generator_type = p_params->pulse_generator_type;
pitch_table_type = p_params->pitch_table_type;

Expand Down Expand Up @@ -106,6 +106,10 @@ String SiOPMOperatorParams::_to_string() const {
return "SiOPMOperatorParams: " + params;
}

void SiOPMOperatorParams::_bind_methods() {
// TODO: Expose methods and properties for this class.
}

SiOPMOperatorParams::SiOPMOperatorParams() {
initialize();
}
12 changes: 5 additions & 7 deletions src/chip/siopm_operator_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
#ifndef SIOPM_OPERATOR_PARAMS_H
#define SIOPM_OPERATOR_PARAMS_H

#include <godot_cpp/classes/object.hpp>
#include <godot_cpp/classes/ref_counted.hpp>
#include <godot_cpp/variant/string.hpp>
#include "sion_enums.h"

using namespace godot;

// Operator parameters for SiONVoice.
// FIXME: Should likely be RefCounted instead, just like channel params.
class SiOPMOperatorParams : public Object {
GDCLASS(SiOPMOperatorParams, Object)
class SiOPMOperatorParams : public RefCounted {
GDCLASS(SiOPMOperatorParams, RefCounted)

friend class SiOPMChannelParams;
friend class TranslatorUtil;
Expand Down Expand Up @@ -64,8 +63,7 @@ class SiOPMOperatorParams : public Object {
bool envelope_reset_on_attack = false;

protected:
// TODO: Expose methods and properties for this class.
static void _bind_methods() {}
static void _bind_methods();

String _to_string() const;

Expand Down Expand Up @@ -123,7 +121,7 @@ class SiOPMOperatorParams : public Object {
void set_envelope_reset_on_attack(bool p_reset) { envelope_reset_on_attack = p_reset; }

void initialize();
void copy_from(SiOPMOperatorParams *p_params);
void copy_from(const Ref<SiOPMOperatorParams> &p_params);

SiOPMOperatorParams();
~SiOPMOperatorParams() {}
Expand Down
3 changes: 1 addition & 2 deletions src/chip/siopm_sound_chip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void SiOPMSoundChip::_bind_methods() {
}

SiOPMSoundChip::SiOPMSoundChip() {
init_operator_params = memnew(SiOPMOperatorParams);
init_operator_params.instantiate();

output_stream = memnew(SiOPMStream);

Expand All @@ -96,7 +96,6 @@ SiOPMSoundChip::SiOPMSoundChip() {
}

SiOPMSoundChip::~SiOPMSoundChip() {
memdelete(init_operator_params);
memdelete(output_stream);

memdelete(zero_buffer);
Expand Down
6 changes: 3 additions & 3 deletions src/chip/siopm_sound_chip.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
#include <godot_cpp/core/object.hpp>
#include <godot_cpp/templates/list.hpp>
#include <godot_cpp/templates/vector.hpp>
#include "chip/siopm_operator_params.h"
#include "templates/singly_linked_list.h"

using namespace godot;

class SiOPMOperatorParams;
class SiOPMStream;

class SiOPMSoundChip : public Object {
GDCLASS(SiOPMSoundChip, Object)

SiOPMOperatorParams *init_operator_params = nullptr;
Ref<SiOPMOperatorParams> init_operator_params;
SinglyLinkedList<int> *zero_buffer = nullptr;

SiOPMStream *output_stream = nullptr;
Expand All @@ -42,7 +42,7 @@ class SiOPMSoundChip : public Object {
static const int STREAM_SEND_SIZE = 8;
static const int PIPE_SIZE = 5;

SiOPMOperatorParams *get_init_operator_params() const { return init_operator_params; }
Ref<SiOPMOperatorParams> get_init_operator_params() const { return init_operator_params; }
SinglyLinkedList<int> *get_zero_buffer() const { return zero_buffer; }

SiOPMStream *get_output_stream() const { return output_stream; }
Expand Down
4 changes: 2 additions & 2 deletions src/sequencer/simml_ref_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void SiMMLRefTable::_dump_ym2413_register(const Ref<SiMMLVoice> &p_voice, uint32
channel_params->set_operator_count(2);
channel_params->set_algorithm(0);

SiOPMOperatorParams *op_params0 = channel_params->get_operator_params(0);
SiOPMOperatorParams *op_params1 = channel_params->get_operator_params(1);
Ref<SiOPMOperatorParams> op_params0 = channel_params->get_operator_params(0);
Ref<SiOPMOperatorParams> op_params1 = channel_params->get_operator_params(1);

op_params0->set_amplitude_modulation_shift(((p_u0 >> 31) & 1) << 1);
op_params1->set_amplitude_modulation_shift(((p_u0 >> 23) & 1) << 1);
Expand Down
2 changes: 1 addition & 1 deletion src/sequencer/simml_sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ void SiMMLSequencer::_register_event_listeners() {
}

void SiMMLSequencer::_reset_initial_operator_params() {
SiOPMOperatorParams *op_params = _sound_chip->get_init_operator_params();
Ref<SiOPMOperatorParams> op_params = _sound_chip->get_init_operator_params();

op_params->set_attack_rate(63);
op_params->set_decay_rate(0);
Expand Down
2 changes: 1 addition & 1 deletion src/sion_voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void SiONVoice::set_analog_like(int p_connection_type, int p_wave_shape1, int p_

void SiONVoice::set_envelope(int p_attack_rate, int p_decay_rate, int p_sustain_rate, int p_release_rate, int p_sustain_level, int p_total_level) {
for (int i = 0; i < channel_params->get_operator_count(); i++) {
SiOPMOperatorParams *op_params = channel_params->get_operator_params(i);
Ref<SiOPMOperatorParams> op_params = channel_params->get_operator_params(i);
op_params->set_attack_rate(p_attack_rate);
op_params->set_decay_rate(p_decay_rate);
op_params->set_sustain_rate(p_sustain_rate);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sion_voice_preset_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ void SiONVoicePresetUtil::_create_percussive_voice(const String &p_key, const St
voice->set_default_gate_time(0);
} else {
// gate time != 0
SiOPMOperatorParams *op_params = voice->get_channel_params()->get_operator_params(0);
Ref<SiOPMOperatorParams> op_params = voice->get_channel_params()->get_operator_params(0);
op_params->set_decay_rate(p_release_rate);
op_params->set_sustain_rate(p_release_rate);
op_params->set_release_rate(p_release_rate);
Expand Down
Loading

0 comments on commit 5cabcdf

Please sign in to comment.