voicemeeter_api_ruby 4.1.1 → 4.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e456329651c6151ed9756893125b802c099733fcefe64db8259f933539ee0587
4
- data.tar.gz: 2d93a67a6f476d2ec173a267f479ecf5be9c6e333ead5a891e0f5ac1fbc74541
3
+ metadata.gz: acb76cc78cf77a922519ddd770f228678575da40dfa679b2adfdbedee6ea1ee6
4
+ data.tar.gz: daebcd5921873299ba38c5108e624997423566d2fe3c217c0bc2ca994c372825
5
5
  SHA512:
6
- metadata.gz: dd26be5c5387a6c0ac1ca97d9c99e943205e05c76418e041d776e5fef6268a6a488bf98d63c10fc886e82469b5df140c5e0e8ea563b5ef955be878859b0f92b5
7
- data.tar.gz: 5b04f810179c775e861b6ee1e79415d960ef9a7aac2cab490bd1b21019169b950cba869a9e0dc6a363fa9d9ceeb01dd27e93335b325aeeb934336f5f0700472c
6
+ metadata.gz: b2bc3f136101f0f77cddabcc1311d2be414cae27435a15a638db9c2e1314cd390710f7972deb4f2d77e8658679360a2aacf19c2aee3eabdd8fbd8298efe2d35f
7
+ data.tar.gz: 4cf31208007f988dc8a114ad76cbec5581b0783276d325a305deec988be3a847a08938bb4e2094b9894ecb9de1bd4f6e769eb8edefec923f2cf38d6ec946458b
data/README.md CHANGED
@@ -374,7 +374,7 @@ vm.vban.outstream[0].set_multi(on: true, name: 'streamname', bit: 24)
374
374
 
375
375
  ## Config Files
376
376
 
377
- `vm.set_config(<configname>)`
377
+ `vm.apply_config(<configname>)`
378
378
 
379
379
  You may load config files in TOML format.
380
380
  Three example configs have been included with the package. Remember to save
@@ -383,10 +383,10 @@ current settings before loading a config. To set one you may do:
383
383
  ```ruby
384
384
  require 'voicemeeter'
385
385
  vm = Voicemeeter.remote('banana')
386
- vm.run { vm.set_config('example') }
386
+ vm.run { vm.apply_config('example') }
387
387
  ```
388
388
 
389
- will load a config file at configs/banana/example.toml for Voicemeeter Banana.
389
+ will load a config file at mydir/configs/banana/example.toml for Voicemeeter Banana.
390
390
 
391
391
  ## `Voicemeeter Module`
392
392
 
