Skip to content

Commit f0ee52c

Browse files
committed
create AudioStreamEffect
1 parent b89c47b commit f0ee52c

9 files changed

+842
-0
lines changed

doc/classes/AudioStreamEffect.xml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="AudioStreamEffect" inherits="AudioStream" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
Applies effects to an audio stream.
5+
</brief_description>
6+
<description>
7+
[AudioStreamEffect] applies [AudioEffect]s to a child [AudioStream]. Effects are applied in the order in which they are listed.
8+
[b]Note:[/b] Different effects can require vastly different amounts of processing power. Be mindful of how often intensive effects such as reverb and delay are used with your set-up.
9+
</description>
10+
<tutorials>
11+
</tutorials>
12+
<methods>
13+
<method name="add_effect">
14+
<return type="void" />
15+
<param index="0" name="index" type="int" />
16+
<param index="1" name="effect" type="AudioEffect" />
17+
<param index="2" name="bypass" type="bool" default="false" />
18+
<description>
19+
Inserts an effect at the specified index. If [param index] is less than 0, the effect will be added to the end.
20+
</description>
21+
</method>
22+
<method name="get_effect" qualifiers="const">
23+
<return type="AudioEffect" />
24+
<param index="0" name="index" type="int" />
25+
<description>
26+
Returns the audio effect at the specified index.
27+
</description>
28+
</method>
29+
<method name="get_effect_bypass_enabled" qualifiers="const">
30+
<return type="bool" />
31+
<param index="0" name="index" type="int" />
32+
<description>
33+
Returns if the audio effect at the specified index is currently bypassed.
34+
</description>
35+
</method>
36+
<method name="move_effect">
37+
<return type="void" />
38+
<param index="0" name="index_from" type="int" />
39+
<param index="1" name="index_to" type="int" />
40+
<description>
41+
Moves the effect at [param index_from] to [param index_to]. If [param index_to] is below 0, the effect will be moved to the end of the list.
42+
[b]Note:[/b] Due to the way elements are moved, if [param index_to] is greater than [param index_from], the final index of the moved item will be one less than [param index_to].
43+
</description>
44+
</method>
45+
<method name="remove_effect">
46+
<return type="void" />
47+
<param index="0" name="index" type="int" />
48+
<description>
49+
Removes the effect at the specified index. Shifts all elements past the specified index back.
50+
</description>
51+
</method>
52+
<method name="set_effect">
53+
<return type="void" />
54+
<param index="0" name="index" type="int" />
55+
<param index="1" name="effect" type="AudioEffect" />
56+
<description>
57+
Sets the audio effect at the specified index.
58+
</description>
59+
</method>
60+
<method name="set_effect_bypass_enabled">
61+
<return type="void" />
62+
<param index="0" name="index" type="int" />
63+
<param index="1" name="enabled" type="bool" />
64+
<description>
65+
Enables or disables bypass on the effect at the specified index.
66+
Bypassing an effect disables the effect's influence on the sound, essentially turning it off.
67+
</description>
68+
</method>
69+
</methods>
70+
<members>
71+
<member name="effect_count" type="int" setter="set_effect_count" getter="get_effect_count" default="0">
72+
The total amount of effect slots in the [AudioStreamEffect].
73+
</member>
74+
<member name="process_bypassed_effects" type="bool" setter="set_process_bypassed" getter="get_process_bypassed" default="false">
75+
If [code]true[/code], effects that are bypassed will still be processed.
76+
Useful for effects like reverb, where pausing processing will "freeze" the state of the effect, and un-bypassing will resume the effect from where it left off, potentially causing a sudden burst of sound.
77+
Setting this to [code]true[/code] will negate any performance improvements gained from enabling bypass on effects, as effects will still be processed.
78+
</member>
79+
<member name="stream" type="AudioStream" setter="set_stream" getter="get_stream">
80+
The [AudioStream] resource to play and apply effects to.
81+
</member>
82+
<member name="tail_fade_curve" type="float" setter="set_tail_fade_curve" getter="get_tail_fade_curve" default="1.0">
83+
The volume curve to apply to the tail as it fades out. Set to a low value such as 0.0001 to mimic a hard cut when the tail ends.
84+
</member>
85+
<member name="tail_time" type="float" setter="set_tail_time" getter="get_tail_time" default="0.0">
86+
The amount of time, in seconds, to wait after the child stream stops before stopping this stream. Useful for letting effects like reverb ring out.
87+
</member>
88+
</members>
89+
</class>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<class name="AudioStreamPlaybackEffect" inherits="AudioStreamPlayback" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3+
<brief_description>
4+
Playback instance of [AudioStreamEffect].
5+
</brief_description>
6+
<description>
7+
</description>
8+
<tutorials>
9+
</tutorials>
10+
</class>

