Table of Contents
Ai Example
Artnet Video Switch
Takes an Artnet channel, and compiles and sends ethernet commands, to toggle an external video switch. The command is being displayed for reference.
by: | Sebastian Beutel, Aug. 2014 |
---|---|
published: | here (2018); mentioned in the forum (2014) |
tested in version: | 8 |
download: | artnet_video_switch_en.scb |
Hint: click the images to show them larger.
Background
There was an external video switch (Blackmagic Smart Videohub) which was planned to be used in order to extend the possible video inputs. To accomplish this, the video switch needed to be controlled by Artnet. However, the Balcmagic Smart Videohub can only be ctrolled by TCP commands. This patch shows how this can be done in Ai: an Artnet channel triggers the thernet commands, sends and shows the compiled command. (The extra bonus is not relevant anymore - the old software couldn't ouput TCP but only UDP - hence a little external program was used to convert the protocols).
To make it look neat only the relevant items are put in the visible viewport, and the connections are hidden. To get a better overview expand the window to the right, right-click the background and select Show All Connections
.
Used Modules and Patches
Solution
For a better overview the entire patch can be split into some functional parts:
In total, when e.g. an Artnet level of 5 is received, the outcome of the whole patch should be
- the command being sent like this
VIDEO OUTPUT ROUTING: 3 5
And here is how it is done:
- the white part contains the inputs and outputs
- the green part takes the artnet input and extracts the significant integer number as string
- the yellow part takes this and assembles the command string which the device expects
- the lightblue part constantly checks the combined string for changes, and only if a change is detected, triggers the command to be actually sent
- the orange part takes the compiled string and renders it into a video stream which is shown as test. Also, this is used as Render Path for the Ethernet Command module (closing the window would stop the module from outputting).
White: Inputs and Outputs
- ArtNet Input Small sets there this patch expects an input. You set the network adaptor, universe and channel.
- Video output is a text input which expects only a number. This is how the video switcher expects the command:
VIDEO OUTPUT ROUTING {output} {input}
- Ethernet Command is where the compiled message is finally sent. Adjust the network adaptro and the target address and port here.
ArtNet Video Control
is a window module. The main purpose is to provide a render path which is required for the Ethernet Comman module to function. As soon as you close this window there is no network output.
Green: Extract Number
The modules in the green section extract the number string. The Artnet module (white section) provides a normalized level between 0 and 1, being deected when the Artnet channel is 0, and 1.0 being detected when the Artnet channel is full = 255. Example level: 110 ( = 43.13%)
- the
Formula
multiplies by 255, hence we have an output of numbers 0…255 with always .000000 as decimal places. In our example: 110.000000 - the
Monitor
is only for convenience :) Convert To String
takes the result - a math figure - and converts it into a string - a bunch of characters. Obviously this still looks the same: 110.000000- Out of this string we need only the 'part before the decimal point'. Luckily, Ai shows numbers here always with 6 decimal places. in our example, we'd only need the first 3 characters out of a 10 character string. We use
Sub String
, always starting at the left-most character (Constant
= 0), chopping off the last 7 characters (the decimal point and the 6 decimal places) - this is whatString Length
andFormula0
do.
The result of this procedure is the 'String Out' of the Sub String module: a neat 110
.
Yellow: Assemble the String
The yellow section assembles the string cor us. A part of this are the newlines and spaces - it is simply a question of concatenating various strings:
- the first part is set in the notpad module
Command string part 1
VIDEO OUTPUT ROUTING:
- note the invisible newline after the 'ROUTING:'
- next comes the value for
Video Output
(from the input area) - then: a blank space - set in a seemingly blank notepad (
Command str. part - Space
) - followed by the input string number which we have derived in the green section
- finally two newline characters (again from a notepad module:
Command str. part - Newline
)
The result is already the string which is ready to be sent - hence, the output of the last String Combine2
goes already to the Ethernet Command module.
Light-Blue: Check for Changes
However we still need a trigger for the Ethernet Command, so that the module knows when to send the command. Of course the command should be sent when the contents changes - this is, when in the final string (where the other command strings might have changed!) the 'video input' part has changed. That's why it looks a bit complicated:
String Length0
takes the string part before the input (in out example, 'VIDEO OUTPUT ROUTING 3 '),Formula3
adds one for the space - and the result is the Start Index for out trigger stringString Length1
takes the full string,Formula2
deducts 2 (the two newlines) - the result is the End IndexSub String0
finally extracts the substring (the110
)String To Number
converts this back to a math entityConst Diff
extracts changes, i.e if e.g. the next value is 108 then the output would be -2- the last
Formula1
outputs 1 of there is no change, and 0 if there is a change. This results in a true trigger behaviours as the Send Command' expects a temporary signal:- as long as the input signal is constant, the trigger is constantly 1
- when the input signal changes the trigger is 0
- when the input doesn't change anymore (after a previous change) the trigger toggles back to 1 - and this is exactly what triggers the network send command.
Orange: Render Control Output
The Ethernet Command module requires a render path - we could have simply a window connected. however, this is a little excercise to render a string to a video out - this way we have a reliable check for what is being sent
String Texture
is the main module here - it renders a texture from our compiled string- the parameters are the Font Size, taken from
Constant0
, and the Texture Size, taken fromVector
(here: a two-dimensional math entity) - the texture is then rendered by the
Rectangle
module
The result is then sent to the Render Merge in the In/Out section, and finally to our output window.
UDP to TCP: socat
When this patch was used there was only the Ethernet Command
module in Ai to talk to a network - but Ethernet Command can only send UDP messages. In order to convert them to TCP - which the Blackmagic device needed - a small external program was used: socat, see https://github.com/StudioEtrange/socat-windows. Look for the Cygwin binaries. Download and unzip it, open a DOS prompt in the right folder, and issue a command like this:
socat -s udp4-listen:9091,reuseaddr TCP:192.168.0.100:9090
This way, socat listens on port 9091/UDP, and forwards everything it receives to 192.168.0.100 port 9090/TCP. You'll get a nice little window like this:
We can now easily use Ai's ethernet command module. Instead of sending the data to our target device, we must now send it to the local network, because this is where socat sits and listens - on port 9091, that is. I found that I needed to send it to broadcast (I didn't bother to install a loopback adaptor).
Of course nowadays this can be solved much more elegantly with Ai's TCP Client Module module, hence the socat solution is here merely for reference .