data/lib/base.rb CHANGED
@@ -1,219 +1,219 @@
1
- require 'observer'
2
-
3
- require_relative 'runvm'
4
- require_relative 'configs'
5
- require_relative 'errors'
6
-
7
- class Base
8
- '
9
- Base class responsible for wrapping the C Remote API
10
-
11
- Mixin required modules
12
- '
13
- include Observable
14
- include Configs
15
- include RunVM
16
-
17
- attr_accessor :strip, :bus, :button, :vban, :command, :recorder, :device
18
- attr_accessor :strip_mode
19
-
20
- attr_reader :kind, :p_in, :v_in, :p_out, :v_out, :retval, :cache
21
- attr_reader :running, :_strip_comp, :_bus_comp
22
-
23
- DELAY = 0.001
24
- SYNC = false
25
- RATELIMIT = 0.033
26
- SIZE = 1
27
-
28
- def initialize(kind, **kwargs)
29
- @kind = kind
30
- @p_in, @v_in = kind.layout[:strip].values
31
- @p_out, @v_out = kind.layout[:bus].values
32
- @cache = Hash.new
33
- @sync = kwargs[:sync] || SYNC
34
- @ratelimit = kwargs[:ratelimit] || RATELIMIT
35
- @running = false
36
- @strip_mode = 0
37
- @delay = DELAY
38
- end
39
-
40
- def init_thread
41
- @running = true
42
- @cache['strip_level'], @cache['bus_level'] = _get_levels
43
- Thread.new do
44
- loop do
45
- Thread.stop if !@running
46
- if pdirty?
47
- changed
48
- notify_observers('pdirty')
49
- elsif mdirty?
50
- changed
51
- notify_observers('mdirty')
52
- elsif ldirty?
53
- changed
54
- @_strip_comp =
55
- @cache['strip_level'].map.with_index do |x, i|
56
- !(x == @strip_buf[i])
57
- end
58
- @_bus_comp =
59
- @cache['bus_level'].map.with_index do |x, i|
60
- !(x == @bus_buf[i])
61
- end
62
- @cache['strip_level'] = @strip_buf
63
- @cache['bus_level'] = @bus_buf
64
- notify_observers('ldirty')
65
- end
66
- sleep(@ratelimit)
67
- end
68
- end
69
- end
70
-
71
- def end_thread
72
- @running = false
73
- end
74
-
75
- def login
76
- @@cdll.call(:login)
77
- clear_polling
78
- rescue CAPIErrors => error
79
- case
80
- when error.value == 1
81
- self.start(@kind.name)
82
- clear_polling
83
- when error.value < 0
84
- raise
85
- end
86
- end
87
-
88
- def logout
89
- clear_polling
90
- sleep(0.1)
91
- @@cdll.call(:logout)
92
- end
93
-
94
- def type
95
- c_type = FFI::MemoryPointer.new(:long, SIZE)
96
- @@cdll.call(:vmtype, c_type)
97
- types = { 1 => 'basic', 2 => 'banana', 3 => 'potato' }
98
- types[c_type.read_long]
99
- end
100
-
101
- def version
102
- c_ver = FFI::MemoryPointer.new(:long, SIZE)
103
- @@cdll.call(:vmversion, c_ver)
104
- v1 = (c_ver.read_long & 0xFF000000) >> 24
105
- v2 = (c_ver.read_long & 0x00FF0000) >> 16
106
- v3 = (c_ver.read_long & 0x0000FF00) >> 8
107
- v4 = c_ver.read_long & 0x000000FF
108
- "#{v1}.#{v2}.#{v3}.#{v4}"
109
- end
110
-
111
- def get_parameter(name, is_string = false)
112
- self.polling('get_parameter', name: name) do
113
- if is_string
114
- c_get = FFI::MemoryPointer.new(:string, 512, true)
115
- @@cdll.call(:get_parameter_string, name, c_get)
116
- c_get.read_string
117
- else
118
- c_get = FFI::MemoryPointer.new(:float, SIZE)
119
- @@cdll.call(:get_parameter_float, name, c_get)
120
- c_get.read_float.round(1)
121
- end
122
- end
123
- end
124
-
125
- def set_parameter(name, value)
126
- if value.is_a? String
127
- @@cdll.call(:set_parameter_string, name, value)
128
- else
129
- @@cdll.call(:set_parameter_float, name, value.to_f)
130
- end
131
- @cache.store(name, value)
132
- end
133
-
134
- def get_buttonstatus(id, mode)
135
- self.polling('get_buttonstatus', id: id, mode: mode) do
136
- c_get = FFI::MemoryPointer.new(:float, SIZE)
137
- @@cdll.call(:get_buttonstatus, id, c_get, mode)
138
- c_get.read_float.to_i
139
- end
140
- end
141
-
142
- def set_buttonstatus(id, state, mode)
143
- @@cdll.call(:set_buttonstatus, id, state, mode)
144
- @cache.store("mb_#{id}_#{mode}", state)
145
- end
146
-
147
- def set_parameter_multi(param_hash)
148
- param_hash.each do |(key, val)|
149
- prop, m2, m3, *rem = key.to_s.split('_')
150
- if m2.to_i.to_s == m2
151
- m2 = m2.to_i
152
- elsif m3.to_i.to_s == m3
153
- m3 = m3.to_i
154
- end
155
-
156
- case prop
157
- when 'strip'
158
- self.strip[m2].set_multi(val)
159
- when 'bus'
160
- self.bus[m2].set_multi(val)
161
- when 'button', 'mb'
162
- self.button[m2].set_multi(val)
163
- when 'vban'
164
- if %w[instream in].include? m2
165
- self.vban.instream[m3].set_multi(val)
166
- elsif %w[outstream out].include? m2
167
- self.vban.outstream[m3].set_multi(val)
168
- end
169
- end
170
- sleep(DELAY)
171
- end
172
- end
173
-
174
- def get_level(type, index)
175
- c_get = FFI::MemoryPointer.new(:float, SIZE)
176
- @@cdll.call(:get_level, type, index, c_get)
177
- c_get.read_float
178
- end
179
-
180
- def _get_levels
181
- s = (0...(2 * @p_in + 8 * @v_in)).map { |i| get_level(0, i) }
182
- b = (0...(8 * (@p_out + @v_out))).map { |i| get_level(3, i) }
183
- [s, b]
184
- end
185
-
186
- def get_num_devices(direction)
187
- unless %w[in out].include? direction
188
- raise VMRemoteErrors.new('expected in or out')
189
- end
190
- if direction == 'in'
191
- val = @@cdll.call(:get_num_indevices)
192
- else
193
- val = @@cdll.call(:get_num_outdevices)
194
- end
195
- val[0]
196
- end
197
-
198
- def get_device_description(index, direction)
199
- unless %w[in out].include? direction
200
- raise VMRemoteErrors.new('expected in or out')
201
- end
202
- c_type = FFI::MemoryPointer.new(:long, SIZE)
203
- c_name = FFI::MemoryPointer.new(:string, 256, true)
204
- c_hwid = FFI::MemoryPointer.new(:string, 256, true)
205
- if direction == 'in'
206
- @@cdll.call(:get_desc_indevices, index, c_type, c_name, c_hwid)
207
- else
208
- @@cdll.call(:get_desc_outdevices, index, c_type, c_name, c_hwid)
209
- end
210
- [c_name.read_string, c_type.read_long, c_hwid.read_string]
211
- end
212
-
213
- alias_method 'set_multi', :set_parameter_multi
214
- alias_method 'get', :get_parameter
215
- alias_method 'set', :set_parameter
216
- alias_method 'pdirty', :pdirty?
217
- alias_method 'mdirty', :mdirty?
218
- alias_method 'ldirty', :ldirty?
219
- end
1
+ require "observer"
2
+
3
+ require_relative "runvm"
4
+ require_relative "configs"
5
+ require_relative "errors"
6
+
7
+ class Base
8
+ "
9
+ Base class responsible for wrapping the C Remote API
10
+
11
+ Mixin required modules
12
+ "
13
+ include Observable
14
+ include Configs
15
+ include RunVM
16
+
17
+ attr_accessor :strip, :bus, :button, :vban, :command, :recorder, :device
18
+ attr_accessor :strip_mode
19
+
20
+ attr_reader :kind, :p_in, :v_in, :p_out, :v_out, :retval, :cache
21
+ attr_reader :running, :_strip_comp, :_bus_comp, :delay
22
+
23
+ DELAY = 0.001
24
+ SYNC = false
25
+ RATELIMIT = 0.033
26
+ SIZE = 1
27
+
28
+ def initialize(kind, **kwargs)
29
+ @kind = kind
30
+ @p_in, @v_in = kind.layout[:strip].values
31
+ @p_out, @v_out = kind.layout[:bus].values
32
+ @cache = Hash.new
33
+ @sync = kwargs[:sync] || SYNC
34
+ @ratelimit = kwargs[:ratelimit] || RATELIMIT
35
+ @running = false
36
+ @strip_mode = 0
37
+ @delay = DELAY
38
+ end
39
+
40
+ def init_thread
41
+ @running = true
42
+ @cache["strip_level"], @cache["bus_level"] = _get_levels
43
+ Thread.new do
44
+ loop do
45
+ Thread.stop if !@running
46
+ if pdirty?
47
+ changed
48
+ notify_observers("pdirty")
49
+ end
50
+ if mdirty?
51
+ changed
52
+ notify_observers("mdirty")
53
+ end
54
+ if ldirty?
55
+ changed
56
+ @_strip_comp =
57
+ @cache["strip_level"].map.with_index do |x, i|
58
+ !(x == @strip_buf[i])
59
+ end
60
+ @_bus_comp =
61
+ @cache["bus_level"].map.with_index { |x, i| !(x == @bus_buf[i]) }
62
+ @cache["strip_level"] = @strip_buf
63
+ @cache["bus_level"] = @bus_buf
64
+ notify_observers("ldirty")
65
+ end
66
+ sleep(@ratelimit)
67
+ end
68
+ end
69
+ end
70
+
71
+ def end_thread
72
+ @running = false
73
+ end
74
+
75
+ def login
76
+ @@cdll.call(:login)
77
+ clear_polling
78
+ rescue CAPIErrors => error
79
+ case
80
+ when error.value == 1
81
+ self.start(@kind.name)
82
+ clear_polling
83
+ when error.value < 0
84
+ raise
85
+ end
86
+ end
87
+
88
+ def logout
89
+ clear_polling
90
+ sleep(0.1)
91
+ @@cdll.call(:logout)
92
+ end
93
+
94
+ def type
95
+ c_type = FFI::MemoryPointer.new(:long, SIZE)
96
+ @@cdll.call(:vmtype, c_type)
97
+ types = { 1 => "basic", 2 => "banana", 3 => "potato" }
98
+ types[c_type.read_long]
99
+ end
100
+
101
+ def version
102
+ c_ver = FFI::MemoryPointer.new(:long, SIZE)
103
+ @@cdll.call(:vmversion, c_ver)
104
+ v1 = (c_ver.read_long & 0xFF000000) >> 24
105
+ v2 = (c_ver.read_long & 0x00FF0000) >> 16
106
+ v3 = (c_ver.read_long & 0x0000FF00) >> 8
107
+ v4 = c_ver.read_long & 0x000000FF
108
+ "#{v1}.#{v2}.#{v3}.#{v4}"
109
+ end
110
+
111
+ def get_parameter(name, is_string = false)
112
+ self.polling("get_parameter", name: name) do
113
+ if is_string
114
+ c_get = FFI::MemoryPointer.new(:string, 512, true)
115
+ @@cdll.call(:get_parameter_string, name, c_get)
116
+ c_get.read_string
117
+ else
118
+ c_get = FFI::MemoryPointer.new(:float, SIZE)
119
+ @@cdll.call(:get_parameter_float, name, c_get)
120
+ c_get.read_float.round(1)
121
+ end
122
+ end
123
+ end
124
+
125
+ def set_parameter(name, value)
126
+ if value.is_a? String
127
+ @@cdll.call(:set_parameter_string, name, value)
128
+ else
129
+ @@cdll.call(:set_parameter_float, name, value.to_f)
130
+ end
131
+ @cache.store(name, value)
132
+ end
133
+
134
+ def get_buttonstatus(id, mode)
135
+ self.polling("get_buttonstatus", id: id, mode: mode) do
136
+ c_get = FFI::MemoryPointer.new(:float, SIZE)
137
+ @@cdll.call(:get_buttonstatus, id, c_get, mode)
138
+ c_get.read_float.to_i
139
+ end
140
+ end
141
+
142
+ def set_buttonstatus(id, state, mode)
143
+ @@cdll.call(:set_buttonstatus, id, state, mode)
144
+ @cache.store("mb_#{id}_#{mode}", state)
145
+ end
146
+
147
+ def set_parameter_multi(param_hash)
148
+ param_hash.each do |(key, val)|
149
+ prop, m2, m3, *rem = key.to_s.split("_")
150
+ if m2.to_i.to_s == m2
151
+ m2 = m2.to_i
152
+ elsif m3.to_i.to_s == m3
153
+ m3 = m3.to_i
154
+ end
155
+
156
+ case prop
157
+ when "strip"
158
+ self.strip[m2].set_multi(val)
159
+ when "bus"
160
+ self.bus[m2].set_multi(val)
161
+ when "button", "mb"
162
+ self.button[m2].set_multi(val)
163
+ when "vban"
164
+ if %w[instream in].include? m2
165
+ self.vban.instream[m3].set_multi(val)
166
+ elsif %w[outstream out].include? m2
167
+ self.vban.outstream[m3].set_multi(val)
168
+ end
169
+ end
170
+ sleep(DELAY)
171
+ end
172
+ end
173
+
174
+ def get_level(type, index)
175
+ c_get = FFI::MemoryPointer.new(:float, SIZE)
176
+ @@cdll.call(:get_level, type, index, c_get)
177
+ c_get.read_float
178
+ end
179
+
180
+ def _get_levels
181
+ s = (0...(2 * @p_in + 8 * @v_in)).map { |i| get_level(@strip_mode, i) }
182
+ b = (0...(8 * (@p_out + @v_out))).map { |i| get_level(3, i) }
183
+ [s, b]
184
+ end
185
+
186
+ def get_num_devices(direction)
187
+ unless %w[in out].include? direction
188
+ raise VMRemoteErrors.new("expected in or out")
189
+ end
190
+ if direction == "in"
191
+ val = @@cdll.call(:get_num_indevices)
192
+ else
193
+ val = @@cdll.call(:get_num_outdevices)
194
+ end
195
+ val[0]
196
+ end
197
+
198
+ def get_device_description(index, direction)
199
+ unless %w[in out].include? direction
200
+ raise VMRemoteErrors.new("expected in or out")
201
+ end
202
+ c_type = FFI::MemoryPointer.new(:long, SIZE)
203
+ c_name = FFI::MemoryPointer.new(:string, 256, true)
204
+ c_hwid = FFI::MemoryPointer.new(:string, 256, true)
205
+ if direction == "in"
206
+ @@cdll.call(:get_desc_indevices, index, c_type, c_name, c_hwid)
207
+ else
208
+ @@cdll.call(:get_desc_outdevices, index, c_type, c_name, c_hwid)
209
+ end
210
+ [c_name.read_string, c_type.read_long, c_hwid.read_string]
211
+ end
212
+
213
+ alias_method "set_multi", :set_parameter_multi
214
+ alias_method "get", :get_parameter
215
+ alias_method "set", :set_parameter
216
+ alias_method "pdirty", :pdirty?
217
+ alias_method "mdirty", :mdirty?
218
+ alias_method "ldirty", :ldirty?
219
+ end
data/lib/bus.rb CHANGED
@@ -1,97 +1,105 @@
1
- require_relative 'iremote'
2
- require_relative 'mixin'
1
+ require_relative "iremote"
3
2
 
