Home › Forums › General › Programming › “Global” On Mouse Down
Tagged: L(comp:getOwner():getName()), mouse down
- This topic has 2 replies, 3 voices, and was last updated 3 years, 1 month ago by
goodweather.
-
AuthorPosts
-
October 29, 2020 at 6:16 am #120467
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
October 30, 2020 at 1:16 am #120472In 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.October 31, 2020 at 11:40 am #120488Interesting 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)"
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.