Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel

defineSlotLocal(name)

Description

Function to attain global variables that operate independently per slot. You can call defineSlotLocal before or after the initialization of the corresponding variable, but it is common practice to call the function in advance. For more details see Using Slot Local Variables.

Available in: Controller, Processor.

Arguments

nameThe name of the global variable.string

Example

Code Block
-- store held notes in a note buffer and print them out

-- declare the note buffer as slot local
defineSlotLocal("noteBuffer")

-- initialize the note buffer
noteBuffer = {}

-- print all notes in the note buffer
function printNoteBuffer()
    for note, velocity in pairs(noteBuffer) do
        print("Note# = "..note..", Velocity = "..velocity)
    end
    print()
end

-- write notes to the buffer and print them
function onNote(event)
    postEvent(event)
    noteBuffer[event.note] = event.velocity
    printNoteBuffer()
end

-- remove notes from the buffer and print the remaining ones
function onRelease(event)
    postEvent(event)
    noteBuffer[event.note] = nil
    printNoteBuffer()
end

...