4
3
  class Bus < IRemote
5
- '
6
- Concrete Bus class
7
- '
8
- include Channel_Meta_Functions
9
- include Fades
10
-
11
- attr_accessor :mode, :levels
12
-
13
- def self.make(remote, layout_bus)
14
- '
15
- Factory function for Bus classes.
16
- '
17
- p_out, v_out = layout_bus.values
18
- (0...(p_out + v_out)).map do |i|
19
- i < p_out ? PhysicalBus.new(remote, i) : VirtualBus.new(remote, i)
20
- end
21
- end
22
-
23
- def initialize(remote, i)
24
- super
25
- self.make_accessor_bool :mute, :mono, :eq, :sel
26
- self.make_accessor_float :gain
27
- self.make_accessor_string :label
28
-
29
- @mode = BusModes.new(remote, i)
30
- @levels = BusLevels.new(remote, i)
31
- end
32
-
33
- def identifier
34
- "bus[#{@index}]"
4
+ "
5
+ Concrete Bus class
6
+ "
7
+ include Channel_Meta_Functions
8
+
9
+ attr_accessor :mode, :levels
10
+
11
+ def self.make(remote, layout_bus)
12
+ "
13
+ Factory function for Bus classes.
14
+ "
15
+ p_out, v_out = layout_bus.values
16
+ (0...(p_out + v_out)).map do |i|
17
+ i < p_out ? PhysicalBus.new(remote, i) : VirtualBus.new(remote, i)
35
18
  end
