midi-daemon 0.9.5

A Lua-scriptable MIDI routing daemon
local subPath = ""
local heartbeatPath = ""
local discPath = ""

local heartbeatDelay = 5000
local lastHeartbeat = 0
local heartbeatActive = false

function init()
  
  
  port = self.tag
  subPath = "/" .. self.name .. "/subscribe"
  heartbeatPath = "/" .. self.name .. "/heartbeat"
  discPath = "/" .. self.name .. "/unsubscribe"

  -- Send initial subscription
  sendOSC({ subPath, { { tag = 'i', value = self.tag }, { tag = 'i', value = 30 } } })

  -- Arm the heartbeat
  lastHeartbeat = getMillis()
  heartbeatActive = true
end

function update()
  if not heartbeatActive then return end
  local now = getMillis()
  if (now - lastHeartbeat >= heartbeatDelay) then
    lastHeartbeat = now
    sendOSC({ heartbeatPath, { { tag = 'i', value = self.tag } } })
  end
end

function onReceiveNotify(message, argument)
  if message == "LayoutClosing" then
    -- Stop the heartbeat
    heartbeatActive = false

    -- Send disconnect
    sendOSC({ discPath, { { tag = 'i', value = self.tag } } })
  end
end