i created a script for generating unison duets with garritan personal orchestra, but it could in principle be used iwth other chromatically sampled libraries.
unfortunately, you need kontakt2 full version in order to use it.


load this script with a solo instrument patch, like violin 1 solo, trumpet 1 solo, etc.

now, if you play a single note, the note is doubled with the same tune, allowing
to play a unison duet as you were playing two solo instruments at once!
but if you keep a note held, and play a second note, you will be playing
two singles note NOT in unison!, so that the "duet polyphony" is still 2, and you will
still have only two voices playing, not 4!

this script should save you from doubling instrments in Kontakt 2 and in the midi sequencer!
you would be albe (if everything works correctly!!) to handle two instruments lines (like 2 flutes, 2 trumpets... parts) within a single MIDI track, maintaining a certain degree of realism.

you can randomize the velocity, the delay, the volume and the tuning of the unison
generated notes, and set the pan for the two instruments playing the duet

this script was tested with garritan orchestra (K2 patches), and it still lacks a lot
of improvements., like:
- if you release the second note and hold the first, a unison note should be generated
- you should be able to set instrument range, as well as the difference in semitones
of the unison-generated-note (applications to non-chromatic sampled instruments)
- the original idea was to create ensambles of 3 or 4 instruments, for use for example with brass patches. i will try to improve it! ;-)
- it didn undergo to a deep test, but GPO controllers sould works as usually! (damn, i did it in 2 hours
after dinner!! the version is 0.1!)

comments and suggestion are welcome!


download it from here:

http://www.alchemystudio.it/docs/duet_maker.nkp

the full script, with comments:

PS: i'm not a serious programmer... maybe there are other and better ways to this... :-)


{
DUET MAKER 0.1
CREATED BY MATTEO BOSI

This script permits to play a real duet using chromatic sampled solo instruments

load a solo instrument patch - e.g. a violin, trumpet, flute
and load this script into K2 script editor
now, if you play a single note, the note is doubled with the same tune, allowing
to play a unison duet.
now, if you keep a note held, and play a second note, you will be playing
two singles note NOT in unison!, so that the "duet plyphony" is still 2, and you will
still have only two instruments playing, not 4!

you can randomize the velocity, the delay, the volume and the tuning of the unison
generated notes, and set the pan for the two instruments playing the duet

this script was originally tested with garritan orchestra, and it still lacks a lot
of improvements., like:
- if you release the second note and hold the first, a unison note should be generated
- you should be able to set instrument range, as well as the difference in semitones
of the unison-generated-note (applications to non-chromatic sampled instruments)

comments and suggestion are welcome!
write me at matteo@alchemystudio.it and visit my website! www.alchemystudio.it}

on init

declare polyphonic $note1
declare polyphonic $note2
declare polyphonic $note3
declare $polyphony
declare $polyphony2
declare $temp:=0
declare $temp2:=0
declare %bank [8]
declare %bank2 [8]
declare $index:=1
declare $index2:=1

declare $random_vel
declare $random_time

declare ui_knob $random_vel_add (0,25,1)
make_persistent ($random_vel_add)
set_text ($random_vel_add, "rand.vel")

declare ui_knob $delay (1,25000,1000)
make_persistent ($delay)
set_text ($delay, "rand.dly")

declare ui_knob $random_vol (0,9000,100)
make_persistent ($random_vol)
set_text ($random_vol, "rand.vol")

declare ui_knob $random_tune2 (0,15000,1000)
make_persistent ($random_tune2)
$random_tune2:=0
set_text ($random_tune2, "rand.tun")

declare ui_knob $pan1 (-1000,1000,100)
make_persistent ($pan1)
$pan1:=-100

declare ui_knob $pan2 (-1000,1000,100)
make_persistent ($pan2)
$pan2:=100

declare ui_label $text (6,1)
move_control ($text,1,3)
set_text ($text,"Duet maker, created by www.alchemystudio.it - play
automatic duets with chromatically sampled solo isntruments")

message ("")

end on

on note
$polyphony2:=0 {polyphony and polyphony2 counts the note polyphony actually playing}
$polyphony:=0
$temp:=0 {temp is a variable used for the polyphony count}
while ($temp<127)
$polyphony:=$polyphony+%KEY_DOWN[$temp]
$temp:=$temp+1
end while

{Generates random velocity for the unison event}

$random_vel:=$EVENT_VELOCITY+random(-$random_vel_add,$random_vel_add)
if ($random_vel>127)
$random_vel:=$EVENT_VELOCITY-random(0,$random_vel_add)
end if
if ($random_vel<127)
$random_vel:=$EVENT_VELOCITY+random(0,$random_vel_ add)
end if

{note handling}

ignore_event($EVENT_ID)
$note1 := play_note ($EVENT_NOTE ,$EVENT_VELOCITY,0,-1)
change_pan ($note1,$pan1,-1) {play the first note played only by changing pan}

wait ($delay) {random delay wait for the generated unison event}

{play a unison notea semitone higher with random velocity}
$note2 := play_note ($EVENT_NOTE+1,$random_vel,0,-1)
change_vol ($note2,random(0,-$random_vol),-1) {randomly change volume of the unison note}
change_pan ($note2,$pan2,-1) {pan change for the unison note}

{the following is tricky: since i have to handle events generated by different
note callbacks, i have to store every single note_id event in order to be able to
address to it even when a new note callback is generated.
In order to do this i create an array - bank[] - and i store the note_id
for the duet generated note in it, using an index which is incremented by one
for every $note2 that is created. i decided arbitrarily to make the array length=8,
for no particular reason. i know i have to better handle when index comes back to 0}

if ($index>=8)
$index:=1
end if
%bank[$index]:=$note2
$index:=$index+1


{now i handle the polyphony. if i have played only one note, then polyphony=1 and i
have to handle the a new duet unison note (=$note2)}

if ($polyphony=1)
change_tune ($note2,-100000+random(-$random_tune2,$random_tune2),1)

{and here i cancel the previous unison note generated,using the bank[] array,
in orded to maintain the polyphony=2}

note_off (%bank2[$index2-1])

{if polyphony>1 it means that i have played two notes on the keyboard, and
i don't need the unison note, so i cancel them!}

else
note_off (%bank[$index-1])
note_off (%bank[$index-2])

{now another tricky part: if i play for example a single notes, followed by
another single note - for example i'm playing a scale - it could happen
that there is overlap between the notes of the scale. the overlay is
seen as polyphony=2, so even if i want two unison note playing a scale, the
script would play 4 notes. So i have to wait for some time and check if the new
note was actually just an overlapping event or if it really a "true" second note}

wait (80000)
$polyphony2:=0 {i count the polyphony again, after a short delay}
$temp2:=0

while ($temp2<127)
$polyphony2:=$polyphony2+%KEY_DOWN[$temp2]
$temp2:=$temp2+1
end while

{if polyphony2=1 it means that there was an overlap between two single notes
and i must generate a new unison event - note3 - and i have to deal with it
with the bank2[] array just as the previous one}

if ($polyphony2=1)
$note3 := play_note ($EVENT_NOTE+1,$random_vel,0,-1)
change_tune ($note3,-100000+random(-$random_tune2,$random_tune2),1)
change_vol ($note3,random(0,-$random_vol),-1)
change_pan ($note3,$pan2,-1)

if ($index2>=8)
$index2:=1
end if
%bank2[$index2]:=$note3
$index2:=$index2+1
else
note_off (%bank2[$index2-1])
end if

end if

end on




{that's all! :-) }