WARNING:root:Clock MASTER.... probably processing is too heavy

Description:

Hi all
The code run but I think some of the parts may be slightly out of sync…and once Thorny just closed. My PC specs are ok I think, Windows 11; 64GB DDR5 Ram; Processor is i7-10700K CPU @ 3.8GHz 8 cores 16 logical processors
I am only running Thorny and I did another version of the code where I save all the computations for the envelope in a list so nothing is computed as I go through the for loop…Any suggestions will be appreciated …thanks in advance

Error printout:

WARNING:root:Clock MASTER (beat=2.833333333333333) is running noticeably behind real time (0.06216 s) on a wait call of 0 s; probably processing is too heavy.

(Place the error printout here)

The full code that resulted in the error:

(Place code here)
staccato,staccatissimo,marcato,tenuto,accent ="staccato", "staccatissimo", "marcato" , "tenuto", "accent"

```def playInstrument(inst, interval, whenNotToPlay, listMelody,listRhythm ):
    articulations = [staccato,staccatissimo,marcato,accent] #[staccato,staccatissimo,marcato,tenuto,accent] 
    for pitch, rhythm in zip(listMelody,listRhythm ):
        if counter%whenNotToPlay==0 and counter >0:wait(rhythm)
        else:
            levels, curves = [],[]
            for i in range(0,randint(2,6)):
                levels.append(round((random()+0.1),2))  #round to 2 decimal places
                curves.append(randint(-5,5))
            avTime = rhythm/(len(levels)) #(len(levels)-1)
            dur = [avTime]*(len(levels)-1)
            fp_cres = Envelope.from_levels_and_durations(levels, dur, curves)
            if random() <=0.75: articulation = articulations[2]
            else : articulation = choice(articulations)
            inst.play_note(pitch+interval , fp_cres,rhythm, articulation)
    #wait(
cello_whenNotToPlay,oboe_whenNotToPlay, piano_whenNotToPlay, brass_whenNotToPlay = randint(2,6),randint(2,6) ,randint(2,6) ,randint(2,6)        
cello_interval,oboe_interval,piano_interval,brass_interval = 0,31,16,-12
                #playInstrument(cello, cello_interval, cello_whenNotToPlay, listMelody,listRhythm )
fork(playInstrument, args = [cello, cello_interval, cello_whenNotToPlay, listMelody,listRhythm ])
fork(playInstrument, args = [oboe,  oboe_interval,  oboe_whenNotToPlay,  listMelody,listRhythm ])
fork(playInstrument, args = [piano, piano_interval, piano_whenNotToPlay, listMelody,listRhythm ])
fork(playInstrument, args = [brass, brass_interval, brass_whenNotToPlay, listMelody,listRhythm ])
s.wait_for_children_to_finish()

#**************************************************************************************************************
#i tried this version to store values calculated for the envelope(levels, durations, curves ) into a list so that as the play_note loops through the melody list there will not be much calculations i thought.... but with the same problem
# def playInstrument(inst, interval, whenNotToPlay, listMelody,listRhythm ):
#     articulations = [staccato,staccatissimo,marcato,accent] #[staccato,staccatissimo,marcato,tenuto,accent]
#     list_fp_cres, list_articulation = [],[] #[[]],[[]],[]
#     for pitch, rhythm in zip(listMelody,listRhythm ):
#         if counter%whenNotToPlay==0 and counter >0:wait(rhythm)
#         else:
#             levels, curves = [],[]
#             for i in range(0,randint(2,6)):
#                 levels.append(round((uniform(0.05, 0.7)),2))  #round to 2 decimal places
#                 curves.append(randint(-5,5))
#             avTime = rhythm/(len(levels)) #(len(levels)-1)
#             dur = [avTime]*(len(levels)-1)
#             fp_cres = Envelope.from_levels_and_durations(levels, dur, curves)
#             if random() <=0.75: articulation = articulations[2]
#             else : articulation = choice(articulations)
#             list_fp_cres.append(fp_cres)
#             list_articulation.append(articulation)
#     for pitch, rhythm, fp, art in zip(listMelody,listRhythm, list_fp_cres,list_articulation): inst.play_note(pitch+interval , fp,rhythm, art)
#     
# cello_whenNotToPlay,oboe_whenNotToPlay, piano_whenNotToPlay, brass_whenNotToPlay = randint(2,6),randint(2,6) ,randint(2,6) ,randint(2,6)        
# cello_interval,oboe_interval,piano_interval,brass_interval = 0,31,16,-12
#                 #playInstrument(cello, cello_interval, cello_whenNotToPlay, listMelody,listRhythm )
# fork(playInstrument, args = [cello, cello_interval, cello_whenNotToPlay, listMelody,listRhythm ])
# fork(playInstrument, args = [oboe,  oboe_interval,  oboe_whenNotToPlay,  listMelody,listRhythm ])
# fork(playInstrument, args = [piano, piano_interval, piano_whenNotToPlay, listMelody,listRhythm ])
# fork(playInstrument, args = [brass, brass_interval, brass_whenNotToPlay, listMelody,listRhythm ])
# s.wait_for_children_to_finish()

Thanks for posting this question. I also want to ask for advice on this issue. I run my music code in VS code IDE. For all the times I run, that warning msg is printed out (WARNING:root:Clock MASTER beat=…) but the code is working perfectly. If I want to repeat a piece several times, the sounds at the first iteration are always a bit out of synced, but from the second iteration, they all are good.
My temporary solution is putting wait(1) at top of the loop, so the sounds at the first iteration are perfect. I believe there is something with the configuration for the clockmaster on each computer.

1 Like

Hi! I think the code you posted is missing some of the setup, which I need to be able to test it.

1 Like

Hi
here is the code

from scamp import *
from random import *
from math import *

listRhythm= [0.17, 0.5, 0.17, 0.17, 0.5, 0.17, 1.5, 0.17, 0.33, 1.67, 1.67, 0.5, 0.5, 2.17, 3.17, 5.33, 2.0, 2.83, 1.0, 6.67, 2.17]
listMelody=[65,   64,  65,   64,   62,  64,   65,  64,   65,   64,   65,   60,  62,  57,   58,   60,   62,  64,   65,  67,   69]
staccato,staccatissimo,marcato,tenuto,accent ="staccato", "staccatissimo", "marcato" , "tenuto", "accent"

s = Session(tempo =60)  # or canleave blank and add later ...
cello =s.new_part("Cello")
oboe = s.new_part("Oboe")
piano = s.new_part("Piano Merlin ")
electricPiano = s.new_part("E.Piano 1")
brass = s.new_part("brass")
bass = s.new_part("Fingered Bass")
TenorSax = s.new_part("Tenor Sax")
organ = s.new_part("Organ 1")

def playInstrument(inst, interval, whenNotToPlay, listMelody,listRhythm ):
    articulations = [staccato,staccatissimo,marcato,accent] #[staccato,staccatissimo,marcato,tenuto,accent]
    counter =0
    for pitch, rhythm in zip(listMelody,listRhythm ):
        if counter%whenNotToPlay==0 and counter >0:wait(rhythm)
        else:
            levels, curves = [],[]
            for i in range(0,randint(2,6)):
                levels.append(round((random()+0.1),2))  #round to 2 decimal places
                curves.append(randint(-5,5))
            avTime = rhythm/(len(levels)) #(len(levels)-1)
            dur = [avTime]*(len(levels)-1)
            fp_cres = Envelope.from_levels_and_durations(levels, dur, curves)
            if random() <=0.75: articulation = articulations[2]
            else : articulation = choice(articulations)
            inst.play_note(pitch+interval , fp_cres,rhythm, articulation)
        counter +=1
cello_whenNotToPlay,oboe_whenNotToPlay, piano_whenNotToPlay, brass_whenNotToPlay = randint(2,6),randint(2,6) ,randint(2,6) ,randint(2,6)        
cello_interval,oboe_interval,piano_interval,brass_interval = 0,31,16,-12
                #playInstrument(cello, cello_interval, cello_whenNotToPlay, listMelody,listRhythm )
fork(playInstrument, args = [cello, cello_interval, cello_whenNotToPlay, listMelody,listRhythm ])
fork(playInstrument, args = [oboe,  oboe_interval,  oboe_whenNotToPlay,  listMelody,listRhythm ])
fork(playInstrument, args = [piano, piano_interval, piano_whenNotToPlay, listMelody,listRhythm ])
fork(playInstrument, args = [brass, brass_interval, brass_whenNotToPlay, listMelody,listRhythm ])
s.wait_for_children_to_finish()

Hi Marc
Hope you are well
I posted the full code as requested because the initial code was not complete so i just thought to remind you incase you had not seen the full code

I couldn’t replicate the problem on my machine.

But you might try adding:

s.synchronization_policy = 0.7

after you create the session. This allows the clock to catch up more. by shaving off time from wait calls.

1 Like

thanks i will try it

hi Marc- I tried the s.synchronization_policy=0.7 after I created the session but i get an error whioch is below
File “C:\Users\User\AppData\Roaming\Python\Python310\site-packages\clockblocks\clock.py”, line 336, in synchronization_policy
raise ValueError('Invalid synchronization policy “{}”. Must be one of (“all relatives”, “all descendants”, ’
ValueError: Invalid synchronization policy “0.7”. Must be one of (“all relatives”, “all descendants”, “no synchronization”, “inherit”).

Sorry! I meant s.timing_policy = 0.7

1 Like

Hi Marc,

I added some simple interactivity to your ScheduledNotes example script and I get this output:

Using preset Piano Merlin for piano
Play again (y/n)?y
WARNING:root:Clock MASTER (beat=6.0) is running noticeably behind real time (2.99459 s) on a wait call of 0 s; probably processing is too heavy.
Play again (y/n)?n

Here’s the modified program:

from scamp import *

s = Session()

piano = s.new_part("piano")

# format: (pitch, start_time, duration)
notes = [
    # top part
    (74, 0.0, 1.0),
    (67, 1.0, 0.5),
    (69, 1.5, 0.5),
    (71, 2.0, 0.5),
    (72, 2.5, 0.5),
    (74, 3.0, 1.0),
    (67, 4.0, 1.0),
    (67, 5.0, 1.0),
    # bottom part
    (55, 0.0, 2.0),
    (59, 0.0, 2.0),
    (62, 0.0, 2.0),
    (57, 2.0, 1.0),
    (59, 3.0, 3.0),
]

notes.sort(key=lambda note: note[1])

def play_tune(score):
    t = 0
    for note in score:
        time_til_note = note[1] - t
        wait(time_til_note)
        t += time_til_note
        piano.play_note(note[0], 0.7, note[2], blocking=False)

    wait_for_children_to_finish()
    
done = False
while (not done):
    play_tune(notes)
    c = input("Play again (y/n)?")
    if c == 'n':
        done = True

Any thoughts?

Thanks,
Andrew

Any time you use input or something like that, SCAMP thinks that it’s running behind, because the input takes an arbitrary amount of time, and then it checks in and realizes it’s way later than expected.

The way to do it, for now, is to use:

s = Session.run_as_server()

and then later to fork play_tune:

s.fork(play_tune, args=(notes, ))

See if that works!

Hi andrewk

I replicated your problem in Thonny using the Interpreter of Thonny. When I used the Python interpreter I didn’t get the error.