# Scripting “Scripted” legato?



## Wenlone (Dec 3, 2020)

Hello all,

I want to script my own legato. I’m aware of SIPS and factory scripts. Not that they don’t work for me but I want to learn how to do it myself.

I did something that linearly crossfades volume and tune between notes depending on the interval. It’s velocity and speed responsive. So I came this far. It sounds better than I expected

I didn’t share my script because I want a fresh start, another perspective. For those who did scripted legato before, are there any tips, tricks, resources? Anything is appreciated. Even a very small hint.

Thank you in advance.


----------



## EvgenyEmelyanov (Dec 3, 2020)

Depending on what samples you work with. For instance, we scripted a good-sounding portamento for pluck-sounding instruments (guitars, bass, uke, etc). But it *does not* work for sustained strings. IMO, it's not really possible to emulate good legato for sustained strings with only crossfades or pitch-modulating. It should be some kind of "mathematical-physical modeling" or something. In short, true-legato is easier.


----------



## Wenlone (Dec 3, 2020)

EvgenyEmelyanov said:


> Depending on what samples you work with. For instance, we scripted a good-sounding portamento for pluck-sounding instruments (guitars, bass, uke, etc). But it *does not* work for sustained strings. IMO, it's not really possible to emulate good legato for sustained strings with only crossfades or pitch-modulating. It should be some kind of "mathematical-physical modeling" or something. In short, true-legato is easier.


Of course, it depends on the sample content. I am gonna use this in almost any kind of sounds including plucks, winds, strings. Even without physical modeling or real legato, I am pretty sure I can achieve decent results. I am experimenting


----------



## taha (Dec 6, 2020)

check this out 






Kontakt Scripting Video Tutorial Collection


The complete collection of David Healey's original Kontakt scripting tutorial video series. Featuring four lessons to turn you into a Kontakt script ninja.




xtant-audio.com


----------



## Wenlone (Dec 6, 2020)

taha said:


> check this out
> 
> 
> 
> ...


Thank you. Great series for learning Kontakt scripting. But I already finished them all. He covered real legato script, but no scripted/fake legato.


----------



## taha (Dec 6, 2020)

Wenlone said:


> Thank you. Great series for learning Kontakt scripting. But I already finished them all. He covered real legato script, but no scripted/fake legato.



try this
move it to {WIN USERS}

C:\Users\<computer name>\Documents\Native Instruments\Kontakt\presets\Scripts

then you will find it in the user menu in kontakt script

source 



Solo Instrument Performance Suite


----------



## d.healey (Dec 6, 2020)

Read section 4.6 it will give you some good tips for writing your own.


----------



## Wenlone (Dec 6, 2020)

d.healey said:


> Read section 4.6 it will give you some good tips for writing your own.


Thank you, David Healey. That was exactly the type of thing I've been looking for. There are some great tips!


----------



## d.healey (Dec 6, 2020)

I also just remembered, HISE has a built in synthetic legato module, the source code is in C++ but it's really simple so it shouldn't be too difficult to convert to KSP. Search this file for the LegatoProcessor class.
https://github.com/christophhart/HI...cripting/scripting/HardcodedScriptProcessor.h


----------



## Wenlone (Dec 6, 2020)

d.healey said:


> I also just remembered, HISE has a built in synthetic legato module, the source code is in C++ but it's really simple so it shouldn't be too difficult to convert to KSP. Search this file for the LegatoProcessor class.
> https://github.com/christophhart/HI...cripting/scripting/HardcodedScriptProcessor.h


Thank you again, I'll take a look. 

I also found one of your topics on HISE forum. Well commented code. Looks like I can learn few things from there too. https://forum.hise.audio/topic/228/synthetic-legato


----------



## d.healey (Dec 6, 2020)

Wenlone said:


> Thank you again, I'll take a look.
> 
> I also found one of your topics on HISE forum. Well commented code. Looks like I can learn few things from there too. https://forum.hise.audio/topic/228/synthetic-legato


Yeah I have a few such scripts floating around, they are GPL licensed though so can only be used in other projects with a compatible license.


----------



## raidmarji (Dec 7, 2020)

Unisono-Portamento script is the best legato for synth but a difficult one to understand


----------



## taha (Dec 7, 2020)

this may help as well 

simple portamento script


