voicemeeter_api_ruby 4.4.0 → 4.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,251 +1,251 @@
1
- require_relative "errors"
2
-
3
- module Voicemeeter
4
- module Conversions
5
- module_function
6
-
7
- def Boolean(value)
8
- case value
9
- when true, 1
10
- true
11
- when false, nil, 0
12
- false
13
- else
14
- raise ArgumentError, "invalid value for Boolean(): \"#{value.inspect}\""
15
- end
16
- end
17
- end
18
-
19
- module Meta_Functions
20
- private
21
-
22
- include Conversions
23
-
24
- def make_accessor_bool(*params)
25
- params.each do |param|
26
- define_singleton_method("#{param}") do
27
- return !(self.getter("#{param}")).zero?
28
- end
29
-
30
- define_singleton_method("#{param}=") do |value|
31
- self.setter("#{param}", Boolean(value) ? 1 : 0)
32
- end
33
- end
34
- end
35
-
36
- def make_accessor_int(*params)
37
- params.each do |param|
38
- define_singleton_method("#{param}") do
39
- return self.getter("#{param}").to_i
40
- end
41
-
42
- define_singleton_method("#{param}=") do |value|
43
- self.setter("#{param}", value)
44
- end
45
- end
46
- end
47
-
48
- def make_accessor_float(*params)
49
- params.each do |param|
50
- define_singleton_method("#{param}") { return self.getter("#{param}") }
51
-
52
- define_singleton_method("#{param}=") do |value|
53
- self.setter("#{param}", value)
54
- end
55
- end
56
- end
57
-
58
- def make_accessor_string(*params)
59
- params.each do |param|
60
- define_singleton_method("#{param}") do
61
- return self.getter("#{param}", true)
62
- end
63
-
64
- define_singleton_method("#{param}=") do |value|
65
- self.setter("#{param}", value)
66
- end
67
- end
68
- end
69
-
70
- def make_reader_only(*params)
71
- params.each do |param|
72
- define_singleton_method("#{param}") { return self.getter("#{param}") }
73
- end
74
- end
75
-
76
- def make_writer_only(*params)
77
- params.each do |param|
78
- define_singleton_method("#{param}=") do |value = 1|
79
- self.setter("#{param}", value)
80
- end
81
- end
82
- end
83
-
84
- def make_action_prop(*params)
85
- params.each do |param|
86
- define_singleton_method("#{param}") { self.setter("#{param}", 1) }
87
- end
88
- end
89
- end
90
-
91
- module Channel_Meta_Functions
92
- private
93
-
94
- include Meta_Functions
95
-
96
- def make_accessor_bool(*params)
97
- params.each do |param|
98
- cmds = { eq: "EQ.on", eq_ab: "EQ.ab" }
99
- if cmds.key? param
100
- cmd = cmds[param]
101
- else
102
- cmd = param
103
- end
104
-
105
- define_singleton_method("#{param}") do
106
- return !(self.getter("#{cmd}")).zero?
107
- end
108
-
109
- define_singleton_method("#{param}=") do |value|
110
- self.setter("#{cmd}", Boolean(value) ? 1 : 0)
111
- end
112
- end
113
- end
114
-
115
- def make_reader_only(*params)
116
- params.each do |param|
117
- cmds = { device: "device.name", sr: "device.sr" }
118
- if cmds.key? param
119
- cmd = cmds[param]
120
- else
121
- cmd = param
122
- end
123
-
124
- define_singleton_method("#{param}") do
125
- case param
126
- when :device
127
- return self.getter("#{cmd}", true)
128
- when :sr
129
- return self.getter("#{cmd}").to_i
130
- end
131
- end
132
- end
133
- end
134
-
135
- def make_bus_modes(*params)
136
- params.each do |param|
137
- define_singleton_method("#{param}") do
138
- @remote.clear_polling
139
- return !(self.getter("#{param}")).zero?
140
- end
141
-
142
- define_singleton_method("#{param}=") do |value|
143
- self.setter("#{param}", Boolean(value) ? 1 : 0)
144
- end
145
- end
146
- end
147
- end
148
-
149
- module Vban_Meta_Functions
150
- private
151
-
152
- include Meta_Functions
153
-
154
- def make_reader_int(*params)
155
- params.each do |param|
156
- define_singleton_method("#{param}") do
157
- case param
158
- when :bit
159
- return self.getter("#{param}").to_i == 1 ? 16 : 24
160
- else
161
- return self.getter("#{param}").to_i
162
- end
163
- end
164
- end
165
- end
166
-
167
- def make_accessor_int(*params)
168
- params.each do |param|
169
- define_singleton_method("#{param}") do
170
- case param
171
- when :bit
172
- return self.getter("#{param}").to_i == 1 ? 16 : 24
173
- else
174
- return self.getter("#{param}").to_i
175
- end
176
- end
177
-
178
- opts = {
179
- sr: [
180
- 11_025,
181
- 16_000,
182
- 22_050,
183
- 24_000,
184
- 32_000,
185
- 44_100,
186
- 48_000,
187
- 64_000,
188
- 88_200,
189
- 96_000
190
- ],
191
- channel: (1..8),
192
- bit: [16, 24],
193
- quality: (0..4),
194
- route: (0..8)
195
- }
196
-
197
- define_singleton_method("#{param}=") do |value|
198
- unless opts[param].member? value
199
- raise OutOfBoundsErrors.new(opts[param])
200
- end
201
- case param
202
- when :bit
203
- self.setter("#{param}", value == 16 ? 1 : 2)
204
- else
205
- self.setter("#{param}", value)
206
- end
207
- end
208
- end
209
- end
210
- end
211
-
212
- module MacroButton_Meta_Functions
213
- private
214
-
215
- include Conversions
216
-
217
- def make_accessor_macrobutton(*params)
218
- params.each do |param|
219
- mode = { state: 1, stateonly: 2, trigger: 3 }
220
-
221
- define_singleton_method("#{param}") do
222
- return !(self.getter(mode[param])).zero?
223
- end
224
-
225
- define_singleton_method("#{param}=") do |value|
226
- self.setter(Boolean(value) ? 1 : 0, mode[param])
227
- end
228
- end
229
- end
230
- end
231
-
232
- module Commands_Meta_Functions
233
- private
234
-
235
- include Meta_Functions
236
- def make_writer_bool(*params)
237
- params.each do |param|
238
- cmds = { showvbanchat: "DialogShow.VBANCHAT" }
239
- if cmds.key? param
240
- cmd = cmds[param]
241
- else
242
- cmd = param
243
- end
244
-
245
- define_singleton_method("#{param}=") do |value|
246
- self.setter("#{cmd}", Boolean(value) ? 1 : 0)
247
- end
248
- end
249
- end
250
- end
251
- end
1
+ require_relative "errors"
2
+
3
+ module Voicemeeter
4
+ module Conversions
5
+ module_function
6
+
7
+ def Boolean(value)
8
+ case value
9
+ when true, 1
10
+ true
11
+ when false, nil, 0
12
+ false
13
+ else
14
+ raise ArgumentError, "invalid value for Boolean(): \"#{value.inspect}\""
15
+ end
16
+ end
17
+ end
18
+
19
+ module Meta_Functions
20
+ private
21
+
22
+ include Conversions
23
+
24
+ def make_accessor_bool(*params)
25
+ params.each do |param|
26
+ define_singleton_method("#{param}") do
27
+ return !(self.getter("#{param}")).zero?
28
+ end
29
+
30
+ define_singleton_method("#{param}=") do |value|
31
+ self.setter("#{param}", Boolean(value) ? 1 : 0)
32
+ end
33
+ end
34
+ end
35
+
36
+ def make_accessor_int(*params)
37
+ params.each do |param|
38
+ define_singleton_method("#{param}") do
39
+ return self.getter("#{param}").to_i
40
+ end
41
+
42
+ define_singleton_method("#{param}=") do |value|
43
+ self.setter("#{param}", value)
44
+ end
45
+ end
46
+ end
47
+
48
+ def make_accessor_float(*params)
49
+ params.each do |param|
50
+ define_singleton_method("#{param}") { return self.getter("#{param}") }
51
+
52
+ define_singleton_method("#{param}=") do |value|
53
+ self.setter("#{param}", value)
54
+ end
55
+ end
56
+ end
57
+
58
+ def make_accessor_string(*params)
59
+ params.each do |param|
60
+ define_singleton_method("#{param}") do
61
+ return self.getter("#{param}", true)
62
+ end
63
+
64
+ define_singleton_method("#{param}=") do |value|
65
+ self.setter("#{param}", value)
66
+ end
67
+ end
68
+ end
69
+
70
+ def make_reader_only(*params)
71
+ params.each do |param|
72
+ define_singleton_method("#{param}") { return self.getter("#{param}") }
73
+ end
74
+ end
75
+
76
+ def make_writer_only(*params)
77
+ params.each do |param|
78
+ define_singleton_method("#{param}=") do |value = 1|
79
+ self.setter("#{param}", value)
80
+ end
81
+ end
82
+ end
83
+
84
+ def make_action_prop(*params)
85
+ params.each do |param|
86
+ define_singleton_method("#{param}") { self.setter("#{param}", 1) }
87
+ end
88
+ end
89
+ end
90
+
91
+ module Channel_Meta_Functions
92
+ private
93
+
94
+ include Meta_Functions
95
+
96
+ def make_accessor_bool(*params)
97
+ params.each do |param|
98
+ cmds = { eq: "EQ.on", eq_ab: "EQ.ab" }
99
+ if cmds.key? param
100
+ cmd = cmds[param]
101
+ else
102
+ cmd = param
103
+ end
104
+
105
+ define_singleton_method("#{param}") do
106
+ return !(self.getter("#{cmd}")).zero?
107
+ end
108
+
109
+ define_singleton_method("#{param}=") do |value|
110
+ self.setter("#{cmd}", Boolean(value) ? 1 : 0)
111
+ end
112
+ end
113
+ end
114
+
115
+ def make_reader_only(*params)
116
+ params.each do |param|
117
+ cmds = { device: "device.name", sr: "device.sr" }
118
+ if cmds.key? param
119
+ cmd = cmds[param]
120
+ else
121
+ cmd = param
122
+ end
123
+
124
+ define_singleton_method("#{param}") do
125
+ case param
126
+ when :device
127
+ return self.getter("#{cmd}", true)
128
+ when :sr
129
+ return self.getter("#{cmd}").to_i
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ def make_bus_modes(*params)
136
+ params.each do |param|
137
+ define_singleton_method("#{param}") do
138
+ @remote.clear_polling
139
+ return !(self.getter("#{param}")).zero?
140
+ end
141
+
142
+ define_singleton_method("#{param}=") do |value|
143
+ self.setter("#{param}", Boolean(value) ? 1 : 0)
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ module Vban_Meta_Functions
150
+ private
151
+
152
+ include Meta_Functions
153
+
154
+ def make_reader_int(*params)
155
+ params.each do |param|
156
+ define_singleton_method("#{param}") do
157
+ case param
158
+ when :bit
159
+ return self.getter("#{param}").to_i == 1 ? 16 : 24
160
+ else
161
+ return self.getter("#{param}").to_i
162
+ end
163
+ end
164
+ end
165
+ end
166
+
167
+ def make_accessor_int(*params)
168
+ params.each do |param|
169
+ define_singleton_method("#{param}") do
170
+ case param
171
+ when :bit
172
+ return self.getter("#{param}").to_i == 1 ? 16 : 24
173
+ else
174
+ return self.getter("#{param}").to_i
175
+ end
176
+ end
177
+
178
+ opts = {
179
+ sr: [
180
+ 11_025,
181
+ 16_000,
182
+ 22_050,
183
+ 24_000,
184
+ 32_000,
185
+ 44_100,
186
+ 48_000,
187
+ 64_000,
188
+ 88_200,
189
+ 96_000
190
+ ],
191
+ channel: (1..8),
192
+ bit: [16, 24],
193
+ quality: (0..4),
194
+ route: (0..8)
195
+ }
196
+
197
+ define_singleton_method("#{param}=") do |value|
198
+ unless opts[param].member? value
199
+ raise OutOfBoundsErrors.new(opts[param])
200
+ end
201
+ case param
202
+ when :bit
203
+ self.setter("#{param}", value == 16 ? 1 : 2)
204
+ else
205
+ self.setter("#{param}", value)
206
+ end
207
+ end
208
+ end
209
+ end
210
+ end
211
+
212
+ module MacroButton_Meta_Functions
213
+ private
214
+
215
+ include Conversions
216
+
217
+ def make_accessor_macrobutton(*params)
218
+ params.each do |param|
219
+ mode = { state: 1, stateonly: 2, trigger: 3 }
220
+
221
+ define_singleton_method("#{param}") do
222
+ return !(self.getter(mode[param])).zero?
223
+ end
224
+
225
+ define_singleton_method("#{param}=") do |value|
226
+ self.setter(Boolean(value) ? 1 : 0, mode[param])
227
+ end
228
+ end
229
+ end
230
+ end
231
+
232
+ module Commands_Meta_Functions
233
+ private
234
+
235
+ include Meta_Functions
236
+ def make_writer_bool(*params)
237
+ params.each do |param|
238
+ cmds = { showvbanchat: "DialogShow.VBANCHAT" }
239
+ if cmds.key? param
240
+ cmd = cmds[param]
241
+ else
242
+ cmd = param
243
+ end
244
+
245
+ define_singleton_method("#{param}=") do |value|
246
+ self.setter("#{cmd}", Boolean(value) ? 1 : 0)
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
@@ -1,20 +1,20 @@
1
- require_relative "iremote"
2
- require_relative "meta"
3
-
4
- module Voicemeeter
5
- class Recorder < IRemote
6
- "
7
- Concrete Recorder class
8
- "
9
- include Mixin::Outputs
10
-
11
- def initialize(remote)
12
- super
13
- self.make_action_prop :play, :stop, :record, :ff, :rew
14
- end
15
-
16
- def identifier
17
- :recorder
18
- end
19
- end
20
- end
1
+ require_relative "iremote"
2
+ require_relative "meta"
3
+
4
+ module Voicemeeter
5
+ class Recorder < IRemote
6
+ "
7
+ Concrete Recorder class
8
+ "
9
+ include Mixin::Outputs
10
+
11
+ def initialize(remote)
12
+ super
13
+ self.make_action_prop :play, :stop, :record, :ff, :rew
14
+ end
15
+
16
+ def identifier
17
+ :recorder
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,77 @@
1
+ module Voicemeeter
2
+ include RunVM
3
+
4
+ private
5
+
6
+ class Remote < Base
7
+ include Kinds
8
+ "
9
+ Remote class, subclasses Base
10
+
11
+ Console layout built according to a kind
12
+
13
+ Offers a run method for resource closure.
14
+ "
15
+ def initialize(kind, **kwargs)
16
+ super
17
+ self.strip = Strip.make(self, kind.layout[:strip])
18
+ self.bus = Bus.make(self, kind.layout[:bus])
19
+ self.button = MacroButton.make(self, kind.layout[:mb])
20
+ self.vban = Vban.new(self, kind.layout[:vban])
21
+ self.command = Command.new(self)
22
+ self.recorder = Recorder.new(self)
23
+ self.device = Device.new(self)
24
+ end
25
+
26
+ def run
27
+ "
28
+ Handles login/logout
29
+
30
+ Starts/stops the observable thread.
31
+ "
32
+ login
33
+ init_worker
34
+
35
+ yield if block_given?
36
+ ensure
37
+ end_worker
38
+ logout
39
+ end
40
+ end
41
+
42
+ public
43
+
44
+ def self.remote(kind_id, **kwargs)
45
+ "
46
+ Factory method for remotes.
47
+
48
+ Creates a hash of remote classes, one for each kind.
49
+
50
+ Handles kind_id request errors.
51
+
52
+ Returns a remote class of the kind requested.
53
+ "
54
+ _remotes =
55
+ Kinds.kinds_all.to_h do |kind|
56
+ [kind.name.to_s, Remote.new(kind, **kwargs)]
57
+ end
58
+
59
+ unless _remotes.key? kind_id
60
+ raise VMRemoteErrors.new("Unknown Voicemeeter Kind.")
61
+ end
62
+ _remotes[kind_id]
63
+ end
64
+
65
+ def self.testing
66
+ "
67
+ Returns a random Remote class
68
+ "
69
+ unless ENV["RACK_ENV"] == "dev"
70
+ raise VMRemoteErrors.new("Not in developer mode")
71
+ end
72
+
73
+ Remote.new(Kinds.kinds_all.sample)
74
+ end
75
+
76
+ module_function :start
77
+ end
@@ -1,31 +1,31 @@
1
- require_relative "cbindings"
2
- require_relative "kinds"
3
-
4
- module Voicemeeter
5
- module RunVM
6
- "
7
- Starts Voicemeeter of the Kind requested.
8
- "
9
- include CBindings
10
- include Kinds
11
-
12
- def start(kind_id)
13
- unless Kinds.kind_map.key? kind_id
14
- raise VMRemoteErrors.new("Unknown Voicemeeter Kind.")
15
- end
16
-
17
- enums =
18
- Kinds.kinds_all.map.with_index do |kind, i|
19
- if CBindings::OS_BITS == 64 && kind.name.to_s == "potato"
20
- [kind.name.to_s, i + 4]
21
- else
22
- [kind.name.to_s, i + 1]
23
- end
24
- end
25
- exes = enums.to_h { |k, v| [k, v.to_i] }
26
-
27
- CBindings.vm_runvm(exes[kind_id])
28
- sleep(1)
29
- end
30
- end
31
- end
1
+ require_relative "cbindings"
2
+ require_relative "kinds"
3
+
4
+ module Voicemeeter
5
+ module RunVM
6
+ "
7
+ Starts Voicemeeter of the Kind requested.
8
+ "
9
+ include CBindings
10
+ include Kinds
11
+
12
+ def start(kind_id)
13
+ unless Kinds.kind_map.key? kind_id
14
+ raise VMRemoteErrors.new("Unknown Voicemeeter Kind.")
15
+ end
16
+
17
+ enums =
18
+ Kinds.kinds_all.map.with_index do |kind, i|
19
+ if CBindings::OS_BITS == 64 && kind.name.to_s == "potato"
20
+ [kind.name.to_s, i + 4]
21
+ else
22
+ [kind.name.to_s, i + 1]
23
+ end
24
+ end
25
+ exes = enums.to_h { |k, v| [k, v.to_i] }
26
+
27
+ CBindings.vm_runvm(exes[kind_id])
28
+ sleep(1)
29
+ end
30
+ end
31
+ end