voicemeeter-rb/lib/voicemeeter/bus.rb

137 lines
2.6 KiB
Ruby
Raw Normal View History

require_relative "iremote"
require_relative "kinds"
require_relative "mixins"
module Voicemeeter
module Bus
2023-07-27 10:58:26 +01:00
class Base
# Base class for Bus types
include IRemote
include Mixins::Fades
include Mixins::Return
attr_reader :eq, :mode, :levels
def self.make(remote, i)
p_out = remote.kind.phys_out
2023-07-14 11:44:49 +01:00
(i < p_out) ? PhysicalBus.new(remote, i) : VirtualBus.new(remote, i)
end
def initialize(remote, i)
super
make_accessor_bool :mute, :mono, :sel, :monitor
make_accessor_float :gain
make_accessor_string :label
@eq = BusEq.new(remote, i)
@mode = BusModes.new(remote, i)
@levels = BusLevels.new(remote, i)
end
def identifier
"bus[#{@index}]"
end
end
2023-07-27 10:58:26 +01:00
class PhysicalBus < Base
# Represents a Physical Bus
end
2023-07-27 10:58:26 +01:00
class VirtualBus < Base
# Represents a Virtual Bus
end
2023-07-27 10:58:26 +01:00
class BusEq
include IRemote
def initialize(remote, i)
super
make_accessor_bool :on, :ab
end
def identifier
"bus[#{@index}].eq"
end
end
2023-07-27 10:58:26 +01:00
class BusModes
include IRemote
def initialize(remote, i)
super
make_accessor_bool :normal,
2023-07-14 11:44:49 +01:00
:amix,
:bmix,
:repeat,
:composite,
:tvmix,
:upmix21,
:upmix41,
:upmix61,
:centeronly,
:lfeonly,
:rearonly
end
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 }
2023-07-14 11:44:49 +01:00
vals = if @remote.running && @remote.event.ldirty
@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
def initialize(remote, i)
super
make_reader_only :name, :sr
make_writer_only :wdm, :ks, :mme, :asio
end
def identifier
"bus[#{@index}].device"
end
end
end