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,83 +1,83 @@
1
- require "toml"
2
- require_relative "kinds"
3
-
4
- module Voicemeeter
5
- module Configs
6
- private
7
-
8
- @@configs = Hash.new
9
-
10
- class TOMLStrBuilder
11
- def initialize(kind)
12
- @p_in, @v_in = kind[:layout][:strip].values
13
- @p_out, @v_out = kind[:layout][:bus].values
14
- @vs_params =
15
- ["mute = false", "mono = false", "solo = false", "gain = 0.0"] +
16
- (1..@p_out).map { |i| "A#{i} = false" } +
17
- (1..@v_out).map { |i| "B#{i} = false" }
18
-
19
- @ps_params = @vs_params + ["comp = 0.0", "gate = 0.0"]
20
- @bus_params = ["mono = false", "eq = false", "mute = false"]
21
- end
22
-
23
- def build
24
- "
25
- Builds a TOML script for the parser
26
- "
27
- @ps = (0...@p_in).map { |i| ["[strip_#{i}]"] + @ps_params }
28
- @ps.map! { |a| a.map { |s| s.gsub("B1 = false", "B1 = true") } }
29
- @vs =
30
- (@p_in...(@p_in + @v_in)).map { |i| ["[strip_#{i}]"] + @vs_params }
31
- @vs.map! { |a| a.map { |s| s.gsub("A1 = false", "A1 = true") } }
32
-
33
- @b = (0...(@p_out + @v_out)).map { |i| ["[bus_#{i}]"] + @bus_params }
34
-
35
- [@ps + @vs + @b].join("\n")
36
- end
37
- end
38
-
39
- def parser(data)
40
- TOML::Parser.new(data).parsed
41
- end
42
-
43
- def get_configs(kind_id)
44
- file_path = File.join(Dir.pwd, "configs", "#{kind_id}")
45
-
46
- if Dir.exist?(file_path)
47
- Dir
48
- .glob(File.join(file_path, "*.toml"))
49
- .to_h do |toml_file|
50
- filename = File.basename(toml_file, ".toml")
51
- puts "loading config #{kind_id}/#{filename} into memory"
52
- [filename, parser(File.read(toml_file))]
53
- end
54
- end
55
- end
56
-
57
- def loader
58
- if @@configs.empty?
59
- builder = TOMLStrBuilder.new(@kind)
60
- puts "loading config reset into memory"
61
- @@configs["reset"] = parser(builder.build)
62
- configs = get_configs(@kind.name.to_s)
63
-
64
- @@configs.merge!(configs) unless configs.nil?
65
- end
66
- end
67
-
68
- public
69
-
70
- def set_config(value)
71
- loader
72
- unless @@configs.key? value
73
- raise VMRemoteErrors.new("No profile with name #{value} was loaded")
74
- end
75
-
76
- self.send("set_multi", @@configs[value])
77
- puts "config #{@kind.name}/#{value} applied!"
78
- sleep(@delay)
79
- end
80
-
81
- alias_method "apply_config", :set_config
82
- end
83
- end
1
+ require "toml"
2
+ require_relative "kinds"
3
+
4
+ module Voicemeeter
5
+ module Configs
6
+ private
7
+
8
+ @@configs = Hash.new
9
+
10
+ class TOMLStrBuilder
11
+ def initialize(kind)
12
+ @p_in, @v_in = kind[:layout][:strip].values
13
+ @p_out, @v_out = kind[:layout][:bus].values
14
+ @vs_params =
15
+ ["mute = false", "mono = false", "solo = false", "gain = 0.0"] +
16
+ (1..@p_out).map { |i| "A#{i} = false" } +
17
+ (1..@v_out).map { |i| "B#{i} = false" }
18
+
19
+ @ps_params = @vs_params + ["comp = 0.0", "gate = 0.0"]
20
+ @bus_params = ["mono = false", "eq = false", "mute = false"]
21
+ end
22
+
23
+ def build
24
+ "
25
+ Builds a TOML script for the parser
26
+ "
27
+ @ps = (0...@p_in).map { |i| ["[strip_#{i}]"] + @ps_params }
28
+ @ps.map! { |a| a.map { |s| s.gsub("B1 = false", "B1 = true") } }
29
+ @vs =
30
+ (@p_in...(@p_in + @v_in)).map { |i| ["[strip_#{i}]"] + @vs_params }
31
+ @vs.map! { |a| a.map { |s| s.gsub("A1 = false", "A1 = true") } }
32
+
33
+ @b = (0...(@p_out + @v_out)).map { |i| ["[bus_#{i}]"] + @bus_params }
34
+
35
+ [@ps + @vs + @b].join("\n")
36
+ end
37
+ end
38
+
39
+ def parser(data)
40
+ TOML::Parser.new(data).parsed
41
+ end
42
+
43
+ def get_configs(kind_id)
44
+ file_path = File.join(Dir.pwd, "configs", "#{kind_id}")
45
+
46
+ if Dir.exist?(file_path)
47
+ Dir
48
+ .glob(File.join(file_path, "*.toml"))
49
+ .to_h do |toml_file|
50
+ filename = File.basename(toml_file, ".toml")
51
+ puts "loading config #{kind_id}/#{filename} into memory"
52
+ [filename, parser(File.read(toml_file))]
53
+ end
54
+ end
55
+ end
56
+
57
+ def loader
58
+ if @@configs.empty?
59
+ builder = TOMLStrBuilder.new(@kind)
60
+ puts "loading config reset into memory"
61
+ @@configs["reset"] = parser(builder.build)
62
+ configs = get_configs(@kind.name.to_s)
63
+
64
+ @@configs.merge!(configs) unless configs.nil?
65
+ end
66
+ end
67
+
68
+ public
69
+
70
+ def set_config(value)
71
+ loader
72
+ unless @@configs.key? value
73
+ raise VMRemoteErrors.new("No profile with name #{value} was loaded")
74
+ end
75
+
76
+ self.send("set_multi", @@configs[value])
77
+ puts "config #{@kind.name}/#{value} applied!"
78
+ sleep(@delay)
79
+ end
80
+
81
+ alias_method "apply_config", :set_config
82
+ end
83
+ end
@@ -1,43 +1,43 @@
1
- module Voicemeeter
2
- module Errors
3
- class VMRemoteErrors < StandardError
4
- end
5
-
6
- class InstallErrors < VMRemoteErrors
7
- end
8
-
9
- class CAPIErrors < VMRemoteErrors
10
- attr_accessor :value, :func
11
-
12
- def initialize(value, func)
13
- self.value = value
14
- self.func = func
15
- end
16
-
17
- def message
18
- "
19
- When attempting to run function #{@func} the
20
- C API returned value #{@value}. See documentation for further info
21
- "
22
- end
23
- end
24
-
25
- class OutOfBoundsErrors < VMRemoteErrors
26
- attr_accessor :range
27
-
28
- def initialize(range)
29
- self.range = range
30
- end
31
-
32
- def message
33
- if @range.kind_of?(Range)
34
- "Value error, expected value in range (#{range.first}..#{range.last})"
35
- elsif @range.kind_of?(Array)
36
- "Value error, expected one of: #{@range}"
37
- else
38
- "Value error, expected #{@range}"
39
- end
40
- end
41
- end
42
- end
43
- end
1
+ module Voicemeeter
2
+ module Errors
3
+ class VMRemoteErrors < StandardError
4
+ end
5
+
6
+ class InstallErrors < VMRemoteErrors
7
+ end
8
+
9
+ class CAPIErrors < VMRemoteErrors
10
+ attr_accessor :value, :func
11
+
12
+ def initialize(value, func)
13
+ self.value = value
14
+ self.func = func
15
+ end
16
+
17
+ def message
18
+ "
19
+ When attempting to run function #{@func} the
20
+ C API returned value #{@value}. See documentation for further info
21
+ "
22
+ end
23
+ end
24
+
25
+ class OutOfBoundsErrors < VMRemoteErrors
26
+ attr_accessor :range
27
+
28
+ def initialize(range)
29
+ self.range = range
30
+ end
31
+
32
+ def message
33
+ if @range.kind_of?(Range)
34
+ "Value error, expected value in range (#{range.first}..#{range.last})"
35
+ elsif @range.kind_of?(Array)
36
+ "Value error, expected one of: #{@range}"
37
+ else
38
+ "Value error, expected #{@range}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,27 +1,27 @@
1
- require "win32/registry"
2
- require "pathname"
3
- require_relative "errors"
4
-
5
- module Voicemeeter
6
- module InstallationFunctions
7
- private
8
-
9
- def get_vmpath(os_bits)
10
- vm_key = "VB:Voicemeeter {17359A74-1236-5467}"
11
- reg_key =
12
- "Software#{os_bits == 64 ? "\\WOW6432Node" : ""}\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
13
- Win32::Registry::HKEY_LOCAL_MACHINE.open(reg_key + vm_key) do |reg|
14
- value = reg["UninstallString"]
15
-
16
- pn = Pathname.new(value)
17
- return pn.dirname
18
- end
19
- raise InstallErrors.new("Could not get the Voicemeeter path")
20
- end
21
-
22
- def vm_dll=(value)
23
- raise InstallErrors.new("Could not fetch the dll file") unless value.file?
24
- @vm_dll = value
25
- end
26
- end
27
- end
1
+ require "win32/registry"
2
+ require "pathname"
3
+ require_relative "errors"
4
+
5
+ module Voicemeeter
6
+ module InstallationFunctions
7
+ private
8
+
9
+ def get_vmpath(os_bits)
10
+ vm_key = "VB:Voicemeeter {17359A74-1236-5467}"
11
+ reg_key =
12
+ "Software#{os_bits == 64 ? "\\WOW6432Node" : ""}\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
13
+ Win32::Registry::HKEY_LOCAL_MACHINE.open(reg_key + vm_key) do |reg|
14
+ value = reg["UninstallString"]
15
+
16
+ pn = Pathname.new(value)
17
+ return pn.dirname
18
+ end
19
+ raise InstallErrors.new("Could not get the Voicemeeter path")
20
+ end
21
+
22
+ def vm_dll=(value)
23
+ raise InstallErrors.new("Could not fetch the dll file") unless value.file?
24
+ @vm_dll = value
25
+ end
26
+ end
27
+ end
@@ -1,34 +1,34 @@
1
- require_relative "meta"
2
- require_relative "errors"
3
-
4
- module Voicemeeter
5
- class IRemote
6
- "
7
- Common interface between base class and higher classes.
8
- "
9
- include Meta_Functions
10
-
11
- def initialize(remote, i = nil)
12
- @remote = remote
13
- @index = i
14
- end
15
-
16
- def getter(param, is_string = false)
17
- @remote.get_parameter("#{self.identifier}.#{param}", is_string)
18
- end
19
-
20
- def setter(param, value)
21
- @remote.set_parameter("#{self.identifier}.#{param}", value)
22
- end
23
-
24
- def identifier
25
- raise "Called abstract method: identifier"
26
- end
27
-
28
- def set_multi(param_hash)
29
- param_hash.each { |(key, val)| self.send("#{key}=", val) }
30
- end
31
-
32
- alias_method "apply", :set_multi
33
- end
34
- end
1
+ require_relative "meta"
2
+ require_relative "errors"
3
+
4
+ module Voicemeeter
5
+ class IRemote
6
+ "
7
+ Common interface between base class and higher classes.
8
+ "
9
+ include Meta_Functions
10
+
11
+ def initialize(remote, i = nil)
12
+ @remote = remote
13
+ @index = i
14
+ end
15
+
16
+ def getter(param, is_string = false)
17
+ @remote.get_parameter("#{self.identifier}.#{param}", is_string)
18
+ end
19
+
20
+ def setter(param, value)
21
+ @remote.set_parameter("#{self.identifier}.#{param}", value)
22
+ end
23
+
24
+ def identifier
25
+ raise "Called abstract method: identifier"
26
+ end
27
+
28
+ def set_multi(param_hash)
29
+ param_hash.each { |(key, val)| self.send("#{key}=", val) }
30
+ end
31
+
32
+ alias_method "apply", :set_multi
33
+ end
34
+ end
@@ -1,79 +1,79 @@
1
- module Voicemeeter
2
- module Kinds
3
- "
4
- A Kind struct for each version of Voicemeeter
5
- "
6
- attr_reader :kind_map, :kinds_all
7
-
8
- Kind = Struct.new(:name, :layout)
9
- basic =
10
- Kind.new(
11
- "basic",
12
- {
13
- strip: {
14
- p_in: 2,
15
- v_in: 1
16
- },
17
- bus: {
18
- p_out: 1,
19
- v_out: 1
20
- },
21
- vban: {
22
- instream: 4,
23
- outstream: 4
24
- },
25
- mb: 80
26
- }
27
- )
28
-
29
- banana =
30
- Kind.new(
31
- "banana",
32
- {
33
- strip: {
34
- p_in: 3,
35
- v_in: 2
36
- },
37
- bus: {
38
- p_out: 3,
39
- v_out: 2
40
- },
41
- vban: {
42
- instream: 8,
43
- outstream: 8
44
- },
45
- mb: 80
46
- }
47
- )
48
-
49
- potato =
50
- Kind.new(
51
- "potato",
52
- {
53
- strip: {
54
- p_in: 5,
55
- v_in: 3
56
- },
57
- bus: {
58
- p_out: 5,
59
- v_out: 3
60
- },
61
- vban: {
62
- instream: 8,
63
- outstream: 8
64
- },
65
- mb: 80
66
- }
67
- )
68
-
69
- @kind_map = [basic, banana, potato].to_h { |kind| [kind.name, kind] }
70
-
71
- def get_kind(kind_id)
72
- @kind_map[kind_id]
73
- end
74
-
75
- @kinds_all = @kind_map.values
76
-
77
- module_function :get_kind, :kind_map, :kinds_all
78
- end
79
- end
1
+ module Voicemeeter
2
+ module Kinds
3
+ "
4
+ A Kind struct for each version of Voicemeeter
5
+ "
6
+ attr_reader :kind_map, :kinds_all
7
+
8
+ Kind = Struct.new(:name, :layout)
9
+ basic =
10
+ Kind.new(
11
+ "basic",
12
+ {
13
+ strip: {
14
+ p_in: 2,
15
+ v_in: 1
16
+ },
17
+ bus: {
18
+ p_out: 1,
19
+ v_out: 1
20
+ },
21
+ vban: {
22
+ instream: 4,
23
+ outstream: 4
24
+ },
25
+ mb: 80
26
+ }
27
+ )
28
+
29
+ banana =
30
+ Kind.new(
31
+ "banana",
32
+ {
33
+ strip: {
34
+ p_in: 3,
35
+ v_in: 2
36
+ },
37
+ bus: {
38
+ p_out: 3,
39
+ v_out: 2
40
+ },
41
+ vban: {
42
+ instream: 8,
43
+ outstream: 8
44
+ },
45
+ mb: 80
46
+ }
47
+ )
48
+
49
+ potato =
50
+ Kind.new(
51
+ "potato",
52
+ {
53
+ strip: {
54
+ p_in: 5,
55
+ v_in: 3
56
+ },
57
+ bus: {
58
+ p_out: 5,
59
+ v_out: 3
60
+ },
61
+ vban: {
62
+ instream: 8,
63
+ outstream: 8
64
+ },
65
+ mb: 80
66
+ }
67
+ )
68
+
69
+ @kind_map = [basic, banana, potato].to_h { |kind| [kind.name, kind] }
70
+
71
+ def get_kind(kind_id)
72
+ @kind_map[kind_id]
73
+ end
74
+
75
+ @kinds_all = @kind_map.values
76
+
77
+ module_function :get_kind, :kind_map, :kinds_all
78
+ end
79
+ end