Script to trigger 2nd group when same zone played twice in a row

benjaminfrog
benjaminfrog Member Posts: 3 Member
edited October 2024 in Scripting Workshop

Rather than set up a round robin that alternates between two groups with every note event, I'm trying to write a script that only triggers the 2nd group when the same zone is played twice in a row. Unfortunately, the results I'm getting are that of a standard round robin. Can anyone tell me where I'm going wrong?

on init

  declare $last_zone

  declare $last_group

end on


on note

disallow_group($ALL_GROUPS)

  if (($last_zone = get_event_par($EVENT_ID,$EVENT_PAR_ZONE_ID)) and ($last_group = 0))

    allow_group(1)  

    $last_group := 1

  else 

    allow_group(0)

    $last_group := 0

  end if

  $last_zone := get_event_par($EVENT_ID,$EVENT_PAR_ZONE_ID)

end on

Comments

  • medusa
    medusa Member Posts: 98 Helper
    edited June 2023

    To GET the zone ID from the event, you need to wait(1) ... ie. retrieve the zone ID after the EVENT begins, so you can't use this method to choose which group/robin plays, because you get the information too late.

    If you collect all the zone IDs in advance, and store them in an array, then you could look them up instantly and use that to control the group/robin choice. This is indeed a method I've used and seen others use..

    I assume there are actually more than 2 groups in your instrument, because you don't really need this level of detail for just two possibilites. ie. you could just store whether group 0 or 1 was played last for each key in an Array[$EVENT_NOTE]

  • stephen24
    stephen24 Member Posts: 428 Pro
    edited June 2023

    Not done this myself, but why not try: ignore event, play event_note/velocity with duration = 1 or 2 microseconds, wait (1), disallow all groups, decide which group to allow, play the event_note/velocity with normal release (duration = -1), update variables. (I would guess note played for 1-2 microseconds won't be noticed)

    Alternatively don't ignore event, but wait(1) then read the zone ID, note_off(EVENT_NOTE), decide which group to allow, play the event_note/velocity with normal release (duration = -1), update variables.

  • medusa
    medusa Member Posts: 98 Helper
    edited June 2023

    That might work! :-) You can set the volume of the blip note -96dB just to be sure it's not heard.


    Seriously though, if you're just using the zone IDs to define a 128*128 velocity*pitch map for robins, it really makes sense to do it in advance and save it.

  • benjaminfrog
    benjaminfrog Member Posts: 3 Member

    Thanks for the suggestions! I'm not sure I understand them all and I may not have been entirely clear in how I want it to function. It's for a kick drum. There are only two groups. I want it to default to the first group, unless there are two successive note events that would otherwise trigger the exact same zone, at which point, I want it to flip to the other group for just that event and then go back to the first group.

    I think I will try stephen24's second suggestion and see how it goes. Thanks again!

  • stephen24
    stephen24 Member Posts: 428 Pro

    (I would guess note played for 1-2 microseconds won't be noticed)

    With tongue in cheek. (At 44.1 kHz the 2nd sample won't arrive for another 20 microseconds or so.)

This discussion has been closed.
Back To Top