Home › Forums › General › Panels, Components, Macros › panel MIDI channel change
Tagged: practical examples; Lua;
- This topic has 25 replies, 4 voices, and was last updated 7 years ago by human fly.
-
AuthorPosts
-
April 11, 2017 at 8:40 am #71821
ok, a few days on, and i’ve had a general look round.
just glimpsing how much i don’t know ! so i’ve tried
some really basic stuff, like getting a button to
switch on a LED, and i’m failing even to do that.
i need to master fundamentals better, and videos and
manual are not covering something i can transpose into
use with Ctrlr – for the limited use i feel i have at
this stage.also, i’m looking at some other panels and their lua,
and i’m still confused why i can’t get that simple thing
to work. the truth is, i’m still poking around in the dark.so: how about a ‘Lua for Ctrlr for Beginners’ topic? i’m
not sure what the best way to approach it would be, but
it might be useful for future new users searching the
forum for a ‘get started’.i’m unclear about (?) statements like getComponent/getModulator/
setEtc/. i thought i was getting to grips with giving things
names and if and elseif and ‘==’, but…not. and some practical
exercises+discussion/explanation would be good.for instance: i can deal with setVisible, but i’m not getting
any luck with setValue, and i realise i don’t know which of
these are defined and exist within ctrlr, or Lua, or if i have
to create and define them myself?
(hoping that i’m not a hopeless case…)April 15, 2017 at 7:08 am #71836Human fly, you have my sympathies.
Ctrlr is really amazing however even though I can code C, C++, VB, many scripting languages, Max/M4L etc etc… i still don’t know where to write a line of lua code in Ctrlr. I’m thinking i’m probably missing something since there has to be like a hello world kind of sample program somewhere. I mean where do i find the information that shows how to do a very simple thing such as taking a component value, adding 2, and updating another component with the new value. I have no worries with lua since it has documentation and popularly used but i can not even see the simplest ctrlr-lua integration. The documentation section shows how to make a panel and send data with it, that’s great but nothing about a simple code of lua. I really don’t need anything about lua here, i just need to learn how ctrlr uses lua and i can not find any information about it.
I think the big question is, when you figure out getting a button to
switch on a LED, will you explain it here 🙂April 15, 2017 at 8:44 am #71837try this: rightclick and Add Component > Button.
you get the blue button with false/true on it.you’ve just created a ‘modulator’ – ha, not confusing
at all: you added a ‘component’ and created a modulator..
(with a component in it ? )now, right-side properties pane > ‘Modulator’> scroll down
to where it says: ‘Called when the modulator value changes’,
with 3 symbols/buttons next to it – it says ‘none’ in the box,
because no ‘method’ is selected. if you have a look there, you
have a few standard ‘lua'(methods) – i reckon this would be an
excellent place to have a large library of readymade methods ! 😉so you can call up one of those, and click the 1st button ‘edit..’
to open the Lua Editor – which you can also open from the top menu
under Panel>Lua Editor …ah ! hahaaa, *there* is the ******’n
CONSOLE..yeah i was wondering about that, trying out some Print()
examples…so there you are. that’s what i know.
i made a very rufff led 2-frame image in paintdotnet quickly,
saved it as ‘led.png’ – you have to ‘add’ any external resources
such as images via the Resources Tab, under the Properties –the only way i could see to add that as a slave LED was to create
a ‘image button’, which i then set as Component Generic>’component is
disabled’ – tick – so that it doesn’t respond to mouse clicks.you can use ‘Link to Modulator’ and ‘modulator value’ property to
link the led action to the button (not sure what other parameters
should set to optimise this) – but that isn’t much use if you wanted
to switch onoff FOUR leds, for example, or have a more complex logic
thing you want to do. that’s where Lua comes in as a better option:
i realised that a Lua method doesn’t care what group or tab a modulator
is on, it only refers to it via its assigned name(?string? soz, prog’ging
newb, clueless – or is the word ‘variable’? hitherto, in my midi world,
‘variable’ is just the value variable in a sysex string 🙂 )right, so i got a true/false thing going with a command ‘setVisible’..
is it a command? a function? i don’t know where it is defined, but it
works: i can have one box of parameters showing, or another, depending
on what option is selected on another control. great.(except it is
starting up weird, with both boxes showing until i establish a setting
on the selector parameter-will need to resolve that somehow)ok, next then: i’ve also seen things like getModulatorValue, getValue,
and ah: ‘setValue’/’setModulatorValue’ – so, is there a difference there? –
so i figure ok, i can use that as i did with the other method, just
interpose ‘setValue’ where i had ‘setVisible’, and it should do something,
whether i need to use boolean ‘==’, false/true, or (?int?) values, and
‘=’
and it compiled ok, unless i tried to use ‘=’, syntax error, but then
reports errors when i activate the button, ie: run it. either ‘-1’
callback error, or method fail/disabled if i try it another way.
eg: couldn’t get it to work. tried loads of things, still won’t.
Proton gave me an explanation i struggled with(‘!? duh?’), and
dissipated any notion i was actually getting to grips with this.need to look at: defining a variable, assigning a value, defining
a function, ‘declaring’, local, global, arguments, statements,
‘operator'(?), … maybe actually having found the console this
morning will help now loli quite like building logic structures in synthedit but this looks
..painful. i think i know my limits, i just want to do some simple
things. i have however found some excellent stuff to crib from,
and i’m also finding that browsing through the ‘programming’
forum questions, going back quite far, is kicking up some info.
need to do some more digging. but your insight from previous
programming would be helpful.(have a look at how the jx3p and
jx8p panels handle ‘load/save’ buttons)April 15, 2017 at 9:15 am #71839*update* :o)
Ho-Kaay..! got my led working – i do my leedle daaance …-
success. i’m so chuffed. that took me DAYS. (‘how many Ctrlr
users does it take to switch on a lightbulb?’…)what i did: i nicked atom’s method for switching onoff menu view:
which is:—
— Called when a modulator value changes
— @mod http://ctrlr.org/api/class_ctrlr_modulator.html
— @value new numeric value of the modulator
—
toggle_menu = function(–[[ CtrlrModulator –]] mod, –[[ number –]] value, –[[ number –]] source)
if value == 1 then
panel:getPanelEditor():setProperty(“uiPanelMenuBarVisible”, 1, false)
else
panel:getPanelEditor():setProperty(“uiPanelMenuBarVisible”, 0, false)
end
endand changed that to:
—
— Called when a modulator value changes
— @mod http://ctrlr.org/api/class_ctrlr_modulator.html
— @value new numeric value of the modulator
— compiles, doesn’t do anything 🙁
toggle_led = function(–[[ CtrlrModulator –]] mod, –[[ number –]] value, –[[ number –]] source)if value == 1 then
panel:getModulatorByName(“led”):setProperty(“value”, 1, false)
else
panel:getModulatorByName(“led”):setProperty(“value”, 0, false)
end
endand that didn’t work. so i changed setProperty to the thing
i wasn’t getting to work, ‘setValue’, and got rid of the “..”,
thus:—
— Called when a modulator value changes
— @mod http://ctrlr.org/api/class_ctrlr_modulator.html
— @value new numeric value of the modulator— try setValue now
toggle_led2 = function(–[[ CtrlrModulator –]] mod, –[[ number –]] value, –[[ number –]] source)
if value == 1 then
panel:getModulatorByName(“led”):setValue(1, false)
else
panel:getModulatorByName(“led”):setValue(0, false)
end
endand this works. i’m sure i’ve been round this way several
times without success, but there it is. i don’t know what
‘false’ is there for though.(?)April 15, 2017 at 9:29 am #71840here the panel in a zip with led image file
https://app.box.com/s/i9259vjw7dnbeg2gfzhf4z61ip3cj8u2
tried to assign a local name to simplify it a bit:
—
— Called when a modulator value changes
— @mod http://ctrlr.org/api/class_ctrlr_modulator.html
— @value new numeric value of the modulator— try to assign local name
toggle_led3 = function(–[[ CtrlrModulator –]] mod, –[[ number –]] value, –[[ number –]] source)
led = panel:getModulatorByName(“led”)
if value == 1 then
led:setValue(1, false)
else
led:setValue(0, false)
end
enddon’t know why this wasn’t working before…wasn’t using ‘false’ there.
April 15, 2017 at 12:45 pm #71842right, so i tried that again without the ‘false’ entry,
and it doesn’t work. so i have to check to find out what
that’s for.otherwise all working and i can light up multiple leds etc.
now, so what shorter ways to write this are there?
-
AuthorPosts
- The forum ‘Panels, Components, Macros’ is closed to new topics and replies.