SOLVED: What’s wrong in my function

Home Forums General Programming SOLVED: What’s wrong in my function

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #117083
    EnzoF04
    Participant
    • Topics: 17
    • Replies: 96
    • Total: 113
    • ★★

    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 1 month, 1 week ago by EnzoF04.
    • This topic was modified 1 month, 1 week ago by EnzoF04.
    • This topic was modified 1 month, 1 week ago by EnzoF04.
    • This topic was modified 4 weeks ago by EnzoF04.
    Attachments:
    You must be logged in to view attached files.
    #117089
    dnaldoogdnaldoog
    Participant
    • Topics: 1
    • Replies: 236
    • Total: 237
    • ★★
    requestProgramDump = 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))
    

    :)

    #117096
    goodweathergoodweather
    Participant
    • Topics: 41
    • Replies: 443
    • Total: 484
    • ★★

    Hi,
    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 before

    Have fun!

    #117099
    EnzoF04
    Participant
    • Topics: 17
    • Replies: 96
    • Total: 113
    • ★★

    Thanks for your replies! I’m going in to it!

    #117101
    EnzoF04
    Participant
    • Topics: 17
    • Replies: 96
    • Total: 113
    • ★★

    – 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.

    #117289
    EnzoF04
    Participant
    • Topics: 17
    • Replies: 96
    • Total: 113
    • ★★

    Here 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 3 weeks, 6 days ago by EnzoF04.
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
There is currently 1 user and 38 guests online
denmla
Forum Statistics
Threads: 2,308, Posts: 16,186, Members: 59,526
Most users ever online was 12 on January 22, 2019 3:47 pm
Do NOT follow this link or you will be banned from the site!