Develop lua in external editor (not browser)

Hi

I would like to develop the lua code in an external editor like visual studio code, as i sometimes find it difficult to keep an overview of the whole code in the editor inside the browser.
Is this possible and how would i upload the code to electra one?
How do you develop lua code for complex presets?

Thank you for your answers.
Michael

There are many editors for lua , I sometimes use zerobrane Studio for this purpose

1 Like

I use an on line Lua compiler to test out a lot of the non-Electra specific code. Not a full solution, but when I need to work with arrays of values or text or other complex data structures, it’s faster and safer :grinning_face_with_smiling_eyes: to work outside the E1. I tend to use onecompiler (Online lua.

2 Likes

@NewIgnis and @oldgearguy Thank you for your responses.

When you code outside the provided E1 editor, do you copy and paste the lua code into the E1 editor after having made some changes? Or are you able to upload the code automatically with sysex messages to the E1?

1 Like

I copy and paste. That works fine and fast for me.

I haven’t used any sysex ever so far to communicate between PC and the E1. Not had the need either.

All Sysex efforts so far for me are on E1 versus synths.

given that you have a sendmidi tool installed, you can use a simple shell script like this:

#!/bin/bash

# Check for input file
if [ $# -ne 1 ]; then
    echo "Usage: $0 <lua_file>"
    exit 1
fi

DATA_FILE="$1"

# Check if file exists
if [ ! -f "$DATA_FILE" ]; then
    echo "File not found: $DATA_FILE"
    exit 1
fi

# Create a temp file
TMP_FILE=$(mktemp)

# Add lua upload sysex header 
printf '\xF0\x00\x21\x45\x01\x0C' > "$TMP_FILE"

# Append lua file contents
cat "$DATA_FILE" >> "$TMP_FILE"

# Add sysex footer 
printf '\xF7' >> "$TMP_FILE"

# Send via sendmidi to Electa's CTRL port 
sendmidi dev "Electra Controller Electra CTRL" syf "$TMP_FILE"

# Delete the temp file
rm -f "$TMP_FILE"

chmod it to 755 and you can use from the command line:

./uploadLua.sh youfile.lua

Visual Studio Code can call by by using Make or other build tool.

The controller will execute the newly uploaded Lua immediately after the upload is completed.

1 Like

Thank you @martin!

I actually want to split my source code into different files, i.e. that each class is inside another lua file. I found a solution where i use gulp to assemble the lua files into a single lua file (i.e. app.lua). Then i convert the app.lua to a app.syx file with 0xF0, 0x00, 0x21, 0x45, 0x01, 0x0C at the beginning and 0xF7 at the end. This is done with the help of a python script. And finally the sysex file is sent to E1 with sendmidi.

All these described steps are defined in a gulp file, so whenever i save any lua file, app.lua is reassambled, converted to sysex and finally sent to the E1 automatically with the command gulp watch.

So far this works fine, except that i something minor in my code doesn’t work when done this way. It is related to a custom controller and runPaintCallback. I get the error: attempt to index a nil value (local 'potEvent'). Do i somehow have to wait for something? The custom controller is setup/created in preset.onLoad().

When i restart E1, the preset and lua script load fine, without any errors. So i guess it is related with the uploading of the lua code.