Welcome to the new and improved Native Instruments online community. Join our active forum of 40,000+ members for discussions and much more.

Waveform Graphic changes with group menu select

MTC84
MTC84 Member Posts: 16 Sine

Hi,

I found this code on an old thread but it is missing the on_persistence code. I have tried everything I can think of but can't seem to figure it out! Please can someone put me out of my misery!?

The group select element works as it should but no waveform graphic is displayed.

Thanks in advance!

https://www.native-instruments.com/forum/threads/displaying-samples-from-two-layers-in-different-waveforms.409171/page-2

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

Comments

  • corbo-billy
    corbo-billy Member Posts: 49 Tri

    It's work fine, at home: you must apply again your script, in the KSP editor .

  • MTC84
    MTC84 Member Posts: 16 Sine

    I tested again - it definitely is missing something (the on persistence_changed code). The group menu's work correctly but there is no waveform displayed in the area defined. Just 2 black boxes.

    The guy who posted originally on the other forum said " I had to reattach the zone on persistence_changed."

    I tried to add this code myself but could not get anything to work. I'm puzzled.

  • medusa
    medusa Member Posts: 32 Tri
    edited February 9

    Attach the zones again in persistence changed then. You'll need to store their zone IDs for recall.

  • MTC84
    MTC84 Member Posts: 16 Sine
    edited February 10

    Thanks for the reply.

    I have tested the above code again on my Studio PC and it almost works properly - I am still not sure why the change of PC has had any impact!

    The problem now is that the waveforms only show when I select a group from one of the drop down menu's. The weaveform shows up as it should when I use the dropdown. Is there a way for the 1st group of each menu to be loaded by default?

    I still don't understand what code I am missing - the on persistence_changed and storing the zone ID's. Please could someone show me what I am missing? I am very much a novice coder.

    Thanks for any help.

  • MTC84
    MTC84 Member Posts: 16 Sine
    edited February 10

    I have done some further trial and error style coding to see if I could get it working...

    I have added the following code and everything seems to be working properly. The waveforms now show up when I load the instrument and no longer blanks out when I hit the Apply button in the Script Editor.

    Is there anything I am missing now?

    on persistence_changed
    
    	$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)
    
    
    	$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
    
    
    
  • MTC84
    MTC84 Member Posts: 16 Sine
    edited February 10

    I have been trying to add Previous and Next buttons to each of the 2 Menus for easy navigation between samples. I have got Menu_A and its associated buttons working perfectly but Menu_B's buttons aren't working at all. Can anyone help me please?

    Menu_B's code is the same as Menu_A's but obviously tweaked accordingly.

    Thanks a lot.

    {ON UI CONTROLS - NEXT & PREVIOUS BUTTONS}
    
    	on ui_control($Menu_A_Prev_Button)
    	$MENU_A := (get_control_par(get_ui_id($MENU_A), $CONTROL_PAR_NUM_ITEMS)+$MENU_A-1) mod get_control_par(get_ui_id($MENU_A), $CONTROL_PAR_NUM_ITEMS)
    
    	$Menu_A_Prev_Button := 0
    
       	$i := $Menu_A_First
    	while ($i<=$Menu_A_Last)
    		purge_group($i, 0)
    		inc($i)
    	end while
    	purge_group($Menu_A, 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_A)
    		wait(1)
    	$zoneID := get_event_par($event_ID, $EVENT_PAR_ZONE_ID)
    	attach_zone($Waveform_A, $zoneID, 0)
    end on
    
    on ui_control($Menu_A_Next_Button)
    	$Menu_A := ($Menu_A+1) mod get_control_par(get_ui_id($Menu_A), $CONTROL_PAR_NUM_ITEMS)
    
    	$Menu_A_Next_Button := 0
    
       	$i := $Menu_A_First
    	while ($i<=$Menu_A_Last)
    		purge_group($i, 0)
    		inc($i)
    	end while
    	purge_group($Menu_A, 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_A)
    		wait(1)
    	$zoneID := get_event_par($event_ID, $EVENT_PAR_ZONE_ID)
    	attach_zone($Waveform_A, $zoneID, 0)
    end on
    
    on ui_control($Menu_B_Prev_Button)
    	$MENU_B := (get_control_par(get_ui_id($MENU_B), $CONTROL_PAR_NUM_ITEMS)+$MENU_B-1) mod get_control_par(get_ui_id($MENU_B), $CONTROL_PAR_NUM_ITEMS)
    
    	$Menu_B_Prev_Button := 0
    
    	$i := $Menu_B_First
    	while ($i<=$Menu_B_Last)
    		purge_group($i, 0)
    		inc($i)
    	end while
    	purge_group($Menu_B, 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_B)
    		wait(1)
    	$zoneID := get_event_par($event_ID, $EVENT_PAR_ZONE_ID)
    	attach_zone($Waveform_B, $zoneID, 0)
    end on
    
    
    on ui_control($Menu_B_Next_Button)
    	$Menu_B := ($Menu_B+1) mod get_control_par(get_ui_id($Menu_B), $CONTROL_PAR_NUM_ITEMS)
    
    	$Menu_B_Next_Button := 0
    
    	$i := $Menu_B_First
    	while ($i<=$Menu_B_Last)
    		purge_group($i, 0)
    		inc($i)
    	end while
    	purge_group($Menu_B, 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_B)
    		wait(1)
    	$zoneID := get_event_par($event_ID, $EVENT_PAR_ZONE_ID)
    	attach_zone($Waveform_B, $zoneID, 0)
    end on
    
  • MTC84
    MTC84 Member Posts: 16 Sine
    edited February 13

    I believe I have finally cracked this. All seems to be working as it should. Thanks for the help.

Back To Top