What's new

HELP! Dual volume control not working correctly with group(0)

Troy M

Member
Why do both of the volume and pan controls operate group(0) when its set to only work with Layer1? The other three groups respond correctly?

Code:
on init
        set_ui_width_px(400)
        set_ui_height_px(250)
        make_perfview
        message("")
    declare $i 
    declare %layer1groups[2] := (0,1)
    declare %layer2groups[2] := (2,3) 
        declare const $LAYER1_FIRST := 0
        declare const $LAYER1_LAST := 1
        declare const $LAYER2_FIRST := 2
        declare const $LAYER2_LAST := 3


    {--- Volume + Pan --------------------------------------------------}

    declare ui_slider $knb_vol1(0, 700000) 
        set_control_par_str(get_ui_id($knb_vol1),$CONTROL_PAR_PICTURE,"volume_slider")
        if (1=1)
        set_control_par(get_ui_id($knb_vol1),$CONTROL_PAR_MOUSE_BEHAVIOUR,-2000) 
        end if
        make_persistent($knb_vol1)
        read_persistent_var($knb_vol1)

    declare ui_slider $knb_vol2(0, 700000) 
        set_control_par_str(get_ui_id($knb_vol2),$CONTROL_PAR_PICTURE,"volume_slider")  
        if (1=1)
        set_control_par(get_ui_id($knb_vol2),$CONTROL_PAR_MOUSE_BEHAVIOUR,-2000) 
        end if
        make_persistent($knb_vol2)
        read_persistent_var($knb_vol2)

    declare ui_slider $knb_pan1(0, 1000000) 
        set_control_par_str(get_ui_id($knb_pan1),$CONTROL_PAR_PICTURE,"pan_knob")
        if (1=1)
        set_control_par(get_ui_id($knb_pan1),$CONTROL_PAR_MOUSE_BEHAVIOUR,-800)
        end if
        make_persistent($knb_pan1)
        read_persistent_var($knb_pan1)

    declare ui_slider $knb_pan2(0, 1000000) 
        set_control_par_str(get_ui_id($knb_pan2),$CONTROL_PAR_PICTURE,"pan_knob")
        if (1=1)
        set_control_par(get_ui_id($knb_pan2),$CONTROL_PAR_MOUSE_BEHAVIOUR,-800)
        end if
        make_persistent($knb_pan2)
        read_persistent_var($knb_pan2)
            

    declare ui_menu $Layer1
        set_control_par_str(get_ui_id($Layer1),$CONTROL_PAR_TEXT,"")
        set_control_par_str(get_ui_id($Layer1),$CONTROL_PAR_PICTURE,"Menu2")
        set_control_par(get_ui_id($Layer1),$CONTROL_PAR_TEXT_ALIGNMENT,1)
        set_control_par(get_ui_id($Layer1), $CONTROL_PAR_TEXTPOS_Y,4)
        set_control_par(get_ui_id($Layer1),$CONTROL_PAR_HEIGHT,20)
        set_control_par(get_ui_id($Layer1),$CONTROL_PAR_WIDTH,200)
        make_persistent($Layer1)

        $i := $LAYER1_FIRST
    while ($i<=$LAYER1_LAST)
        add_menu_item($Layer1,group_name($i),$i)
        inc($i)
    end while

    declare ui_menu $Layer2
        set_control_par_str(get_ui_id($Layer2),$CONTROL_PAR_TEXT,"")
        set_control_par_str(get_ui_id($Layer2),$CONTROL_PAR_PICTURE,"Menu2")
        set_control_par(get_ui_id($Layer2),$CONTROL_PAR_TEXT_ALIGNMENT,1)
        set_control_par(get_ui_id($Layer2), $CONTROL_PAR_TEXTPOS_Y,4)
        set_control_par(get_ui_id($Layer2),$CONTROL_PAR_HEIGHT,20)
        set_control_par(get_ui_id($Layer2),$CONTROL_PAR_WIDTH,200)
        make_persistent($Layer2)

        $i := $LAYER2_FIRST
    while ($i<=$LAYER2_LAST)
        add_menu_item($Layer2,group_name($i),$i)
        inc($i)
    end while

    move_control_px($Layer1, 20, 20)
    move_control_px($Layer2, 250, 20)
    move_control_px($knb_vol1, 40, 60)
    move_control_px($knb_vol2, 250, 60)
    move_control_px($knb_pan1, 40, 160)
    move_control_px($knb_pan2, 290, 160)
end on 

on ui_control ($knb_vol1)
    $i := 0
    while ($i < 202)   
        set_engine_par($ENGINE_PAR_VOLUME,$knb_vol1,%layer1groups[$i],-1,-1)
        inc($i)
    end while
end on

on ui_control ($knb_vol2)
    $i := 0
    while ($i < 202)   
        set_engine_par($ENGINE_PAR_VOLUME,$knb_vol2,%layer2groups[$i],-1,-1)
        inc($i)
    end while
end on

on ui_control ($knb_pan1)
    $i := 0
    while ($i < 202)   
        set_engine_par($ENGINE_PAR_PAN,$knb_pan1,%layer1groups[$i],-1,-1)
        inc($i)
    end while
end on

on ui_control ($knb_pan2)
    $i := 0
    while ($i < 202)   
        set_engine_par($ENGINE_PAR_PAN,$knb_pan2,%layer2groups[$i],-1,-1)
        inc($i)
    end while
end on

on ui_control ($Layer1)
    $i := $LAYER1_FIRST
    while ($i<=$LAYER1_LAST)
        purge_group($i,0)
        inc($i)
    end while
    purge_group($Layer1,1)
end on

on ui_control ($Layer2)
    $i := $LAYER2_FIRST
    while ($i<=$LAYER2_LAST)
        purge_group($i,0)
        inc($i)
    end while
    purge_group($Layer2,1)
end on
 

polypx

Hoser
Because 202. There are not 202 elements in either of your arrays, there are only 2. Change 202 to 2.

EDIT or better, safer, use num_elements. ie. while ($i < num_elements(%layer2groups)) ... then if you change the size of the arrays it will still work.
 
Last edited:
OP
Troy M

Troy M

Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #3
Because 202. There are not 202 elements in either of your arrays, there are only 2. Change 202 to 2.

EDIT or better, safer, use num_elements. ie. while ($i < num_elements(%layer2groups)) ... then if you change the size of the arrays it will still work.
Thanks polypx! Life Saver!!
 

berto

Active Member
wouldn't just write a single line per set_engine_par save you some lines?


instead of

on ui_control ($knb_vol1) $i := 0 while ($i < 2) set_engine_par($ENGINE_PAR_VOLUME,$knb_vol1,%layer1groups[$i],-1,-1) inc($i) end while end on

you could write in less lines...

on ui_control ($knb_vol1) set_engine_par($ENGINE_PAR_VOLUME,$knb_vol1,0,-1,-1) set_engine_par($ENGINE_PAR_VOLUME,$knb_vol1,1,-1,-1) end on
 
Top Bottom