voicemeeter_api_ruby 3.0.0 → 4.0.0

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.
data/lib/bus.rb CHANGED
@@ -1,9 +1,10 @@
1
- require_relative 'channel'
1
+ require_relative 'iremote'
2
2
 
3
- class Bus < IChannel
3
+ class Bus < IRemote
4
4
  '
5
5
  Concrete Bus class
6
6
  '
7
+ include Channel_Meta_Functions
7
8
  include Fades
8
9
 
9
10
  attr_accessor :mode
@@ -20,7 +21,7 @@ class Bus < IChannel
20
21
 
21
22
  def initialize(remote, i)
22
23
  super
23
- self.make_accessor_bool :mute, :mono, :eq
24
+ self.make_accessor_bool :mute, :mono, :eq, :sel
24
25
  self.make_accessor_float :gain
25
26
  self.make_accessor_string :label
26
27
 
@@ -28,16 +29,23 @@ class Bus < IChannel
28
29
  end
29
30
 
30
31
  def identifier
31
- :bus
32
+ "bus[#{@index}]"
32
33
  end
33
34
  end
34
35
 
35
36
  class PhysicalBus < Bus
37
+ def initialize(remote, i)
38
+ super
39
+ self.make_reader_only :device, :sr
40
+ end
36
41
  end
42
+
37
43
  class VirtualBus < Bus
38
44
  end
39
45
 
40
- class BusModes < IChannel
46
+ class BusModes < IRemote
47
+ include Channel_Meta_Functions
48
+
41
49
  def initialize(remote, i)
42
50
  super
43
51
  self.make_bus_modes :normal,
@@ -55,10 +63,6 @@ class BusModes < IChannel
55
63
  end
56
64
 
57
65
  def identifier
58
- :bus
59
- end
60
-
61
- def cmd
62
- "#{super}.mode"
66
+ "bus[#{@index}].mode"
63
67
  end
64
68
  end
data/lib/button.rb CHANGED
@@ -1,13 +1,16 @@
1
+ require_relative 'iremote'
1
2
  require_relative 'meta'
2
3
 
3
- class IMacroButton
4
+ class MacroButton < IRemote
4
5
  include MacroButton_Meta_Functions
5
6
 
6
- attr_accessor :remote, :index
7
+ def self.make(remote, num_buttons)
8
+ (0...num_buttons).map { |i| MacroButton.new(remote, i) }
9
+ end
7
10
 
8
- def initialize(remote, index)
9
- self.remote = remote
10
- self.index = index
11
+ def initialize(remote, i)
12
+ super
13
+ self.make_accessor_macrobutton :state, :stateonly, :trigger
11
14
  end
12
15
 
13
16
  def getter(mode)
@@ -17,20 +20,4 @@ class IMacroButton
17
20
  def setter(set, mode)
18
21
  @remote.set_buttonstatus(@index, set, mode)
19
22
  end
20
-
21
- def set_multi(param_hash)
22
- param_hash.each { |(key, val)| self.send("#{key}=", val) }
23
- sleep(remote.delay)
24
- end
25
- end
26
-
27
- class MacroButton < IMacroButton
28
- def self.make(remote, num_buttons)
29
- (0...num_buttons).map { |i| MacroButton.new(remote, i) }
30
- end
31
-
32
- def initialize(remote, i)
33
- super
34
- self.make_accessor_macrobutton :state, :stateonly, :trigger
35
- end
36
23
  end
data/lib/cbindings.rb CHANGED
@@ -14,63 +14,85 @@ module CBindings
14
14
  private
15
15
 
16
16
  begin
17
- OS_BITS = get_arch
17
+ OS_BITS = FFI::Platform::CPU.downcase == 'x64' ? 64 : 32
18
18
  VM_PATH = get_vmpath(OS_BITS)
19
19
  DLL_NAME = "VoicemeeterRemote#{OS_BITS == 64 ? '64' : ''}.dll"
20
20
 
21
- self.vmr_dll = VM_PATH.join(DLL_NAME)
21
+ self.vm_dll = VM_PATH.join(DLL_NAME)
22
22
  rescue InstallErrors => error
23
23
  puts "ERROR: #{error.message}"
24
24
  raise
25
25
  end
26
26
 
27
- ffi_lib @vmr_dll
27
+ ffi_lib @vm_dll
28
28
  ffi_convention :stdcall
