Reply To: MIDI Out LED

Home Forums General Programming MIDI Out LED Reply To: MIDI Out LED

  • Topics: 2
  • Replies: 31
  • Total: 33

No, like I said above, I think there are two different use cases here – your one where you have little tiny packets you can break up, one at a time – in which case yes, you’d put the send in the timer function.
My use case is completely different – I have one single big packet that I can’t split. So putting it in the timer wouldn’t accomplish anything – I can’t split it, so I can’t do the bar thing, or fire off the packets one at a time to the timer.
In my code fragment above, encodesysex is the bad boy that puts together all the controllers into one sysex string – the Poly800 doesn’t understand CC’s, so it can only take one big sysex load.
My problem was this – sendMidiMessageNow is ASYNCHRONOUS. So putting one giant packet send in the timer would be meaningless, as it would just send it and return instantaneously, then spend 2-3 seconds doing the upload of that giant packet. BUT – and this was the breakthrough moment – if I can accurately calculate the exact time it takes to send that giant packet, I can tell the timer EXACTLY how long to make the LED red. So the timer callback, as above, is purely the place where it makes the LED black at the end of the 2-3 second send. Does that make sense now? There are two different use cases.
Yours works for split packets – not for giant floaters 😀
To prevent any more confusion, here is the use case for big packets in full:

function sendSysex()

-- This stops index issues during panel bootup
	if panel:getRestoreState() or panel:getBootstrapState() then

    local mysysexData, my_c0, programChange, tempProg, j, currMidi, s, totwait;

	if timer:isRegistered(40) == false then
	    -- console ("timer40 not registered, do it now");
		timer:setCallback(40, timer40Callback);

	if timer:isTimerRunning(40) then
		-- console ("timer40 already running, stop it");

-- update sysex and add crc
    mysysexData=encodeSysex();  -- create the full sysex dump

    s = mysysexData:getSize();

    totwait = tonumber( ( s * 0.32 ) + 5 ); -- 5ms for the global delay, totwait in ms

    -- console("start timer40...");
    panel:getModulatorByName("sendDumpButton"):getComponent():setProperty ("uiButtonTextColourOff","FFFF4545",true); -- make it red
    timer:startTimer (40, totwait); 



function timer40Callback()
    panel:getModulatorByName("sendDumpButton"):getComponent():setProperty ("uiButtonTextColourOff","FF454545",true); -- back to black
    -- console("stop timer40");
Do NOT follow this link or you will be banned from the site!