Hello! I wanna know if there's a way to check if an specific sound in a sample library is currently playing through the SamplePlayer, like checking by name.
In my project (a musical instrument game), my goal is to play a note if it's not already playing, and checking if a voice is active (SamplePlayer.isvoiceactive) is not a solution, since the index can change because of the polyphonic nature of the instrument.
The instrument have samples named according to its midi number (A1 = 045, E7 = 112, etc), just for you to know what will be inside the notes_playing array.
Here's my current code:
extends Node
var notes_playing = []
func _ready():
set_process(true)
func _process(delta):
var sample_player = self.get_node("sample_player")
# If there's notes playing
if notes_playing != []:
# Process all notes to play
for note in notes_playing:
var current_note = str(note)
# Avoid issues with two digit sample names (ex: 53 must be 053)
if int(current_note) < 100:
current_note = str("0" + current_note)
# Play note
if "current_note IN sample_player IS NOT PLAYING":
sample_player.play(current_note)
# If there's not notes playing
if notes_playing == [] and sample_player.is_active()::
sample_player.stop_all()