19
+ end
20
+
21
+ def initialize(remote, i)
22
+ super
23
+ self.make_accessor_bool :mute, :mono, :eq, :sel
24
+ self.make_accessor_float :gain
25
+ self.make_accessor_string :label
26
+
27
+ @mode = BusModes.new(remote, i)
28
+ @levels = BusLevels.new(remote, i)
29
+ end
30
+
31
+ def identifier
32
+ "bus[#{@index}]"
33
+ end
34
+
35
+ def fadeto(target, time)
36
+ self.setter("FadeTo", "(#{target}, #{time})")
37
+ sleep(@remote.delay)
38
+ end
39
+
40
+ def fadeby(change, time)
41
+ self.setter("FadeBy", "(#{change}, #{time})")
42
+ sleep(@remote.delay)
43
+ end
36
44
  end
37
45
 
38
46
  class PhysicalBus < Bus
39
- def initialize(remote, i)
40
- super
41
- self.make_reader_only :device, :sr
42
- end
47
+ def initialize(remote, i)
48
+ super
49
+ self.make_reader_only :device, :sr
50
+ end
43
51
  end
44
52
 
45
53
  class VirtualBus < Bus
46
54
  end
47
55
 
48
56
  class BusModes < IRemote
49
- include Channel_Meta_Functions
50
-
51
- def initialize(remote, i)
52
- super
53
- self.make_bus_modes :normal,
54
- :amix,
55
- :bmix,
56
- :repeat,
57
- :composite,
58
- :tvmix,
59
- :upmix21,
60
- :upmix41,
61
- :upmix61,
62
- :centeronly,
63
- :lfeonly,
64
- :rearonly
65
- end
66
-
67
- def identifier
68
- "bus[#{@index}].mode"
69
- end
57
+ include Channel_Meta_Functions
58
+
59
+ def initialize(remote, i)
60
+ super
61
+ self.make_bus_modes :normal,
62
+ :amix,
63
+ :bmix,
64
+ :repeat,
65
+ :composite,
66
+ :tvmix,
67
+ :upmix21,
68
+ :upmix41,
69
+ :upmix61,
70
+ :centeronly,
71
+ :lfeonly,
72
+ :rearonly
73
+ end
74
+
75
+ def identifier
76
+ "bus[#{@index}].mode"
77
+ end
70
78
  end
71
79
 
72
80
  class BusLevels < IRemote
73
- def initialize(remote, i)
74
- super
75
- @init = i * 8
76
- @offset = 8
77
- end
78
-
79
- def identifier
80
- "bus[#{@index}]"
81
+ def initialize(remote, i)
82
+ super
83
+ @init = i * 8
84
+ @offset = 8
85
+ end
86
+
87
+ def identifier
88
+ "bus[#{@index}]"
89
+ end
90
+
91
+ def getter(mode)
92
+ if @remote.running
93
+ vals = @remote.cache["bus_level"][@init, @offset]
94
+ else
95
+ vals = (@init...@offset).map { |i| @remote.get_level(mode, i) }
81
96
  end
97
+ vals.map { |x| x > 0 ? (20 * Math.log(x, 10)).round(1) : -200.0 }
98
+ end
82
99
 
83
- def getter(mode)
84
- if @remote.running
85
- vals = @remote.cache['bus_level'][@init, @offset]
86
- else
87
- vals = (@init...@offset).map { |i| @remote.get_level(mode, i) }
88
- end
89
- vals.map { |x| x > 0 ? (20 * Math.log(x, 10)).round(1) : -200.0 }
90
- end
91
-
92
- def all
93
- getter(3)
94
- end
100
+ def all
101
+ getter(3)
102
+ end
95
103
 
96
- def isdirty?() = @remote._bus_comp[@init, @offset].any?
104
+ def isdirty? = @remote._bus_comp[@init, @offset].any?
97
105
  end