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

Cycle random samples within one group ?

Discussion in 'Scripting Workshop' started by hifi3000, Nov 15, 2009.

Thread Status:
Not open for further replies.
  1. hifi3000

    hifi3000 NI Product Owner

    Messages:
    47
    Hey,

    i am absolutely new to scripting and it´s possibilities. And i have a question.
    Is it possible to have a cycle-random function within one group and its samplezones content? I understand that i could choose different groups for every sample i got and then go with the cycle-random feature which is already there.

    Now here´s the problem. What i want to do is to sample one of my hardware-synths. As it is a analog one, the same note sounds a little different with every single hit. So i plan to sample lets say 4 samples for every key (no velocity switching). Next i would like to give every key its own group. Having 4 samples for every key, i would like to bring kontakt to play the four samples in a random way and only one of the 4 samples at a time. At the end i have a little of what the synth does all the time. Nice little differences for every note i play.

    As i understand it, the cycle random feature on group-level can´t help. Could i achieve this by the possiblities of scripting?

    I am grateful for every advice.

    Thanks in advance.
     
  2. David Das

    David Das Moderator Moderator

    Messages:
    7,060
    If you wanted to do it in scripting, you could do that, but the easier way to do it would be to split the 4 "takes" of each notes into separate groups, then set the Group Start options for each group to cycle random.
     
  3. hifi3000

    hifi3000 NI Product Owner

    Messages:
    47

    Thanks for your fast reply,

    yeah, i tried it that way. But this works only if we are talkin about one key. Imagine a full oktave. The problem with the group feature is, that if you have more then one key, you can´t bring kontakt to make differences between the two or more keys.

    Here is what i did. Importing key one. 4 samples so i set up 4 groups. As long as it is this key, everything is fine. Now importing key 2. As for key 1 setting up 4 groups. The first problem occurs, now i got 8 groups, 4 belonging to key 1 and the other belonging to key 2.
    Having them all set to cycle-random means that playing key 1 on the keyboard cycles through all groups. If the cycle reaches one of the groups of key 2 you get no sound. Which is logical as it tries to play a group that has no content on the key i am playing. So this is useless as there are 4 possible gaps for each of the two keys (12 keys x 4 groupes = 44 possible gaps per oktave :D ). If i could dedicate groups to certain keys it probabaly would be possible, but unfortunately you can´t.

    So the script in question should be able to manage groups (one for each key) with more than one samplezone for each of the groups. Next cycling the zonescontent of each group randomly, only one zone per group at a time and independently of every other group.

    Would that be possible ? Or am i still missing something ?

    Thanks again.
     
  4. kotori

    kotori NI Product Owner

    Messages:
    1,153
    The script required to achieve the same thing is not overly complex though:

    on note
    change_velo($EVENT_ID, random(1, 127))
    end on

    ;)
     
  5. hifi3000

    hifi3000 NI Product Owner

    Messages:
    47
    hey kotori,

    is that the answer to my second post? Really? As is said i´ve never used the scriptfeature. Say it is that simple :D .
     
  6. kotori

    kotori NI Product Owner

    Messages:
    1,153
    Well, as you may have guessed by the post time I actually wrote it before that post. I'm not sure what you mean when you say that you want to random alternation to occur independantly for each group. If you map the samples among which you want to alternate evenly over the 1-127 velocity range then the script above will pick a random velocity for each note and hence trigger a random sample. If multiple groups are activated at the same time (by one and the same midi note) then the same velocity will be used for all groups since the randomization occurs per note event. If that's a problem it's possible split up the incoming note into multiple outgoing notes each with their own velocity and have them each activate certain groups.

    Btw. mapping the alternations to velocity layers would of course make it impossible to use velocity for modulation purposes.
     
  7. hifi3000

    hifi3000 NI Product Owner

    Messages:
    47
    Yeah, you are right. The bad thing about it is that one is loosing velocity to modulate volume or having a corresponding velocityzone to the samples. Thats not my goal. I would like to achieve to have 4 samples for every key. The samples are overlapping meaning every sample reaches from velo 0 to velo 127. Now playing one key should play a different of the four samples with every hit no matter what velocity actually is recieved. That way covering the little differences in attack and phase of the original synth.
    Even when playing a chord i want the script to choose which sample to play for every key pressed. But in a random way. Lets say playing the chord ones it goes:

    Key one (Samples A1-A4): plays A2
    Key two (Samples B1-B4): plays B1
    Key three (Samples C1-C4): plays C4

    and on next pressing the chord the script chooses:

    Key one: plays Sample A1
    Key two: plays Sample B4
    Key three: plays Sample C1

    But the script has to know which Samples are belonging to which key. So my guess is, it would be necessary to have one group for each key and than having the script monitoring and selecting which sample is played for every key (group) pressed.
    I hope this is possible.

    Ok. With the possibilies i´ve been given i could achieve that behavior like this:

    1) Setting up a ful instrument for every key i want to sample. Lets say a octave, makes 12 instruments.
    2) Setting every instrument to the same midichannel
    3) Within every instrument having the samples of the key mapped to the same apropriate key. Every Sample has its own group. Groups are cycling randomly. As the different keys are mapped to theire own instrument i have what i want. Every note i press will trigger a different of its samples with every time i press it and the keys are independant because they are arranged in different instruments, so the groups can not come into conflict.

    But that is not elegant plus you would need a full kontakt instance to have 64 keys playing that way. Having that imagenary script i would need one instrument with all 64 keys samplecontent in it. And the script is taking care of the sample playorder of every key. That would be it.

    Was i clear(er)? I hope so. Do you think there is a script?

    Thanks a lot!
     
  8. kotori

    kotori NI Product Owner

    Messages:
    1,153
    I wrote a little script for you that you can perhaps use as a starting point:

    Code:
    on init  
      declare const $RANGE_LEFT := 60 { middle C }
      declare const $RANGE_RIGHT:= 62 { the D closest to the middle C }
      declare const $NUM_ALTERNATIONS := 4 { number of groups per key }
      declare $group
    end on
    
    on note
      if (in_range($EVENT_NOTE, $RANGE_LEFT, $RANGE_RIGHT))
        { calculate group index }
        $group := ($EVENT_NOTE - $RANGE_LEFT) * $NUM_ALTERNATIONS + random(0, $NUM_ALTERNATIONS-1) 
        
        { activate only the selected group }
        disallow_group($ALL_GROUPS)
        allow_group($group)
      end if
    end on
    
    The script assumes the following mapping: an instrument with three notes - middle C, C# and D. Each note has four groups and the groups are entered in the order of the notes (starting with low notes and ending with high ones). For example, this instrument could have the following groups:
    C variation 1
    C variation 2
    C variation 3
    C variation 4
    C# variation 1
    C# variation 2
    C# variation 3
    C# variation 4
    D variation 1
    D variation 2
    D variation 3
    D variation 4

    If you want to change the number of variations for each note or the key range you can just modify the three constants at the top of the script. I hope this helps.

    In case you try to dechiper the script it's good to be aware of that group indices in KSP are zero-based. So the first group has index 0, the second group has index 1 and so on.
     
  9. hifi3000

    hifi3000 NI Product Owner

    Messages:
    47
     
  10. kotori

    kotori NI Product Owner

    Messages:
    1,153
    You know, I did exactly that for the Cinesamples Drums of War script. It features round-robin per note AND velocity layer.

    As of late this has gotten easier to implement since NI increased the maximum size of KSP arrays (lists).
     
  11. hifi3000

    hifi3000 NI Product Owner

    Messages:
    47
    Hey kotori,

    just wanted to say that the script works perfectly well. Thanks a lot. And as i found out even velocity switching is no problem. As long as the samples are straightly mapped to theire corresponding groups, everything is workin´absolutely perfect. Great!

    Now, writing this, i think about what is gonna happen, if i choose to have not every key sampled. Didn´t checked it. But lets say you sample C3 with 4 Samples but the keyzone is C3 to E3. So the sampler pitches the samples. But i guess that wouldn´t bring any advantage in terms of saving time, as one would still need to map all 4 samples 6 times to the specific keys and groups to have the script doing it´s job, right?. I will ckeck it.

    And have you been involved in the production of "drums of war" or tuned your copy of it?

    Cheers.
     
  12. kotori

    kotori NI Product Owner

    Messages:
    1,153
    I'm glad it worked well for you.

    If you want more flexibility you can replace the line "$group := ($EVENT_NOTE - $RANGE_LEFT) * $NUM_ALTERNATIONS + random(0, $NUM_ALTERNATIONS-1)" by something like:

    Code:
      select ($EVENT_NOTE)
        case 60 to 62 { any note between middle C and the D next to it }
          $group := find_group("<< name of group with first alternation - sample type 1 >>") + random(0, $NUM_ALTERNATIONS)
        case 63 to 72  { any note in the rest of the octave }
          $group := find_group("<< name of group with first alternation - sample type 2 >>") + random(0, $NUM_ALTERNATIONS)
      end select
    (You would need to replace the group name placeholders with the corresponding names of the first variation for each type of sample)

    This way you can also customize the number of alternations per key range. By adding some variables one could also easily extend it to perform round-robin per note. I would suggest that have a look at the script manual. The basics are quite easy to learn and it gives you a lot of flexibility.

    About Drums of War - yes, the script is written by me. I was not involved in the wider sense of production though (recording and such).
     
  13. medusa

    medusa NI Product Owner

    Messages:
    239
    Wouldn't it be simpler to have 4 groups in Random Robin.

    Each of those groups has all the notes you need, say C1 to C5, or whatever.

    But each group has a different version (recording) of each of those notes.

    So you have 4 complete "sets" of notes, and use Kontakts Group Random.

    Or maybe I'm missing something else you need to do.
     
  14. kotori

    kotori NI Product Owner

    Messages:
    1,153
    Yes, that's easier if one wants Round Robin. If you however want random cycling it's not possible to have multiple sets of groups since you get random cycling within all groups of the instrument.

    Furthermore, if one wants a Round Robin behaviour and some set has 3 groups and another one has 4 groups then one needs to use a script since Kontakt doesn't handle that very well (at least that has been the case for earlier Kontakt versions) - unless one is prepared to setup 12 alternations (the least common multiple of 3 and 4).
     
Thread Status:
Not open for further replies.