Class: ATEM::Switcher
- Inherits:
-
Object
- Object
- ATEM::Switcher
- Defined in:
- lib/atem/switcher.rb,
lib/atem/switcher/input.rb,
lib/atem/switcher/input/audio.rb,
lib/atem/switcher/input_collection.rb
Defined Under Namespace
Classes: Input, InputCollection
Instance Attribute Summary collapse
-
#master ⇒ Object
readonly
Returns the value of attribute master.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#topology ⇒ Object
readonly
Returns the value of attribute topology.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
-
#video_mode ⇒ Object
readonly
Returns the value of attribute video_mode.
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#handle(packet) ⇒ Object
YIKES!.
-
#initialize(config) ⇒ Switcher
constructor
A new instance of Switcher.
- #inputs ⇒ Object
- #multithreading ⇒ Object
- #multithreading=(enabled) ⇒ Object
- #preview(id) ⇒ Object
- #program(id) ⇒ Object
- #reset_audio_peaks ⇒ Object
- #use_audio_levels ⇒ Object
- #use_audio_levels=(enabled) ⇒ Object
Constructor Details
#initialize(config) ⇒ Switcher
7 8 9 10 11 |
# File 'lib/atem/switcher.rb', line 7 def initialize config @config = config @inputs = ATEM::Switcher::InputCollection.new self @_audio_by_index = [] end |
Instance Attribute Details
#master ⇒ Object (readonly)
Returns the value of attribute master.
5 6 7 |
# File 'lib/atem/switcher.rb', line 5 def master @master end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
5 6 7 |
# File 'lib/atem/switcher.rb', line 5 def product @product end |
#topology ⇒ Object (readonly)
Returns the value of attribute topology.
5 6 7 |
# File 'lib/atem/switcher.rb', line 5 def topology @topology end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/atem/switcher.rb', line 5 def version @version end |
#video_mode ⇒ Object (readonly)
Returns the value of attribute video_mode.
5 6 7 |
# File 'lib/atem/switcher.rb', line 5 def video_mode @video_mode end |
Instance Method Details
#connect ⇒ Object
13 14 15 16 17 18 19 20 21 |
# 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 ⇒ Object
90 91 92 93 94 |
# File 'lib/atem/switcher.rb', line 90 def disconnect @airtower.disconnect end |
#handle(packet) ⇒ Object
YIKES!
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 ⇒ Object
96 97 98 |
# File 'lib/atem/switcher.rb', line 96 def inputs @inputs end |
#multithreading ⇒ Object
100 101 102 |
# File 'lib/atem/switcher.rb', line 100 def multithreading @thread != nil end |
#multithreading=(enabled) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# 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) ⇒ Object
148 149 150 |
# File 'lib/atem/switcher.rb', line 148 def preview id @airtower.send! "CPvI", [0, 0, id].pack("CCS>") end |
#program(id) ⇒ Object
152 153 154 |
# File 'lib/atem/switcher.rb', line 152 def program id @airtower.send! "CPgI", [0, 0, id].pack("CCS>") end |
#reset_audio_peaks ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# 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 ⇒ Object
126 127 128 |
# File 'lib/atem/switcher.rb', line 126 def use_audio_levels @use_audio_levels end |
#use_audio_levels=(enabled) ⇒ Object
130 131 132 133 134 135 |
# 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 |