2022-06-22 20:51:25 +01:00
|
|
|
package voicemeeter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2022-07-09 19:01:58 +01:00
|
|
|
// A Remote type represents the API for a kind
|
|
|
|
type Remote struct {
|
2022-07-18 16:23:15 +01:00
|
|
|
Kind *kind
|
2022-07-10 23:08:14 +01:00
|
|
|
Strip []iStrip
|
|
|
|
Bus []iBus
|
2022-06-28 14:34:03 +01:00
|
|
|
Button []button
|
|
|
|
Command *command
|
|
|
|
Vban *vban
|
2022-06-28 16:29:13 +01:00
|
|
|
Device *device
|
2022-06-28 14:34:03 +01:00
|
|
|
Recorder *recorder
|
2022-06-25 20:11:15 +01:00
|
|
|
|
2022-06-26 01:41:05 +01:00
|
|
|
pooler *pooler
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// String implements the fmt.stringer interface
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) String() string {
|
2022-07-18 16:23:15 +01:00
|
|
|
return fmt.Sprintf("Voicemeeter %s", r.Kind)
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// Login logs into the API
|
|
|
|
// then it intializes the pooler
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) Login() {
|
2022-07-18 16:23:15 +01:00
|
|
|
login(r.Kind.Name)
|
|
|
|
r.pooler = newPooler(r.Kind)
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// Logout logs out of the API
|
|
|
|
// it also terminates the pooler
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) Logout() {
|
2022-06-26 01:41:05 +01:00
|
|
|
r.pooler.run = false
|
2022-06-22 20:51:25 +01:00
|
|
|
logout()
|
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// Type returns the type of Voicemeeter (basic, banana, potato)
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) Type() string {
|
2022-06-22 20:51:25 +01:00
|
|
|
return getVMType()
|
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// Version returns the version of Voicemeeter as a string
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) Version() string {
|
2022-06-22 20:51:25 +01:00
|
|
|
return getVersion()
|
|
|
|
}
|
|
|
|
|
2022-06-30 23:08:35 +01:00
|
|
|
// Pdirty returns true iff a parameter value has changed
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) Pdirty() bool {
|
2022-06-30 23:08:35 +01:00
|
|
|
return pdirty()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mdirty returns true iff a macrobutton value has changed
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) Mdirty() bool {
|
2022-06-30 23:08:35 +01:00
|
|
|
return mdirty()
|
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// SendText sets multiple parameters by script
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) SendText(script string) {
|
2022-06-22 20:51:25 +01:00
|
|
|
setParametersMulti(script)
|
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// Register forwards the register method to Pooler
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) Register(o observer) {
|
2022-06-26 01:41:05 +01:00
|
|
|
r.pooler.Register(o)
|
2022-06-26 01:36:32 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// Deregister forwards the deregister method to Pooler
|
2022-07-09 19:01:58 +01:00
|
|
|
func (r *Remote) Deregister(o observer) {
|
2022-06-26 01:41:05 +01:00
|
|
|
r.pooler.Deregister(o)
|
2022-06-26 01:36:32 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// remoteBuilder defines the interface builder types must satisfy
|
2022-06-25 16:22:16 +01:00
|
|
|
type remoteBuilder interface {
|
|
|
|
setKind() remoteBuilder
|
|
|
|
makeStrip() remoteBuilder
|
|
|
|
makeBus() remoteBuilder
|
|
|
|
makeButton() remoteBuilder
|
|
|
|
makeCommand() remoteBuilder
|
|
|
|
makeVban() remoteBuilder
|
2022-06-28 16:29:13 +01:00
|
|
|
makeDevice() remoteBuilder
|
2022-06-28 14:34:03 +01:00
|
|
|
makeRecorder() remoteBuilder
|
|
|
|
Build() remoteBuilder
|
2022-07-09 19:01:58 +01:00
|
|
|
Get() *Remote
|
2022-06-25 16:22:16 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// directory is responsible for directing the genericBuilder
|
2022-06-25 16:22:16 +01:00
|
|
|
type director struct {
|
|
|
|
builder remoteBuilder
|
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// SetBuilder sets the appropriate builder type for a kind
|
2022-06-25 16:22:16 +01:00
|
|
|
func (d *director) SetBuilder(b remoteBuilder) {
|
|
|
|
d.builder = b
|
|
|
|
}
|
2022-06-22 20:51:25 +01:00
|
|
|
|
2022-06-28 14:34:03 +01:00
|
|
|
// Construct calls the build function for the specific builder
|
2022-06-25 16:22:16 +01:00
|
|
|
func (d *director) Construct() {
|
2022-06-28 14:34:03 +01:00
|
|
|
d.builder.Build()
|
2022-06-25 16:22:16 +01:00
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// Get forwards the Get method to the builder
|
2022-07-09 19:01:58 +01:00
|
|
|
func (d *director) Get() *Remote {
|
2022-06-25 16:22:16 +01:00
|
|
|
return d.builder.Get()
|
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// genericBuilder represents a generic builder type
|
2022-06-25 16:22:16 +01:00
|
|
|
type genericBuilder struct {
|
|
|
|
k *kind
|
2022-07-09 19:01:58 +01:00
|
|
|
r Remote
|
2022-06-25 16:22:16 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// setKind sets the kind for a builder of a kind
|
2022-06-25 16:22:16 +01:00
|
|
|
func (b *genericBuilder) setKind() remoteBuilder {
|
2022-07-18 16:23:15 +01:00
|
|
|
b.r.Kind = b.k
|
2022-06-25 16:22:16 +01:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// makeStrip makes a strip slice and assigns it to remote.Strip
|
2022-07-10 23:08:14 +01:00
|
|
|
// []iStrip comprises of both physical and virtual strip types
|
2022-06-25 16:22:16 +01:00
|
|
|
func (b *genericBuilder) makeStrip() remoteBuilder {
|
|
|
|
fmt.Println("building strip")
|
2022-07-18 16:23:15 +01:00
|
|
|
_strip := make([]iStrip, b.k.NumStrip())
|
|
|
|
for i := 0; i < b.k.NumStrip(); i++ {
|
|
|
|
if i < b.k.PhysIn {
|
2022-06-30 20:08:46 +01:00
|
|
|
_strip[i] = newPhysicalStrip(i, b.k)
|
2022-06-23 10:42:11 +01:00
|
|
|
} else {
|
2022-06-30 20:08:46 +01:00
|
|
|
_strip[i] = newVirtualStrip(i, b.k)
|
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
|
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// makeBus makes a bus slice and assigns it to remote.Bus
|
|
|
|
// []t_bus comprises of both physical and virtual bus types
|
2022-06-25 16:22:16 +01:00
|
|
|
func (b *genericBuilder) makeBus() remoteBuilder {
|
|
|
|
fmt.Println("building bus")
|
2022-07-18 16:23:15 +01:00
|
|
|
_bus := make([]iBus, b.k.NumBus())
|
|
|
|
for i := 0; i < b.k.NumBus(); i++ {
|
|
|
|
if i < b.k.PhysOut {
|
2022-06-30 20:08:46 +01:00
|
|
|
_bus[i] = newPhysicalBus(i, b.k)
|
2022-06-23 10:42:11 +01:00
|
|
|
} else {
|
2022-06-30 20:08:46 +01:00
|
|
|
_bus[i] = newVirtualBus(i, b.k)
|
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
|
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// makeButton makes a button slice and assigns it to remote.Button
|
2022-06-25 16:22:16 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-07-09 19:01:58 +01:00
|
|
|
// makeCommand makes a command type and assigns it to remote.Command
|
2022-06-25 16:22:16 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-07-09 19:01:58 +01:00
|
|
|
// makeVban makes a vban type and assigns it to remote.Vban
|
2022-06-25 16:22:16 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-07-09 19:01:58 +01:00
|
|
|
// makeDevice makes a device type and assigns it to remote.Device
|
2022-06-28 16:29:13 +01:00
|
|
|
func (b *genericBuilder) makeDevice() remoteBuilder {
|
2022-07-01 00:01:56 +01:00
|
|
|
fmt.Println("building device")
|
2022-06-28 16:29:13 +01:00
|
|
|
b.r.Device = newDevice()
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2022-07-09 19:01:58 +01:00
|
|
|
// makeRecorder makes a recorder type and assigns it to remote.Recorder
|
2022-06-28 14:34:03 +01:00
|
|
|
func (b *genericBuilder) makeRecorder() remoteBuilder {
|
|
|
|
fmt.Println("building recorder")
|
|
|
|
b.r.Recorder = newRecorder()
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
2022-06-26 01:36:32 +01:00
|
|
|
// Get returns a fully constructed remote type for a kind
|
2022-07-09 19:01:58 +01:00
|
|
|
func (b *genericBuilder) Get() *Remote {
|
2022-06-25 16:22:16 +01:00
|
|
|
return &b.r
|
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// basicBuilder represents a builder specific to basic type
|
2022-06-25 16:22:16 +01:00
|
|
|
type basicBuilder struct {
|
|
|
|
genericBuilder
|
|
|
|
}
|
|
|
|
|
2022-06-28 14:34:03 +01:00
|
|
|
// Build defines the steps required to build a basic type
|
|
|
|
func (basb *genericBuilder) Build() remoteBuilder {
|
2022-06-28 16:29:13 +01:00
|
|
|
return basb.setKind().makeStrip().makeBus().makeButton().makeCommand().makeVban().makeDevice()
|
2022-06-28 14:34:03 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// bananaBuilder represents a builder specific to banana type
|
2022-06-25 16:22:16 +01:00
|
|
|
type bananaBuilder struct {
|
|
|
|
genericBuilder
|
|
|
|
}
|
|
|
|
|
2022-06-28 14:34:03 +01:00
|
|
|
// Build defines the steps required to build a banana type
|
|
|
|
func (banb *bananaBuilder) Build() remoteBuilder {
|
2022-06-28 16:29:13 +01:00
|
|
|
return banb.setKind().makeStrip().makeBus().makeButton().makeCommand().makeVban().makeDevice().makeRecorder()
|
2022-06-28 14:34:03 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 23:35:56 +01:00
|
|
|
// potatoBuilder represents a builder specific to potato type
|
2022-06-25 16:22:16 +01:00
|
|
|
type potatoBuilder struct {
|
|
|
|
genericBuilder
|
|
|
|
}
|
|
|
|
|
2022-06-28 14:34:03 +01:00
|
|
|
// Build defines the steps required to build a potato type
|
|
|
|
func (potb *potatoBuilder) Build() remoteBuilder {
|
2022-06-28 16:29:13 +01:00
|
|
|
return potb.setKind().makeStrip().makeBus().makeButton().makeCommand().makeVban().makeDevice().makeRecorder()
|
2022-06-28 14:34:03 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 23:08:14 +01:00
|
|
|
// NewRemote returns a Remote type for a kind
|
2022-06-26 01:36:32 +01:00
|
|
|
// this is the interface entry point
|
2022-07-10 23:08:14 +01:00
|
|
|
func NewRemote(kindId string) *Remote {
|
2022-06-25 16:22:16 +01:00
|
|
|
_kind, ok := kindMap[kindId]
|
|
|
|
if !ok {
|
|
|
|
err := fmt.Errorf("unknown Voicemeeter kind '%s'", kindId)
|
|
|
|
fmt.Println(err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
director := director{}
|
2022-07-18 16:23:15 +01:00
|
|
|
switch _kind.Name {
|
2022-06-25 16:22:16 +01:00
|
|
|
case "basic":
|
2022-07-09 19:01:58 +01:00
|
|
|
director.SetBuilder(&basicBuilder{genericBuilder{_kind, Remote{}}})
|
2022-06-25 16:22:16 +01:00
|
|
|
case "banana":
|
2022-07-09 19:01:58 +01:00
|
|
|
director.SetBuilder(&bananaBuilder{genericBuilder{_kind, Remote{}}})
|
2022-06-25 16:22:16 +01:00
|
|
|
case "potato":
|
2022-07-09 19:01:58 +01:00
|
|
|
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
|
|
|
}
|