29
29
 
30
- attach_function :vmr_login, :VBVMR_Login, [], :long
31
- attach_function :vmr_logout, :VBVMR_Logout, [], :long
32
- attach_function :vmr_runvm, :VBVMR_RunVoicemeeter, [:long], :long
33
- attach_function :vmr_vmtype, :VBVMR_GetVoicemeeterType, [:pointer], :long
30
+ attach_function :vm_login, :VBVMR_Login, [], :long
31
+ attach_function :vm_logout, :VBVMR_Logout, [], :long
32
+ attach_function :vm_runvm, :VBVMR_RunVoicemeeter, [:long], :long
33
+ attach_function :vm_vmtype, :VBVMR_GetVoicemeeterType, [:pointer], :long
34
+ attach_function :vm_vmversion, :VBVMR_GetVoicemeeterVersion, [:pointer], :long
34
35
 
35
- attach_function :vmr_mdirty, :VBVMR_MacroButton_IsDirty, [], :long
36
- attach_function :vmr_get_buttonstatus,
36
+ attach_function :vm_mdirty, :VBVMR_MacroButton_IsDirty, [], :long
37
+ attach_function :vm_get_buttonstatus,
37
38
  :VBVMR_MacroButton_GetStatus,
38
39
  %i[long pointer long],
39
40
  :long
40
- attach_function :vmr_set_buttonstatus,
41
+ attach_function :vm_set_buttonstatus,
41
42
  :VBVMR_MacroButton_SetStatus,
42
43
  %i[long float long],
43
44
  :long
44
45
 
45
- attach_function :vmr_pdirty, :VBVMR_IsParametersDirty, [], :long
46
- attach_function :vmr_get_parameter_float,
46
+ attach_function :vm_pdirty, :VBVMR_IsParametersDirty, [], :long
47
+ attach_function :vm_get_parameter_float,
47
48
  :VBVMR_GetParameterFloat,
48
49
  %i[string pointer],
49
50
  :long
50
- attach_function :vmr_set_parameter_float,
51
+ attach_function :vm_set_parameter_float,
51
52
  :VBVMR_SetParameterFloat,
52
53
  %i[string float],
53
54
  :long
54
55
 
55
- attach_function :vmr_get_parameter_string,
56
+ attach_function :vm_get_parameter_string,
56
57
  :VBVMR_GetParameterStringA,
57
58
  %i[string pointer],
58
59
  :long
59
- attach_function :vmr_set_parameter_string,
60
+ attach_function :vm_set_parameter_string,
60
61
  :VBVMR_SetParameterStringA,
61
62
  %i[string string],
62
63
  :long
63
64
 
64
- attach_function :vmr_set_parameter_multi,
65
+ attach_function :vm_set_parameter_multi,
65
66
  :VBVMR_SetParameters,
66
67
  [:string],
67
68
  :long
68
69
 
69
- attach_function :vmr_get_level,
70
+ attach_function :vm_get_level,
70
71
  :VBVMR_GetLevel,
71
72
  %i[long long pointer],
72
73
  :long
73
74
 
75
+ attach_function :vm_get_num_indevices,
76
+ :VBVMR_Input_GetDeviceNumber, [], :long
77
+ attach_function :vm_get_desc_indevices,
78
+ :VBVMR_Input_GetDeviceDescA, %i[long pointer pointer pointer],
79
+ :long
80
+
81
+ attach_function :vm_get_num_outdevices,
82
+ :VBVMR_Output_GetDeviceNumber, [], :long
83
+ attach_function :vm_get_desc_outdevices,
84
+ :VBVMR_Output_GetDeviceDescA, %i[long pointer pointer pointer],
85
+ :long
86
+
87
+
88
+
89
+ @@cdll =
90
+ lambda do |func, *args|
91
+ self.retval = [send("vm_#{func}", *args), func]
92
+ end
93
+
94
+ def clear_polling() = while pdirty? || mdirty?; end
95
+
74
96
  def polling(func, **kwargs)
75
97
  params = {
76
98
  'get_parameter' => kwargs[:name],
@@ -78,7 +100,7 @@ module CBindings
78
100
  }
79
101
  return @cache.delete(params[func]) if @cache.key? params[func]
80
102
 
81
- self.clear_polling if @sync
103
+ clear_polling if @sync
82
104
 
83
105
  yield
84
106
  end
