# Realistic instrument: script for random-without-repeat sample on "zone level"?



## armän (Mar 19, 2008)

hello
I´d like to program a quite lively instrument with round robin/random-without-repeat sample on "zone level". Kontakt has round robin on group level but in a few cases that´s not enough: as the groups cycle through globally, that means if I have e.g. 4 different samples per note (each sample in 1 of 4 groups) and I play repetatively 4 notes, c,d,e,f, each time the same note is reached the same sample would be played. To avoid that I´d like to have a script that says: each time a certain note is hit, choose any of following specific samples: "..." randomly and play back, but not any of the samples that were played the 2 times before when that certain note was reached. So the script should "memorise" the 2 last samples that where played on that note.
So far to my goals in this case... 
thanx for ideas
in another forum I had some suggestion to that:

"The script language doesn't give any special access to zones, but if one knows how they are mapped one can use the note number and velocity of the incoming notes to determine the layer and switch between groups based on that.

By hard-coding the velocity layer ranges into the script or by providing the user with an interface with which it can be set, it is possible to write a round-robin script that works per zone. It's not overly complicated to write a script like that. I suggest you take your question over to the VI-Control forum. There have been some scripts posted there which implements random-without-repeat sample alternation, although not yet on the zone level as far as I know."


----------



## Thonex (Mar 19, 2008)

HI Arman,

Welcome to the forum :D 

This could be fairly easily done with an array and some code as follows (I haven't tested this code... this is just to get you started... but may work as-is):


*on init*
```*declare* %Note_counter [128] _{this would track the round robin of each indevidual note on the keyboard}_
*end on*

*on note*
```
```ignore_event ($EVENT_ID)
```disallow_group ($ALL_GROUPS)
```allow_group (%Note_counter [$EVENT_NOTE])
```play_note ($EVENT_NOTE, $EVENT_VELOCITY, 0, -1)
```%Note_counter [$EVENT_NOTE] := (%Note_counter [$EVENT_NOTE] + 1) mod 4 _{this gives a circular increment fr the next time that note is played}_
```
*end on*


----------



## kotori (Mar 19, 2008)

armän, when you say "zone-level" do you mean note-level or sample-level (=zone-level)?
Is there any real advantage in applying it to the zone-level rather than to the note-level as Thonex did above?


----------



## armän (Mar 20, 2008)

Hi Thonex
thanx for your quick programming skills! 
Hi kotori, nice to meet you here! (kotori programmed another nice script here:
http://www.native-instruments.com/forum ... hp?t=63077 )

I tested the script, maybe it´s really close... it cycles through the groups, but then after some notes I hear nothing, it may trigger groups that don´t exist (..I don´t know, I´m very new to scripts.. :oops: ).. 
do I understand the script corectly: it tells each key which of 4 groups should be triggered next (the next one in the round from the one that was played before on that note)? Then yes, it would work in that way I think...

In that case an advantage I can see in having it on sample-level (=zone-level) is that each note could have independent numbers of samples to trigger (?), the one would have y cycle of 3, the other 5.. but I´m fine if I have a fixed number (lest´s say 4) of samples per every note.
Another advantage of zone-level would be that we could use the groups for any other function..


----------



## Thonex (Mar 20, 2008)

armän @ Thu Mar 20 said:


> I tested the script, maybe it´s really close... it cycles through the groups, but then after some notes I hear nothing, it may trigger groups that don´t exist (..I don´t know, I´m very new to scripts.. :oops: )..
> do I understand the script corectly: it tells each key which of 4 groups should be triggered next (the next one in the round from the one that was played before on that note)? Then yes, it would work in that way I think...



I think you understand the script correctly. Each "note" on the keyboard has it's own RR counter that enables groups incrementally... in a circular pattern.

A couple of reasons you might nothear some notes is that there are less groups than there are increments in the round robin. Try changing the 4 (second to last line of code) to a 3 or a 2 (however many groups you cycle between).

Also, make sure to bypass Kontakt's 'built in' Round Robin feature.

Hope this helps.

T


----------



## kotori (Mar 20, 2008)

armän @ Thu Mar 20 said:


> an advantage I can see in having it on sample-level (=zone-level) is that each note could have independent numbers of samples to trigger (?), the one would have y cycle of 3, the other 5.. but I´m fine if I have a fixed number (lest´s say 4) of samples per every note.
> Another advantage of zone-level would be that we could use the groups for any other function..



Using different number of cycles for different velocity layers is perhaps not so common, but actually not a bad idea. It's can be good to concentrate on the velocity layers used more often.

The last sentence I don't understand. Do you mean that one would discard velocity layers and instead use the layers for cycling through similar samples? By zone-level alternation I meant cycling dependant on which zone was triggered, not alternation between zones (which one get in either case).


----------



## armän (Mar 20, 2008)

I found out some logic thing about the hearing nothing issue.. when I start on one note and press it 4 times I can go to the next note, press it 4 times and so on, it cycles through the 4 groups, fine. But if I´m playing that first note only 3 times, then pressing any other key I won´t hear anything, and going back to the first key no sound appears unless I press that second key a multiple of 4 times (these times are counted even if any other key is hit inbetween.. but then the logic get really complex because only if all 4 groups are counted through on every note that was hit, the sound will appear again :? ) thx for ideas..


----------



## armän (Mar 20, 2008)

I ment that if we don´t need groups for cycling as we may be able to use some script that cycles through samples per note, the "group feature" could be used for something else.. yes, I understood the idea to discard velocity layers and instead use the layers for cycling through similar samples... hope I understand your question, kotori. 
And using independant number cycles for individual velocity layers would be the really cool thing, I´m glad if we manage the "per note" thing..


----------