```
{---simple portamento script-------}
on init
message("")

declare const $pitch_change_interval := 100

declare $glide_on
declare $currentnote_id
declare $newnote_id
declare $oldnote1_id
declare $oldnote2_id
declare $oldnote3_id
declare $current_pitch
declare $target_pitch
declare $pitch_shift
declare $actual_glide
declare $interval_cents

declare polyphonic $this_id

declare ui_knob $Glide(1000, 1000000, 1000000)
declare ui_knob $Start(0, 1000000, 1000000)
declare ui_knob $Scaling(100, 200, 100)

declare ui_value_edit $Threshold(0, 127, 1)


$Glide := 120000
$Start := 5000
$Scaling := 125
$Threshold := 12

move_control($Glide,1,1)
move_control($Start,2,1)
move_control($Scaling,3,1)
move_control($Threshold,4,1)

make_persistent($Start)
make_persistent($Glide)
make_persistent($Scaling)
make_persistent($Threshold)



end on

on note
if ($glide_on=1)
ignore_event($EVENT_ID)
$newnote_id := play_note($EVENT_NOTE,$EVENT_VELOCITY,$Start,-1)
$this_id := $newnote_id
change_tune($newnote_id,$current_pitch-($EVENT_NOTE*100000),0)
$target_pitch := $EVENT_NOTE*100000
$interval_cents := abs($target_pitch/1000-($current_pitch/1000))

if ($interval_cents>($Threshold*100))
$interval_cents := $Threshold*100
end if

$actual_glide := $Glide+($Glide*$interval_cents/1200*($Scaling-100)/100)
fade_out($newnote_id,0,1)
fade_in($newnote_id,$actual_glide)
fade_out($currentnote_id,$actual_glide,1)
note_off($oldnote3_id)

$oldnote3_id := $oldnote2_id
$oldnote2_id := $oldnote1_id
$oldnote1_id := $currentnote_id
$currentnote_id := $newnote_id
$pitch_shift := ($target_pitch-$current_pitch)/($actual_glide/$pitch_change_interval)

wait($pitch_change_interval)

while (abs($target_pitch-$current_pitch)>abs($pitch_shift))
if ($currentnote_id=$this_id)
change_tune($currentnote_id,$pitch_shift,1)
change_tune($oldnote1_id,$pitch_shift,1)
change_tune($oldnote2_id,$pitch_shift,1)
change_tune($oldnote3_id,$pitch_shift,1)

$current_pitch := $current_pitch+$pitch_shift

wait($pitch_change_interval)
else
exit
end if
end while

if ($currentnote_id=$this_id)
$pitch_shift := $target_pitch-$current_pitch
change_tune($currentnote_id,$pitch_shift,1)
change_tune($oldnote1_id,$pitch_shift,1)
change_tune($oldnote2_id,$pitch_shift,1)
change_tune($oldnote3_id,$pitch_shift,1)
$current_pitch := $target_pitch
end if

else
$currentnote_id := $EVENT_ID
$current_pitch := $EVENT_NOTE*100000
$glide_on := 1
end if
end on

on release
if ($EVENT_ID=$currentnote_id)
$glide_on := 0
note_off($oldnote3_id)
note_off($oldnote2_id)
note_off($oldnote1_id)
$current_pitch := $target_pitch
end if

if ($glide_on=1 and ($EVENT_ID # $oldnote3_id))
ignore_event($EVENT_ID)
wait($Glide)
note_off($EVENT_ID)
end if


end on
```


----------



## Wenlone (Dec 7, 2020)

taha said:


> this may help as well
> 
> simple portamento script
> 
> ...



Sounds very similar with what I wrote. But it's a bit different approach. One thing I noticed with this script is with higher portamento time it's more responsive to faster playing. Thank you.


----------



## raidmarji (Dec 7, 2020)

Wenlone said:


> Sounds very similar with what I wrote. But it's a bit different approach. One thing I noticed with this script is with higher portamento time it's more responsive to faster playing. Thank you.


Can you share it?
[email protected]
And I’ll send you a nice one that I use


----------



## Wenlone (Dec 7, 2020)

raidmarji said:


> Can you share it?
> [email protected]
> And I’ll send you a nice one that I use



Hi, I am still working on it. It's not working perfectly, but once I am done I will share it with everyone here. I can still send you the unfinished version tomorrow if you want.


----------



## raidmarji (Dec 8, 2020)

Wenlone said:


> Hi, I am still working on it. It's not working perfectly, but once I am done I will share it with everyone here. I can still send you the unfinished version tomorrow if you want.


Great, so we can share new ideas


----------



## raidmarji (Dec 8, 2020)

taha said:


> this may help as well
> 
> simple portamento script
> 
> ...



This simple script is not good for Synth sounds, it is created by fizbin in 2005. Some companies used it like Ethnaudio


----------

