#hs.blackmagic

Support for the Blackmagic DaVinci Resolve Speed Editor Keyboard and Editor Keyboard.

Example Usage:

blackmagic = nil local callback = function(obj, buttonID, pressed, mode, value) if buttonID == "JOG WHEEL" then print("Jog Wheel Mode " .. mode .. ", value: " .. value) else -- If Jog Wheel button pressed, change jog wheel mode -- and activate the LED for that job wheel mode: if buttonID == "SHTL" or buttonID == "JOG" or buttonID == "SCRL" then local jogMode if buttonID == "SHTL" then jogMode = "RELATIVE" end if buttonID == "JOG" then jogMode = "ABSOLUTE" end if buttonID == "SCRL" then jogMode = "ABSOLUTE ZERO" end blackmagic:jogMode(jogMode) blackmagic:led({ ["SHTL"] = buttonID == "SHTL", ["JOG"] = buttonID == "JOG", ["SCRL"] = buttonID == "SCRL" }) return end -- If a normal button is pressed: if pressed then print(buttonID .. " pressed") blackmagic:led({[buttonID] = true}) else print(buttonID .. " released") hs.timer.doAfter(5, function() blackmagic:led({[buttonID] = false}) end) end end end local discoveryCallback = function(connected, device) if connected then print(string.format("Device Connected: %s - %s", device:deviceType(), device:serialNumber())) blackmagic = device blackmagic:led({["SHTL"] = true}) -- Defaults to SHTL jog mode blackmagic:jogMode("RELATIVE") blackmagic:callback(callback) else print(string.format("Device Disconnected: %s - %s", device:deviceType(), device:serialNumber())) end end hs.blackmagic.init(discoveryCallback)

This extension was thrown together by Chris Hocking for CommandPost.

This extension would not be possible without Sylvain Munaut's genius work figuring out the authentication protocol.

This extension is based off Chris Jones' hs.streamdeck extension.

Special thanks to David Peterson, Morten Bentsen, Håvard Njåstad and Sondre Tungesvik Njåstad.

This extension uses code based off Sylvain Munaut's Python Scripts under the following license:

Copyright 2021 Sylvain Munaut tnt@246tNt.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


#API Overview

Constants - Useful values which cannot be changed

Functions - API calls offered directly by the extension

Methods - API calls which can only be made on an object returned by a constructor


#API Documentation

#Constants

Signaturehs.blackmagic.buttonNames
TypeConstant
DescriptionA table of the button names used.
NotesNone
Sourceextensions/blackmagic/blackmagic.lua line 93

Signaturehs.blackmagic.deviceTypes
TypeConstant
DescriptionA table of the supported device types.
NotesNone
Sourceextensions/blackmagic/blackmagic.lua line 85

Signaturehs.blackmagic.jogModeNames
TypeConstant
DescriptionA table of the jog mode names used by each device type.
NotesNone
Sourceextensions/blackmagic/blackmagic.lua line 223

Signaturehs.blackmagic.ledNames
TypeConstant
DescriptionA table of the LED names used by each device type.
NotesNone
Sourceextensions/blackmagic/blackmagic.lua line 189

#Functions

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.blackmagic.discoveryCallback(fn) -> none | | Type | Function | | Description | Sets/clears a callback for reacting to device discovery events. | | Parameters |

  • fn - A function that will be called when a Blackmagic device is connected or disconnected. It should take the following arguments: A boolean, true if a device was connected, false if a device was disconnected. An hs.blackmagic object, being the device that was connected/disconnected.
| | Returns |
  • None
| | Notes | None | | Examples | None | | Source | extensions/blackmagic/libblackmagic.m line 53 |


Signaturehs.blackmagic.getDevice(num) -> hs.blackmagic``
TypeFunction
DescriptionGets an hs.blackmagic object for the specified device.
Parameters
  • num - A number that should be within the bounds of the number of connected devices.
Returns
  • An hs.blackmagic object or nil if something goes wrong.
NotesNone
ExamplesNone
Sourceextensions/blackmagic/libblackmagic.m line 94

| | | | --------------------------------------------|-------------------------------------------------------------------------------------| | Signature | hs.blackmagic.init(fn) -> none | | Type | Function | | Description | Initialises the Blackmagic driver and sets a discovery callback. | | Parameters |

  • fn - A function that will be called when a Blackmagic device is connected or disconnected. It should take the following arguments: A boolean, true if a device was connected, false if a device was disconnected. An hs.blackmagic object, being the device that was connected/disconnected.