editor/icons/AudioStreamEffect.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**************************************************************************/
2+
/* audio_stream_effect_editor_plugin.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "audio_stream_effect_editor_plugin.h"
32+
33+
#include "editor/editor_node.h"
34+
#include "editor/editor_undo_redo_manager.h"
35+
#include "scene/resources/audio_stream_effect.h"
36+
37+
void AudioStreamEffectEditorPlugin::edit(Object *p_object) {
38+
}
39+
40+
bool AudioStreamEffectEditorPlugin::handles(Object *p_object) const {
41+
return false;
42+
}
43+
44+
void AudioStreamEffectEditorPlugin::make_visible(bool p_visible) {
45+
}
46+
47+
void AudioStreamEffectEditorPlugin::_move_effect_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos) {
48+
EditorUndoRedoManager *undo_redo_man = Object::cast_to<EditorUndoRedoManager>(p_undo_redo);
49+
ERR_FAIL_NULL(undo_redo_man);
50+
51+
AudioStreamEffect *stream = Object::cast_to<AudioStreamEffect>(p_edited);
52+
if (!stream) {
53+
return;
54+
}
55+
56+
// Compute the array indices to save.
57+
int begin = 0;
58+
int end;
59+
if (p_array_prefix == "effect_") {
60+
end = stream->get_effect_count();
61+
} else {
62+
ERR_FAIL_MSG("Invalid array prefix for AudioStreamEffect.");
63+
}
64+
if (p_from_index < 0) {
65+
// Adding new.
66+
if (p_to_pos >= 0) {
67+
begin = p_to_pos;
68+
} else {
69+
end = 0; // Nothing to save when adding at the end.
70+
}
71+
} else if (p_to_pos < 0) {
72+
// Removing.
73+
begin = p_from_index;
74+
} else {
75+
// Moving.
76+
begin = MIN(p_from_index, p_to_pos);
77+
end = MIN(MAX(p_from_index, p_to_pos) + 1, end);
78+
}
79+
80+
#define ADD_UNDO(obj, property) undo_redo_man->add_undo_property(obj, property, obj->get(property));
81+
// Save layers' properties.
82+
if (p_from_index < 0) {
83+
undo_redo_man->add_undo_method(stream, "remove_effect", p_to_pos < 0 ? stream->get_effect_count() : p_to_pos);
84+
} else if (p_to_pos < 0) {
85+
undo_redo_man->add_undo_method(stream, "add_effect", p_from_index, Ref<AudioEffect>());
86+
}
87+
88+
List<PropertyInfo> properties;
89+
stream->get_property_list(&properties);
90+
for (PropertyInfo pi : properties) {
91+
if (pi.name.begins_with(p_array_prefix)) {
92+
String str = pi.name.trim_prefix(p_array_prefix);
93+
int to_char_index = 0;
94+
while (to_char_index < str.length()) {
95+
if (str[to_char_index] < '0' || str[to_char_index] > '9') {
96+
break;
97+
}
98+
to_char_index++;
99+
}
100+
if (to_char_index > 0) {
101+
int array_index = str.left(to_char_index).to_int();
102+
if (array_index >= begin && array_index < end) {
103+
ADD_UNDO(stream, pi.name);
104+
}
105+
}
106+
}
107+
}
108+
#undef ADD_UNDO
109+
110+
if (p_from_index < 0) {
111+
undo_redo_man->add_do_method(stream, "add_effect", p_to_pos, Ref<AudioEffect>(), false);
112+
} else if (p_to_pos < 0) {
113+
undo_redo_man->add_do_method(stream, "remove_effect", p_from_index);
114+
} else {
115+
undo_redo_man->add_do_method(stream, "move_effect", p_from_index, p_to_pos);
116+
}
117+
}
118+
119+
AudioStreamEffectEditorPlugin::AudioStreamEffectEditorPlugin() {
120+
EditorNode::get_editor_data().add_move_array_element_function(SNAME("AudioStreamEffect"), callable_mp(this, &AudioStreamEffectEditorPlugin::_move_effect_array_element));
121+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**************************************************************************/
2+
/* audio_stream_effect_editor_plugin.h */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#pragma once
32+
33+
#include "editor/plugins/editor_plugin.h"
34+
35+
class AudioStreamEffectEditorPlugin : public EditorPlugin {
36+
GDCLASS(AudioStreamEffectEditorPlugin, EditorPlugin);
37+
38+
private:
39+
void _move_effect_array_element(Object *p_undo_redo, Object *p_edited, const String &p_array_prefix, int p_from_index, int p_to_pos);
40+
41+
public:
42+
virtual String get_plugin_name() const override { return "AudioStreamEffect"; }
43+
bool has_main_screen() const override { return false; }
44+
virtual void edit(Object *p_object) override;
45+
virtual bool handles(Object *p_object) const override;
46+
virtual void make_visible(bool p_visible) override;
47+
48+
AudioStreamEffectEditorPlugin();
49+
};

