voicemeeter-rb/lib/voicemeeter/vban.rb

98 lines
2.3 KiB
Ruby
Raw Normal View History

module Voicemeeter
module Vban
2023-08-29 14:07:52 +01:00
# Base class for Vban In/Out Streams
2023-07-27 10:58:26 +01:00
class VbanStream
include IRemote
extend MetaFunctions
2023-07-27 10:58:26 +01:00
attr_accessor_bool :on
attr_accessor_string :name, :ip
attr_accessor_int :quality, :route
def identifier
"vban.#{direction}stream[#{@index}]"
end
def direction
2023-07-27 11:15:04 +01:00
raise "Called abstract method: direction"
end
end
2023-08-29 11:21:05 +01:00
# Represents a Vban InStream
class VbanInstream < VbanStream
attr_reader_int :sr, :channel, :bit
def direction
:in
end
end
# Represents a Vban Audio InStream
2023-08-29 11:21:05 +01:00
class VbanAudioInstream < VbanInstream; end
# Represents a Vban Midi InStream
2023-08-29 11:21:05 +01:00
class VbanMidiInstream < VbanInstream; end
# Represents a Vban Text InStream
2023-08-29 11:21:05 +01:00
class VbanTextInstream < VbanInstream; end
2023-08-29 11:21:05 +01:00
# Represents a Vban OutStream
class VbanOutstream < VbanStream
attr_accessor_int :sr, :channel, :bit
def direction
:out
end
end
# Represents a Vban Audio OutStream
2023-08-29 11:21:05 +01:00
class VbanAudioOutstream < VbanOutstream; end
# Represents a Vban Midi OutStream
2023-08-29 11:21:05 +01:00
class VbanMidiOutstream < VbanOutstream; end
class RequestVbanStream
def self.for(remote, i, dir)
vban_in, vban_out, midi, _ = remote.kind.vban
case dir
when :in
if i < vban_in
VbanAudioInstream.new(remote, i)
elsif i < vban_in + midi
VbanMidiInstream.new(remote, i)
else
VbanTextInstream.new(remote, i)
end
when :out
if i < vban_out
VbanAudioOutstream.new(remote, i)
elsif i < vban_out + midi
VbanMidiOutstream.new(remote, i)
end
end
end
end
2023-08-29 14:07:52 +01:00
# Base class for Vban
2023-07-27 10:58:26 +01:00
class Base
2023-07-09 05:50:39 +01:00
attr_reader :instream, :outstream
def initialize(remote)
vban_in, vban_out, midi, text = remote.kind.vban
@instream = (0...vban_in + midi + text).map { RequestVbanStream.for(remote, _1, :in) }
@outstream = (0...vban_out + midi).map { RequestVbanStream.for(remote, _1, :out) }
@remote = remote
end
def enable
@remote.set("vban.enable", 1)
2023-07-09 05:50:39 +01:00
end
def disable
@remote.set("vban.enable", 0)
2023-07-09 05:50:39 +01:00
end
end
end
end