Home › Forums › General › Programming › Changing Images – what could be wrong in that LUA code
- This topic has 33 replies, 2 voices, and was last updated 11 years, 9 months ago by Cramp.
-
AuthorPosts
-
June 18, 2012 at 1:24 pm #625
hi,
I faced to issue with LUA code. Need your proffessional opinion.
Here is modulators which I would like to manipulate
[img:2lkxidoc]http://dl.dropbox.com/u/4202790/swithfilter.png[/img:2lkxidoc]Left side controls are Filter Slope and Filter Type of Nord Lead 3 in Single Filter Mode
Right side has Slider controlling Frequency 2 (as CC 59 when Multi Filter Mode is enabled) and Distortion (as CC 114 ).Now I want to do 2 things – visual and change the MIDI CC controller number using LUA.
1. To clarify how should work visuals – if you press the knob on Nord Lead 3 on the right hand (Multi Filter Mode marked as Green) then the Filter Slope and Filter Type on the left hand (as Single Filter Mode marked as Orange) should have inactive leds. In other way if you press Single Filter Mode knob with types of Filters like (LP, HP, Classic and etc.) the Multi Filter mode leds should set to inactive mode as shown on picture.
I created knob and leds with ‘off’ suffix ) Created LUA script and assigned to both knobs (Filter Typs on single and multi modes)
Code
[code:2lkxidoc]–
— Called when a modulator value changes
— @modulator http://ctrlr.org/api/class_ctrlr_modulator.html
— @newValue new numeric value of the modulator
—
FilterSwitch = function(modulator, newValue)— Images for filters on of are sixfold_selection_filteroff and sixfold_selection_filter
— Images for filte slope are led_three_upward2 and led_three_upward_off
— Images for Slider nord_led_pot_full_off and nord_led_pot_full— Slider FilterFreq2 in Single Mode CC is 114 and in Multi Mode CC is 59
— filterslope modulator
fs = panel:getModulatorByName("FilterSlope")— Single Filter Type modulator
sft = panel:getModulatorByName("FilterType")— Multi Filter Type and Led Modulators
mft = panel:getModulatorByName("FilterEnvCtrl")
mftl = panel:getModulatorByName("FilterEnvCtrlLed")
— Filter Freq Dist slider
ff = panel:getModulatorByName("FilterFreq2")if newValue >58 then
if fs ~= nil and sft ~= nil and ff ~= nil and mft ~= nil and mftl ~= nil then
x = fs.getComponent()
x:setPropertyString ("uiImageResource" , "led_three_upward_off")
x = sft.getComponent()
x:setPropertyString ("uiImageResource" , "sixfold_selection_filteroff")
x = ff.getComponent()
x:setPropertyString ("uiImageResource" , "nord_led_pot_full")
x = mft.getComponent()
x:setPropertyString ("uiImageResource" , "sixfold_selection_filter")
mftl:setModulatorValue(1,false,false,true)
end
else
if fs ~= nil and sft ~= nil and ff ~= nil and mft ~= nil and mftl ~= nil then
x = fs.getComponent()
x:setPropertyString ("uiImageResource" , "led_three_upward2")
x = sft.getComponent()
x:setPropertyString ("uiImageResource" , "sixfold_selection_filter")
x = ff.getComponent()
x:setPropertyString ("uiImageResource" , "nord_led_pot_full_off")
x = mft.getComponent()
x:setPropertyString ("uiImageResource" , "sixfold_selection_filteroff")
mftl:setModulatorValue(0,false,false,true)
end
end
end[/code:2lkxidoc]Single Filter and Multi Filte MIDI CC 44 assigned as with following values
[b:2lkxidoc]Single Filter Mode[/b:2lkxidoc]
LP=0
HP=12
BP=24
BR=35
CLASSIC=47
DISTLP=58[b:2lkxidoc]Multi Filter Mode[/b:2lkxidoc]
LP-BP=70
LP-HP=81
HP-LP=93
BP-BP=104
MultiPeak=116
MultiNotch=127That is why code has caution if CC value higher then 58 then pictures should be changed.
But if I start panel it gives me an error (see picture below) if I press on of the knobs of the filters
[img:2lkxidoc]http://dl.dropbox.com/u/4202790/error.png[/img:2lkxidoc]I’m using the latest Nightly on Win. and at home i’m using Mac – will check code also there. But I think there will be the same error
2. Is there any example code how to assign the specific MIDI CC controller value to modulator ?
The thing is that the behaviour of Single Filter type on device in case of value set to Dist LP (MIDI CC44 with value 58) uses Slider Freq2Dist (marked in Green field). Other Filter types disabling that Slider.
As I said before right side has Slider controlling Frequency 2 (as CC 59 when Multi Filter Mode is enabled) and Distortion (as CC 114 ).
When you switch Multi Filter Mode this Slider should chnage MIDI CC Value to 59?
Is there anyway to make that things working as device do?Really crazy algorythm. I need your help in code or could you just direct me in right way
Many thanks in advanceJune 18, 2012 at 2:45 pm #4438Definetly using "." for object operations os wrong, you got some of it right and some wrong always use ":" for object operations
[code:29pwhc6j]
x = fs.getComponent() — WRONG
x = fs:getComponent() — CORRECT
[/code:29pwhc6j]June 18, 2012 at 6:09 pm #4439"atom":2zsls0nb wrote:Definetly using "." for object operations os wrong, you got some of it right and some wrong always use ":" for object operations
[code:2zsls0nb]
x = fs.getComponent() — WRONG
x = fs:getComponent() — CORRECT
[/code:2zsls0nb][/quote:2zsls0nb]
hmmm,will fix…didn’t notice that.thanks mate
what about the way setting the different value for MIDI CC Controller?
like x:setPropertyInt("MIDI Controller",value)?June 18, 2012 at 6:17 pm #4440the properties have special names those visible in the properties pane are only friendly names, have a look here http://ctrlrv4.svn.sourceforge.net/view … rlrIDs.xml for mappings, the cc number will be midiMessageCtrlrNumber, but this is the property of the midi message object not the modulator or the component you should use the getMidiMessage() method of the modulator object to get it’s midi message object.
June 19, 2012 at 8:55 am #4441"atom":1qhay9jr wrote:the properties have special names those visible in the properties pane are only friendly names, have a look here http://ctrlrv4.svn.sourceforge.net/view … rlrIDs.xml for mappings, the cc number will be midiMessageCtrlrNumber, but this is the property of the midi message object not the modulator or the component you should use the getMidiMessage() method of the modulator object to get it’s midi message object.[/quote:1qhay9jr]ok, I created two LUA scritps – one is assigned to Single FIlter knob modulator and another one to Multi Filter Knob modulator.
Firstly, they were also haven’t display the visualization as I requested, I checked your CtrlR ID values and found out that I used[b:1qhay9jr] "uiImageResource"[/b:1qhay9jr] which did nothing for me instead of using the right ones as shown in your ID table – [b:1qhay9jr]"uiImageButtonResource"[/b:1qhay9jr] or [b:1qhay9jr]"uiImageSliderResource"[/b:1qhay9jr]. So that is clear for me know.
1st script – works fine – visualizations working properly
[code:1qhay9jr]FilterSwitch = function(modulator, newValue)— Images for filters on of are sixfold_selection_filteroff and sixfold_selection_filter
— Images for filte slope are led_three_upward2 and led_three_upward_off
— Images for Slider nord_led_pot_full_off and nord_led_pot_full— Slider FilterFreq2 in Single Mode CC is 114 and in Multu Mode CC is 59
— filterslope modulator
fs = panel:getModulatorByName("FilterSlope")— Single Filter Type modulator
sft = panel:getModulatorByName("FilterType")— Multi Filter Type and Led Modulators
mft = panel:getModulatorByName("FilterEnvCtrl")
mftl = panel:getModulatorByName("FilterEnvCtrlLed")— Filter Freq Dist slider
ff = panel:getModulatorByName("FilterFreq2")filtermode=1
if filtermode == 1 then
z = sft:getComponent()
z:setPropertyString ("uiImageButtonResource" , "sixfold_selection_filter")
z = fs:getComponent()
z:setPropertyString ("uiImageButtonResource" , "led_three_upward2")
z = ff:getComponent()
z:setPropertyString ("uiImageSliderResource" , "nord_led_pot_full_off")
z = mft:getComponent()
z:setPropertyString ("uiImageButtonResource" , "sixfold_selection_filteroff")
end
— Enabling Dist Slider if DIST LP (58) is Selected on Filter Typeif newValue == 5 then
z = ff:getComponent()
z:setPropertyString ("uiImageSliderResource" , "nord_led_pot_full")
fs:setModulatorValue(1, false, true, true)
else
z = ff:getComponent()
z:setPropertyString ("uiImageSliderResource" , "nord_led_pot_full_off")
fs:setModulatorValue(2, false, true, true)
end
— Disabling Filter Slope if BR (35) is Selected on Filter Typeif newValue == 3 then
z = fs:getComponent()
z:setPropertyString ("uiImageButtonResource" , "led_three_upward_off")
else
z = fs:getComponent()
z:setPropertyString ("uiImageButtonResource" , "led_three_upward2")end
end[/code:1qhay9jr]2nd script -visualizations working properly as well
[code:1qhay9jr]–
— Called when a modulator value changes
— @modulator http://ctrlr.org/api/class_ctrlr_modulator.html
— @newValue new numeric value of the modulator
—
FilterSwitch2 = function(modulator, newValue)
— Images for filters on of are sixfold_selection_filteroff and sixfold_selection_filter
— Images for filte slope are led_three_upward2 and led_three_upward_off
— Images for Slider nord_led_pot_full_off and nord_led_pot_full— Slider FilterFreq2 in Single Mode CC is 114 and in Multu Mode CC is 59
— filterslope modulator
fs = panel:getModulatorByName("FilterSlope")— Single Filter Type modulator
sft = panel:getModulatorByName("FilterType")— Multi Filter Type and Led Modulators
mft = panel:getModulatorByName("FilterEnvCtrl")— Filter Freq Dist slider
ff = panel:getModulatorByName("FilterFreq2")filtermode=2
if filtermode == 2 then
if fs ~= nil and sft ~= nil and ff ~= nil and mft ~= nil and mftl ~= nil then
z = fs:getComponent()
z:setPropertyString ("uiImageButtonResource" , "led_three_upward_off")
z = sft:getComponent()
z:setPropertyString ("uiImageButtonResource" , "sixfold_selection_filteroff")
z = ff:getComponent()
z:setPropertyString ("uiImageSliderResource" , "nord_led_pot_full")
z = mft:getComponent()
z:setPropertyString ("uiImageButtonResource" , "sixfold_selection_filter")— Assign to FilterFreq2 CC number 59
xx=ff:getMidiMessage()
end
else
if fs ~= nil and sft ~= nil and ff ~= nil and mft ~= nil and mftl ~= nil then
z = fs:getComponent()
z:setPropertyString ("uiImageButtonResource" , "led_three_upward2")
z = sft:getComponent()
z:setPropertyString ("uiImageButtonResource" , "sixfold_selection_filter")
z = ff:getComponent()
z:setPropertyString ("uiImageSliderResource" , "nord_led_pot_full_off")
z = mft:getComponent()
z:setPropertyString ("uiImageButtonResource" , "sixfold_selection_filteroff")
filtermode=1— Assign to FilterFreq2 CC number 114
end
endend[/code:1qhay9jr]
But if you may see there is a code within that 2nd script . I tried to call method you have suggested to get modulator MIDI message.
[code:1qhay9jr]
— Assign to FilterFreq2 CC number 59xx=ff:getMidiMessage()
[/code:1qhay9jr]This code gives an error
[img:1qhay9jr]http://dl.dropbox.com/u/4202790/error2.png[/img:1qhay9jr]Seems it is not registered in CtrlR.
I wonder is there any other way to set the CC value to modulator using LUA code? I wish I could find an examples. But nothingJune 19, 2012 at 2:05 pm #4442I’m outta town tofay but ill post a complete example later today.
June 19, 2012 at 2:52 pm #4443"atom":g4a4pxoh wrote:I’m outta town tofay but ill post a complete example later today.[/quote:g4a4pxoh]
thanks mateJune 20, 2012 at 7:42 pm #4444That should work now, i had to fix some stuff, the getMidiMessage() method should work and you should be able to set it’s properties.
June 21, 2012 at 4:41 am #4445"atom":x9t8okc3 wrote:That should work now, i had to fix some stuff, the getMidiMessage() method should work and you should be able to set it’s properties.[/quote:x9t8okc3]
thanks mate. gonna check NightlyJune 21, 2012 at 10:13 am #4446"atom":1t2y57k6 wrote:That should work now, i had to fix some stuff, the getMidiMessage() method should work and you should be able to set it’s properties.[/quote:1t2y57k6]
I didn’t try that method yet but the only issue I faced was if I change Image Resource of modulator (selecting images from the list) it doesn’t change in fact on panel. When I restart the CtrlR application. Changes are applied. Strange thing. Use last Nightly on Windows 1053.June 21, 2012 at 10:33 am #4447"atom":2l6zgz6m wrote:I’m outta town tofay but ill post a complete example later today.[/quote:2l6zgz6m]
can I have an example mate?June 21, 2012 at 12:41 pm #4448Sure, here is how i change a CC number from 32 to 64
[code:1r0lycey]
—
— Called when a modulator value changes
— @modulator http://ctrlr.org/api/class_ctrlr_modulator.html
— @newValue new numeric value of the modulator
—
changeControllerNumber = function(modulator, newValue)— we’re attaching this method to a button with a true/false state
— first let’s get the modulator we want to change
mod = panel:getModulatorByName("filterCutoff")if mod ~= nil then
— we got the modulaotr, now let’s see if it has a valid MIDI message attached
midi = mod:getMidiMessage()
if midi ~= nil then— allright we have all the data we need, now depending on the button state
— we’ll set the controller numberif newValue == 1 then
midi:setPropertyInt ("midiMessageCtrlrNumber", 32)
else
midi:setPropertyInt ("midiMessageCtrlrNumber", 64)
end
end
end
end
[/code:1r0lycey]June 21, 2012 at 1:09 pm #4449"atom":1qnxx4ev wrote:Sure, here is how i change a CC number from 32 to 64
[/quote:1qnxx4ev]
thank mate for an example. will check this code at home. but really cannot understand the strange slider behaviour and its image resource wrong value.June 21, 2012 at 1:24 pm #4450I’ve placed the image resource demo and the midi controller demo onto a panel. It should help you with those two issues.
[attachment=0:18fpbxy5]Property Demo_1_0_Buttcheek_201206211522.bpanelz[/attachment:18fpbxy5]
June 22, 2012 at 6:18 am #4451"atom":t7n6vy8d wrote:I’ve placed the image resource demo and the midi controller demo onto a panel. It should help you with those two issues.[attachment=0:t7n6vy8d]Property Demo_1_0_Buttcheek_201206211522.bpanelz[/attachment:t7n6vy8d][/quote:t7n6vy8d]
I tried eveything but it doesn’t work for me with latest Nightly as on Mac and Win. Do not understand why. I sent PM the bpanel to you. could you please assist?
June 22, 2012 at 11:22 am #4452Does the panel i’ve sent work ?
June 24, 2012 at 5:00 pm #4453"atom":3fw2zzbd wrote:Does the panel i’ve sent work ?[/quote:3fw2zzbd]
Property worked but my stoped working… something wrong with NightlyJune 24, 2012 at 5:01 pm #4454Could you be more specific ? With the latest nightly the panel i’ve attached here, is it working ?
June 24, 2012 at 5:05 pm #4455"atom":2gbqxpy4 wrote:Could you be more specific ? With the latest nightly the panel i’ve attached here, is it working ?[/quote:2gbqxpy4]
I sent PM to you with all details recently. Have you got it?Before you implemented Nightly with new method to control MIDI CC values it was 1047. Vizualizations were working as programmed. After I did install the new one Nightly they stoped working as expected but your example worked in tha Nightly –
Could you please verify if panel I sent you is working as I described in PM?June 24, 2012 at 5:18 pm #4456I looked at your panel but i’m afraid i don’t understand what you are trying to achieve and what’s nor working. I can work with simple examples if can provide them. If my example panel is working then the midi-cc and resource changing properties are working and so your code should work also.
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.