editor/register_editor_types.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
#include "editor/import/resource_importer_wav.h"
7373
#include "editor/plugins/animation_tree_editor_plugin.h"
7474
#include "editor/plugins/audio_stream_editor_plugin.h"
75+
#include "editor/plugins/audio_stream_effect_editor_plugin.h"
7576
#include "editor/plugins/audio_stream_randomizer_editor_plugin.h"
7677
#include "editor/plugins/bit_map_editor_plugin.h"
7778
#include "editor/plugins/bone_map_editor_plugin.h"
@@ -212,6 +213,7 @@ void register_editor_types() {
212213
EditorPlugins::add_by_type<AnimationTreeEditorPlugin>();
213214
EditorPlugins::add_by_type<AudioStreamEditorPlugin>();
214215
EditorPlugins::add_by_type<AudioStreamRandomizerEditorPlugin>();
216+
EditorPlugins::add_by_type<AudioStreamEffectEditorPlugin>();
215217
EditorPlugins::add_by_type<BitMapEditorPlugin>();
216218
EditorPlugins::add_by_type<BoneMapEditorPlugin>();
217219
EditorPlugins::add_by_type<Camera3DEditorPlugin>();

scene/register_scene_types.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
#include "scene/main/window.h"
109109
#include "scene/resources/animation_library.h"
110110
#include "scene/resources/atlas_texture.h"
111+
#include "scene/resources/audio_stream_effect.h"
111112
#include "scene/resources/audio_stream_polyphonic.h"
112113
#include "scene/resources/audio_stream_wav.h"
113114
#include "scene/resources/bit_map.h"
@@ -1074,6 +1075,8 @@ void register_scene_types() {
10741075

10751076
OS::get_singleton()->yield(); // may take time to init
10761077

1078+
GDREGISTER_CLASS(AudioStreamEffect);
1079+
GDREGISTER_CLASS(AudioStreamPlaybackEffect);
10771080
GDREGISTER_CLASS(AudioStreamPlayer);
10781081
GDREGISTER_CLASS(AudioStreamWAV);
10791082
GDREGISTER_CLASS(AudioStreamPolyphonic);

0 commit comments

Comments
 (0)