OmnichordGodot/scripts/ChordController.gd

26 lines
680 B
GDScript3
Raw Normal View History

2024-06-26 23:09:42 -03:00
extends Node
# Add asset here
var ChordPlayer: AudioStreamPlayer
var ChordAudio: AudioStreamOggVorbis
# Called when the node enters the scene tree for the first time.
func _ready():
ChordPlayer = get_node("/root/Control/ChordPlayer")
2024-06-26 23:49:24 -03:00
var resource_string = "res://audio/%s/%s-chord.ogg" % [self.name, self.name]
2024-06-26 23:09:42 -03:00
var resource = load(resource_string)
ChordAudio = resource
2024-06-26 23:49:24 -03:00
self.pressed.connect(button_pressed)
Global.loop_changed.connect(loop_changed)
2024-06-26 23:09:42 -03:00
func button_pressed():
# Play chord
ChordPlayer.stream = ChordAudio
ChordPlayer.play()
Global.chord_changed.emit(self.name)
2024-06-26 23:49:24 -03:00
func loop_changed(state: bool):
ChordAudio.loop = state
if (!state):
ChordPlayer.stop()