Skip to content

Commit

Permalink
Add a method to forcefully clear the driver data
Browse files Browse the repository at this point in the history
This is needed because compilation and rendering
can leave a data object after themselves, but
calling stop() does nothing if we are not currently
streaming.

You can work around this by calling play() and
stop() immediately after each other, but it's better
to introduce an explicit method.
  • Loading branch information
YuriSizov committed Oct 5, 2024
1 parent 182bdf5 commit ae87baa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
12 changes: 12 additions & 0 deletions doc_classes/SiONDriver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<tutorials>
</tutorials>
<methods>
<method name="clear_data">
<return type="void" />
<description>
Clears current data set previously by [method play], [method compile], or [method render]. Note that calling [method stop] during streaming does this already.
</description>
</method>
<method name="compile">
<return type="SiONData" />
<param index="0" name="mml" type="String" />
Expand Down Expand Up @@ -80,6 +86,12 @@
Returns the time it took to perform the last compile task (including calls to [method play]).
</description>
</method>
<method name="get_data" qualifiers="const">
<return type="SiONData" />
<description>
Returns current data set previously by [method play], [method compile], or [method render].
</description>
</method>
<method name="get_effector" qualifiers="const">
<return type="SiEffector" />
<description>
Expand Down
11 changes: 6 additions & 5 deletions src/sion_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,6 @@ void SiONDriver::play(const Variant &p_data, bool p_reset_effector) {
_audio_playback = _audio_player->get_stream_playback();

_set_processing_immediate();
_update_node_processing();
}

void SiONDriver::stop() {
Expand All @@ -636,11 +635,10 @@ void SiONDriver::stop() {
_preserve_stop = false;
_is_paused = false;
_is_streaming = false;
_data = Ref<SiONData>(); // Original SiON doesn't do that, but that seems like an oversight.

clear_data(); // Original SiON doesn't do that, but that seems like an oversight.
clear_background_sound();
_clear_processing();
_update_node_processing();

_fader->stop();
_fader_volume = 1;
Expand Down Expand Up @@ -890,8 +888,8 @@ void SiONDriver::_prepare_process(const Variant &p_data, bool p_reset_effector)

// Order of operations below is critical.

sound_chip->initialize(_channel_num, _bitrate, _buffer_length); // Initialize DSP.
sound_chip->reset(); // Reset all channels.
sound_chip->initialize(_channel_num, _bitrate, _buffer_length); // Initialize DSP.
sound_chip->reset(); // Reset all channels.

if (p_reset_effector) { // Initialize or reset effectors.
effector->initialize();
Expand Down Expand Up @@ -1328,6 +1326,9 @@ void SiONDriver::_bind_methods() {
ClassDB::bind_method(D_METHOD("sequence_on", "data", "voice", "length", "delay", "quantize", "track_id", "disposable"), &SiONDriver::sequence_on, DEFVAL((Object *)nullptr), DEFVAL(0), DEFVAL(0), DEFVAL(1), DEFVAL(0), DEFVAL(true));
ClassDB::bind_method(D_METHOD("sequence_off", "track_id", "delay", "quantize", "stop_with_reset"), &SiONDriver::sequence_off, DEFVAL(0), DEFVAL(1), DEFVAL(false));

ClassDB::bind_method(D_METHOD("get_data"), &SiONDriver::get_data);
ClassDB::bind_method(D_METHOD("clear_data"), &SiONDriver::clear_data);

// Execution queue.

ClassDB::bind_method(D_METHOD("get_queue_job_progress"), &SiONDriver::get_queue_job_progress);
Expand Down
1 change: 1 addition & 0 deletions src/sion_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class SiONDriver : public Node {
// Compiling only.
String get_mml_string() const { return _mml_string; }
Ref<SiONData> get_data() const { return _data; }
void clear_data() { _data = Ref<SiONData>(); }

Ref<SiOPMWaveTable> set_wave_table(int p_index, Vector<double> p_table);
Ref<SiOPMWavePCMData> set_pcm_wave(int p_index, const Variant &p_data, double p_sampling_note = 69, int p_key_range_from = 0, int p_key_range_to = 127, int p_src_channel_num = 2, int p_channel_num = 0);
Expand Down

0 comments on commit ae87baa

Please sign in to comment.