Class: Voicemeeter::Base
- Inherits:
-
Object
- Object
- Voicemeeter::Base
- Defined in:
- lib/voicemeeter/base.rb
Direct Known Subclasses
Constant Summary collapse
- DELAY =
0.001
- SYNC =
false
- RATELIMIT =
0.033
- SIZE =
1
Instance Attribute Summary collapse
-
#_bus_comp ⇒ Object
readonly
Returns the value of attribute _bus_comp.
-
#_strip_comp ⇒ Object
readonly
Returns the value of attribute _strip_comp.
-
#bus ⇒ Object
Returns the value of attribute bus.
-
#button ⇒ Object
Returns the value of attribute button.
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#command ⇒ Object
Returns the value of attribute command.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#device ⇒ Object
Returns the value of attribute device.
-
#event ⇒ Object
Returns the value of attribute event.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#midi ⇒ Object
Returns the value of attribute midi.
-
#p_in ⇒ Object
readonly
Returns the value of attribute p_in.
-
#p_out ⇒ Object
readonly
Returns the value of attribute p_out.
-
#recorder ⇒ Object
Returns the value of attribute recorder.
-
#retval ⇒ Object
readonly
Returns the value of attribute retval.
-
#running ⇒ Object
readonly
Returns the value of attribute running.
-
#strip ⇒ Object
Returns the value of attribute strip.
-
#strip_mode ⇒ Object
Returns the value of attribute strip_mode.
-
#v_in ⇒ Object
readonly
Returns the value of attribute v_in.
-
#v_out ⇒ Object
readonly
Returns the value of attribute v_out.
-
#vban ⇒ Object
Returns the value of attribute vban.
Instance Method Summary collapse
- #_get_levels ⇒ Object
- #get_buttonstatus(id, mode) ⇒ Object
- #get_device_description(index, direction) ⇒ Object
- #get_level(type, index) ⇒ Object
- #get_midi_message ⇒ Object
- #get_num_devices(direction) ⇒ Object
- #get_parameter(name, is_string = false) ⇒ Object (also: #get)
-
#initialize(kind, **kwargs) ⇒ Base
constructor
A new instance of Base.
- #login ⇒ Object
- #logout ⇒ Object
- #set_buttonstatus(id, state, mode) ⇒ Object
- #set_parameter(name, value) ⇒ Object (also: #set)
- #set_parameter_multi(param_hash) ⇒ Object (also: #set_multi, #apply)
- #to_s ⇒ Object
- #type ⇒ Object
- #version ⇒ Object
Methods included from Worker
Methods included from RunVM
Methods included from Kinds
Methods included from CBindings
#clear_polling, #ldirty?, #mdirty?, #pdirty?
Methods included from Configs
Constructor Details
#initialize(kind, **kwargs) ⇒ Base
Returns a new instance of Base.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/voicemeeter/base.rb', line 34 def initialize(kind, **kwargs) @kind = kind @sync = kwargs.delete(:sync) || SYNC @ratelimit = kwargs.delete(:ratelimit) || RATELIMIT @p_in, @v_in = kind.layout[:strip].values @p_out, @v_out = kind.layout[:bus].values @running = false @strip_mode = 0 @delay = DELAY @cache = Hash.new @midi = Midi.new @event = Event.new(**kwargs) end |
Instance Attribute Details
#_bus_comp ⇒ Object (readonly)
Returns the value of attribute _bus_comp.
27 28 29 |
# File 'lib/voicemeeter/base.rb', line 27 def _bus_comp @_bus_comp end |
#_strip_comp ⇒ Object (readonly)
Returns the value of attribute _strip_comp.
27 28 29 |
# File 'lib/voicemeeter/base.rb', line 27 def _strip_comp @_strip_comp end |
#bus ⇒ Object
Returns the value of attribute bus.
22 23 24 |
# File 'lib/voicemeeter/base.rb', line 22 def bus @bus end |
#button ⇒ Object
Returns the value of attribute button.
22 23 24 |
# File 'lib/voicemeeter/base.rb', line 22 def @button end |
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
26 27 28 |
# File 'lib/voicemeeter/base.rb', line 26 def cache @cache end |
#command ⇒ Object
Returns the value of attribute command.
22 23 24 |
# File 'lib/voicemeeter/base.rb', line 22 def command @command end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
27 28 29 |
# File 'lib/voicemeeter/base.rb', line 27 def delay @delay end |
#device ⇒ Object
Returns the value of attribute device.
22 23 24 |
# File 'lib/voicemeeter/base.rb', line 22 def device @device end |
#event ⇒ Object
Returns the value of attribute event.
24 25 26 |
# File 'lib/voicemeeter/base.rb', line 24 def event @event end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
26 27 28 |
# File 'lib/voicemeeter/base.rb', line 26 def kind @kind end |
#midi ⇒ Object
Returns the value of attribute midi.
23 24 25 |
# File 'lib/voicemeeter/base.rb', line 23 def midi @midi end |
#p_in ⇒ Object (readonly)
Returns the value of attribute p_in.
26 27 28 |
# File 'lib/voicemeeter/base.rb', line 26 def p_in @p_in end |
#p_out ⇒ Object (readonly)
Returns the value of attribute p_out.
26 27 28 |
# File 'lib/voicemeeter/base.rb', line 26 def p_out @p_out end |
#recorder ⇒ Object
Returns the value of attribute recorder.
22 23 24 |
# File 'lib/voicemeeter/base.rb', line 22 def recorder @recorder end |
#retval ⇒ Object (readonly)
Returns the value of attribute retval.
26 27 28 |
# File 'lib/voicemeeter/base.rb', line 26 def retval @retval end |
#running ⇒ Object (readonly)
Returns the value of attribute running.
27 28 29 |
# File 'lib/voicemeeter/base.rb', line 27 def running @running end |
#strip ⇒ Object
Returns the value of attribute strip.
22 23 24 |
# File 'lib/voicemeeter/base.rb', line 22 def strip @strip end |
#strip_mode ⇒ Object
Returns the value of attribute strip_mode.
24 25 26 |
# File 'lib/voicemeeter/base.rb', line 24 def strip_mode @strip_mode end |
#v_in ⇒ Object (readonly)
Returns the value of attribute v_in.
26 27 28 |
# File 'lib/voicemeeter/base.rb', line 26 def v_in @v_in end |
#v_out ⇒ Object (readonly)
Returns the value of attribute v_out.
26 27 28 |
# File 'lib/voicemeeter/base.rb', line 26 def v_out @v_out end |
#vban ⇒ Object
Returns the value of attribute vban.
22 23 24 |
# File 'lib/voicemeeter/base.rb', line 22 def vban @vban end |
Instance Method Details
#_get_levels ⇒ Object
159 160 161 162 163 164 |
# File 'lib/voicemeeter/base.rb', line 159 def _get_levels [ (0...(2 * @p_in + 8 * @v_in)).map { |i| get_level(@strip_mode, i) }, (0...(8 * (@p_out + @v_out))).map { |i| get_level(3, i) } ] end |
#get_buttonstatus(id, mode) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/voicemeeter/base.rb', line 113 def (id, mode) self.polling("get_buttonstatus", id: id, mode: mode) do c_get = FFI::MemoryPointer.new(:float, SIZE) @@cdll.call(:get_buttonstatus, id, c_get, mode) c_get.read_float.to_i end end |
#get_device_description(index, direction) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/voicemeeter/base.rb', line 178 def get_device_description(index, direction) unless %w[in out].include? direction raise VMRemoteErrors.new("expected in or out") end c_type = FFI::MemoryPointer.new(:long, SIZE) c_name = FFI::MemoryPointer.new(:string, 256, true) c_hwid = FFI::MemoryPointer.new(:string, 256, true) if direction == "in" @@cdll.call(:get_desc_indevices, index, c_type, c_name, c_hwid) else @@cdll.call(:get_desc_outdevices, index, c_type, c_name, c_hwid) end [c_name.read_string, c_type.read_long, c_hwid.read_string] end |
#get_level(type, index) ⇒ Object
153 154 155 156 157 |
# File 'lib/voicemeeter/base.rb', line 153 def get_level(type, index) c_get = FFI::MemoryPointer.new(:float, SIZE) @@cdll.call(:get_level, type, index, c_get) c_get.read_float end |
#get_midi_message ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/voicemeeter/base.rb', line 193 def c_msg = FFI::MemoryPointer.new(:string, 1024, true) res = @@cdll.call(:get_midi_message, c_msg, 1024) if res[0] > 0 vals = c_msg.read_string.bytes vals.each_slice(3) do |ch, key, vel| @midi.channel = ch if @midi.channel.nil? || @midi.channel != ch @midi.current = key.to_i @midi.set(key.to_i, vel.to_i) end elsif res[0] == -1 || res[0] == -2 raise CAPIErrors.new("VBVMR_GetMidiMessage returned #{msg[0]}") end res[0] > 0 end |
#get_num_devices(direction) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/voicemeeter/base.rb', line 166 def get_num_devices(direction) unless %w[in out].include? direction raise VMRemoteErrors.new("expected in or out") end if direction == "in" res = @@cdll.call(:get_num_indevices) else res = @@cdll.call(:get_num_outdevices) end res[0] end |
#get_parameter(name, is_string = false) ⇒ Object Also known as: get
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/voicemeeter/base.rb', line 90 def get_parameter(name, is_string = false) self.polling("get_parameter", name: name) do if is_string c_get = FFI::MemoryPointer.new(:string, 512, true) @@cdll.call(:get_parameter_string, name, c_get) c_get.read_string else c_get = FFI::MemoryPointer.new(:float, SIZE) @@cdll.call(:get_parameter_float, name, c_get) c_get.read_float.round(1) end end end |
#login ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/voicemeeter/base.rb', line 52 def login @@cdll.call(:login) clear_polling LOGGER.info("Logged into #{self}") rescue CAPIErrors => error case when error.value == 1 self.start(@kind.name) clear_polling when error.value < 0 raise end end |
#logout ⇒ Object
66 67 68 69 70 71 |
# File 'lib/voicemeeter/base.rb', line 66 def logout clear_polling sleep(0.1) @@cdll.call(:logout) LOGGER.info("Logged out of #{self}") end |
#set_buttonstatus(id, state, mode) ⇒ Object
121 122 123 124 |
# File 'lib/voicemeeter/base.rb', line 121 def (id, state, mode) @@cdll.call(:set_buttonstatus, id, state, mode) @cache.store("mb_#{id}_#{mode}", state) end |
#set_parameter(name, value) ⇒ Object Also known as: set
104 105 106 107 108 109 110 111 |
# File 'lib/voicemeeter/base.rb', line 104 def set_parameter(name, value) if value.is_a? String @@cdll.call(:set_parameter_string, name, value) else @@cdll.call(:set_parameter_float, name, value.to_f) end @cache.store(name, value) end |
#set_parameter_multi(param_hash) ⇒ Object Also known as: set_multi, apply
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/voicemeeter/base.rb', line 126 def set_parameter_multi(param_hash) param_hash.each do |(key, val)| prop, m2, m3, *rem = key.to_s.split("_") if m2.to_i.to_s == m2 m2 = m2.to_i elsif m3.to_i.to_s == m3 m3 = m3.to_i end case prop when "strip" self.strip[m2].set_multi(val) when "bus" self.bus[m2].set_multi(val) when "button", "mb" self.[m2].set_multi(val) when "vban" if %w[instream in].include? m2 self.vban.instream[m3].set_multi(val) elsif %w[outstream out].include? m2 self.vban.outstream[m3].set_multi(val) end end sleep(DELAY) end end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/voicemeeter/base.rb', line 48 def to_s "Voicemeeter #{@kind}" end |
#type ⇒ Object
73 74 75 76 77 78 |
# File 'lib/voicemeeter/base.rb', line 73 def type c_type = FFI::MemoryPointer.new(:long, SIZE) @@cdll.call(:vmtype, c_type) types = { 1 => "basic", 2 => "banana", 3 => "potato" } types[c_type.read_long] end |
#version ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/voicemeeter/base.rb', line 80 def version c_ver = FFI::MemoryPointer.new(:long, SIZE) @@cdll.call(:vmversion, c_ver) v1 = (c_ver.read_long & 0xFF000000) >> 24 v2 = (c_ver.read_long & 0x00FF0000) >> 16 v3 = (c_ver.read_long & 0x0000FF00) >> 8 v4 = c_ver.read_long & 0x000000FF "#{v1}.#{v2}.#{v3}.#{v4}" end |