# Note Duration



## br1252 (May 2, 2006)

Looking for a way to find note duration, would like to write something like:

on note 
ignore_event ($EVENT_ID)
{If note duration is so long then fire a keyswitch}
if (%NOTE_DURATION[$EVENT_NOTE]>1000)
{do keyswitch}
play_note(24,127,0,3)
{wait for ks to take effect}
wait(100)
{now play original note}
play note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
end if
end on

(above numbers are fudged)

Baically I want to write a script that looks at an upcoming notes duration to figure out what keyswitch to use (not based on a previous events).

-- Bob


----------



## Hans Adamson (May 2, 2006)

Nils and Bob are the experts on this, but how will the script know the note duration of the $EVENT_NOTE on note on? The note duration can only be determined after the note is released, and by that time the script is already executed?


----------



## br1252 (May 2, 2006)

My bad, you're right. The host sends a note on followed by a note off (at some time later). It doesn't send a note value and duration.

Sorry.

-- Bob


----------



## Thonex (May 2, 2006)

YOu may be able to figure something out with these built in variables:

$DURATION_QUARTER
duration of a quarter note, with respect to the current tempo

$DURATION_EIGHTH
duration of an eighth note, with respect to the current tempo

$DURATION_SIXTEENTH
duration of a sixteenth note, with respect to the current tempo

$DURATION_QUARTER_TRIPLET
duration of a triplet quarter note, with respect to the current tempo

$DURATION_EIGHTH_TRIPLET
duration of a triplet eighth note, with respect to the current tempo

$DURATION_SIXTEENTH_TRIPLET
duration of a triplet sixteenth note, with respect to the current tempo

$ENGINE_UPTIME
Returns the time period in milliseconds (not microseconds) that has passed since the start of the script


Or maybe you could set up a 'while' loop and if $whilecounter = 10000 then trigger keyswitch. Just thinking out loud.

Cheers,

T


----------



## kotori (May 3, 2006)

I don't know any details of the VST standard, but I've read that virtual instruments could be provided with the note duration by the host (this of course only works on playback and not when playing live). Unfortunately I don't think Kontakt exposes these note durations to scripts so there no way to know in advance how long a note will be. In essence live playing and playback look the same to scripts - they cannot look into the future. Whether this is good or bad depends on your taste. Being able to do automatic keyswitching based on note length (determined on 'note on') would be interesting. On the other hand this would lead to music being played back in a different way than it sounded like when it was recorded, which some think is bad. Personally I think it would be nice to have a choice.

The %NOTE_DURATION variable represents the time passed since the note-on. It's possible to use this in both 'on note' and 'on release'. However, it's probably not useful for keyswitching. Btw - Bob, is the wait function after the keyswitch really necessary in the script above?

Cheers,
Nils


----------



## br1252 (May 3, 2006)

I would think that a "wait" would be necessary if the synth needs to get the notes in the correct sequnce and have enough time to switch. I have noticed this in regular sequencing, that you need a couple of ticks between keyswitch and the next note to get it to work right.

-- Bob


----------



## kotori (May 3, 2006)

br1252 @ Wed May 03 said:


> I would think that a "wait" would be necessary if the synth needs to get the notes in the correct sequnce and have enough time to switch. I have noticed this in regular sequencing, that you need a couple of ticks between keyswitch and the next note to get it to work right.
> 
> -- Bob


Hi Bob,
I see what you mean. But I don't think the wait function is necessary in this case. AFAIK the only thing that matters is the order in which the notes are played. 

Nils


----------

