OmnichordGodot/scripts/NoteController.gd

25 lines
636 B
GDScript3
Raw Normal View History

2024-06-26 23:09:42 -03:00
extends Node
var NotePlayer: AudioStreamPlayer
var NoteAudio: AudioStreamOggVorbis
func _ready():
2024-06-27 01:11:23 -03:00
# Make new player each so notes can overlap
NotePlayer = AudioStreamPlayer.new()
add_child(NotePlayer)
2024-06-26 23:09:42 -03:00
Global.chord_changed.connect(chord_changed)
2024-06-26 23:49:24 -03:00
self.pressed.connect(button_pressed)
2024-06-27 01:11:23 -03:00
Global.note_volume.connect(change_volume)
2024-06-26 23:09:42 -03:00
func button_pressed():
NotePlayer.stream = NoteAudio
NotePlayer.play()
func chord_changed(chord):
2024-06-26 23:49:24 -03:00
var resource_string = "res://audio/%s/%s%s.ogg" % [chord, chord, self.name]
2024-06-26 23:09:42 -03:00
var resource = load(resource_string)
NoteAudio = resource
2024-06-27 01:11:23 -03:00
func change_volume(vol: float):
NotePlayer.set_volume_db(vol)