@@ -86,18 +108,15 @@ module CBindings
86
108
  def retval=(values)
87
109
  ' Writer validation for CAPI calls '
88
110
  retval, func = *values
89
- raise CAPIErrors.new(retval, func) if retval&.nonzero?
111
+ unless [:get_num_indevices, :get_num_outdevices].include? func
112
+ raise CAPIErrors.new(retval, func) if retval&.nonzero?
113
+ end
90
114
  @retval = retval
91
115
  end
92
116
 
93
117
  public
94
118
 
95
- def clear_polling
96
- while self.pdirty? || self.mdirty?
97
- end
98
- end
99
-
100
- def pdirty?() = vmr_pdirty&.nonzero?
119
+ def pdirty?() = vm_pdirty&.nonzero?
101
120
 
102
- def mdirty?() = vmr_mdirty&.nonzero?
121
+ def mdirty?() = vm_mdirty&.nonzero?
103
122
  end
data/lib/command.rb CHANGED
@@ -1,27 +1,18 @@
1
+ require_relative 'iremote'
1
2
  require_relative 'meta'
2
3
 
3
- class ICommand
4
+ class Command < IRemote
4
5
  include Commands_Meta_Functions
5
6
 
6
7
  def initialize(remote)
7
- @remote = remote
8
- end
9
-
10
- def setter(param, value)
11
- @remote.set_parameter("#{self.identifier}.#{param}", value)
8
+ super
9
+ self.make_action_prop :show, :restart, :shutdown
10
+ self.make_writer_bool :showvbanchat, :lock
12
11
  end
13
12
 
14
13
  def identifier
15
14
  :command
16
15
  end
17
- end
18
-
19
- class Command < ICommand
20
- def initialize(remote)
21
- super
22
- self.make_action_prop :show, :restart, :reset, :shutdown
23
- self.make_writer_bool :showvbanchat, :lock
24
- end
25
16
 
26
17
  def hide
27
18
  self.setter('show', 0)
@@ -38,4 +29,8 @@ class Command < ICommand
38
29
  self.setter('save', value)
39
30
  sleep(0.2)
40
31
  end
32
+
33
+ def reset
34
+ @remote.set_config('reset')
35
+ end
41
36
  end
data/lib/configs.rb ADDED
@@ -0,0 +1,79 @@
1
+ require 'kinds'
2
+ require 'toml'
3
+
4
+ module Configs
5
+ private
6
+
7
+ @@configs = Hash.new
8
+
9
+ class TOMLStrBuilder
10
+ def initialize(kind)
11
+ @p_in, @v_in = kind[:layout][:strip].values
12
+ @p_out, @v_out = kind[:layout][:bus].values
13
+ @vs_params =
14
+ ['mute = false', 'mono = false', 'solo = false', 'gain = 0.0'] +
15
+ (1..@p_out).map { |i| "A#{i} = false" } +
16
+ (1..@v_out).map { |i| "B#{i} = false" }
17
+
18
+ @ps_params = @vs_params + ['comp = 0.0', 'gate = 0.0']
19
+ @bus_params = ['mono = false', 'eq = false', 'mute = false']
20
+ end
21
+
22
+ def build
23
+ '
24
+ Builds a TOML script for the parser
25
+ '
26
+ @ps = (0...@p_in).map { |i| ["[strip_#{i}]"] + @ps_params }
27
+ @ps.map! { |a| a.map { |s| s.gsub('B1 = false', 'B1 = true') } }
28
+ @vs =
29
+ (@p_in...(@p_in + @v_in)).map do |i|
30
+ ["[strip_#{i}]"] + @vs_params
31
+ end
32
+ @vs.map! { |a| a.map { |s| s.gsub('A1 = false', 'A1 = true') } }
33
+
34
+ @b =
35
+ (0...(@p_out + @v_out)).map { |i| ["[bus_#{i}]"] + @bus_params }
36
+
37
+ [@ps + @vs + @b].join("\n")
38
+ end
39
+ end
40
+
41
+ def parser(data)
42
+ TOML::Parser.new(data).parsed
43
+ end
44
+
45
+ def get_configs(kind_id)
46
+ file_pattern =
47
+ File.join(File.dirname(__dir__), 'configs', "#{kind_id}", '*.toml')
48
+
49
+ Dir
50
+ .glob(file_pattern)
51
+ .to_h do |toml_file|
52
+ filename = File.basename(toml_file, '.toml')
53
+ puts "loading config #{kind_id}/#{filename} into memory"
54
+ [filename, parser(File.read(toml_file))]
55
+ end
56
+ end
57
+
58
+ def loader
59
+ if @@configs.empty?
60
+ builder = TOMLStrBuilder.new(@kind)
61
+ puts 'loading config reset into memory'
62
+ @@configs['reset'] = parser(builder.build)
63
+ @@configs.merge!(get_configs(@kind.name.to_s))
64
+ end
65
+ end
66
+
67
+ public
68
+
69
+ def set_config(value)
70
+ loader
71
+ unless @@configs.key? value
72
+ raise VMRemoteErrors.new("No profile with name #{value} was loaded")
73
+ end
74
+
75
+ self.send('set_multi', @@configs[value])
76
+ puts "config #{@kind.name}/#{value} applied!"
77
+ sleep(@delay)
78
+ end
79
+ end
data/lib/device.rb ADDED
@@ -0,0 +1,24 @@
1
+ require_relative 'iremote'
2
+ require_relative 'meta'
3
+
4
+ class Device
5
+ def initialize(remote)
6
+ @remote = remote
7
+ end
8
+
9
+ def getter(**kwargs)
10
+ return @remote.get_num_devices(kwargs[:direction]) if kwargs[:index].nil?
11
+
12
+ vals = @remote.get_device_description(kwargs[:index], kwargs[:direction])
13
+ types = { 1 => 'mme', 3 => 'wdm', 4 => 'ks', 5 => 'asio' }
14
+ { 'name': vals[0], 'type': types[vals[1]], 'id': vals[2] }
15
+ end
16
+
17
+ def ins() = getter(direction: 'in')
18
+
19
+ def outs() = getter(direction: 'out')
20
+
21
+ def input(i) = getter(index: i, direction: 'in')
22
+
23
+ def output(i) = getter(index: i, direction: 'out')
24
+ end
data/lib/inst.rb CHANGED
@@ -7,15 +7,6 @@ include Errors
7
7
  module InstallationFunctions
