Last active
December 11, 2015 13:36
-
-
Save austensatterlee/c565bd311a1fcde5e334 to your computer and use it in GitHub Desktop.
Kontakt Round Robin Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on init | |
declare $last_groupid := -1 | |
declare $new_groupid | |
declare $N | |
end on | |
on note | |
$N := $NUM_GROUPS | |
disallow_group($ALL_GROUPS) | |
{ Check if a note has been played yet } | |
if($last_groupid = -1) | |
$new_groupid := random(0,$N-1) | |
else { Choose a random group, excluding the last group we selected } | |
$new_groupid := random(0,$N-2) | |
{ | |
This is our way of mapping the numbers 0...$N-2 | |
to our set of acceptable group id's. | |
If we have 4 groups, and we chose group 2 last time, | |
this will create the following mapping: | |
In Out | |
------------ | |
0 -> 0 | |
1 -> 1 | |
2 | |
2 -> 3 | |
3 -> 4 | |
} | |
if($new_groupid >= $last_groupid) | |
{ | |
Increment the number we chose by one to exclude | |
the last group id from our selection space | |
} | |
inc($new_groupid) | |
end if | |
end if | |
allow_group($new_groupid) | |
{ Uncomment the next line to show last group played, and current group played } | |
{ message($last_groupid & ", " & $new_groupid) } | |
{ Reassign last_groupid } | |
$last_groupid := $new_groupid | |
end on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment