ValueError: Duration to target must extend beyond the last existing target

Description: ok there is 2 errors but the first one about Clock Master is being dealt with in another post. However the problem to be addressed here is the last line of the error printout which is sayingDuration to target must extend beyond the last existing target. I have been following the exercise on tempo speeds -using s.set_tempo_targets() the duration numbers match the temp_target counts and the curve_shapes…

thanks in advance

Error printout:

WARNING:root:Clock MASTER (beat=10.53) is running noticeably behind real time (0.09333 s) on a wait call of 0.0 s; probably processing is too heavy.
Traceback (most recent call last):
File “D:\Dropbox\2018Music\Production\scamp\error_2023_02_27.py”, line 65, in
s.set_tempo_targets(tempo_targets=listTempos , durations=listDurations, curve_shapes = [(randint(-6,6)),(randint(-6,6)),(randint(-6,6))], duration_units = “time”)
File “C:\Users\User\AppData\Roaming\Python\Python310\site-packages\clockblocks\clock.py”, line 80, in wrapper
return fn(self, *args, **kwargs)
File “C:\Users\User\AppData\Roaming\Python\Python310\site-packages\clockblocks\clock.py”, line 625, in set_tempo_targets
self.tempo_history.set_tempo_targets(tempo_targets, durations, curve_shapes, metric_phase_targets,
File “C:\Users\User\AppData\Roaming\Python\Python310\site-packages\clockblocks\tempo_envelope.py”, line 696, in set_tempo_targets
self.set_beat_length_targets([60 / x for x in tempo_targets], durations, curve_shapes, metric_phase_targets,
File “C:\Users\User\AppData\Roaming\Python\Python310\site-packages\clockblocks\tempo_envelope.py”, line 536, in set_beat_length_targets
self._add_segment(beat_length_target, duration, curve_shape, None, duration_units)
File “C:\Users\User\AppData\Roaming\Python\Python310\site-packages\clockblocks\tempo_envelope.py”, line 488, in _add_segment
raise ValueError(“Duration to target must extend beyond the last existing target.”)
ValueError: Duration to target must extend beyond the last existing target.

(Place the error printout here)

The full code that resulted in the error:

(Place code here)
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")

#-------------setting differnt tempos--sound intersting
def playSustain(inst, note, dur, levels):
    newLevels = [val*0.35 for val in levels]
    curves = [uniform(-1,2) for i in range(len(levels)-1)]
    durList =[dur/(len(levels)-1) for i in curves]
    vol =Envelope.from_levels_and_durations(newLevels, durList, curves)
    if random() < 0.4:    listChord =[note, note+3, note+6, note+9, note+13]
    elif random() < 0.8 : listChord =[note, note+7, note+11, note+14, note+17]
    else:                 listChord =[note, note+5, note+7, note+14]
    inst.play_chord(listChord , vol,dur*3)
#     if random() <0.5 :inst.play_chord(listChord , vol,dur*3)
#     else: inst.play_chord(listChord , choice(levels)*0.45,dur*3) 
def playInstrument(inst, boolFp,interval, whenNotToPlay, listMelody,listRhythm ):
    articulations = [staccato,staccatissimo,marcato,accent] #[staccato,staccatissimo,marcato,tenuto,accent]
    list_fp_cres, list_articulation = [],[] #[[]],[[]],[]
    levels = [round((uniform(0.05, 0.9)),2) for i in range(0,randint(2,3))]
    curves =[float(randint(-1,2)) for i in range (len(levels)-1)]
    counter =0
    for pitch, rhythm in zip(listMelody,listRhythm ):
        if counter%whenNotToPlay==0 and counter >0:wait(rhythm)
        else:
            if boolFp :
                #levels = [round((uniform(0.05, 0.9)),2) for i in range(0,randint(2,3))]
                #curves =[float(randint(-1,2)) for i in range (len(levels)-1)]
                avTime = rhythm/(len(levels)-1) #(len(levels)-1)
                dur = [avTime]*(len(levels)-1)
                fp_cres = Envelope.from_levels_and_durations(levels, dur, curves)
                if inst ==cello:
                    if random() > 0.65:playSustain(organ, pitch, rhythm, fp_cres.levels) #fork(playSustain, args =[organ, pitch, rhythm, fp_cres.levels])
                if random() <=0.35:  inst.play_note(pitch+interval , fp_cres,rhythm, staccatissimo)   #,blocking =False
                else:                inst.play_note(pitch+interval , fp_cres,rhythm)
            else:
                fp_cres=choice([0.25,0.5,0.75])
                if random() <=0.35:  inst.play_note(pitch+interval , fp_cres,rhythm, staccatissimo)   #,blocking =False
                else:                inst.play_note(pitch+interval , fp_cres,rhythm)
        counter +=1
    wait(0.1)    
    
cello_whenNotToPlay,oboe_whenNotToPlay, piano_whenNotToPlay, brass_whenNotToPlay = randint(2,3),randint(2,9) ,randint(2,5) ,randint(2,8)        
cello_interval,oboe_interval,piano_interval,brass_interval = 0,31,16,-12
startTempo =60
listTempos    = [startTempo,200,startTempo] 
avTempoDur    = sum(listRhythm)/ (len(listTempos)+1)
listDurations = [avTempoDur,avTempoDur,avTempoDur ]# note that durations have to either be the same or increasing else error code
s.tempo=startTempo
playInstrument(cello, True,  cello_interval, cello_whenNotToPlay, listMelody,listRhythm )
s.set_tempo_targets(tempo_targets=listTempos , durations=listDurations, curve_shapes = [(randint(-6,6)),(randint(-6,6)),(randint(-6,6))], duration_units = "time")  
fork(playInstrument,                     args = [cello, True,  cello_interval, cello_whenNotToPlay, listMelody,listRhythm ])
fork(playInstrument, initial_tempo = 90, args = [oboe,  True, oboe_interval,  oboe_whenNotToPlay,  listMelody,listRhythm ])
fork(playInstrument, initial_tempo = 60, args = [piano, True, piano_interval, piano_whenNotToPlay, listMelody,listRhythm ])
fork(playInstrument, initial_tempo = 20, args = [brass, True, brass_interval, brass_whenNotToPlay, listMelody,listRhythm ])
s.wait_for_children_to_finish()

i wonder if this has to do with the fact that i have a list of durations
(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])
and so
inst.play_note(pitch, volume, duration) would have run out of durations by the time one or more target temp is reached

.set_tempo_targets(tempo_targets=[20,200,20], durations=[sum(listRhythm)/3, sum(listRhythm)/3, sum(listRhythm)/3], curve_shapes = [-1,-1,-1], duration_units = “time”)

set_tempo_targets takes a list of durations from the current beat, which I know is kind of confusing.

So if you wanted, say, three 5-beat long tempo changes, you’d have to set the durations as [5, 10, 15].

I know this is confusing! And looking at the documentation, I think the documentation is misleading.

1 Like

thanks. i got it