8
8
  private
9
9
 
10
- def get_arch
11
- key = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'
12
- Win32::Registry::HKEY_LOCAL_MACHINE.open(key) do |reg|
13
- os_bits = reg['PROCESSOR_ARCHITECTURE']
14
- return 64 if os_bits.include? '64'
15
- return 32
16
- end
17
- end
18
-
19
10
  def get_vmpath(os_bits)
20
11
  vm_key = 'VB:Voicemeeter {17359A74-1236-5467}'
21
12
  reg_key =
@@ -29,10 +20,10 @@ module InstallationFunctions
29
20
  raise InstallErrors.new('Could not get the Voicemeeter path')
30
21
  end
31
22
 
32
- def vmr_dll=(value)
23
+ def vm_dll=(value)
33
24
  unless value.file?
34
25
  raise InstallErrors.new('Could not fetch the dll file')
35
26
  end
36
- @vmr_dll = value
27
+ @vm_dll = value
37
28
  end
38
29
  end
@@ -1,31 +1,27 @@
1
1
  require_relative 'meta'
2
2
  require_relative 'errors'
3
3
 
4
- class IChannel
4
+ class IRemote
5
5
  '
6
- Base Channel class
6
+ Common interface between base class and higher classes.
7
7
  '
8
- include Channel_Meta_Functions
8
+ include Meta_Functions
9
9
 
10
- def initialize(remote, i)
10
+ def initialize(remote, i = nil)
11
11
  @remote = remote
12
12
  @index = i
13
13
  end
14
14
 
15
15
  def getter(param, is_string = false)
16
- @remote.get_parameter("#{self.cmd}.#{param}", is_string)
16
+ @remote.get_parameter("#{self.identifier}.#{param}", is_string)
17
17
  end
18
18
 
19
19
  def setter(param, value)
20
- @remote.set_parameter("#{self.cmd}.#{param}", value)
21
- end
22
-
23
- def cmd
24
- "#{self.identifier}[#{@index}]"
20
+ @remote.set_parameter("#{self.identifier}.#{param}", value)
25
21
  end
26
22
 
27
23
  def identifier
28
- raise 'Called abstract mehod: identifier'
24
+ raise 'Called abstract method: identifier'
29
25
  end
30
26
 
