“Global” On Mouse Down

Home Forums General Programming “Global” On Mouse Down

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #120467
    Jsh
    Participant
    • Topics: 6
    • Replies: 12
    • Total: 18

    Heya Ctrlr Forum,

    I’m working on functionality for a panel that currently uses a listbox full of modulator names for selecting modulators to manipulate (randomize). Basically the user selects all the parameters/modulators they would like to randomize in a uiListBox, select the randomize scale, hit randomize and then can use a slider to “lerp” between the randomized value and the initial value which I have working fine. What I’d like to do is replace the list box and instead have a “select modulators/parameters” mode which, while active, would allow the user to just click which modulators they would like to be randomized – which would be displayed by changing the modulator colors/appearance of the modulators that are selected.

    I think I could figure out how to do this for the most part but I’m not sure how I would approach the selecting modulator on mouse down, without having every modulator have an on mouse down function and a with a if bRandomizeSelectMode == true then …which would be a crazy number of methods doing the same thing, when if there is a way of doing a “global on mouse down” of sorts, which simply returns the name of any modulator clicked for example, this would save a lot of headache.

    Any ideas?

    Cheers, Jsh

    #120472
    dnaldoog
    Participant
    • Topics: 4
    • Replies: 477
    • Total: 481
    • ★★

    In a generic mousedown method/callback function, you can get the modulator userdata and the name of the modulator through comp.

    You would first get the name of the component that fired the mousedown.

    local mName=L(comp:getOwner:getName())

    and then you can do an if/else on the name passed in for example.

    See panel attached:

    Attachments:
    You must be logged in to view attached files.
    #120488
    goodweather
    Participant
    • Topics: 45
    • Replies: 549
    • Total: 594
    • ★★★

    Interesting way of working for the randomizer!

    Exactly as dnaldoog explained; I’m doing that all the time by sending the same type of modulator (button, rotary, rotary negative/postivie, pulldown, triple switches…) to a unique method then based on the name you adjust what you want.
    If you assign all your mods to variables as well then you can write a complete generic code.
    This is working for “value on change” or “component on click”, you just need to secure the distinction for name and value in your code.
    You can also call your on click method from the on change one to avoid running the same code (but this is depending on what you doing in your code of course).

    “value on change” method:

    --
    -- Called when a modulator value changes
    -- @mod   http://ctrlr.org/api/class_ctrlr_modulator.html
    -- @value    new numeric value of the modulator
    --
    PositiveValue_OnChange = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)
    
    	-- No action while loading a program or if the panel is in bootstrap or program states
    	if bLoadingProgram or not isPanelReady() then
    		return
    	end	
    
    	PositiveValue_OnClick(mod:getComponent())
    
    	sName= L(mod:getName())
    
    end
    

    “Component on click” method:

    --
    -- Called when a mouse is down on this component
    -- Used to display parameter name and description for components with 0..n values
    --
    
    PositiveValue_OnClick = function(--[[ CtrlrComponent --]] comp, --[[ MouseEvent --]] event)
    
    	-- No action while the panel is in bootstrap or program states
    	if not isPanelReady() or not bLCD then
    		return
    	end	
    
    	local sName = L(comp:getOwner():getName())
    
    	-- Get parameter name and description to be displayed
    	if sName == "VCO1Shape" then
     		sParameter = "Oscillator 1 Shape (0..1023)"
    	elseif sName == "VCO2Shape" then
     		sParameter = "Oscillator 2 Shape (0..1023)"
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
There is currently 0 users and 30 guests online
No users are currently active
Forum Statistics
Threads: 2,452, Posts: 17,259, Members: 47,979
Most users ever online was 12 on January 22, 2019 3:47 pm
Do NOT follow this link or you will be banned from the site!