Arturia Keylab : display on LCD screen

I’m not the author of this script, but since it was buried deep in a thread, I thought I could post it here so it could help others, like it helped me. I only tweaked it so it could display the current song name (if in setlist mode) and the rackspace name on the LCD screen of the Keylab. You can of course create your own display logic by modifying the strings fed to the KeylabLCD function on line 74.

It has been tested with the Keylab Essential and the Keylab MkII.

    SysexMng         : SysexManager
    KeylabMidiOut    : MidiOutBlock  // Replace 'KeylabMidiOut' with your own handle 
    KEYLAB_LCD_PRE   : String
    KEYLAB_LCD_SEP   : String
    KEYLAB_LCD_END   : String
    ASCII_STRING     : String
    ASCII_HEX_STRING : String array
    ASCII_STRING     = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[Y]^_`abcdefghijklmnopqrstuvwxyz{|}><";
    ASCII_HEX_STRING = ["20","21","22","23","24","25","26","27","28","29","2A","2B","2C","2D","2E","2F","30","31","32","33","34","35","36","37","38","39","3A","3B","3C","3D","3E","3F","40","41","42","43","44","45","46","47","48","49","4A","4B","4C","4D","4E","4F","50","51","52","53","54","55","56","57","58","59","5A","5B","5C","5D","5E","5F","60","61","62","63","64","65","66","67","68","69","6A","6B","6C","6D","6E","6F","70","71","72","73","74","75","76","77","78","79","7A","7B","7C","7D","7E","7F"];
    KEYLAB_LCD_PRE  = "# F0 00 20 6B 7F 42 04 00 60 01 "
    KEYLAB_LCD_SEP  = " 00 02 "
    KEYLAB_LCD_END  = " 00 F7"

// ******************** Utils ********************

Function Trim(s : String) returns string
    /* Trim the string if its length is greater than 16 characters */

    var temp : String  // Avoid modifying argument in-place
    If Length(s) > 16 Then
        temp = CopySubstring(s, 0, 16)
        temp = s
    result = temp

Function StringToHexString(str : String) Returns String
    /* Hack provided by David-san */
    var i : Integer
    result = ""

    For i=0; i<Length(str) ; i=i+1 Do
        result = result + ASCII_HEX_STRING[IndexOfSubstring(ASCII_STRING, CopySubstring(str,i,1), True)]

// ***************** Keylab display ***************** 

Function KeylabLCD(line1 : String, line2 : String)
    /* Display each line on the LCD screen of the Keylab */
    var msg : String
    msg = KEYLAB_LCD_PRE + StringToHexString(Trim(line1)) + KEYLAB_LCD_SEP + StringToHexString(Trim(line2)) + KEYLAB_LCD_END
    SM_CreateSysexFromString(SysexMng, msg)
    SM_SendMidiOut(SysexMng, KeylabMidiOut)

// ******************* Callbacks *******************

On Activate
    var song : String
    If InSetlistMode() Then
        song = GetCurrentSongName()
        song = "N/A"

    KeylabLCD("S:" + song, "R:" + GetRackspaceName())

The original post can be found here: Dynamic composition of a SysEx message with variable content and length

1 Like

That’s a good initiative to make us remember this script from @rbmj. I hope you enjoyed the nice possibilities of the GPScript and of course I encourage you to go on scripting :wink:

Man, GPScript is honestly the best feature I wasn’t aware of when I bought GP3! I look forward to the day when global scripts and code reuse will be a thing :wink:

I also have a question:
I’m trying to execute code when I press the arrow buttons on my Keylab, which send a SysEx message. So I’m trying to find a callback function for SysEx messages. I read the documentation, but there doesn’t seem to be a way to catch those. I tried using the MidiEvent callback, which seemed to be the most generic one, but to no avail, even if the message shows up in the MIDI console. Is this feasible?

Hummm, I think there is no callback responding to SysEx, but it could be a good idea to put an entry in the feature request category. I don’t know if it is doable.