Receive MidiMessage in a modulator function Lua script?

Home Forums General Programming Receive MidiMessage in a modulator function Lua script?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #763
    • Topics: 25
    • Replies: 160
    • Total: 185
    • ★★

    I am trying to receive a small sysex dump in a modulator’s function but i can’t seem to get my head around it.

    I need to do this for safely deleting presets/voices/etc in my emu 6400 panel, because when a non-existing number is targeted the emu freaks out and locks up. I want to be able to request the number of existing presets/voices/etc and use the received data as a safety.

    I’m stuck on getting the received sysex data’s values into the script, have no clue what to do….

    Here’s how it looks now:

    [code:1yl4suql]DeleteVoiceSafely = function(modulator, newValue)

    –request total number of voices in a preset

    fetchTotalVoices = {0xF0; 0x18, 0x21, 0x01, 0x55, 0x16, 0xF7}
    panel:sendMidiMessageNow(CtrlrMidiMessage(fetchTotalVoices)) // working

    –pause script and receive the sysex string that is returned from device


    –disable/skip rest of the script + throw some error message if a non-existing number is targeted // todo

    –retrieve target preset number + print to console for debugging // working

    c = panel:getModulatorByName("select preset"):getMidiMessage():getLuaData():getByte(9)
    console (string.format "delete voice in preset nr")
    console (string.format (getPresetNr))

    –retrieve target voice number + print to console for debugging // working

    d = panel:getModulatorByName("select voice"):getMidiMessage():getLuaData():getByte(9)
    console (string.format "delete voice nr")
    console (string.format (getVoice))

    –construct delete command with retrieved preset and voice values + print to console for debugging // working

    del = {0xF0; 0x18, 0x21, 0x01, 0x55, 0x21,0x00, c, d, 0x00, 0xF7}
    dellua = CtrlrLuaObjectWrapper(del)
    mb1 = CtrlrLuaMemoryBlock()
    console (string.format("sysex message"))
    console (mb1:toHexString(4))

    –send out delete voice command // working



    • Topics: 219
    • Replies: 732
    • Total: 951
    • ★★★

    ok, so you want to put the script that sends the dump request on a modulator.

    Then, in edit mode, click your ctrlr panel’s background. The properties/attributes editor on the far right should now populate with properties/attributes of your base panel. Near the very top you should see "Called when the panel receives a MIDI message". You want to create a script there, appropriate name for the script would be something like midiMessageReceived.

    This midiMessageReceived script will be called ANY TIME a midi message comes into through the selected MIDI device for this panel.

    I’m not sure how the formatting of a script here looks when created from scratch I could check but you want the first line (declaration) to be something like:
    [code:32vnwzlj]midiMessageReceived = function(midiMessage)[/code:32vnwzlj]

    When this script is run, the midiMessage function (in the core of ctrlr) is run which deals with… you guessed it. midi messages.

    Now you need some way of determining what kind of message is the type of message you want to grab data from depending on what it is you’re trying to do. Most every sysex message has some sort of IDM or Message ID. This tells whatever is receiving the sysex message what the hell it is. it could be a program dump, a parameter change, a sample, a wavetable, program name, etc. Check your manual for what the IDM is.. it’s usually the first value (from the left) that actually changes depending on the type of message sent.

    I just today replied to synthetech’s topic in this same programming thread, check my last post there for how to "sniff" the incoming message to determine what kind of message it is.

    I don’t know what you are wanting to do in the end here but to get data from a sysex dump coming from a synth into your panel you’d want to create a function that assigns a byte/all the bytes to a variable.. or possibly a string. You can search here for assigning stuff to a string but a good starting point either way to help get to your answer would be just to assign the whole message to a variable. Something a little different from synthetic’s example, just for a little diversity… example:

    [code:32vnwzlj]function drinkBeer(midiMessage) — I dunno, call your function whatever you want.

    appropriateVariableName= midiMessage:getLuaData():getRange(7,12)


    this is assuming the bytes you want to capture into your variable are the eighth to thirteenth byte of the entire message starting from the F0. Remember bytes are indexed from 0, so the first byte, which is across the board on any synth by MIDI spec is F0 will be byte index 0. This is typically referred to as the first byte of the message, but it’s index is 0. <img loading=” title=”Smile” />

    Any number in sysex is hex. You should know that. MIDI data is always indexed and it’s always indexed starting at 00.

    Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

    • Topics: 25
    • Replies: 160
    • Total: 185
    • ★★

    Great thank you for taking time to explain this <img loading=” title=”Very Happy” />
    I will delve into this today, i already figured out how to manipulate sysex strings between modulators; getting and setting bytes n stuff so i think i’ll be able to crack this.
    I will also check out the other thread you mention for more insight.


    • Topics: 2
    • Replies: 5
    • Total: 7

    That’s what I was looking for.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Programming’ is closed to new topics and replies.
There is currently 1 user and 25 guests online
Forum Statistics
Threads: 2,460, Posts: 17,299, Members: 53,064
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!