2022-06-22 20:51:25 +01:00
|
|
|
package voicemeeter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// A remote type represents the API for a kind,
|
|
|
|
// comprised of slices representing each member
|
|
|
|
type remote struct {
|
2022-06-23 14:06:48 +01:00
|
|
|
kind *kind
|
|
|
|
Strip []t_strip
|
|
|
|
Bus []t_bus
|
|
|
|
Button []button
|
|
|
|
Command *command
|
|
|
|
Vban *vban
|
2022-06-25 20:11:15 +01:00
|
|
|
|
|
|
|
Pooler *Pooler
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// String implements the stringer interface
|
|
|
|
func (r *remote) String() string {
|
|
|
|
return fmt.Sprintf("Voicemeeter %s", r.kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *remote) Login() {
|
2022-06-25 20:11:15 +01:00
|
|
|
r.Pooler = newPooler()
|
2022-06-22 20:51:25 +01:00
|
|
|
login(r.kind.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *remote) Logout() {
|
2022-06-25 20:11:15 +01:00
|
|
|
r.Pooler.run = false
|
2022-06-22 20:51:25 +01:00
|
|
|
logout()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *remote) Type() string {
|
|
|
|
return getVMType()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *remote) Version() string {
|
|
|
|
return getVersion()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *remote) SendText(script string) {
|
|
|
|
setParametersMulti(script)
|
|
|
|
}
|
|
|
|
|
2022-06-25 16:22:16 +01:00
|
|
|
type remoteBuilder interface {
|
|
|
|
setKind() remoteBuilder
|
|
|
|
makeStrip() remoteBuilder
|
|
|
|
makeBus() remoteBuilder
|
|
|
|
makeButton() remoteBuilder
|
|
|
|
makeCommand() remoteBuilder
|
|
|
|
makeVban() remoteBuilder
|
|
|
|
Get() *remote
|
|
|
|
}
|
|
|
|
|
|
|
|
type director struct {
|
|
|
|
builder remoteBuilder
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *director) SetBuilder(b remoteBuilder) {
|
|
|
|
d.builder = b
|
|
|
|
}
|
2022-06-22 20:51:25 +01:00
|
|
|
|
2022-06-25 16:22:16 +01:00
|
|
|
func (d *director) Construct() {
|
|
|
|
d.builder.setKind().makeStrip().makeBus().makeButton().makeCommand().makeVban()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *director) Get() *remote {
|
|
|
|
return d.builder.Get()
|
|
|
|
}
|
|
|
|
|
|
|
|
type genericBuilder struct {
|
|
|
|
k *kind
|
|
|
|
r remote
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *genericBuilder) setKind() remoteBuilder {
|
|
|
|
b.r.kind = b.k
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *genericBuilder) makeStrip() remoteBuilder {
|
|
|
|
fmt.Println("building strip")
|
|
|
|
_strip := make([]t_strip, b.k.numStrip())
|
|
|
|
for i := 0; i < b.k.numStrip(); i++ {
|
|
|
|
if i < b.k.physIn {
|
2022-06-25 01:18:20 +01:00
|
|
|
_strip[i] = newPhysicalStrip(i)
|
2022-06-23 10:42:11 +01:00
|
|
|
} else {
|
2022-06-25 01:18:20 +01:00
|
|
|
_strip[i] = newVirtualStrip(i)
|
2022-06-23 10:42:11 +01:00
|
|
|
}
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-06-25 16:22:16 +01:00
|
|
|
b.r.Strip = _strip
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *genericBuilder) makeBus() remoteBuilder {
|
|
|
|
fmt.Println("building bus")
|
|
|
|
_bus := make([]t_bus, b.k.numBus())
|
|
|
|
for i := 0; i < b.k.numBus(); i++ {
|
|
|
|
if i < b.k.physOut {
|
2022-06-25 01:18:20 +01:00
|
|
|
_bus[i] = newPhysicalBus(i)
|
2022-06-23 10:42:11 +01:00
|
|
|
} else {
|
2022-06-25 01:18:20 +01:00
|
|
|
_bus[i] = newVirtualBus(i)
|
2022-06-23 10:42:11 +01:00
|
|
|
}
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-06-25 16:22:16 +01:00
|
|
|
b.r.Bus = _bus
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *genericBuilder) makeButton() remoteBuilder {
|
|
|
|
fmt.Println("building button")
|
2022-06-22 20:51:25 +01:00
|
|
|
_button := make([]button, 80)
|
|
|
|
for i := 0; i < 80; i++ {
|
|
|
|
_button[i] = newButton(i)
|
|
|
|
}
|
2022-06-25 16:22:16 +01:00
|
|
|
b.r.Button = _button
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *genericBuilder) makeCommand() remoteBuilder {
|
|
|
|
fmt.Println("building command")
|
2022-06-25 20:11:15 +01:00
|
|
|
b.r.Command = newCommand()
|
2022-06-25 16:22:16 +01:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *genericBuilder) makeVban() remoteBuilder {
|
|
|
|
fmt.Println("building vban")
|
2022-06-25 20:11:15 +01:00
|
|
|
b.r.Vban = newVban(b.k)
|
2022-06-25 16:22:16 +01:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *genericBuilder) Get() *remote {
|
|
|
|
return &b.r
|
|
|
|
}
|
|
|
|
|
|
|
|
type basicBuilder struct {
|
|
|
|
genericBuilder
|
|
|
|
}
|
|
|
|
|
|
|
|
type bananaBuilder struct {
|
|
|
|
genericBuilder
|
|
|
|
}
|
|
|
|
|
|
|
|
type potatoBuilder struct {
|
|
|
|
genericBuilder
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetRemote(kindId string) *remote {
|
|
|
|
_kind, ok := kindMap[kindId]
|
|
|
|
if !ok {
|
|
|
|
err := fmt.Errorf("unknown Voicemeeter kind '%s'", kindId)
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
director := director{}
|
|
|
|
switch _kind.name {
|
|
|
|
case "basic":
|
|
|
|
director.SetBuilder(&basicBuilder{genericBuilder{_kind, remote{}}})
|
|
|
|
case "banana":
|
|
|
|
director.SetBuilder(&bananaBuilder{genericBuilder{_kind, remote{}}})
|
|
|
|
case "potato":
|
|
|
|
director.SetBuilder(&potatoBuilder{genericBuilder{_kind, remote{}}})
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-06-25 16:22:16 +01:00
|
|
|
director.Construct()
|
|
|
|
return director.Get()
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|