debug("Loaded Lua "); local ResponseCodes = {} ResponseCodes.Unknown = -1 ResponseCodes.Fail_SyntaxError = 100 ResponseCodes.Fail_UnsupportedParameter = 101 ResponseCodes.Fail_InvalidValue = 102 ResponseCodes.Fail_Unsupported = 103 ResponseCodes.Fail_DiskFull = 104 ResponseCodes.Fail_NoDisk = 105 ResponseCodes.Fail_DiskError = 106 ResponseCodes.Fail_TimelineEmpty = 107 ResponseCodes.Fail_OutOfRange = 109 ResponseCodes.Fail_NoInput = 110 ResponseCodes.Fail_RemoteControlDisabled = 111 ResponseCodes.Fail_ConnectionRejected = 120 ResponseCodes.Fail_InvalidState = 150 ResponseCodes.Async_ConnectionInfo = 500 ResponseCodes.Async_SlotInfo = 502 ResponseCodes.Async_TransportInfo = 508 ResponseCodes.Async_RemoteInfo = 510 ResponseCodes.Command_Ok = 200 ResponseCodes.Command_Help = 201 ResponseCodes.Command_SlotInfo = 202 ResponseCodes.Command_DeviceInfo = 204 ResponseCodes.Command_ClipsInfo = 205 ResponseCodes.Command_DiskList = 206 ResponseCodes.Command_TransportInfo = 208 ResponseCodes.Command_Notify = 209 ResponseCodes.Command_RemoteInfo = 210 ResponseCodes.Command_Configuration = 211 ResponseCodes.Command_Commands = 212 ResponseCodes.Command_DiskreBooting = 213 ResponseCodes.Command_ClipCount = 214 local m m = GetMessage("Protocol") m.PropertyChanged:add( function(sender, event) : void debug("PropertyChanged Name:" .. sender.Name .. " Value:" .. sender.Value) end ) local speed = CreateMessageProtocolParams("Speed", "ReadWrite", "speed", 208,508) speed.OnSetValue:add( function(sender, strValue) :void SendCommand("play: speed: " .. tonumber(strValue)) end ) local videoformat = CreateMessageProtocolParams("VideoFormat", "Read", "video format",208,508) local clipid = CreateMessageProtocolParams("CurrentClip", "ReadWrite", "clip id",208,508) clipid.OnSetValue.add( function(sender, strValue):void -- check that the name supplied is not empty if strValue ~= "" then -- start a recording and expect transport status to change -- not this is a write only param local clipNum = tonumber(strValue) --tonumber(clipCount.Value) if clipNum > 0 and clipNum <= 20 then SendCommand("goto: clip id: " .. clipNum) end end end ) local displaytimecode = CreateMessageProtocolParams("DisplayTimecode", "Read", "display timecode",208,508) local slot1 = {} slot1.id = CreateMessage("Slot_01", "Read") slot1.id.Value = "1" slot1.status = CreateMessage("Slot_01_Status", "Read") slot1.volume = CreateMessage("Slot_01_Name", "Read") slot1.recording = CreateMessage("Slot_01_Recording", "Read") slot1.format = CreateMessage("Slot_01_Format", "Read") local slot2 = {} slot2.id = CreateMessage("Slot_02", "Read") slot2.id.Value = "2" slot2.status = CreateMessage("Slot_02_Status", "Read") slot2.volume = CreateMessage("Slot_02_Name", "Read") slot2.recording = CreateMessage("Slot_02_Recording", "Read") slot2.format = CreateMessage("Slot_02_Format", "Read") local activeSlot = CreateMessageProtocolParams("ActiveSlot","Read", "slot id", ResponseCodes.Async_TransportInfo, ResponseCodes.Command_TransportInfo) activeSlot.OnSetValue.add( function(sender, strValue):void -- check that the name supplied is not empty if strValue ~= "" then -- start a recording and expect transport status to change -- not this is a write only param local slotNum = tonumber(strValue) if slotNum == 1 or slotNum == 2 then SendCommand("slot select: slot id: " .. slotNum) end end end ) local fileFormat = CreateMessageProtocolParams("FileFormat", "Read","file format", 211) local audioInput = CreateMessageProtocolParams("AudioInput", "Read","audio input", 211) local videoInput = CreateMessageProtocolParams("VideoInput", "Read","video input", 211) local recordNamedClip = CreateMessageProtocolParams("RecordNamedClip", "ReadWrite", "", 0) recordNamedClip.OnSetValue.add( function(sender, strValue):void -- check that the name supplied is not empty if strValue ~= "" then -- start a recording and expect transport status to change -- not this is a write only param SendCommand("record: name: " .. strValue) end end ) local transportValues = {} transportValues.stop = "stop" transportValues.stopped = "stop" transportValues.play = "play: speed: 100" transportValues.playloop = "play: loop: true" transportValues.record = "record" transportValues.rewind = function() i = tonumber(speed.Value) if i > -100 then return "play: speed: -100" elseif i > -200 then return "play: speed: -200" elseif i > -400 then return "play: speed: -400" elseif i > -800 then return "play: speed: -800" elseif i > -1600 then return "play: speed: -1600" end end transportValues.forward = function() i = tonumber(speed.Value) if i < 200 then return "play: speed: 200" elseif i < 400 then return "play: speed: 400" elseif i < 800 then return "play: speed: 800" elseif i < 1600 then return "play: speed: 1600" end end transportValues.next = "goto: clip id: +1" transportValues.previous = "goto: clip id: -1" local playLoop = CreateMessageProtocolParams("Loop", "ReadWrite", "loop", 208,508) playLoop.OnSetValue.add( function(sender, strValue):void if strValue ~= "" then if strValue == "true" then SendCommand("play: loop: true") elseif strValue == "false" then SendCommand("play: loop: false") end end end ) local transportCommand = CreateMessageProtocolParams("TransportCommand", "ReadWrite", "status", 208,508) transportCommand.OnSetValue.add( function(sender, strValue):void value = transportValues[strValue] if value ~= nil then if type(value) == "function" then SendCommand(value()) else SendCommand(value) end end end ) transportCommand.PropertyChanged:add( function(sender, event) : void --If the device is playing get the timecode from it faster if sender.Value == "stopped" or sender.Value == "preview" then PingLength(5000) else PingLength(990) end end ) local clipCount = CreateMessageProtocolParams("Clips_Count", "Read", "clip count", 214) local clipList = {} for i=1,20,1 do if (i < 10) then clipList[i] = CreateMessageProtocolParams("Clip_0" .. i, "Read", i, ResponseCodes.Command_ClipsInfo) else clipList[i] = CreateMessageProtocolParams("Clip_" .. i, "Read", i, ResponseCodes.Command_ClipsInfo) end end local nameToClipId = {} local diskList = {} for i=1,20,1 do if (i < 10) then --diskList[i] = CreateMessageProtocolParams("DiskClip_0" .. i, "Read", i, ResponseCodes.Command_DiskList) diskList[i] = CreateMessage("DiskClip_0" .. i, "Read") else --diskList[i] = CreateMessageProtocolParams("DiskClip_" .. i, "Read", i, ResponseCodes.Command_DiskList) diskList[i] = CreateMessage("DiskClip_0" .. i, "Read") end end -- clear the clip name slots that are above the clip count clipCount.PropertyChanged:add( function(sender, event) : void debug("PropertyChanged Name:" .. sender.Name .. " Value:" .. sender.Value) local count = tonumber(sender.Value) for i=1,20,1 do if(i > count) then clipList[i].Value = "" diskList[i].Value = "" end end end ) function UpdateSlotInfo(value) if(value ~= nil) then if(value.ResponseArguments[0].Parameter == "slot id") then local t = nil if(value.ResponseArguments[0].Value == 1) then t = slot1 else t = slot2 end if(t ~= nil) then debug("Setting Name:" .. t.status.Name .. " Param:" .. value.ResponseArguments[1].Parameter .. " Value:" .. value.ResponseArguments[1].Value) t.status.Value = value.ResponseArguments[1].Value --These are only sent in the Slot info command if(value.ResponseCode == ResponseCodes.Command_SlotInfo) then t.volume.Value = value.ResponseArguments[2].Value t.recording.Value = value.ResponseArguments[3].Value t.format.Value = value.ResponseArguments[4].Value else SendCommand("slot info: slot id: " .. value.ResponseArguments[0].Value) end end end end end function Update(value) debug(value) debug(value.ResponseCodeText) debug(value.ResponseText) debug(value.ResponseArguments) local i = 0 if(value.ResponseArguments ~= nil) then foreach arg in value.ResponseArguments do i = i + 1 debug(i .. ":" .. arg.Parameter .. "=" .. arg.Value) end end if(value.ResponseCode == ResponseCodes.Command_SlotInfo or value.ResponseCode == ResponseCodes.Async_SlotInfo) then UpdateSlotInfo(value) elseif value.ResponseCode == ResponseCodes.Command_Ok then SendCommand("transport info") elseif(value.ResponseCode == ResponseCodes.Async_TransportInfo) then SendCommand("clips count") SendCommand("clips get") SendCommand("disk list") elseif(value.ResponseCode == ResponseCodes.Async_SlotInfo) then -- this has no effect SendCommand("clips count") SendCommand("clips get") SendCommand("disk list") elseif(value.ResponseCode == ResponseCodes.Command_ClipsInfo) then nameToClipId = {} foreach arg in value.ResponseArguments do num = tonumber(arg.Parameter) if(num ~= nil) then valSplit = arg.Value.Split(".mov") nameToClipId[valSplit[0]] = num end end elseif(value.ResponseCode == ResponseCodes.Command_DiskList) then foreach arg in value.ResponseArguments do valSplit = arg.Value.Split(".mov") val = nameToClipId[valSplit[0]] if(val ~= nil) then if val > 0 and val <= 20 then diskList[val].Value = arg.Value end end end end end function PingCommand() local t = {} t.command = "transport info" if transportCommand.Value == "record" then t.getTimeLeft = "slot info" end return t end function StartUpCommands() debug("In StartUpCommands") local t = {} t.remote = "remote: enable: true override: true" t.notify = "notify: transport: true slot: true remote: true configuration: true" t.transport = "transport info" t.notifyInfo = "notify" t.device = "device info" t.config = "configuration" t.clipcount = "clips count" t.clipget = "clips get" t.disklist = "disk list" t.slot1 = "slot info: slot id: 1" t.slot2 = "slot info: slot id: 2" --Clear Write Only Slots recordNamedClip.Value = "" return t end