voicemeeter-rb/lib/voicemeeter/bus.rb

125 lines
2.5 KiB
Ruby
Raw Permalink Normal View History

module Voicemeeter
module Bus
2023-08-29 14:07:52 +01:00
# Base class for Bus
2023-07-27 10:58:26 +01:00
class Base
include IRemote
include Mixins::Fades
include Mixins::Return
extend MetaFunctions
attr_reader :eq, :mode, :levels
attr_accessor_bool :mute, :mono, :sel, :monitor
attr_accessor_float :gain
attr_accessor_string :label
def self.make(remote, i)
2023-07-29 18:06:34 +01:00
(i < remote.kind.phys_out) ? PhysicalBus.new(remote, i) : VirtualBus.new(remote, i)
end
def initialize(remote, i)
super
@eq = BusEq.new(remote, i)
@mode = BusModes.new(remote, i)
@levels = BusLevels.new(remote, i)
end
def identifier
"bus[#{@index}]"
end
end
2023-08-01 23:41:23 +01:00
# Represents a Physical Bus
2023-08-29 11:21:05 +01:00
class PhysicalBus < Base; end
2023-08-01 23:41:23 +01:00
# Represents a Virtual Bus
2023-08-29 11:21:05 +01:00
class VirtualBus < Base; end
2023-07-27 10:58:26 +01:00
class BusEq
include IRemote
extend MetaFunctions
2023-07-27 10:58:26 +01:00
attr_accessor_bool :on, :ab
def identifier
"bus[#{@index}].eq"
end
end
2023-07-27 10:58:26 +01:00
class BusModes
include IRemote
extend MetaFunctions
2023-07-27 10:58:26 +01:00
attr_accessor_bool :normal,
:amix,
:bmix,
:repeat,
:composite,
:tvmix,
:upmix21,
:upmix41,
:upmix61,
:centeronly,
:lfeonly,
:rearonly
def identifier
"bus[#{@index}].mode"
end
2023-07-18 10:34:51 +01:00
def get
sleep(@remote.delay)
%i[amix bmix repeat composite tvmix upmix21 upmix41 upmix61 centeronly lfeonly rearonly].each do |mode|
if send(mode)
return mode
end
end
:normal
end
end
end
2023-07-27 10:58:26 +01:00
class BusLevels
include IRemote
def initialize(remote, i)
super
@init = i * 8
@offset = 8
end
def identifier
"bus[#{@index}]"
end
def getter(mode)
2023-07-25 10:20:31 +01:00
convert = ->(x) { (x > 0) ? (20 * Math.log(x, 10)).round(1) : -200.0 }
vals = if @remote.running? && @remote.event.ldirty
2023-07-14 11:44:49 +01:00
@remote.cache[:bus_level][@init, @offset]
else
2023-07-14 11:44:49 +01:00
(@init...@init + @offset).map { |i| @remote.get_level(mode, i) }
end
2023-07-25 10:20:31 +01:00
vals.map(&convert)
end
def all
getter(Mixins::LevelEnum::BUS)
end
def isdirty? = @remote.cache[:bus_comp][@init, @offset].any?
end
2023-07-27 10:58:26 +01:00
class BusDevice
include IRemote
2023-08-30 12:45:55 +01:00
extend MetaFunctions
2023-07-27 10:58:26 +01:00
2023-08-30 12:45:55 +01:00
attr_reader_int :sr
attr_reader_string :name
attr_writer_string :wdm, :ks, :mme, :asio
def identifier
"bus[#{@index}].device"
end
end
end