Home › Forums › General › Programming › A little help please
- This topic has 6 replies, 4 voices, and was last updated 6 years, 6 months ago by goodweather.
-
AuthorPosts
-
October 15, 2017 at 8:21 am #73197
Hey guys,
I have the following code inserted in the “Called when the modulator value changes” method of a uiListBox. It sends four Sysex messeges per list item that is clicked.
My_Knobs_1 = function(value) list = panel:getModulatorByName("list"):getModulatorValue() cc = -1 if list == 0 then for k = 40,61,7 do string.format('%x', k) cc = cc + 1 m1 = CtrlrMidiMessage({0xf0, 0x47, 0x00, 0x72, 0x31, 0x00, 0x04, 0x01, 0x03, k, cc, 0xf7}) panel:sendMidiMessageNow(m1) end elseif list == 1 then cc = 3 for k = 40,61,7 do string.format('%x', k) cc = cc + 1 m1 = CtrlrMidiMessage({0xf0, 0x47, 0x00, 0x72, 0x31, 0x00, 0x04, 0x01, 0x03, k, cc, 0xf7}) panel:sendMidiMessageNow(m1) end elseif list == 2 then cc = 7 for k = 40,61,7 do string.format('%x', k) cc = cc + 1 m1 = CtrlrMidiMessage({0xf0, 0x47, 0x00, 0x72, 0x31, 0x00, 0x04, 0x01, 0x03, k, cc, 0xf7}) panel:sendMidiMessageNow(m1) end end end
What I’m wondering…, is there a way to do this that doesn’t require a bunch of “if” statements? The actual list contains 32
items, but I’ve shortened the code for posting here.When item one is clicked it sends:
F0 47 00 72 31 00 04 01 03 28 00 F7
F0 47 00 72 31 00 04 01 03 2F 01 F7
F0 47 00 72 31 00 04 01 03 36 02 F7
F0 47 00 72 31 00 04 01 03 3D 03 F7When item two is clicked it sends:
F0 47 00 72 31 00 04 01 03 28 04 F7
F0 47 00 72 31 00 04 01 03 2F 05 F7
F0 47 00 72 31 00 04 01 03 36 06 F7
F0 47 00 72 31 00 04 01 03 3D 07 F7etc…
The code works, it’s just I’d rather not use so many “ifs”, if possible?
Any help is greatly appreciated.
Thanks
- This topic was modified 6 years, 6 months ago by Anton.
October 15, 2017 at 8:32 am #73199if it works? …
… why worry? 😀
looks ok.you could have some table if refers to(?)
but it might not end up any shorter.October 16, 2017 at 12:15 pm #73231Hi there Anton,
If ‘list’ can have values ranging from 0-31, then I think this would work:
My_Knobs_1 = function(value) list = panel:getModulatorByName("list"):getModulatorValue() local multiplier = list * 4 local loopEnd = multiplier + 3 k=40 for i=multiplier,loopEnd do m1 = panel:sendMidiMessageNow(CtrlrMidiMessage({0xf0, 0x47, 0x00, 0x72, 0x31, 0x00, 0x04, 0x01, 0x03, k, i, 0xf7})) k=k+7 end
Note: in the attached panel I mistakenly left in the redundant
i=i+2
Regards,
Attachments:
You must be logged in to view attached files.October 16, 2017 at 8:57 pm #73234Hi, saw that question the other day and also wanted to answer it.
Here is a simpler code I think…-- -- Called when a modulator value changes -- @mod http://ctrlr.org/api/class_ctrlr_modulator.html -- @value new numeric value of the modulator -- Combo_OnChange = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) lblSysex = panel:getModulatorByName("lblSysex") modValues = panel:getModulatorByName("cbValues") sText ="" for i=0,3 do mbTemp= MemoryBlock ({0xf0, 0x47, 0x00, 0x72, 0x31, 0x00, 0x04, 0x01, 0x03, 40+i*7, value*4+i, 0xf7}) panel:sendMidiMessageNow (CtrlrMidiMessage(mbTemp)) sText = sText..mbTemp:toHexString(1).."\n" end lblSysex:getComponent():setPropertyString("uiLabelText", sText) end
and the panel from dnaldoog adapted 🙂
Attachments:
You must be logged in to view attached files.October 17, 2017 at 12:34 am #73237Wow – that’s better and even more concise!
October 17, 2017 at 12:18 pm #73240@ dnaldoog & goodweather,
Both scripts work as expected, and I learned a thing or two. 😀
Thank you both, very much appreciated!
October 22, 2017 at 6:21 pm #73275cool 😉
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.