Script for Random Round Robins position w/ two microphones

Babble Member Posts: 1 Newcomer
edited July 2022 in Scripting Workshop

Infant scripting child here, so please be gentle. I'm trying to accomplish something fairly simple, which involves keeping my first five groups (1-5 (mic A)) , and my second set of five groups (6-10 (mic B)) together via their respective round robin position (ie RR position 1 is used for groups 1 & 6, RR position 2 is used for 2 & 7) but using code so that they cycle randomly while not repeating the last sample just played. David Hilowitz had posted a video on this subject, and I've read through some of the other threads, but I still can't find a method that works given the constraints.

on init




declare $mouse_resp := -900


declare ui_slider $NEAR(0,1000000)


declare $k_NEAR

$k_NEAR := get_ui_id($NEAR)





declare ui_slider $Far(0,1000000)


declare $k_Far

$k_Far := get_ui_id($Far)





declare %rr_index[10] := (0,1,2,3,4,5,6,7,8,9) {not sure num is needed}

declare %rr_index_prev[10] := (0,1,2,3,4,5,6,7,8,9) {this may be incorrect}

end on

on ui_control($NEAR)

set_engine_par($ENGINE_PAR_VOLUME, $NEAR, -1, -1, $NI_BUS_OFFSET + 0)

end on

on ui_control($Far)

set_engine_par($ENGINE_PAR_VOLUME, $Far, -1, -1, $NI_BUS_OFFSET + 1)

end on

on note

if (rr_random = 0) {I get an error here saying ) expected}

%rr_index[$EVENT_NOTE] := %rr_index[$EVENT_NOTE] + 1

if %rr_index[$EVENT_NOTE] >= $MAX_RR

%rr_index[$EVENT_NOTE] := 0

end if


%rr_index_prev[$EVENT_NOTE] := %rr_index[$EVENT_NOTE]

while %rr_index[$EVENT_NOTE] = %rr_index_prev[$EVENT_NOTE]

%rr_index[$EVENT_NOTE] := random(0, $MAX_RR-1)

end while

end if


allow_group(%rr_index[$EVENT_NOTE]) { Close? }

allow_group(%rr_index[$EVENT_NOTE] + 10) { Far? }

message("note -> " & $EVENT_NOTE & " / vel = " & $EVENT_VELOCITY & " / rr = " & rr_index[$EVENT_NOTE])

end on


  • EvilDragon
    EvilDragon Moderator Posts: 947 mod

    Please read the sticky about how to post code around here. 😊

    As to your question - you're going in the right direction, but you probably need to just do + 5 instead of + 10 in that second allow_group(), if you have 5 RR groups per mic.

  • neonfeather
    neonfeather Member Posts: 4 Newcomer

    Hey Babble - code noob here as well. I was adapting your code to fit my situation and I got the error in the same spot you pointed yours out. Did you ever solve the error in that line and if so could you share the solution with me? Thank you!

  • brooklynjared
    brooklynjared Member Posts: 5 Newcomer
    edited December 2022

    Not sure about this, but in the on note callback, where is rr_random coming from? It doesn't look like it's been declared anywhere

  • neonfeather
    neonfeather Member Posts: 4 Newcomer

    Good catch - I declared it but wasn't sure what value to give it. In my case I want 4 round robins so I put 4. The code didn't get any errors, but when I press a note it takes a good half second to crunch some huge array before outputting a note (and every output resulted in rr0). While it was processing the array I saw a message at the very bottom of the Kontakt window saying something about the array being out of bounds or something.

  • brooklynjared
    brooklynjared Member Posts: 5 Newcomer

    You probably need to assign it a random value if you want random RRs. So use this plus the range of RRs you have to give it a value. Maybe?

  • neonfeather
    neonfeather Member Posts: 4 Newcomer

    Thank you so much for jumping in to help Jared. This morning I managed to achieve my desired result by using a different code resource I had found and combining it with Babble's idea to add a second "allow group" line with "+4". Worked like a charm - it now randomizes groups 1-4 and triggers the respective group 5-8 alongside it. Beautiful.

    I wanted to share how my code ended up looking, but every time I click "post comment" it does nothing (code is properly formatted too). If I can get it to work I'll share it here!

  • neonfeather
    neonfeather Member Posts: 4 Newcomer

    Trying again - here's what my code ended up looking like:


    on init
    declare %list[4]	
    declare $at := num_elements(%list)	
    declare $x	
    declare $last	
    end on
    on note
    if($at >= num_elements(%list))	
    $last := %list[num_elements(%list) - 1]	
    %list[0] := 0	
    $at := 1	
     while($at # num_elements(%list))	
     $x := random(0, $at)	
     %list[$at] := %list[$x]	
     %list[$x] := $at	
     end while	
    $at := 0	
     if(%list[0] = $last)	
     %list[0] := %list[num_elements(%list) - 1]	
     %list[num_elements(%list) - 1] := $last	
     end if	
    end if	
    end on	

Back To Top