Skip to content

Commit c72f003

Browse files
committed
Initial commit
1 parent 9f65372 commit c72f003

11 files changed

+181
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
* text=auto eol=lf

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ export_presets.cfg
1313
.mono/
1414
data_*/
1515
mono_crash.*.json
16+
17+
# temporary files
18+
*.tmp

AudioEventPlayer.svg

+14
Loading

AudioEventPlayer.svg.import

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://cbm5w12eria8y"
6+
path="res://.godot/imported/AudioEventPlayer.svg-2c0bc192a2b5febd21dd45abd114bf50.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://AudioEventPlayer.svg"
14+
dest_files=["res://.godot/imported/AudioEventPlayer.svg-2c0bc192a2b5febd21dd45abd114bf50.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1
35+
svg/scale=1.0
36+
editor/scale_with_editor_scale=false
37+
editor/convert_colors_with_editor_theme=false

example/Node.gd

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends Node
2+
3+
4+
func _on_audio_event_player_sound_event(soundName, id, at):
5+
print(soundName," ", id, " ", at)
6+
pass # Replace with function body.

example/example.tscn

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[gd_scene load_steps=6 format=3 uid="uid://blmoi66kr60y"]
2+
3+
[ext_resource type="Script" path="res://scripts/AudioStreamPlayerEvents.gd" id="1_n8knq"]
4+
[ext_resource type="Script" path="res://example/Node.gd" id="2_abyoc"]
5+
[ext_resource type="AudioStream" uid="uid://bocx2cwlpp1mc" path="res://example/freebird.wav" id="2_c08da"]
6+
[ext_resource type="Script" path="res://scripts/AudioFileWithEvents.gd" id="3_rdl2a"]
7+
8+
[sub_resource type="Resource" id="Resource_2ro53"]
9+
script = ExtResource("3_rdl2a")
10+
audio = ExtResource("2_c08da")
11+
eventTimes = Array[float]([3.02, 6.96, 13.01])
12+
name = "Audio"
13+
14+
[node name="AudioEventPlayer" type="Node" node_paths=PackedStringArray("audioStreamPlayer")]
15+
script = ExtResource("1_n8knq")
16+
audioStreamPlayer = NodePath("AudioStreamPlayer")
17+
audioEventStream = SubResource("Resource_2ro53")
18+
19+
[node name="Node" type="Node" parent="."]
20+
script = ExtResource("2_abyoc")
21+
22+
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
23+
24+
[connection signal="soundEvent" from="." to="Node" method="_on_audio_event_player_sound_event"]
25+
[connection signal="finished" from="AudioStreamPlayer" to="." method="_on_audio_stream_player_finished"]

example/freebird.wav

2.7 MB
Binary file not shown.

example/freebird.wav.import

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[remap]
2+
3+
importer="wav"
4+
type="AudioStreamWAV"
5+
uid="uid://bocx2cwlpp1mc"
6+
path="res://.godot/imported/freebird.wav-15391728f6f0e2cab5d4ef86b5435e6d.sample"
7+
8+
[deps]
9+
10+
source_file="res://example/freebird.wav"
11+
dest_files=["res://.godot/imported/freebird.wav-15391728f6f0e2cab5d4ef86b5435e6d.sample"]
12+
13+
[params]
14+
15+
force/8_bit=false
16+
force/mono=false
17+
force/max_rate=false
18+
force/max_rate_hz=44100
19+
edit/trim=false
20+
edit/normalize=false
21+
edit/loop_mode=2
22+
edit/loop_begin=0
23+
edit/loop_end=-1
24+
compress/mode=0

project.godot

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=5
10+
11+
[application]
12+
13+
config/name="Audio Events"
14+
run/main_scene="res://example/example.tscn"
15+
config/features=PackedStringArray("4.2", "Forward Plus")
16+
config/icon="res://AudioEventPlayer.svg"

scripts/AudioFileWithEvents.gd

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@icon("res://AudioEventPlayer.svg")
2+
class_name AudioWithEvents
3+
extends Resource
4+
5+
6+
@export var audio : AudioStream
7+
@export var eventTimes : Array[float]
8+
9+
@export var name : String = "Audio"

scripts/AudioStreamPlayerEvents.gd

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
@icon("res://AudioEventPlayer.svg")
2+
class_name AudioEventPlayer
3+
extends Node
4+
5+
const PRECISION = .01
6+
7+
@export var audioStreamPlayer : AudioStreamPlayer
8+
@export var audioEventStream : AudioWithEvents
9+
10+
signal soundEvent(soundName: String, id: int, playedAt: float)
11+
12+
var lastId = -1
13+
14+
func _ready():
15+
var p = get_parent()
16+
if audioEventStream:
17+
audioStreamPlayer.stream = audioEventStream.audio
18+
if p is AudioStreamPlayer:
19+
audioStreamPlayer = p
20+
audioStreamPlayer.play()
21+
22+
func _process(_delta):
23+
if not audioStreamPlayer or not audioEventStream:
24+
return
25+
26+
if !audioStreamPlayer.playing:
27+
return
28+
29+
var pos = audioStreamPlayer.get_playback_position()
30+
var index = -1
31+
for t_i in range(len(audioEventStream.eventTimes)):
32+
var t = audioEventStream.eventTimes[t_i]
33+
if abs(t - pos) <= PRECISION:
34+
pos = t
35+
index = t_i
36+
break
37+
38+
if index != -1 and lastId != index:
39+
soundEvent.emit(audioEventStream.name, index, pos)
40+
lastId = index
41+
42+
43+
func _on_audio_stream_player_finished():
44+
print("finish machine reininger")
45+
pass # Replace with function body.

0 commit comments

Comments
 (0)