31
27
  def set_multi(param_hash)
data/lib/meta.rb CHANGED
@@ -150,7 +150,7 @@ module Channel_Meta_Functions
150
150
  when :device
151
151
  return self.getter("#{cmd}", true)
152
152
  when :sr
153
- return self.getter("#{cmd}", true).to_i
153
+ return self.getter("#{cmd}").to_i
154
154
  end
155
155
  end
156
156
  end
data/lib/recorder.rb CHANGED
@@ -1,28 +1,11 @@
1
+ require_relative 'iremote'
1
2
  require_relative 'meta'
2
3
 
3
- class IRecorder
4
- '
5
- Base Recorder class
6
- '
7
- include Meta_Functions
8
-
9
- def initialize(remote)
10
- @remote = remote
11
- end
12
-
13
- def getter(param)
14
- @remote.get_parameter("#{self.identifier}.#{param}")
15
- end
16
-
17
- def setter(param, value)
18
- @remote.set_parameter("#{self.identifier}.#{param}", value)
19
- end
20
- end
21
-
22
- class Recorder < IRecorder
4
+ class Recorder < IRemote
23
5
  '
24
6
  Concrete Recorder class
25
7
  '
8
+
26
9
  def initialize(remote)
27
10
  super
28
11
  self.make_action_prop :play, :stop, :record, :ff, :rew
data/lib/runvm.rb CHANGED
@@ -15,15 +15,15 @@ module RunVM
15
15
 
16
16
  enums =
17
17
  Kinds.kinds_all.map.with_index do |kind, i|
18
- if OS_BITS == 64 && kind.name == 'potato'
19
- [kind.name, i + 4]
18
+ if OS_BITS == 64 && kind.name.to_s == 'potato'
19
+ [kind.name.to_s, i + 4]
20
20
  else
21
- [kind.name, i + 1]
21
+ [kind.name.to_s, i + 1]
22
22
  end
23
23
  end
24
24
  exes = enums.to_h { |k, v| [k, v.to_i] }
25
25
 
26
- send('vmr_runvm', exes[kind_id])
26
+ send(:vm_runvm, exes[kind_id])
27
27
  sleep(1)
28
28
  end
29
29
  end
data/lib/strip.rb CHANGED
@@ -1,9 +1,10 @@
1
- require_relative 'channel'
1
+ require_relative 'iremote'
2
2
 
3
- class Strip < IChannel
3
+ class Strip < IRemote
4
4
  '
5
5
  Concrete Strip class
6
6
  '
7
+ include Channel_Meta_Functions
7
8
  include Fades
8
9
 
9
10
  attr_accessor :gainlayer
@@ -36,14 +37,14 @@ class Strip < IChannel
36
37
  end
37
38
 
38
39
  def identifier
39
- :strip
40
+ "strip[#{@index}]"
40
41
  end
41
42
  end
42
43
 
43
44
  class PhysicalStrip < Strip
44
45
  def initialize(remote, i)
45
46
  super
46
- self.make_accessor_float :comp, :gate
47
+ self.make_accessor_float :comp, :gate, :audibility
47
48
  self.make_reader_only :device, :sr
48
49
  end
49
50
  end
@@ -53,21 +54,26 @@ class VirtualStrip < Strip
53
54
  super
54
55
  self.make_accessor_bool :mc
55
56
  self.make_accessor_int :k
57
+ self.make_accessor_float :bass, :mid, :treble
56
58
  end
57
59
 
58
- def appgain(name, gain) = self.setter("AppGain", "(\"#{name}\", #{gain})")
60
+ def appgain(name, gain)
61
+ self.setter('AppGain', "(\"#{name}\", #{gain})")
62
+ end
59
63
 
60
- def appmute(name, mute) = self.setter("AppMute", "(\"#{name}\", #{mute ? 1 : 0})")
64
+ def appmute(name, mute)
65
+ self.setter('AppMute', "(\"#{name}\", #{mute ? 1 : 0})")
66
+ end
61
67
  end
62
68
 
63
- class GainLayer < IChannel
69
+ class GainLayer < IRemote
64
70
  def initialize(remote, i, j)
65
71
  super(remote, i)
66
72
  @j = j
67
73
  end
68
74
 
69
75
  def identifier
70
- :strip
76
+ "strip[#{@index}]"
71
77
  end
72
78
 
73
79
  def gain