Created
July 8, 2016 23:32
-
-
Save imorrish/b967ffe16156ff91ee553d6b5a64e8db to your computer and use it in GitHub Desktop.
Windows PowerShell script to control Blackmagic ATEM audio mixer using a MIDI device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample script to control Blackmagic ATEM audio mixer using a MIDI device | |
# This script only runs on Windows 10 and ISE 64bit | |
#Requires ATEMLib.dll and PeteBrown.PowerShellMidi.dll | |
# which can be downloaded from https://ianmorrish.wordpress.com | |
# | |
# Blackmagic ATEM Software Control must also be instaled (v6.4 or grater) | |
#ATEM setup | |
add-type -path 'C:\Users\imorrish\OneDrive\PowerShell\ATEM\SwitcherLib.dll' | |
$Global:atem = New-Object SwitcherLib.Switcher("192.168.1.8") | |
$atem.Connect() | |
$audio = $atem.GetAudioInputs() | |
#MIDI setup | |
# Device ID is for Behringer CMD MM-1 | |
Import-Module 'C:\Users\imorrish\OneDrive\PowerShell\Midi\PeteBrown.PowerShellMidi.dll' | |
$deviceId = "\\?\SWD#MMDEVAPI#MIDII_B5FB4C9F.P_0001#{504be32c-ccf6-4d2c-b73f-6f8b3747e22b}" | |
[PeteBrown.PowerShellMidi.MidiInputPort]$inputPort = Get-MidiInputPort -id $deviceId | |
$inputPort.TranslateZeroVelocityNoteOnMessage = $true; | |
$noteOnSourceId = "NoteOnMessageReceivedID" | |
$controlChangeSourceId = "ControlChangeMessageReceivedID" | |
Unregister-Event -SourceIdentifier $noteOnSourceId -ErrorAction SilentlyContinue | |
Unregister-Event -SourceIdentifier $controlChangeSourceId -ErrorAction SilentlyContinue | |
function logScale($level){ | |
if($level -ne 0){ | |
20 * [System.Math]::Log($level) | |
} | |
else{ | |
-66 | |
} | |
} | |
#offset applied to inputs so we can control 8 (or more) inputs from single controler. | |
$global:g=4 | |
$HandleNoteOn = | |
{ | |
switch ($event.sourceEventArgs.Note) { | |
16{$global:g=0;write-host "Control inputs 1-4";break} | |
17{$global:g=4;write-host "Control inputs 5&6";break} | |
48{$audio[0+$g].InputGain=-66;break} | |
49{$audio[1+$g].InputGain=-66;break} | |
50{$audio[2].InputGain=-66;break} | |
51{$audio[3].InputGain=-66;break} | |
19{if($audio[0+$g].MixOption -eq "bmdSwitcherAudioMixOptionOff"){$audio[0+$g].MixOption="On";} else {$audio[0+$g].MixOption="Off"};write-host "1 $($audio[0+$g].MixOption)";;break} | |
23{if($audio[1+$g].MixOption -eq "bmdSwitcherAudioMixOptionOff"){$audio[1+$g].MixOption="On";} else {$audio[1+$g].MixOption="Off"};write-host "2 $($audio[1+$g].MixOption)";;break} | |
27{if($audio[2].MixOption -eq "bmdSwitcherAudioMixOptionOff"){$audio[2].MixOption="On";} else {$audio[2].MixOption="Off"};write-host "3 $($audio[2].MixOption)";;break} | |
31{if($audio[3].MixOption -eq "bmdSwitcherAudioMixOptionOff"){$audio[3].MixOption="On";} else {$audio[3].MixOption="Off"};write-host "4 $($audio[3].MixOption)";;break} | |
20{$audio[0+$g].MixOption="FollowVideo";break} | |
24{$audio[1+$g].MixOption="FollowVideo";break} | |
28{$audio[2].MixOption="FollowVideo";break} | |
32{$audio[3].MixOption="FollowVideo";break} | |
} | |
} | |
$HandleControlChange = | |
{ | |
switch ($event.sourceEventArgs.Controller) | |
{ | |
48{$audio[0+$g].InputGain=logScale($event.sourceEventArgs.Value/127) } | |
49{$audio[1+$g].InputGain=logScale($event.sourceEventArgs.Value/127) } | |
50{$audio[2].InputGain=logScale($event.sourceEventArgs.Value/127) } | |
51{$audio[3].InputGain=logScale($event.sourceEventArgs.Value/127) } | |
} | |
} | |
#Start event receivers | |
$job1 = Register-ObjectEvent -InputObject $inputPort -EventName NoteOnMessageReceived -SourceIdentifier $noteOnSourceId -Action $HandleNoteOn | |
$job2 = Register-ObjectEvent -InputObject $inputPort -EventName ControlChangeMessageReceived -SourceIdentifier $controlChangeSourceId -Action $HandleControlChange | |
write-Host "Started" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo video of script in action.
https://youtu.be/rIW_97YYxlA