| | Returns |
  • None
| | Notes |
  • This function must be called before any other parts of this module are used.
| | Examples | None | | Source | extensions/blackmagic/libblackmagic.m line 27 |


Signaturehs.blackmagic.numDevices() -> number
TypeFunction
DescriptionGets the number of Blackmagic devices connected.
Parameters
  • None
Returns
  • A number containing the number of Blackmagic devices attached to the system.
NotesNone
ExamplesNone
Sourceextensions/blackmagic/libblackmagic.m line 77

#Methods

Signaturehs.blackmagic:battery() -> boolean, number
TypeMethod
DescriptionGets the battery status for the Blackmagic device.
Parameters
  • None
Returns
  • true if charging, otherwise false
  • The battery level between 0 and 100.
NotesNone
ExamplesNone
Sourceextensions/blackmagic/libblackmagic.m line 183

Signaturehs.blackmagic:callback(fn) -> hs.blackmagic``
TypeMethod
DescriptionSets/clears the button and jog wheel callback function for a Blackmagic device.
Parameters
  • fn - A function to be called when a button is pressed/released, or the jog wheel is rotated on the Blackmagic device.
Returns
  • The hs.blackmagic device
  • The callback function should receive three arguments:
  • The hs.blackmagic userdata object
  • A string containing the name of the button or "JOG WHEEL"
  • A boolean indicating whether the button was pressed (true) or released (false). Not relevant if a Jog Wheel action.
  • The Jog Wheel Mode (if not a button press)
  • The Jog Wheel value (if not a button press)
  • You can use hs.blackmagic.buttonNames[deviceType] to get a table of possible values.
NotesNone
ExamplesNone
Sourceextensions/blackmagic/libblackmagic.m line 125

Signaturehs.blackmagic:deviceType() -> string
TypeMethod
DescriptionGets the device type for the Blackmagic device.
Parameters
  • None
Returns
  • The device type as a string - either "Speed Editor" or "Editor Keyboard".
NotesNone
ExamplesNone
Sourceextensions/blackmagic/libblackmagic.m line 235

Signaturehs.blackmagic:jogMode([value]) -> hs.blackmagic, string
TypeMethod
DescriptionGets or Sets the Jog Mode for the Blackmagic device.
Parameters
  • value - an optional string of "RELATIVE", "ABSOLUTE" and "ABSOLUTE ZERO" if setting.
Returns
  • The hs.blackmagic device
  • "RELATIVE", "ABSOLUTE" and "ABSOLUTE ZERO" as a string, or nil if something has gone wrong.
Notes
  • You can use hs.blackmagic.jogModeNames[deviceType] to get a table of possible values.
  • "RELATIVE" - Returns a “relative” position - a positive number if turning right, and a negative number if turning left. The faster you turn, the higher the number. One step is 360.
  • "ABSOLUTE" - Returns an “absolute” position, based on when the mode was set. It has a range of -4096 (left of 0) to 4096 (right of 0). On the Editor Keyboard it has mechanical hard stops at -4096 and 4096, meaning you only use one half of the wheel.
  • "ABSOLUTE ZERO" - The same as "ABSOLUTE", but has a small dead zone around 0 - which mechincally "snaps" to zero on a Editor Keyboard.
ExamplesNone
Sourceextensions/blackmagic/libblackmagic.m line 257

Signaturehs.blackmagic:led(options) -> hs.blackmagic``
TypeMethod
DescriptionSets the status for the LED lights.
Parameters
  • options - A table where the key is the button ID, and the value is a boolean to turn the LED on or off.
Returns
  • The hs.blackmagic device.
Notes
  • You can also use hs.blackmagic.ledNames[deviceType] to get a table of possible values.
ExamplesNone
Sourceextensions/blackmagic/libblackmagic.m line 156

Signaturehs.blackmagic:serialNumber() -> string
TypeMethod
DescriptionGets the serial number for the Blackmagic device.
Parameters
  • None
Returns
  • The serial number as a string.
Notes
  • The serial number is the unique identifier from the USB Device, and not the product serial number that's on the sticker on the back of the Blackmagic device.
ExamplesNone
Sourceextensions/blackmagic/libblackmagic.m line 210