# Simple MIDI delay script?



## TheoKrueger (Mar 29, 2009)

Hello all,

I was wondering if anyone would be kind enough (and with some time on their hands) to post a simple delay script. One which would simply allow you to do the following things:

Chose a sample group from a drop down box.
Chose the delay for the specific group in miliseconds using a knob. (from 0 to 1 second perhaps?) or even an option for syncing with musical time, that would be great.
Store the delay value for each group.

That's it!

Thanks for any help or code! I appreciate it a lot as I believe that this is something missing from Kontakt but yet very needful.

Thanks again,
Theo.


----------



## Thonex (Mar 29, 2009)

Hi Theo,

I think that script is a little more complex than you think. 

For starters, would the release of the notes be delayed as well? I'm guessing yes so that it would behave like an audio delay. So you'd have to delay the releases too. 

Then, since it may be possible for notes that were "played" first to be "played back" 2nd (because of delay settings), you are shuffling the order of play/releases and whatnot. You'd have to keep careful track of what notes were played and then their "delayed" playback/release order.

Then there is the whole keeping track of the groups thing... which may not be easy. In fact, come to think of it, I'm not sure KSP can tell you which group is triggered when you play a note. I think it's the other way around... you tell it which group to allow and you can then display that... since you already know which group you are allowing. (hope this makes sense).

The concept is simple, I think the execution is not so simple... of course... Nils might show up with a brilliant 4 line piece of code that does it all :lol:


----------



## TheoKrueger (Mar 29, 2009)

Hey guys,

Here's a version that I tried making myself by trimming down the Performance -> Humanizer script:



```
on init
	declare ui_knob $Delay (0,100,1)
	$Delay := 0

	declare ui_label $info (1,1)
	set_text ($info, "Delay:")

	declare $new_time

	make_persistent ($Delay)

end on

on note
	ignore_event ($EVENT_ID)

	$new_time := ($Delay * 10000)

	wait($new_time+1)
	play_note ($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)

end on
```

It works, the only problem is that if I hit a note, I have to keep it pressed until the delay time passes for the note to play. If i let go of the note before the delay time has passed the note never plays (not a problem though for sequenced notes... unless they are too short?)

If somebody knows how to correct this one, please chime in!!!

Thanks! 

Theo.


----------



## TheoKrueger (Mar 29, 2009)

Hey thanks Andrew!!! I was doing the same thing just now (Just saw your reply after posting mine by the way)..

Thanks a lot for taking the time to help out, I really appreciate it.

Do you have an idea about the held note issue I described above?

Cheers,
Theo.


----------



## Thonex (Mar 29, 2009)

TheoKrueger @ Sun Mar 29 said:


> It works, the only problem is that if I hit a note, I have to keep it pressed until the delay time passes for the note to play. If i let go of the note before the delay time has passed the note never plays (not a problem though for sequenced notes... unless they are too short?)
> 
> If somebody knows how to correct this one, please chime in!!!
> 
> ...



The script I posted works. You needed to add an "on release" call back with the appropriate delay time. You also need to make your "-1" in the play_)note line be "0"... ie... play until release call back tells it to stop playing.


----------



## TheoKrueger (Mar 29, 2009)

Thonex @ Sun Mar 29 said:


> TheoKrueger @ Sun Mar 29 said:
> 
> 
> > It works, the only problem is that if I hit a note, I have to keep it pressed until the delay time passes for the note to play. If i let go of the note before the delay time has passed the note never plays (not a problem though for sequenced notes... unless they are too short?)
> ...



Andrew, Thanks a million! I appreciate your help. I just tried your script out in Kontakt and it works a charm, the hold/release problem I described also works as it should! 

Plus I like your implementation with the button!

Thanks again o-[][]-o 
Theo.


----------



## Thonex (Mar 29, 2009)

in its simplest form... here is your script as you intended it to work:


```
on init
  message ("")
  declare polyphonic $Delayed_Note
  declare ui_knob $Delay_ms (0,1000,1)
  $Delay_ms := 0 
  make_persistent ($Delay_ms) 
end on

on note
  ignore_event ($EVENT_ID)
  wait(($Delay_ms * 1000)+1)
  $Delayed_Note := play_note ($EVENT_NOTE, $EVENT_VELOCITY, 0, 0)
end on

on release  
  ignore_event ($EVENT_ID)
  wait(($Delay_ms * 1000)+1)
  note_off ($Delayed_Note)
end on
```


----------



## TheoKrueger (Mar 29, 2009)

Thanks again Andrew,

Exactly what I was looking for. This will find a lot of uses 

Cheers,
Theo


----------

