uvi-script
Musical event scripting with Lua
Loading...
Searching...
No Matches
Event Callbacks

Functions

void onInit ()
 initial callback that is called just after the script initialisation if the script was successfully analyzed.
 
void onLoad (table data)
 callback that is called when restoring a ScriptProcessor state if custom data has been saved.
 
table onSave ()
 callback that is called when saving the ScriptProcessor state.
 
void onEvent (table e)
 event callback that will receive all incoming events if defined.
 
void onNote (table e)
 event callback that will receive all incoming note-on events if defined.
 
void onRelease (table e)
 event callback executed whenever a note off message is received.
 
void onProgramChange (table e)
 event callback that will receive all incoming program-change events if defined.
 
void onController (table e)
 event callback that will receive all incoming control-change events when defined.
 
void onPitchBend (table e)
 event callback that will receive all incoming pitch-bend events if defined.
 
void onAfterTouch (table e)
 event callback that will receive all incoming channel after-touch events if defined.
 
void onPolyAfterTouch (table e)
 event callback that will receive all incoming polyphonic after-touch events if defined.
 
void onTransport (bool playing)
 event callback that is called when the host transport bar state changes.
 

Detailed Description

Event-driven callback functions that define your script's behavior.

Event callbacks are functions you define that are automatically called when specific events are received by the ScriptProcessor. The default behavior (if you don't define a callback) is to forward incoming events unchanged to the output.

Threading Model:

Each callback executes as an independent cooperative micro-thread (Lua coroutine) with its own environment. Unlike traditional OS threads, callbacks cannot be interrupted unless they explicitly yield using wait, waitBeat, or waitForRelease. During suspension, other callbacks can start or resume in parallel.

Available Callbacks:

Transport:

State Management:

Note
Use local variables within callbacks for per-note state. Global variables are shared across all callbacks.
See also
Threading and Timing, Events, spawn, wait

Function Documentation

◆ onAfterTouch()

void onAfterTouch ( table e)

event callback that will receive all incoming channel after-touch events if defined.

AfterTouch to pitch Example:

noteids = {}
function onNote(e)
noteids[e.note] = postEvent(e)
end
function onAfterTouch(e)
for note, id in pairs(noteids) do
changeTune(id, e.value/127)
end
end
void onNote(table e)
event callback that will receive all incoming note-on events if defined.
void onAfterTouch(table e)
event callback that will receive all incoming channel after-touch events if defined.
function postEvent(e, delta)
send a script event back to the script engine event queue.
Definition api.lua:842
function changeTune(voiceId, shift, relative, immediate)
change the tuning of specific voice in (fractionnal) semitones.
Definition api.lua:477
Parameters
eevent table with the following fields:
  • type event type equal to Event.AfterTouch
  • value aftertouch value in [0;127]
  • optional channel MIDI channel in [1;16], only useful to route events to Parts
  • optional input MIDI input in [0,3], only useful to route events to Parts
See also
onEvent, onNote, onRelease, onProgramChange, onController, onPitchBend, onPolyAfterTouch

◆ onController()

void onController ( table e)

event callback that will receive all incoming control-change events when defined.

Example:

function onController(e)
print("CC:", e.controller, "Value:", e.value)
postEvent(e) -- just forward event
end
void onController(table e)
event callback that will receive all incoming control-change events when defined.

Be aware that you need to forward MIDI CC using postEvent(e) if you want your users to be able to MIDI learn script parameters or use pre-programmed MIDI CC modulations.

Parameters
eevent table with the following fields:
  • type event type equal to Event.ControlChange
  • controller MIDI controller type in [0;127]
  • value MIDI controller value in [0;127]
  • optional channel MIDI channel in [1;16], only useful to route events to Parts
  • optional input MIDI input in [0,3], only useful to route events to Parts
See also
onEvent, onNote, onRelease, onProgramChange, onPitchBend, onAfterTouch, onPolyAfterTouch

◆ onEvent()

void onEvent ( table e)

event callback that will receive all incoming events if defined.

If this callback is defined it will take over the other more specialized callbacks like onNote, onRelease. All incoming events are tables with at least the type field defined.

Parameters
eevent table, see other callbacks for the different kind of table fields

Example:

function onEvent(e)
print(e)
postEvent(e) -- forward event
end
void onEvent(table e)
event callback that will receive all incoming events if defined.
See also
onNote, onRelease, onProgramChange, onController, onPitchBend, onAfterTouch, onPolyAfterTouch

◆ onInit()

void onInit ( )

initial callback that is called just after the script initialisation if the script was successfully analyzed.

This the place to start a background process that doesn't require external input like algorithmic event generation.

Note
Don't try to create User Interface widgets here, widget creation functions are disabled right after the main script chunk.

Example:

-- chromatic scale
function onInit()
local velocity = 100
for i=0,11 do
local note = 60 + i
local id = playNote(note, velocity, 0) -- manual release
waitBeat(0.5) -- 8th notes
end
end
void onInit()
initial callback that is called just after the script initialisation if the script was successfully a...
function releaseVoice(voiceId)
release a specific voice by sending it a note off message
Definition api.lua:1008
function playNote(note, vel, duration, layer, channel, input, vol, pan, tune, slice, oscIndex)
helper function to generate a note event.
Definition api.lua:931
function waitBeat(beat)
Suspend execution for a tempo-synchronized duration in beats.
Definition conversions.lua:142

◆ onLoad()

void onLoad ( table data)

callback that is called when restoring a ScriptProcessor state if custom data has been saved.

This is called just after the script initialisation and after restoring widgets values when the processing hasn't started yet.

Parameters
dataa lua value as saved by your onSave function

Example:

local customData = {1, 2, 3, a=1, b="text", c=true, d = {"another table"}}
function onSave()
return customData
end
function onLoad(data)
customData = data
end
table onSave()
callback that is called when saving the ScriptProcessor state.
void onLoad(table data)
callback that is called when restoring a ScriptProcessor state if custom data has been saved.
See also
onSave

◆ onNote()

void onNote ( table e)

event callback that will receive all incoming note-on events if defined.

Example:

function onNote(e)
print("Note:", e.note, "Velocity:", e.velocity)
local id = playNote(e.note, e.velocity, -1) -- auto release
end
Parameters
eevent table with the following fields:
  • type event type equal to Event.NoteOn
  • note MIDI note number in [0;127]
  • velocity MIDI note velocity in [1;127]
  • id voice ID that will be affected to the Voice once triggered
  • optional channel MIDI channel in [1;16], only useful to route events to Parts
  • optional input MIDI input in [0,3], only useful to route events to Parts
  • optional layer in range [1, number of layers], useful to route events to Layers
  • optional vol linear gain in range [0.0, 1.0], default value is 1.0
  • optional pan panoramic value in range [-1.0, 1.0], default value is 0.0
  • optional tune detuning in relative semitones, default value is 0.0. This is a floating point value: use 0.01 for detuning of 1 cents
  • optional slice slice index for slice oscillators
  • optional oscIndex oscillator index within the keygroup
See also
onEvent, onRelease, onProgramChange, onController, onPitchBend, onAfterTouch, onPolyAfterTouch

◆ onPitchBend()

void onPitchBend ( table e)

event callback that will receive all incoming pitch-bend events if defined.

Example:

noteids = {}
function onNote(e)
local id = postEvent(e)
noteids[id] = true
end
function onRelease(e)
noteids[e.id] = nil
end
function onPitchBend(e)
for id, _ in pairs(noteids) do
changeTune(id, e.bend)
end
end
void onPitchBend(table e)
event callback that will receive all incoming pitch-bend events if defined.
void onRelease(table e)
event callback executed whenever a note off message is received.
Parameters
eevent table with the following fields:
  • type event type equal to Event.PitchBend
  • bend bend value scaled to [-1.0; 1.0]
  • optional channel MIDI channel in [1;16], only useful to route events to Parts
  • optional input MIDI input in [0,3], only useful to route events to Parts
See also
onEvent, onNote, onRelease, onProgramChange, onController, onAfterTouch, onPolyAfterTouch

◆ onPolyAfterTouch()

void onPolyAfterTouch ( table e)

event callback that will receive all incoming polyphonic after-touch events if defined.

Example:

noteids = {}
function onNote(e)
noteids[e.note] = postEvent(e)
end
function onPolyAfterTouch(e)
if noteids[e.note] then
changeTune(noteids[e.note], e.value/127)
end
end
void onPolyAfterTouch(table e)
event callback that will receive all incoming polyphonic after-touch events if defined.
Parameters
eevent table with the following fields:
  • type event type equal to Event.PolyAfterTouch
  • note MIDI note number in [0;127]
  • value aftertouch value in [0;127]
  • optional channel MIDI channel in [1;16], only useful to route events to Parts
  • optional input MIDI input in [0,3], only useful to route events to Parts
See also
onEvent, onNote, onRelease, onProgramChange, onController, onPitchBend, onAfterTouch

◆ onProgramChange()

void onProgramChange ( table e)

event callback that will receive all incoming program-change events if defined.

Program Change to MIDI channel Example:

local channel = 0
function onNote(e)
e.channel = channel
end
function onRelease(e)
e.channel = channel
end
function onProgramChange(e)
channel = math.min(e.channel, e.program)
end
void onProgramChange(table e)
event callback that will receive all incoming program-change events if defined.
Parameters
eevent table with the following fields:
  • type event type equal to Event.ProgramChange
  • program program change value in [0;127]
  • optional channel MIDI channel in [1;16], only useful to route events to Parts
  • optional input MIDI input in [0,3], only useful to route events to Parts
See also
onEvent, onNote, onRelease, onController, onPitchBend, onAfterTouch, onPolyAfterTouch

◆ onRelease()

void onRelease ( table e)

event callback executed whenever a note off message is received.

Release trigger Example:

function onRelease(e)
print("noteoff", e.note, e.velocity)
postEvent(e) -- forward original event
local id = playNote(e.note, 64, 0, 100)
end
Parameters
eevent table with the following fields:
  • type event type equal to Event.NoteOff
  • note MIDI note number in [0;127]
  • velocity MIDI note velocity in [0;127]
  • id voice ID that will be affected to the Voice once triggered
  • optional channel MIDI channel in [1;16], only useful to route events to Parts
  • optional input MIDI input in [0,3], only useful to route events to Parts
  • optional layer in range [1, number of layers], useful to route events to Layers
  • optional vol linear gain in range [0.0, 1.0], default value is 1.0
  • optional pan panoramic value in range [-1.0, 1.0], default value is 0.0
  • optional tune detuning in relative semitones, default value is 0.0. This is a floating point value: use 0.01 for detuning of 1 cents
  • optional slice slice index for slice oscillators
  • optional oscIndex oscillator index within the keygroup
See also
onEvent, onNote, onProgramChange, onController, onPitchBend, onAfterTouch, onPolyAfterTouch

◆ onSave()

table onSave ( )

callback that is called when saving the ScriptProcessor state.

This is the place where you can save additional data if you need to. Supported lua types are number, boolean, strings and (nested) tables without (cyclic) references.

Returns
the lua object that you want to save

Example:

local customData = {1, 2, 3, a=1, b="text", c=true, d = {"another table"}}
function onSave()
return customData
end
function onLoad(data)
customData = data
end
See also
onLoad

◆ onTransport()

void onTransport ( bool playing)

event callback that is called when the host transport bar state changes.

Parameters
playingboolean flag that tells whether the transport bar is in playing state

Example:

function onTransport(playing)
if playing then
print("Transport started")
else
print("Transport stopped")
end
end
void onTransport(bool playing)
event callback that is called when the host transport bar state changes.
See also
onInit