Skip to content

Instantly share code, notes, and snippets.

@uniphonic
Forked from austensatterlee/roundrobin.ksp
Created December 11, 2015 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uniphonic/6beaf47a8943c5605c56 to your computer and use it in GitHub Desktop.
Save uniphonic/6beaf47a8943c5605c56 to your computer and use it in GitHub Desktop.
Kontakt Round Robin Script
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