Home › Forums › General › Programming › SOLVED: What’s wrong in my function
- This topic has 5 replies, 3 voices, and was last updated 4 years ago by EnzoF04.
-
AuthorPosts
-
February 26, 2020 at 9:02 pm #117083
After been away for quite a lot of time, I’ve picked up CTRLR again. I’m using an existing panel for the Six-TRAK. Basic idea is to pull stored program data from the Six-TRAK and put it in the panel. So the panel needs to update after it changes program. I’ve programmed/borrowed a function but I get this message back. What am I doing wrong in the function? Thanks for all help!
Best regards
requestProgramDump = function() p = panel:getModulatorByName("Program") pn = p:getModulatorValue() ph = dec2hex(pn) pnr = CtrlrMidiMessage({0xf0, 0x01, 0x00, ph, 0xf7}) console (pnr:toString()) -- panel:sendMidiMessageNow(pnr) console(tostring(ph)) end
- This topic was modified 4 years, 1 month ago by EnzoF04.
- This topic was modified 4 years, 1 month ago by EnzoF04.
- This topic was modified 4 years, 1 month ago by EnzoF04.
- This topic was modified 4 years ago by EnzoF04.
Attachments:
You must be logged in to view attached files.February 27, 2020 at 12:35 am #117089requestProgramDump = function() p = panel:getModulatorByName("Program") pn = p:getModulatorValue() pnr = CtrlrMidiMessage({0xf0, 0x01, 0x00, pn, 0xf7}) console (pnr:toString()) panel:sendMidiMessageNow(pnr) end
Hi EnzoF04
It works for me on Windows 10 version 5.3.201, but I eliminated the dec2hex function. Maybe that is returning a string? Anyway you don’t need it.
You could also do:
value=23 -- for example local sysexString = "f0 43 10 5c 10 %02x f7" local sysexFormula = string.format(sysexString, value) panel:sendMidiMessageNow(CtrlrMidiMessage(sysexFormula))
:)
February 29, 2020 at 9:43 pm #117096Hi,
dec2hex is indeed returning a string si it will not work in your first example.-- -- Returns HEX representation of a DECimal number -- dec2hex = function(num) local hexstr = '0123456789ABCDEF' local s = '' while num > 0 do local mod = math.fmod(num, 16) s = string.sub(hexstr, mod+1, mod+1) .. s num = math.floor(num / 16) end if s == '' then s = '0' end return s end
Some remarks on very good dnaldoog’s answer:
– it is a good habit to declare all your modulators at once in some method that you call at panel load then that you refer to the modulators through the variables instead of redoing panel:getModulatorByName() all the time; To identify my modulators, I’m usually using modXXX
So: modProgram = panel:getModulatorByName(“Program”)
– you can directly put the getModulatorValue() in the message like
pnr = CtrlrMidiMessage({0xf0, 0x01, 0x00, modProgram:getModulatorValue(), 0xf7})
So you spare one variable assignment
– Using his second proposal allows you to use the dec2hex function:
local sysexString = “f0 43 10 5c 10 “..dec2hex(modProgram:getModulatorValue())..” f7″
But this is clearly less straightforward that what I wrote in the bullet point just beforeHave fun!
March 1, 2020 at 8:24 pm #117099Thanks for your replies! I’m going in to it!
March 1, 2020 at 8:37 pm #117101– it is a good habit to declare all your modulators at once in some method that you call at panel load then that you refer to the modulators through the variables instead of redoing panel:getModulatorByName() all the time; To identify my modulators, I’m usually using modXXX
Well my first challenge is to ‘get’ a modulator value into a midi message so I can use it to ‘retrieve a patch (program) from the synth.
Step 2 is the changing of the modulators on the panel so they meet the actual parameters in the patch on the synth.
March 7, 2020 at 3:08 pm #117289Here is how I do it; it’s not a classroom example of good coding but it works for me.
swLfoPls = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source) -- this for sending a midi cc based on the value in a panel component / modulator local modLP = panel:getModulatorByName("modLfoPls") -- putting the specific modulator name in a variable local modLPValue = modLP:getModulatorValue() -- putting the value in the specific modulator in a variable local swLP -- declaring a variable for the midi message if modLPValue == 1 then -- if component value is 1, the send the 'on' value, decimal 127, hex 0x7f modLPValue = 0x7f -- the value 'on' value in hex = 7f or 127 in decimal swLP = CtrlrMidiMessage({0xb5, 0x10, modLPValue}) -- first byte is telling midi CC is be sent, second byte is the cc number, third byte (the variable) is the 'on' value. else modLPValue = 0x00 swLP = CtrlrMidiMessage({0xb5, 0x10, modLPValue}) end panel:sendMidiMessageNow(swLP) end
- This reply was modified 4 years ago by EnzoF04.
-
AuthorPosts
- The forum ‘Programming’ is closed to new topics and replies.