First time here? Check out the FAQ!
x

stayOnFor: not working with Arrays

0 votes
298 views
hello everybody, I am using this script to generate GATES for  a MIDIOutputEvent:

| masterclock position switches voicestealing durations |
masterclock := !Run bpm: (!BPM * 4).
position := masterclock nextIndexMod: 16 reset: !Reset.
switches := 1 to: 16 collect: {[ :n | !sw suffix2: n]}.
voicestealing := (masterclock durationBetweenTriggers s) tick.
durations := 1 to: 16 collect: [:i | !length suffix2: i]}.
(position of: switches) * voicestealing stayOnFor: durations

 

but I am getting an error message which says that:

"the message #literalTimeinSeconds sent to an instance of class Array, was not understood".

 

how can I fix my script?

 

thanks,

d
asked Nov 2, 2016 in Capytalk & Smalltalk by domenico-cipriani (Master) (3,110 points)

1 Answer

+1 vote
 
Best answer

There was a stray } in the code above, but if you change it to this and evaluate using Ctrl+Y:

| masterclock position switches voicestealing durations |
masterclock := !Run bpm: (!BPM * 4).
position := masterclock nextIndexMod: 16 reset: !Reset.
switches := 1 to: 16 collect: [ :n | !sw suffix2: n].
voicestealing := (masterclock durationBetweenTriggers s) tick.
durations := 1 to: 16 collect: [:i | !length suffix2: i].
(position of: switches) * voicestealing stayOnFor: durations

The result is the expression:

(((!Run bpm: !BPM * 4) nextIndexMod: 16 reset: !Reset) of: #( !sw01 !sw02 !sw03 !sw04 !sw05 !sw06 !sw07 !sw08 !sw09 !sw10 !sw11 !sw12 !sw13 !sw14 !sw15 !sw16 )) * (!Run bpm: !BPM * 4) durationBetweenTriggers s tick stayOnFor: #( !Length01 !Length02 !Length03 !Length04 !Length05 !Length06 !Length07 !Length08 !Length09 !Length10 !Length11 !Length12 !Length13 !Length14 !Length15 !Length16 )

so you are using an Array #( !Length01 etc..) as the argument to stayOnFor: which expects a scalar value in seconds.  To fix this, you could index the lengths Array using the same master clock you are using everywhere else, for example:

(((!Run bpm: !BPM * 4) nextIndexMod: 16 reset: !Reset) of: #( !Length01 !Length02 !Length03 !Length04 !Length05 !Length06 !Length07 !Length08 !Length09 !Length10 !Length11 !Length12 !Length13 !Length14 !Length15 !Length16 ))

which you could do by modifying the last line of your code to:

(position of: switches) * voicestealing stayOnFor: (position of: durations)

answered Nov 2, 2016 by ssc (Savant) (128,120 points)
selected Nov 3, 2016 by domenico-cipriani
thanks a lot, now I understand what was the problem
peace.
d
...