mirror of
https://github.com/onyx-and-iris/voicemeeter.git
synced 2024-11-22 04:40:53 +00:00
entry point GetRemote added
director and builder types added, one for each kind. separates construction from representation
This commit is contained in:
parent
37a12713f0
commit
d3289dbb80
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
vmRem = voicemeeter.NewRemote("banana")
|
vmRem = voicemeeter.GetRemote("banana")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -41,9 +41,111 @@ func (r *remote) SendText(script string) {
|
|||||||
setParametersMulti(script)
|
setParametersMulti(script)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRemote returns a remote type of a kind,
|
type remoteBuilder interface {
|
||||||
// this is the interface entry point.
|
setKind() remoteBuilder
|
||||||
func NewRemote(kindId string) *remote {
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
_strip[i] = newPhysicalStrip(i)
|
||||||
|
} else {
|
||||||
|
_strip[i] = newVirtualStrip(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
_bus[i] = newPhysicalBus(i)
|
||||||
|
} else {
|
||||||
|
_bus[i] = newVirtualBus(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.r.Bus = _bus
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *genericBuilder) makeButton() remoteBuilder {
|
||||||
|
fmt.Println("building button")
|
||||||
|
_button := make([]button, 80)
|
||||||
|
for i := 0; i < 80; i++ {
|
||||||
|
_button[i] = newButton(i)
|
||||||
|
}
|
||||||
|
b.r.Button = _button
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *genericBuilder) makeCommand() remoteBuilder {
|
||||||
|
fmt.Println("building command")
|
||||||
|
_command := newCommand()
|
||||||
|
b.r.Command = _command
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *genericBuilder) makeVban() remoteBuilder {
|
||||||
|
fmt.Println("building vban")
|
||||||
|
_vban := newVban(b.k)
|
||||||
|
b.r.Vban = _vban
|
||||||
|
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]
|
_kind, ok := kindMap[kindId]
|
||||||
if !ok {
|
if !ok {
|
||||||
err := fmt.Errorf("unknown Voicemeeter kind '%s'", kindId)
|
err := fmt.Errorf("unknown Voicemeeter kind '%s'", kindId)
|
||||||
@ -51,35 +153,15 @@ func NewRemote(kindId string) *remote {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
_strip := make([]t_strip, _kind.numStrip())
|
director := director{}
|
||||||
for i := 0; i < _kind.numStrip(); i++ {
|
switch _kind.name {
|
||||||
if i < _kind.physIn {
|
case "basic":
|
||||||
_strip[i] = newPhysicalStrip(i)
|
director.SetBuilder(&basicBuilder{genericBuilder{_kind, remote{}}})
|
||||||
} else {
|
case "banana":
|
||||||
_strip[i] = newVirtualStrip(i)
|
director.SetBuilder(&bananaBuilder{genericBuilder{_kind, remote{}}})
|
||||||
}
|
case "potato":
|
||||||
}
|
director.SetBuilder(&potatoBuilder{genericBuilder{_kind, remote{}}})
|
||||||
_bus := make([]t_bus, _kind.numBus())
|
|
||||||
for i := 0; i < _kind.numBus(); i++ {
|
|
||||||
if i < _kind.physOut {
|
|
||||||
_bus[i] = newPhysicalBus(i)
|
|
||||||
} else {
|
|
||||||
_bus[i] = newVirtualBus(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_button := make([]button, 80)
|
|
||||||
for i := 0; i < 80; i++ {
|
|
||||||
_button[i] = newButton(i)
|
|
||||||
}
|
|
||||||
_command := newCommand()
|
|
||||||
_vban := newVban(_kind)
|
|
||||||
|
|
||||||
return &remote{
|
|
||||||
kind: _kind,
|
|
||||||
Strip: _strip,
|
|
||||||
Bus: _bus,
|
|
||||||
Button: _button,
|
|
||||||
Command: _command,
|
|
||||||
Vban: _vban,
|
|
||||||
}
|
}
|
||||||
|
director.Construct()
|
||||||
|
return director.Get()
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
func TestGetBasicRemote(t *testing.T) {
|
func TestGetBasicRemote(t *testing.T) {
|
||||||
//t.Skip("skipping test")
|
//t.Skip("skipping test")
|
||||||
__rem := NewRemote("basic")
|
__rem := GetRemote("basic")
|
||||||
t.Run("Should return a remote basic type", func(t *testing.T) {
|
t.Run("Should return a remote basic type", func(t *testing.T) {
|
||||||
assert.NotNil(t, __rem)
|
assert.NotNil(t, __rem)
|
||||||
})
|
})
|
||||||
@ -25,7 +25,7 @@ func TestGetBasicRemote(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetBananaRemote(t *testing.T) {
|
func TestGetBananaRemote(t *testing.T) {
|
||||||
//t.Skip("skipping test")
|
//t.Skip("skipping test")
|
||||||
__rem := NewRemote("banana")
|
__rem := GetRemote("banana")
|
||||||
t.Run("Should return a remote banana type", func(t *testing.T) {
|
t.Run("Should return a remote banana type", func(t *testing.T) {
|
||||||
assert.NotNil(t, __rem)
|
assert.NotNil(t, __rem)
|
||||||
})
|
})
|
||||||
@ -42,7 +42,7 @@ func TestGetBananaRemote(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetPotatoRemote(t *testing.T) {
|
func TestGetPotatoRemote(t *testing.T) {
|
||||||
//t.Skip("skipping test")
|
//t.Skip("skipping test")
|
||||||
__rem := NewRemote("potato")
|
__rem := GetRemote("potato")
|
||||||
t.Run("Should return a remote basic type", func(t *testing.T) {
|
t.Run("Should return a remote basic type", func(t *testing.T) {
|
||||||
assert.NotNil(t, __rem)
|
assert.NotNil(t, __rem)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user