Best Way To Reset Labels?

AndrewFromTexas
AndrewFromTexas Member Posts: 5 Member
edited October 22 in Scripting Workshop

Hey there everyone,

I'm looking into ways to have labels display values within a ui_control callback and then reset to their original label. For example, "Freq".

So far, all I've been able to come up with is using a for loop to create a timer, of sorts, that resets the text after the UI control has been set for a short period of time. The problem is that the amount of time it takes for the loop to complete seems to be inconsistent. If I actually move the knob, the label resets relatively quickly. If I simply click the knob and its value stays the same, the label seems to take longer to reset to its original text. Very strange.

I'm hoping someone might have a better solution than a for loop within the ui control callback.

Here's my compiled test code.

{ Compiled on Fri Jan 28 14:09:06 2022 }
on init
  make_perfview
  set_ui_height_px(100)
  set_ui_width_px(700)
  declare $i
  declare ui_knob $test_knob(0, 1000000, 1) 
  declare ui_label $test_label(1, 1) 
  set_control_par(get_ui_id($test_knob),$CONTROL_PAR_POS_X,100)
  set_control_par(get_ui_id($test_label),$CONTROL_PAR_POS_X,0)
  set_control_par_str(get_ui_id($test_label),$CONTROL_PAR_TEXT,"TEST")
end on


on ui_control($test_knob)
  set_control_par_str(get_ui_id($test_label),$CONTROL_PAR_TEXT,$test_knob)
  $i := 0
  while ($i<=1000)
    if ($i=1000)
      set_control_par_str(get_ui_id($test_label),$CONTROL_PAR_TEXT,"TEST")
    end if
    wait(10000)
    inc($i)
  end while
end on


Best Answer

Answers

  • soundtrax
    soundtrax Member Posts: 14 Member
    Answer ✓

    Check out the example by EvilDragon in this older thread (post#6): https://www.native-instruments.com/forum/threads/ui_text_edit-on-listener-move_control-problem.322542/

  • AndrewFromTexas
    AndrewFromTexas Member Posts: 5 Member

    Ah ha! Yea that's exactly what I was looking for. Thank you!

    So, to sum up, EvilDragon says to setup a watchdog timer for each label. From what I gather, the %timer array would have an element for each label that needs the timer.

    Here's the revised test script (in the Sublime KScript Editor) with this working functionality.

    on init 
    	make_perfview
    	set_ui_height_px(100)
    	set_ui_width_px(700)
    	declare const $RESET_TIME := 2000000
    	declare const $RESET_WAIT := (RESET_TIME / 1000) - 500
    	declare timers[1]
    	declare ui_knob test_knob (0, 1000000, 1)
    	declare ui_label test_label (1,1)
    	test_knob -> pos_x := 100
    	test_label -> pos_x := 0
    	test_label -> text := 'TEST'
    end on
    on ui_control (test_knob)
    	test_label -> text := test_knob
    	timers[0] := ENGINE_UPTIME
    	wait(RESET_TIME)
    	if (ENGINE_UPTIME - timers[0] > RESET_WAIT)
    		test_label -> text := "TEST"
    	end if
    end on
    
    
  • corbo-billy
    corbo-billy Member Posts: 107 Helper
    edited January 2022

    And for the knob init callback, we can add :


    set_control_par(get_ui_id($test_knob),$CONTROL_PAR_HIDE,$HIDE_PART_VALUE)


    Sorry, I don't find the Code Block _

  • RolyB
    RolyB Member Posts: 3 Member

    heya

    I've got some reactive/resetting labels laid out as below and haven't had any issues. Of course the number of timers in the array will depend on how many labels you need, and $UIWaitTime can be as long or short as you like - 150000 works well for me. Using this method, your wait time of 1000 is imperceptible on my end, so you may find it needs a couple of extra zeroes!


    on init
       declare %timer[9]
       %timer[0] := 0
       %timer[1] := 0
       %timer[2] := 0
       %timer[3] := 0
       %timer[4] := 0
       %timer[5] := 0
       %timer[6] := 0
       %timer[7] := 0
       %timer[8] := 0
    
       declare const $UIWaitTime := 1500000
    
    end on
    
    on ui_control ($Chor_slider)
        inc(%timer[6])
        set_text($Chor_label,get_engine_par_disp($ENGINE_PAR_CHORAL_MIX,-1,2,1) & " %")
    
        set_engine_par($ENGINE_PAR_CHORAL_MIX,$Chor_slider,-1,2,$NI_INSERT_BUS)
    
        wait($UIWaitTime)
        dec(%timer[6])
        if(%timer[6] = 0)
            set_text($Chor_label,"Chorus")
        end if
    end on
    

    Results have been consistent for me! :D

This discussion has been closed.
Back To Top