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 Next/Prev Buttons for Cabinet

Discussion in 'Scripting Workshop' started by Bartolomeo Amati, Sep 1, 2021.

  1. Bartolomeo Amati

    Bartolomeo Amati New Member

    Messages:
    16
    I've been trying to create next/prev buttons for cabinet types, i made this script but it's still not working :


    on init

    declare ui_menu $Cab
    add_menu_item($Cab,"Tweed Green",0)
    add_menu_item($Cab,"Brit 60s",1)
    add_menu_item($Cab,"Chief V-30",2)
    add_menu_item($Cab,"Chief V-30 (Back)",3)
    add_menu_item($Cab,"Tweed Alnico",4)
    add_menu_item($Cab,"Tweed Alnico (Far) ",5)
    add_menu_item($Cab,"UK 70s",6)
    add_menu_item($Cab,"UK 70s (Far)",7)
    add_menu_item($Cab,"Bass-WR",8)
    add_menu_item($Cab,"Bass-WR (Horn)",9)
    add_menu_item($Cab,"Leslie 122",10)

    set_control_par(get_ui_id($Cab),$CONTROL_PAR_WIDTH,106)

    move_control_px($Cab,66,2)

    make_persistent($Cab)

    message("")

    declare ui_switch $PrevMenu
    move_control_px($PrevMenu, 308, 0)
    declare ui_switch $NextMenu
    move_control_px($NextMenu, 198, 0)


    end on


    on ui_control ($Cab)
    set_engine_par($ENGINE_PAR_CABINET_TYPE,$Cab, -1,2,1)
    end on

    on ui_control($PrevMenu)
    $Cab := (get_control_par(get_ui_id($Cab),$CONTROL_PAR_NUM_ITEMS)+$Cab-1) mod get_control_par(get_ui_id($Cab),$CONTROL_PAR_NUM_ITEMS)
    $PrevMenu := 0
    end on

    on ui_control($NextMenu)
    $Cab := ($Cab+1) mod get_control_par(get_ui_id($Cab),$CONTROL_PAR_NUM_ITEMS)
    $NextMenu := 0
    end on
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You're not doing set_engine_par() anywhere.
     
  3. Bartolomeo Amati

    Bartolomeo Amati New Member

    Messages:
    16
    Thank you for your reply!
    I tried adding set_engine_par() but i keep getting errors
    how should i exactly add it on the code? thanks!
     
  4. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    I have testing it but can you try it for $PrevMenu:
    Code:
    set_engine_par($ENGINE_PAR_CABINET_TYPE,$PrevMenu + $Cab-1, -1,2,1)
    anf for $NextMenu:
    Code:
    set_engine_par($ENGINE_PAR_CABINET_TYPE,$NextMenu + $Cab-1, -1,2,1)
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Also this bit of code:

    Code:
    $Cab := (get_control_par(get_ui_id($Cab),$CONTROL_PAR_NUM_ITEMS)+$Cab+1) mod get_control_par(get_ui_id($Cab),$CONTROL_PAR_NUM_ITEMS)
    can be simplified to:

    Code:
    $Cab := $Cab + 1 mod 11
    (use - 1 for prev button of course)

    And you can declare the number of menu items as a constant and use that instead of always getting num items via get_control_par.
     
  6. Bartolomeo Amati

    Bartolomeo Amati New Member

    Messages:
    16
    Thank you guys, that worked!
    I tried to make an image for each cab but i had no luck i used ui_slider for the image then i made 11 different images, but i can't figure out how to slide through them using $NextMenu and $PrevMenu
     
  7. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You should use ui_label(), assign picture to it, then change the state using $CONTROL_PAR_PICTURE_STATE. Unless you really want to use the slider in order to make it draggable.

    If you want to use the slider, you just set the slider's value to the number of cabined (0-10).
     
  8. Bartolomeo Amati

    Bartolomeo Amati New Member

    Messages:
    16
    I did this :

    declare ui_label $CabImgs(0, 10)
    move_control_px($CabImgs, 308, 60)
    set_control_par_str(get_ui_id($CabImgs), $CONTROL_PAR_PICTURE, "cabimgs")

    I just can't figure how to link it to $NextMenu and $PrevMenu
     
  9. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    For the NextMenu callback :

    Code:
    on ui_control ($NextMenu)    
         set_control_par(get_ui_id($CabImgs),$CONTROL_PAR_PICTURE_STATE ,$NextMenu *$Cab+1)
    end on
     
  10. Bartolomeo Amati

    Bartolomeo Amati New Member

    Messages:
    16