I’m playing a track (in Python) then checking when the track has finished playing.
It appears that the while loop is not executed until the track is finihed playing.
Any suggestions?
He is the high level code:
import TsunamiCore as tc
import time
port = “/dev/ttyUSB0”
tc.OpenPort(port)
####################### start of composition ###############################################
tc.PlayPoly(8,1) # call track control routine trck 8 output 1
while tc.TrackPlaying(8):
print(“true”)
####################### end of composition ###############################################
tc.StopAll()
tc.ClosePort(port)
The output is:
Polyphonic Play command for track 8 sent to output 1
Track 1 is False
Stop All command sent
Closing connection on /dev/ttyUSB0…
It’s probably due to ‘blocking’ code
I’d normally just advise to use the configurator app to chain tracks without software intervention https://learn.sparkfun.com/tutorials/tsunami-hookup-guide/all...something like:
[Trigger1]
Function=Normal
Output=1
Track=8
Polyphonic=1
This approach offloads playback control to Tsunami’s internal scheduler via INI file, eliminating the need for software polling.
Otherwise, you have a few options…the main one I’d suggest is to use threading (because you’re using Python already) to run the audio playback in a separate thread, something like:
import threading
# Start playback in a thread
play_thread = threading.Thread(target=tc.PlayPoly, args=(8,1))
play_thread.start()
# Now the main thread can monitor playback
while tc.TrackPlaying(8):
print("true")
time.sleep(0.1) # Add a small delay to avoid CPU hogging
Let me know things shake out!
It appears to be an issue in how I’ve implement isTrackplaying, which nickhayeck did not implement. There is a difference in how this routine is implemented in the Qwiic version and the serial version. Since I am using the serial interface is that the code to follow?
Also is there code which shows an example of the SET_INPUT_MIX?