1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Zone dependent Round Robin by script

Discussion in 'Scripting Workshop' started by FW Instruments, Nov 4, 2016.

  1. FW Instruments

    FW Instruments New Member

    Messages:
    20
    I ever wanted to have this but just found a similar solution which cycles randomized – that could not exactly meet my requirements for the reason it doesn't work well if your cycle chain consists of only 3 samples. After many tries I finally managed to write a script for a cycle round robin.

    I like to share it, because I guess that could be of interest for fans of old analog gear. Here it is:

    on init
    message ("")
    declare $count_808hihat:=0
    declare %count_808hihat[4] := (0, 127, 84, 42 ) {because of the way indexes are being counted I atarted with 0 and made it a 4-fold array}
    end on

    on note
    if ($EVENT_NOTE = 38)
    if ($count_808hihat#4)
    inc($count_808hihat)
    end if
    if ($count_808hihat=4)
    $count_808hihat:=1
    end if
    change_velo($EVENT_ID,%count_808hihat[$count_808hihat])
    message ("Velocity: " & %count_808hihat[$count_808hihat]&", Cycle Position: "&$count_808hihat)
    end if
    end on
     
    Last edited: Nov 5, 2016
  2. David Das

    David Das Moderator Moderator

    Messages:
    7,060
    Moving this to the scripting forum.
     
  3. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    That's not really randomized, though, it cycles from 1 to 3 all the time, but not randomly.
     
  4. FW Instruments

    FW Instruments New Member

    Messages:
    20
    Oh, I see what I wrote in the first sentence is totally misleading. I wanted to say that I just found instructions for this randomized cycling but wanted to have the cycle round robin. Sorry for that, guys! Corrected it. The problem is: At a number of 3 samples randomize cannot do different, than flip flop back and forth between 2 of the samples sometimes. Thus is it nicer to cycle round through it.
     
    Last edited: Nov 5, 2016
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You can write it in a simpler way, too. There's no need to count from 1 to 4, you can count from 0 to 2 and have a regular array with 3 indices, not 4. It is also possible to make a non-repeating random script (also known as Fisher-Yates shuffle), but that's a bit more complicated.

    Here's your code simplified, and this will also work for every key (provided you have exactly 3 RR on each key and same zone velocity splits):

    Code:
    on init
        declare %rr_count[128]
        declare %rr_vel[3] := (127,84,42)
        message("")
    end on
    
    on note
        change_velo($EVENT_ID,%rr_vel[%rr_count[$EVENT_NOTE]])
        if (%rr_count[$EVENT_NOTE] >= 2)
            %rr_count[$EVENT_NOTE] := 0
        else
            inc(%rr_count[$EVENT_NOTE])
        end if
    end on
    If you have a different number of RR on different keys, that can be worked around, too, by storing the number of RR per key in another array, then testing against that. Then if (%rr_count[$EVENT_NOTE] >= 2) would look something like if (%rr_count[$EVENT_NOTE] >= %rr_num[$EVENT_NOTE] - 1)
     
    Last edited: Nov 5, 2016
  6. FW Instruments

    FW Instruments New Member

    Messages:
    20
    Cool! This way its a cleaner solution. Thank you! Also for pointing me to Fisher-Yates, which I'll try to grasp.
     
  7. dougalex1

    dougalex1 NI Product Owner

    Messages:
    16
    I want to utilize the script to play back vocal phrases, one syllable at a time, by repeated press of one keyboard key. (Multiple phrases assigned to different keys).
    I would like the script to always "reset to play the beginning sample in the chain" if any other key is pressed (so if I do not complete a phrase by mistake, it is still guaranteed to reset to start at beginning sample next time I come back to that key)

    Will that script work for that purpose? (with modification to add my reset feature)
    Do I just paste it in a empty scripts module?
    Does a new "Group start option" then appear related to this script?

    Or, based on my questions, do you think I really need to either (a) hire an experienced programmer, or (b) I should take a course. ;)