------- start v3.2.x bug warning - delete when fixed ---------
local function warning()
local version = gma.show.getvar('VERSION')
if version:find('^3.2.') then
local funcName = debug.getinfo(1).source
local txt = [[
V%s may not properly terminate infinite loops.
To terminate this plugin, use OffOffEverythingOff,
or activate its cleanup-procedure manually via cmdline:
Lua "%s_cleanup()"
]]
return gma.gui.confirm('WARNING!!',txt:format(version, funcName))
else
return true
end
end
------- end v3.2.x bug warning - delete when fixed ---------
---------------------------------------------------------------
------------- MidiFeedbackLoop by GLAD - 2016 -----------------
---------------------------------------------------------------
-------- sends Midi note-velocity combinations based ----------
----------- on Lua accessible executor information: -----------
---- empty / non-empty / sequence (off) / sequence (on) -------
---------------------------------------------------------------
--localize global dependencies:
local gma = gma
local pairs, tonumber = pairs, tonumber
-- declare and activate a local environment for the main plugin code
local midifeedback = {}
do local _ENV = midifeedback
local velocity = {0,5,1,3} -- velocity(color)codes for empty, non-empty, sequence (off), sequence (on)
-- shortcuts for functions used more than once
getHandle = gma.show.getobj.handle
getClass = gma.show.getobj.class
getAmount = gma.show.getobj.amount
getChild = gma.show.getobj.child
getProperty = gma.show.property.get
doCommandline = gma.cmd
gotoSleep = gma.sleep
-- scans midiremote setup and returns a lookup table with executorIds and corresponding midinotes
getMidiRemoteSetup = function ()
-- get the handle of the midiremote setup
local midiRemotes = getHandle('Remote "MidiRemotes"')
-- prepare table for found execbutton-remotes
local found = {}
-- loop over all midiremote children (remoteLines)
for i=0, getAmount(midiRemotes)-1 do
-- get each child and examine its properties
local remoteLine = getChild(midiRemotes,i)
local type, button = getProperty(remoteLine, 'Type'), getProperty(remoteLine, 'Button')
-- isolate the executor button remotes
if type == 'Exec' and button == 'Button 1' then
-- get exec and page
local executor, page = getProperty(remoteLine, 'Executor'), getProperty(remoteLine, 'Page')
-- add page to execId if page is a number (not 'current page')
if tonumber(page) then
executor = page..'.'..executor
end
-- get note and channel
local note, channel = getProperty(remoteLine, 'Note'), getProperty(remoteLine, 'Channel')
-- add channel to noteId if channel is a number (not "All')
if tonumber(channel) then
note = channel..'.'..note
end
-- add exec & note to table of found button-executors
found[executor] = note
end
end
return found -- return lookup table with exec to note mapping
end
-- create lookup table with velocity values for the different reported object-classes
class2velocity = { CMD_ROOT = velocity[1], CMD_EXEC = velocity[2], CMD_SEQUENCE = velocity[3], CMD_CUE = velocity[4] }
-- create string templates uses by doCommand and getHandle
midiSyntax, execToken, cueToken = 'MidiNote %s %i', 'Executor %s', 'Executor %s Cue'
-- entrypoint for plugin execution
start = function()
-- enable plugin if warning has been removed, or warning gets confirmed
enabled = not warning or warning()
-- create table of executor buttons with midiremote
exec2midiNote = getMidiRemoteSetup()
-- create cache to hold results from previous scan
cache = {}
gma.echo('MidiFeedbackLoop started')
-- start and continue looping as long as it is enabled
while enabled do
-- iterate over the list of executors with midiremote
for exec, note in pairs(exec2midiNote) do
-- get handle of the executor's active cue, or of the executor itself, if no respons on cuehandle request
local handle = getHandle(cueToken:format(exec)) or getHandle(execToken:format(exec))
-- get the class of the returned object, or object 1 (Root), if no object/handle was found
local class = getClass(handle or 1)
-- if class has changed since last scan
if class ~= cache[exec] then
-- update status cache for this executor
cache[exec] = class
-- lookup velocity for given class
local velocity = class2velocity[class]
-- send midinote-velocity via commandline
doCommandline(midiSyntax:format(note, velocity))
end
end
-- put this loop to sleep. Do not be tempted to lower sleeptime, to get less latency
-- Processor time is better spent on lighting up the stage, than you keypad
gotoSleep(0.5)
end
end
-- entrypoint for plugin termination
stop = function()
-- disable the continous loop
enabled = false
gma.echo('MidiFeedbackLoop terminated')
end
end -- end local enviroment
return midifeedback.start, midifeedback.stop -- return plugin entrypoint and exitpoint
Edited 1 time(s). Last edit at 06/19/2016 06:59PM by glad.