Fixed issue of playing directly after finished and simplified the interface

This commit is contained in:
Tim Krief 2021-05-11 16:19:47 +02:00
parent 430a8d654e
commit 5c06bde646
18 changed files with 419 additions and 108 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=13 format=2]
[ext_resource path="res://sound_effects/walking_character8.wav" type="AudioStream" id=1]
[ext_resource path="res://sound_effects/walking_character7.wav" type="AudioStream" id=2]
@ -8,26 +8,28 @@
[ext_resource path="res://sound_effects/walking_character5.wav" type="AudioStream" id=6]
[ext_resource path="res://sound_effects/walking_character1.wav" type="AudioStream" id=7]
[ext_resource path="res://sound_effects/walking_character6.wav" type="AudioStream" id=8]
[ext_resource path="res://icon.png" type="Texture" id=9]
[ext_resource path="res://addons/randomAudioStreamPlayer/random_audio_stream_player_3D.gd" type="Script" id=12]
[sub_resource type="GDScript" id=1]
script/source = "extends Spatial
onready var soundPlayer3D = get_node(\"Orbit/Sphere/RandomAudioStreamPlayer3D\")
onready var RandomAudioStreamPlayer3D = $Orbit/Sprite3D/RandomAudioStreamPlayer3D
func _process(delta):
if not soundPlayer3D.is_playing():
soundPlayer3D.play()
func _ready():
$Timer.start(.3)
func _on_Timer_timeout():
RandomAudioStreamPlayer3D.play()
$Timer.start(.3)
"
[sub_resource type="SphereMesh" id=2]
[sub_resource type="Animation" id=3]
resource_name = "Orbit"
length = 5.0
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath(".:rotation_degrees")
tracks/0/path = NodePath("Orbit:rotation_degrees")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
@ -39,38 +41,31 @@ tracks/0/keys = {
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 360, 0 ) ]
}
[sub_resource type="ProceduralSky" id=4]
[sub_resource type="Environment" id=5]
background_mode = 2
background_sky = SubResource( 4 )
[node name="Spatial" type="Spatial"]
script = SubResource( 1 )
[node name="Orbit" type="Spatial" parent="."]
[node name="Sphere" type="MeshInstance" parent="Orbit"]
[node name="Sprite3D" type="Sprite3D" parent="Orbit"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 0, 0 )
mesh = SubResource( 2 )
material/0 = null
billboard = 1
texture = ExtResource( 9 )
[node name="RandomAudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="Orbit/Sphere"]
[node name="RandomAudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="Orbit/Sprite3D"]
script = ExtResource( 12 )
streams = [ ExtResource( 7 ), ExtResource( 3 ), ExtResource( 5 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 8 ), ExtResource( 2 ), ExtResource( 1 ) ]
samples = [ ExtResource( 7 ), ExtResource( 3 ), ExtResource( 5 ), ExtResource( 4 ), ExtResource( 6 ), ExtResource( 8 ), ExtResource( 2 ), ExtResource( 1 ) ]
random_strategy = 2
randomize_volume = true
volume_max = 24.0
randomize_pitch = true
pitch_min = 0.5
pitch_max = 1.5
random_volume_range = 5.0
random_pitch_range = 1.0
[node name="AnimationPlayer" type="AnimationPlayer" parent="Orbit"]
[node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.573576, 0.819152, 0, -0.819152, 0.573576, 0, 5, 10 )
fov = 90.0
[node name="Timer" type="Timer" parent="."]
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "Orbit"
anims/Orbit = SubResource( 3 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 5 )
[node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 0.965926, 0.258819, 0, -0.258819, 0.965926, 0, 5, 15 )
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_random_audio_stream_player.svg-5a601129e3a46fa1c72ca5566169f2e6.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/randomAudioStreamPlayer/icon_random_audio_stream_player.svg"
dest_files=[ "res://.import/icon_random_audio_stream_player.svg-5a601129e3a46fa1c72ca5566169f2e6.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_random_audio_stream_player_2_d.svg-4fff6f62acbe173a4573e61fc078f248.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/randomAudioStreamPlayer/icon_random_audio_stream_player_2_d.svg"
dest_files=[ "res://.import/icon_random_audio_stream_player_2_d.svg-4fff6f62acbe173a4573e61fc078f248.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon_random_audio_stream_player_3_d.svg-80090c5d537eba44e71295f1b8e8cd23.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/randomAudioStreamPlayer/icon_random_audio_stream_player_3_d.svg"
dest_files=[ "res://.import/icon_random_audio_stream_player_3_d.svg-80090c5d537eba44e71295f1b8e8cd23.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -1,30 +1,25 @@
tool
extends AudioStreamPlayer
export(Array, AudioStream) var streams
export(Array, AudioStream) var samples
export(int, "Pure", "No consecutive repetition", "Use all samples before repeat") var random_strategy = 0
export(bool) var randomize_volume = false
export(float, -80, 24) var volume_min = 0
export(float, -80, 24) var volume_max = 0
export(bool) var randomize_pitch = false
export(float, 0.01, 32) var pitch_min = 1
export(float, 0.01, 32) var pitch_max = 1
onready var base_volume = volume_db
export(float, 0, 80) var random_volume_range = 0
onready var base_pitch = pitch_scale
export(float, 0, 4) var random_pitch_range = 0
var playing_sample_nb : int = -1
var last_played_sample_nb : int = -1 # only used if random_strategy = 1
var to_play = [] # only used if random_strategy = 2
func play(from_position=0.0):
playing = true
var number_of_samples = len(streams)
# You can use playing_sample_nb to choose what sample to use
func play(from_position=0.0, playing_sample_nb=-1):
var number_of_samples = len(samples)
if number_of_samples > 0:
if playing_sample_nb < 0:
if number_of_samples == 1:
playing_sample_nb = 0
else:
randomize()
match random_strategy:
1:
playing_sample_nb = randi() % (number_of_samples - 1)
@ -41,18 +36,15 @@ func play(from_position=0.0):
last_played_sample_nb = playing_sample_nb
_:
playing_sample_nb = randi() % number_of_samples
if randomize_volume:
set_volume_db(rand_range(volume_min, volume_max))
if randomize_pitch:
set_pitch_scale(rand_range(pitch_min, pitch_max))
set_stream(streams[playing_sample_nb])
if random_volume_range != 0:
.set_volume_db(base_volume + (randf() - .5) * random_volume_range)
if random_pitch_range != 0:
.set_pitch_scale(base_pitch + (randf() - .5) * random_pitch_range)
set_stream(samples[playing_sample_nb])
.play(from_position)
func _ready():
connect("finished", self, "reset_playing_sample_nb")
func reset_playing_sample_nb():
if playing_sample_nb >= 0:
playing_sample_nb = -1
func set_volume_db(new_volume_db):
base_volume = new_volume_db
func set_pitch_scale(new_pitch):
base_pitch = new_pitch

View File

@ -1,30 +1,25 @@
tool
extends AudioStreamPlayer2D
export(Array, AudioStream) var streams
export(Array, AudioStream) var samples
export(int, "Pure", "No consecutive repetition", "Use all samples before repeat") var random_strategy = 0
export(bool) var randomize_volume = false
export(float, -80, 24) var volume_min = 0
export(float, -80, 24) var volume_max = 0
export(bool) var randomize_pitch = false
export(float, 0.01, 32) var pitch_min = 1
export(float, 0.01, 32) var pitch_max = 1
onready var base_volume = volume_db
export(float, 0, 80) var random_volume_range = 0
onready var base_pitch = pitch_scale
export(float, 0, 4) var random_pitch_range = 0
var playing_sample_nb : int = -1
var last_played_sample_nb : int = -1 # only used if random_strategy = 1
var playing_time_remaining = -1
var to_play = []
var to_play = [] # only used if random_strategy = 2
func play(from_position=0.0):
var number_of_samples = len(streams)
# You can use playing_sample_nb to choose what sample to use
func play(from_position=0.0, playing_sample_nb=-1):
var number_of_samples = len(samples)
if number_of_samples > 0:
if playing_sample_nb < 0:
if number_of_samples == 1:
playing_sample_nb = 0
else:
randomize()
match random_strategy:
1:
playing_sample_nb = randi() % (number_of_samples - 1)
@ -41,18 +36,15 @@ func play(from_position=0.0):
last_played_sample_nb = playing_sample_nb
_:
playing_sample_nb = randi() % number_of_samples
if randomize_volume:
set_volume_db(rand_range(volume_min, volume_max))
if randomize_pitch:
set_pitch_scale(rand_range(pitch_min, pitch_max))
set_stream(streams[playing_sample_nb])
if random_volume_range != 0:
.set_volume_db(base_volume + (randf() - .5) * random_volume_range)
if random_pitch_range != 0:
.set_pitch_scale(base_pitch + (randf() - .5) * random_pitch_range)
set_stream(samples[playing_sample_nb])
.play(from_position)
func _ready():
connect("finished", self, "reset_playing_sample_nb")
func reset_playing_sample_nb():
if playing_sample_nb >= 0:
playing_sample_nb = -1
func set_volume_db(new_volume_db):
base_volume = new_volume_db
func set_pitch_scale(new_pitch):
base_pitch = new_pitch

View File

@ -1,30 +1,25 @@
tool
extends AudioStreamPlayer3D
export(Array, AudioStream) var streams
export(Array, AudioStream) var samples
export(int, "Pure", "No consecutive repetition", "Use all samples before repeat") var random_strategy = 0
export(bool) var randomize_volume = false
export(float, -80, 24) var volume_min = 0
export(float, -80, 24) var volume_max = 0
export(bool) var randomize_pitch = false
export(float, 0.01, 32) var pitch_min = 1
export(float, 0.01, 32) var pitch_max = 1
onready var base_volume = unit_db
export(float, 0, 80) var random_volume_range = 0
onready var base_pitch = pitch_scale
export(float, 0, 4) var random_pitch_range = 0
var playing_sample_nb : int = -1
var last_played_sample_nb : int = -1 # only used if random_strategy = 1
var playing_time_remaining = -1
var to_play = []
var to_play = [] # only used if random_strategy = 2
func play(from_position=0.0):
var number_of_samples = len(streams)
# You can use playing_sample_nb to choose what sample to use
func play(from_position=0.0, playing_sample_nb=-1):
var number_of_samples = len(samples)
if number_of_samples > 0:
if playing_sample_nb < 0:
if number_of_samples == 1:
playing_sample_nb = 0
else:
randomize()
match random_strategy:
1:
playing_sample_nb = randi() % (number_of_samples - 1)
@ -41,17 +36,15 @@ func play(from_position=0.0):
last_played_sample_nb = playing_sample_nb
_:
playing_sample_nb = randi() % number_of_samples
if randomize_volume:
set_unit_db(rand_range(volume_min, volume_max))
if randomize_pitch:
set_pitch_scale(rand_range(pitch_min, pitch_max))
set_stream(streams[playing_sample_nb])
if random_volume_range != 0:
.set_unit_db(base_volume + (randf() - .5) * random_volume_range)
if random_pitch_range != 0:
.set_pitch_scale(base_pitch + (randf() - .5) * random_pitch_range)
set_stream(samples[playing_sample_nb])
.play(from_position)
func _ready():
connect("finished", self, "reset_playing_sample_nb")
func reset_playing_sample_nb():
if playing_sample_nb >= 0:
playing_sample_nb = -1
func set_unit_db(new_unit_db):
base_volume = new_unit_db
func set_pitch_scale(new_pitch):
base_pitch = new_pitch

36
icon.png.import Normal file
View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="StreamTexture"
path.s3tc="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.stex"
path.etc2="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex"
metadata={
"imported_formats": [ "s3tc", "etc2" ],
"vram_texture": true
}
[deps]
source_file="res://icon.png"
dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.s3tc.stex", "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.etc2.stex" ]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=true
flags/filter=true
flags/mipmaps=true
flags/anisotropic=false
flags/srgb=1
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=false
svg/scale=1.0

34
icon.svg.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/icon.svg-218a8f2b3041327d8a5756f3a245f83b.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://icon.svg"
dest_files=[ "res://.import/icon.svg-218a8f2b3041327d8a5756f3a245f83b.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -10,7 +10,6 @@ config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
@ -22,4 +21,4 @@ config/icon="res://icon.png"
[editor_plugins]
enabled=PoolStringArray( "randomAudioStreamPlayer" )
enabled=PoolStringArray( "res://addons/randomAudioStreamPlayer/plugin.cfg" )

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/walking_character1.wav-3c8edcf87c8088a10860f5d6013d6da7.sample"
[deps]
source_file="res://sound_effects/walking_character1.wav"
dest_files=[ "res://.import/walking_character1.wav-3c8edcf87c8088a10860f5d6013d6da7.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/walking_character2.wav-288cf4d962fb54a0849aafbe9d5b66b2.sample"
[deps]
source_file="res://sound_effects/walking_character2.wav"
dest_files=[ "res://.import/walking_character2.wav-288cf4d962fb54a0849aafbe9d5b66b2.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/walking_character3.wav-ec043ba7f6edc2201aebeb3312e0a51f.sample"
[deps]
source_file="res://sound_effects/walking_character3.wav"
dest_files=[ "res://.import/walking_character3.wav-ec043ba7f6edc2201aebeb3312e0a51f.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/walking_character4.wav-2b26645a808331aceb492af8c3d61e89.sample"
[deps]
source_file="res://sound_effects/walking_character4.wav"
dest_files=[ "res://.import/walking_character4.wav-2b26645a808331aceb492af8c3d61e89.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/walking_character5.wav-00f10c4872a3aafd4bc8df71ed5887a2.sample"
[deps]
source_file="res://sound_effects/walking_character5.wav"
dest_files=[ "res://.import/walking_character5.wav-00f10c4872a3aafd4bc8df71ed5887a2.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/walking_character6.wav-13e0b43fba5e5714447774139a8a6e93.sample"
[deps]
source_file="res://sound_effects/walking_character6.wav"
dest_files=[ "res://.import/walking_character6.wav-13e0b43fba5e5714447774139a8a6e93.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/walking_character7.wav-610af7a24e82631c81cc6cc09f7fc5fa.sample"
[deps]
source_file="res://sound_effects/walking_character7.wav"
dest_files=[ "res://.import/walking_character7.wav-610af7a24e82631c81cc6cc09f7fc5fa.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0

View File

@ -0,0 +1,21 @@
[remap]
importer="wav"
type="AudioStreamSample"
path="res://.import/walking_character8.wav-de3e223aa19ae6dd101176a59f20e802.sample"
[deps]
source_file="res://sound_effects/walking_character8.wav"
dest_files=[ "res://.import/walking_character8.wav-de3e223aa19ae6dd101176a59f20e802.sample" ]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop=false
compress/mode=0