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. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    hm, I can't get this to work. I have a silent play_note command in the 'on ui_control ($menu_layer1)'. After unpurging the selected group it plays a C3. But the on note CB seems to respond only to actual key strokes, not to the generated C3.
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You need to allow/disallow a group you want to focus on using set_event_par_arr($EVENT_PAR_ALLOW_GROUP, <event ID>, <value>, <group ID>).
     
  3. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    thanks, but still no luck. The attach command in on note CB is still ignoring my generated note.
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Post your code?
     
  5. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    It's just a slightly modified version of the OPs script (for 2x2 groups) - the generated notes are not silenced yet.
    Code:
    on init
    set_ui_height_px(150)
    set_ui_width_px(550)
    make_perfview
    message ("")
    declare $i
    declare %layer_1[2] := (0,1)
    declare %layer_2[2] := (2,3)
    declare %zones1[2] := (0,1)
    declare %zones2[2] := (2,3)
    declare $noteID
    declare $zoneID
    declare const $layer_1first := 0
    declare const $layer_1last := 1
    declare const $layer_2first := 2
    declare const $layer_2last := 3
    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, 5, 30)
    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, 305, 30)
    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)
    set_event_par_arr($EVENT_PAR_ALLOW_GROUP, 60, 1, $menu_layer1)
    play_note (60, 1, 0,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)
    set_event_par_arr($EVENT_PAR_ALLOW_GROUP, 60, 1, $menu_layer2)
    play_note (60, 1, 0,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)
        if ($zoneID < 2)
            attach_zone($waveform_1, $zoneID, 0)
         end if
         if ($zoneID > 1)
            attach_zone($waveform_2, $zoneID, 0)
        end if
    end on
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yeah that's a bit wrong. :)

    You're using note number in set_event_par_arr(), it works on event ID instead. So you need to first play note, store it in the variable, then use that variable as event ID, in order to (dis)allow groups, then wait(1), then get zone ID and attach it to waveform display.
     
  7. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    Yeah, I know that it's obviously wrong because it doesn't work.
    But set_event_par_arr() in the UI CB is right? or should it be in the Note CB?
    I am confused because the manual says that set_event_par_arr() should look like this:
    Code:
    set_event_par_arr(<ID-number>,$EVENT_PAR_ALLOW_GROUP,<value>,<groupindex>)
    but you said earlier:
    Code:
    set_event_par_arr($EVENT_PAR_ALLOW_GROUP, <event ID>, <value>, <group ID>)
    or is this an undocumented command?
     
  8. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Ah right I swapped the order of arguments, sorry. It happens! :)

    Yeah this stuff should be in UICB, you want to change the waveform when you load a different sound, right? So you need to attach the new zone ID to the ui_waveform, so it has to be done after purging.
     
  9. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    Thanks man!
    I still have some major issues here: If I store the event ID in a variable, I get this error message when trying to use it in set_event_par_arr():
    Screen Shot 2020-05-19 at 23.55.38.jpg
    (I guess that's because it expects the note number, at least thats what the manual says)

    I think I'll leave this for now...I've tried a lot of things but I still can't retrieve the zone triggered by the menu change. If you have a working solution I'll be very happy to see it.
     
  10. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Code:
    $event_ID := play_note (60, 1, 0, 1)
    change_vol($event_ID, -200000, 0)
    set_event_par_arr($event_ID, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($event_ID, $EVENT_PAR_ALLOW_GROUP, 1, $menu_layer2)
    wait(1)
    <get zone ID and attach to waveform>
    get/set_event_par() only work on event IDs, not note numbers.
     
    • Like Like x 1
  11. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    Ahh... thanks a lot!! It's actually working now.

    Code:
    on init
    set_ui_height_px(150)
    set_ui_width_px(550)
    make_perfview
    message ("")
    declare $i
    declare %layer_1[2] := (0,1)
    declare %layer_2[2] := (2,3)
    declare %zones1[2] := (0,1)
    declare %zones2[2] := (2,3)
    declare $noteID
    declare $zoneID
    declare $event_ID
    declare const $layer_1first := 0
    declare const $layer_1last := 1
    declare const $layer_2first := 2
    declare const $layer_2last := 3
    declare ui_menu $menu_layer1
    make_persistent($menu_layer1)
          $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, 5, 30)
    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, 305, 30)
    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) 
    $event_ID := play_note (60, 1, 0, 1)
    change_vol($event_ID, -200000, 0)
    set_event_par_arr($event_ID, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($event_ID, $EVENT_PAR_ALLOW_GROUP, 1, $menu_layer1)
    wait(1)
    $zoneID := get_event_par($event_ID,$EVENT_PAR_ZONE_ID)
    attach_zone($waveform_1, $zoneID, 0)
    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)
    $event_ID := play_note (60, 1, 0, 1) 
    change_vol($event_ID, -200000, 0)
    set_event_par_arr($event_ID, $EVENT_PAR_ALLOW_GROUP, 0, $ALL_GROUPS)
    set_event_par_arr($event_ID, $EVENT_PAR_ALLOW_GROUP, 1, $menu_layer2)
    wait(1)
    $zoneID := get_event_par($event_ID,$EVENT_PAR_ZONE_ID)
    attach_zone($waveform_2, $zoneID, 0)
    end on
    
     
    Last edited: Mar 31, 2021
  12. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    This works very nicely, thanks guys! The problem I have now is that I can't find a way to recall the displayed waveform when changing snapshots. I understand that there's no point in making a ui_waveform persistent but can't find a solution... any idea?

    n other words, if I save a snapshot the selected menu entry (sample from Layer1 and Sample from layer 2) is preserved but it doesn't display the waveform...
     
  13. soundtrax

    soundtrax NI Product Owner

    Messages:
    301
    you just have to repeat the menu stuff in an "on persistence_changed" CB.
     
  14. Alessandro Mastroianni

    Alessandro Mastroianni NI Product Owner

    Messages:
    24
    Yeah, I was coming here to answer my own question and found you already (kindly) replied: I had to reattach the zone on persistence_changed.
    Well, the thread was quite a learning experience: awesome! THANK YOU BOTH