Trying to control printing frequency in sync with sound

Hey all! Tnx for the help. I’m working on a project which intends to use the printing in the log window in sync with the audio loop. So I have created 4 lists with the same content and made it in the way that it prints me every possible combination (1 comb each line). My idea is to control the printing frequency and add a sound to each time it prints.

So far, I could manage to make the function play the audio line BUT it prints all the lines at once and then starts the audio loop. While what I wanted is that every line gets printed at each cycle, in synch with the loop. The thing is that the printing function works in a sandbox while using time.sleep(1). like this

import time
def myFunction():
	list1 =["blue", "red", "green", "yellow"]
	list2 =["blue", "red", "green", "yellow"]
	list3 =["blue", "red", "green", "yellow"]
	list4 =["blue", "red", "green", "yellow"]
	for i in list1:
		for u in list2:
			for t in list3:
				for v in list4:
					def printar():
						print(i, u, t, v)
						return
					time.sleep(1)
					printar()

          
myFunction()

it prints every line with a different combination result at each second. So the idea was to include the audio loop inside to be played at each iteration.

but when “translated” to FoxDot/Pulsardo (properly toggled, working and tested) it don’t.

def myFunction():
	list1 =["blue", "red", "green", "yellow"]
	list2 =["blue", "red", "green", "yellow"]
	list3 =["blue", "red", "green", "yellow"]
	list4 =["blue", "red", "green", "yellow"]
	for i in list1:
		for u in list2:
			for t in list3:
				for v in list4:
					def printar():
						print(i, u, t, v)
						bd >> play ("xox-")
						return
					#Clock.future(0.1, printar)
					#Clock.schedule(printar, 0.1)
					printar()

          
myFunction()

Here (with both commented) it prints me everything at once and then starts to play the audio loop (indefinetelly). If I uncomment one of them, it behaves the same but it also “scrambles” the printing result.

I pretty much tried to put Clock.future and/or Clock.schedule everywhere and I can get nice glitchy results, but none of them print me each line at each beat (in synch with the audio loop).

Hope I made myself clear. If anyone have a light I’d appreciate it!

Hey lixt,

If think that Renardo/FoxDot is not really meant to be used like that. You should probably look at the tutorial → how to write a Pattern method in a late chapter instead.

Still even if not very convenient, here is a working example of using loops to schedule things through time:

list1 =["blue", "red", "green", "yellow"]
list2 =["blue", "red", "green", "yellow"]
list3 =["blue", "red", "green", "yellow"]
list4 =["blue", "red", "green", "yellow"]
for a,i in enumerate(list1):
    for b,u in enumerate(list2):
        for c,t in enumerate(list3):
             for d,v in enumerate(list4):
                    def printar(a,b,c,d, i, u, t, v):
                        print(a, b, c, d, i, u, t, v)
                        #plays something like "blueredredyellow"
                        # thats changes over time up to "yellowyellowyellowyellow"
                        bd >> play(i+u+t+v, dur=.125)
                        return
                    # beat_count the time of scheduling depends on the position in the 4 for loops
                    # you also have to pass all the required arguments to the scheduled function
                    Clock.schedule(
                        printar,
                        beat=Clock.now() +(a+1)*16 +(b+1)*8 +(c+1)*4 +(d+1)*2,
                        args=[a,b,c,d,i,u,t,v]
                    )

if it complains with beat argument use beat_count instead.

Don’t hesitate if something is not clear,
Elie

1 Like

hey Elie!

Tnx lots!! Really appreciated it!!

I can see that it synchronizes printing with sound, but, at least for me, I can only see whatever is being printed on the log window (in Pulsar) when I stop the function or re-execute it. While I was imagining to follow up each line being printed in “real time” in the log. Any idea why?

Another thing is that it doesn’t seem to stop. When it reaches “yellowyellowyellowyellow” it goes back to the beginning and starts again.

I also have a question if I may (for learning reasons): In this line bellow,
beat=Clock.now() +(a+1)*16 +(b+1)*8 +(c+1)*4 +(d+1)*2,
why you have multiplied each variable for a multiple of 2 (16, 8, 4, 2)? That seems to make a muted first count until 16 and then restart the count but this time with sound. And why did you use the abcd variables (which contain the indexes) instead of the iutv (which contain the content)?

obs: it works well with beat and gives me an error with beat_count

tnx infinite,

lixt