class ATEM::Switcher

Attributes

master[R]
product[R]
topology[R]
version[R]
video_mode[R]

Public Class Methods

new(config) click to toggle source
# File lib/atem/switcher.rb, line 7
def initialize config
        @config = config
        @inputs = ATEM::Switcher::InputCollection.new self
        @_audio_by_index = []
end

Public Instance Methods

connect() click to toggle source
# File lib/atem/switcher.rb, line 13
def connect

        @airtower = ATEM::Network.new @config[:ip], @config[:port], @config[:uid]

        response = @airtower.hello
        # @airtower.send! "FTSU", "\x0" * 12
        response.each { | c | handle c }

end
disconnect() click to toggle source
# File lib/atem/switcher.rb, line 90
def disconnect

        @airtower.disconnect

end
handle(packet) click to toggle source

YIKES!

# File lib/atem/switcher.rb, line 24
def handle packet

        case packet[0]
        when "_ver"

                @version = packet[1].unpack("S>S>")

        when "_pin"

                @product = packet[1].unpack("a20")[0]

        when "_top"

                top = ["MEs", "Sources", "Colour Generators", "AUX busses", "DSKs", "Stingers", "DVEs", "SuperSources"]
                @topology = Hash[top.zip(packet[1].unpack("CCCCCCCC"))]

        when "VidM"

                @video_mode = packet[1].unpack("C")

        when "InPr"

                input = ATEM::Switcher::Input.from packet[1], self, ATEM::Switcher::Input::Type::VIDEO
                @inputs.add input 

        when "AMIP"

                audio_id = packet[1].unpack("S>")[0] #("S>CxxxCCCxS>s>")

                input = @inputs[audio_id]

                if !@inputs[audio_id] 
                        input = ATEM::Switcher::Input.new self
                        input.init audio_id
                        @inputs.add(input)
                end

                input.type |= ATEM::Switcher::Input::Type::AUDIO
                input.audio = ATEM::Switcher::Input::Audio.from packet[1], self, input

        when "AMLv"

                master = {}
                sources, master[:left], master[:right], master[:left_peak], master[:right_peak],
                        monitor = packet[1].unpack("S>xxl>l>l>l>l>")

                @master = master
                start_offset = 38 + sources * 2

                (0..sources-1).each do | source |

                        source_id = packet[1][(36 + source * 2)..-1].unpack("S>")[0]

                        levels = {}

                        levels[:left], levels[:right], levels[:left_peak], levels[:right_peak] =
                                packet[1][(start_offset + source * 16)..-1].unpack("l>l>l>l>")

                        @inputs[source_id].audio.levels = levels

                end

        end

end
inputs() click to toggle source
# File lib/atem/switcher.rb, line 96
def inputs
        @inputs
end
multithreading() click to toggle source
# File lib/atem/switcher.rb, line 100
def multithreading
        @thread != nil
end
multithreading=(enabled) click to toggle source
# File lib/atem/switcher.rb, line 104
def multithreading= enabled

        @thread.kill if @thread
        @thread = nil
        return if !enabled

        Thread.abort_on_exception = true
        @thread = Thread.new do

                loop do

                        packets = @airtower.receive
                        packets.each do | packet |
                                handle packet
                        end

                end

        end

end
preview(id) click to toggle source
# File lib/atem/switcher.rb, line 148
def preview id
        @airtower.send! "CPvI", [0, 0, id].pack("CCS>")
end
program(id) click to toggle source
# File lib/atem/switcher.rb, line 152
def program id
        @airtower.send! "CPgI", [0, 0, id].pack("CCS>")
end
reset_audio_peaks() click to toggle source
# File lib/atem/switcher.rb, line 137
def reset_audio_peaks

        @inputs.each do | id, input |
                
                puts "Resetting #{input.name}" if input.audio != nil
                @airtower.send! "RAMP", [2, 0, input.audio.id, 1, 0, 0, 0].pack("CCS>CCCC") if input.audio != nil

        end

end
use_audio_levels() click to toggle source
# File lib/atem/switcher.rb, line 126
def use_audio_levels
        @use_audio_levels
end
use_audio_levels=(enabled) click to toggle source
# File lib/atem/switcher.rb, line 130
def use_audio_levels= enabled

        self.multithreading = true if !@thread
        @airtower.send! "SALN", [enabled ? 1 : 0].pack("C") + "\0\0\0"

end