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

Solved Displaying samples from two layers in different waveforms

Discussion in 'Scripting Workshop' started by Alessandro Mastroianni, May 18, 2020.

  1. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    I’m building an instrument with two layers that play at the same time, with samples (groups) that are selectable via drop-down menu. They’re set up so that groups 0 to 39 is layer 1 and groups 40 to 49 is layer 2.

    I’ve been trying to set up two GUI waveforms to display the zone played in each layer and I couldn’t find a solution I was happy with.
    My first attempt was to do something like this, which obviously doesn't work because $zoneID only returns the zone played by layer 2 (as it feature the higher zone ID number). It's also not ideal anyway because adding zones to layer 1 AFTER the ones in layer 2 I will screw everything up.
    Any idea?

    Code:
    on init
    set_ui_height_px(430)
    set_ui_width_px(750)
    make_perfview
    
    declare $i
    declare %layer_1[40] := (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39)
    declare %layer_2[10] := (40,41,42,43,44,45,46,57,48,49)
    declare $noteID
    declare $zoneID
      declare const $layer_1first := 0
      declare const $layer_1last := 39
      declare const $layer_2first := 40
      declare const $layer_2last := 49
    
    declare ui_menu $menu_layer1
      make_persistent(%layer_1)
    
    
          $i := $layer_1first
       while ($i<=$layer_1last)
         add_menu_item($menu_layer1,group_name($i),$i)
         inc($i)
       end while
    
    declare ui_menu $menu_layer2
      make_persistent($menu_layer2)
    
          $i := $layer_2first
       while ($i<=$layer_2last)
         add_menu_item($menu_layer2,group_name($i),$i)
         inc($i)
       end while
    
    
    
    
    
    declare ui_waveform $waveform_1 (6,6)
    set_control_par(get_ui_id($waveform_1),$CONTROL_PAR_WIDTH,300)
    set_control_par(get_ui_id($waveform_1),$CONTROL_PAR_HEIGHT,100)
    move_control_px($waveform_1, 20, 100)
    
    
    declare ui_waveform $waveform_2 (6,6)
    set_control_par(get_ui_id($waveform_2),$CONTROL_PAR_WIDTH,300)
    set_control_par(get_ui_id($waveform_2),$CONTROL_PAR_HEIGHT,100)
    move_control_px($waveform_2, 430, 100)
    
    end on
     
    on ui_control ($menu_layer1)
       $i := $layer_1first
       while ($i<=$layer_1last)
         purge_group($i,0)
         inc($i)
       end while
       purge_group($menu_layer1,1)
    
    end on
    
    on ui_control ($menu_layer2)
       $i := $layer_2first
       while ($i<=$layer_2last)
         purge_group($i,0)
         inc($i)
       end while
       purge_group($menu_layer2,1)
    
    end on
    on note
      ignore_event($EVENT_ID)
        $noteID := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
        wait(1)
        $zoneID := get_event_par($noteID,$EVENT_PAR_ZONE_ID)
    
        select ($zoneID)
          case 0 to 3999
            attach_zone($waveform_1, $zoneID, 0)
          case 4000 to 5000
            attach_zone($waveform_2, $zoneID, 0)
    
        end select
    end on
     
    Last edited: May 18, 2020
  2. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    I haven't tried it but I suppose you need two different zone IDs, one for each waveform.
    And why don't you use code tags? It's really not that difficult to insert it:
    Screen Shot 2020-05-18 at 20.25.15.jpg
     
  3. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    Sorry about the code tags.
    I did think of creating two different zone IDs but I can't work out how to "split" the layers so that each zoneID is stored into a separate $zoneID
     
  4. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    so if I understand your script right, you have 5000 zones: Layer 1 are zones 0-3999, and Layer 2 are zones 4000-5000, right? That's quite a lot!
    (You will definitely have to make sure they all have their right ID numbers. Sometimes, when duplicating or copying groups, weird things can happen to zone ID numbers...)
    I guess this should work for your script:
    Code:
    on note
    ignore_event($EVENT_ID)
    $noteID := play_note($EVENT_NOTE,$EVENT_VELOCITY,0,-1)
    wait(1)
    $zoneID1 := get_event_par($noteID,$EVENT_PAR_ZONE_ID)
    $zoneID2 := get_event_par($noteID,$EVENT_PAR_ZONE_ID)
    if ($zoneID1 < 4000)
        attach_zone($waveform_1, $zoneID1, 0)
    end if
    if ($zoneID2 > 3999)
        attach_zone($waveform_2, $zoneID2, 0)
    end if
    end on
    
    EDIT:
    hmm, no sorry, this doesn't work...
     
    Last edited: May 18, 2020
  5. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    Thank you so much! let me try it out.. But let me say right away that no, I only have about 8/900... However I deleted and rebuilt several times the groups so several zones have IDs that went up to those numbers. If it get's crazy I'll rebuild the groups from scratch
     
  6. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    Ah okay, yes rebuilding the groups might be a good idea. My approach to split up the zone IDs somehow doesnt work, I just checked...
    EDIT: It's because $EVENT_PAR_ZONE_ID can return only one single value (= one zone) when hitting a note. So I guess this is rather impossible to script,
     
    Last edited: May 18, 2020
  7. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    Unfortunately it doesn't work: same problem, only the second waveform (layer2( gets displayed as it has the highest zoneID (and I guess it it the lates "read")..
     
  8. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
  9. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    I wish there was an easier alternative as, for example, the entire "Play Series" does exactly that..
     
  10. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    but in Play series, you only get one waveform for each selected group, not for each zone you play! You can quite easily attach a zone of a selected group to the waveform display. Don't do it in the on note CB but on ui_control of your menu!
     
  11. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    if you want to see zone 4000 you just have to do this: attach_zone ($Waveform,4000,0)
     
  12. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    True, it works differently I just tried, Mt memory was failing me. I could do that as an alternative, I would need to select 1 zone representative of the group selected (at C3 for example). How do I change “4000” in your example with C3 in the active group? I’m not sure it’s much easier
     
  13. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    Open Browser > Expert > Zones and also the mapping editor. Now, when you select a zone in the mapping editor, the zone (with its ID-Nr.) will be highlighted in the Browser tab on the left. That's the number you need.
     
  14. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    Sure I know, but what I mean is that with 50 groups I would need the attached zone to change dynamically on control (depending on the menu entry selected)
     
  15. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    You just have to declare 2 arrays containing all the zones you want to show:
    %zones1 must have 40 entries with all zone numbers you want to show, %zones2 must have the 10 zones you want to show. Then you can simply add this after you unpurge the group (and of course you'll have to do the same with %zones2 in your $menu_layer2 for $waveform_2)
    Code:
    attach_zone ($waveform_1,%zones1[$menu_layer1],0)
     
  16. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    actually in the second menu, you'll have to add a -40 offset to make it work:
    Code:
    attach_zone ($waveform_2,%zones2[$menu_layer2 - 40],0)
     
  17. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    YES! That's a good solution ;) THANK YOU SO MUCH.
     
  18. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Guys, you can always play a silent event focusing on a particular group and after wait(1) you can use get_event_par() to get $EVENT_PAR_ZONE_ID...
     
  19. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    Ah yes, sounds like a good way to do it! So you mean "play_note" when switching to a new group? I just tried this but it's not allowed to set the velo to 0.
     
  20. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Use change_vol() to set the volume of the sample to -200000 mdB, then wait, then get zone ID.