No idea why this script is causing Synth V to crash upon scanning the script

No idea why, but here’s what I did to crash Synth V as it is:

  • Save this code as a lua file called “pitch devia.lua” into Synth V and attempt to run Synth V, or scan for scripts
function getClientInfo()
    return {
        name = "Pitch break demonstration",
        author = "Fyrebreak",
        category = "Tests",
        versionNumber = 1,
        minEditorVersion = 0
    }
end

function main()
    local selectedNotes = SV:getMainEditor():getSelection():getSelectedNotes()
    if #selectedNotes == 0 then
        return
    end

    local setValue = 3
    local setTime = 0.3
    local modValue = setValue*100
    local modTime = SV:seconds2Blick(setTime, )


    local group = selectedNotes[1]:getParent()
    local param = group:getParameter("pitchDelta")
    local def = param:getDefinition()
    local default = def.defaultValue
    for i=1,#selectedNotes do
        local startPos = selectedNotes[i]:getOnset()
        local endPos = selectedNotes[i]:getEnd()
        local startValue = param:get(startPos)
        local postValue = param:get(endPos+1)
        param:add(startPos, startValue)
        param:add(startPos+1, modValue)
        param:add(startPos+ modTime, modValue)
        param:add(startPos+ modTime+1, startValue)
        param:add(endPos, postValue)
    end
    SV:finish()
end


And that’s about it.

If synthv could throw me some sort of exception, that would be helpful in figuring out why the program is even allergic to scanning this file. But it just crashes without any sort of warning whatsoever.

I did just learn Lua a few weeks ago, so I might have made some basic errors but I’m still not sure. Maybe I’ll throw it into Copilot to see if it can roast me.

To give a bit of context about the startup process:

The software validates all dictionaries and scripts on startup. This includes executing each script (but not running its main function) and then calling the getClientInfo function. It uses the values in getClientInfo to build the top menu (ie each script’s name and category).

This will still run into syntax errors inside the functions where they exist – the functions do get parsed, even though they aren’t executed at this time.

The same thing happens each time you select “rescan”.

On Windows, at least in my experience, files without a .js or .lua extension are ignored.


Embedded scripts do tend to have some quirks, not just in SynthV Studio, due to the fact that they’re running in a special environment. In cases where SynthV Studio crashes and you can’t see the error, it can help to run the Lua code in a different environment. A convenient option is this browser-based tool, which probably uses the official Lua CLI on the server side: Online Lua Compiler

When I copy your code in there, I see the following error:
lua: main.lua:20: unexpected symbol near ')'

On line 20, I see a function call that is passing one argument to SV:seconds2Blick, however it also has a comma followed by missing parameter. In this case, you need to provide the bpm as the second argument (you can get the bpm at a specific blick location with TimeAxis:getTempoMarkAt).

Personally I don’t see a crash because of this issue, I get the error from SynthV Studio in a dialog popup:

image


On Windows I have no issues with file paths that contain a space, however you might want to consider using file names following one of the following conventions, since spaces in file names can cause issues in some situations:

camelCase.lua
PascalCase.lua
snake_case.lua
kebab-case.lua

Explanation of programming naming conventions here: Snake Case VS Camel Case VS Pascal Case VS Kebab Case – What's the Difference Between Casings?

3 Likes