diff --git a/voicemeeter/base.go b/voicemeeter/base.go index 47b2e91..917f209 100644 --- a/voicemeeter/base.go +++ b/voicemeeter/base.go @@ -111,7 +111,7 @@ func mdirty() bool { } func sync() { - time.Sleep(5 * time.Millisecond) + time.Sleep(20 * time.Millisecond) for pdirty() || mdirty() { } } @@ -151,7 +151,7 @@ func getParameterFloat(name string) float64 { return math.Round(float64(value)*10) / 10 } -// getParameterFloat sets the value of a float parameter +// setParameterFloat sets the value of a float parameter func setParameterFloat(name string, value float32) { b1 := append([]byte(name), 0) b2 := math.Float32bits(value) diff --git a/voicemeeter/bus.go b/voicemeeter/bus.go index 53d6f4f..f10982a 100644 --- a/voicemeeter/bus.go +++ b/voicemeeter/bus.go @@ -5,6 +5,7 @@ import ( ) type t_bus interface { + String() string GetMute() bool SetMute(val bool) GetEq() bool @@ -23,14 +24,6 @@ type bus struct { iRemote } -// String implements the stringer interface -func (b *bus) String() string { - if b.index < b.kind.physOut { - return fmt.Sprintf("PhysicalBus%d\n", b.index) - } - return fmt.Sprintf("VirtualBus%d\n", b.index) -} - // GetMute returns the value of the Mute parameter func (b *bus) GetMute() bool { return b.getter_bool("Mute") @@ -85,16 +78,26 @@ type physicalBus struct { bus } -func newPhysicalBus(i int, k *kind) t_bus { - pb := physicalBus{bus{iRemote{"bus", i, k}}} +func newPhysicalBus(i int) t_bus { + pb := physicalBus{bus{iRemote{"bus", i}}} return t_bus(&pb) } +// String implements the stringer interface +func (p *physicalBus) String() string { + return fmt.Sprintf("PhysicalBus%d", p.index) +} + type virtualBus struct { bus } -func newVirtualBus(i int, k *kind) t_bus { - vb := virtualBus{bus{iRemote{"bus", i, k}}} +func newVirtualBus(i int) t_bus { + vb := virtualBus{bus{iRemote{"bus", i}}} return t_bus(&vb) } + +// String implements the stringer interface +func (v *virtualBus) String() string { + return fmt.Sprintf("VirtualBus%d", v.index) +} diff --git a/voicemeeter/bus_test.go b/voicemeeter/bus_test.go new file mode 100644 index 0000000..cf34d07 --- /dev/null +++ b/voicemeeter/bus_test.go @@ -0,0 +1,29 @@ +package voicemeeter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetPhysBus(t *testing.T) { + //t.Skip("skipping test") + __bus := newPhysicalBus(0) + t.Run("Should return a physical bus type", func(t *testing.T) { + assert.NotNil(t, __bus) + }) + t.Run("Should return 'PhysicalBus0'", func(t *testing.T) { + assert.Equal(t, "PhysicalBus0", __bus.String()) + }) +} + +func TestGetVirtBus(t *testing.T) { + //t.Skip("skipping test") + __bus := newVirtualBus(4) + t.Run("Should return a basic kind", func(t *testing.T) { + assert.NotNil(t, __bus) + }) + t.Run("Should return 'VirtualBus4'", func(t *testing.T) { + assert.Equal(t, "VirtualBus4", __bus.String()) + }) +} diff --git a/voicemeeter/button.go b/voicemeeter/button.go index c989527..5b5ab23 100644 --- a/voicemeeter/button.go +++ b/voicemeeter/button.go @@ -30,7 +30,7 @@ func (m *button) setter(v bool, mode int) { // String implements the stringer interface func (m *button) String() string { - return fmt.Sprintf("MacroButton%d\n", m.index) + return fmt.Sprintf("MacroButton%d", m.index) } // GetState returns the value of the State parameter diff --git a/voicemeeter/button_test.go b/voicemeeter/button_test.go new file mode 100644 index 0000000..3ae1c03 --- /dev/null +++ b/voicemeeter/button_test.go @@ -0,0 +1,15 @@ +package voicemeeter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetButton(t *testing.T) { + //t.Skip("skipping test") + __mb := newButton(0) + t.Run("Should return a button type", func(t *testing.T) { + assert.NotNil(t, __mb) + }) +} diff --git a/voicemeeter/command_test.go b/voicemeeter/command_test.go new file mode 100644 index 0000000..cbaca22 --- /dev/null +++ b/voicemeeter/command_test.go @@ -0,0 +1,15 @@ +package voicemeeter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetCommand(t *testing.T) { + //t.Skip("skipping test") + __c := newCommand() + t.Run("Should return a command type", func(t *testing.T) { + assert.NotNil(t, __c) + }) +} diff --git a/voicemeeter/iremote.go b/voicemeeter/iremote.go index dc373e4..d142a75 100644 --- a/voicemeeter/iremote.go +++ b/voicemeeter/iremote.go @@ -8,7 +8,6 @@ import ( type iRemote struct { _identifier string index int - kind *kind } func (c *iRemote) identifier() string { diff --git a/voicemeeter/kinds.go b/voicemeeter/kinds.go index 9e42d5f..f1738ef 100644 --- a/voicemeeter/kinds.go +++ b/voicemeeter/kinds.go @@ -5,6 +5,8 @@ import ( "strings" ) +var basic, banana, potato *kind + // A kind represents a Voicemeeter kinds layout type kind struct { name string @@ -27,17 +29,26 @@ func (k *kind) String() string { // newBasicKind returns a basic kind struct address func newBasicKind() *kind { - return &kind{"basic", 2, 1, 1, 1, 4, 4} + if basic == nil { + basic = &kind{"basic", 2, 1, 1, 1, 4, 4} + } + return basic } // newBananaKind returns a banana kind struct address func newBananaKind() *kind { - return &kind{"banana", 3, 2, 3, 2, 8, 8} + if banana == nil { + banana = &kind{"banana", 3, 2, 3, 2, 8, 8} + } + return banana } // newPotatoKind returns a potato kind struct address func newPotatoKind() *kind { - return &kind{"potato", 5, 3, 5, 3, 8, 8} + if potato == nil { + potato = &kind{"potato", 5, 3, 5, 3, 8, 8} + } + return potato } var ( diff --git a/voicemeeter/kinds_test.go b/voicemeeter/kinds_test.go new file mode 100644 index 0000000..6cda08f --- /dev/null +++ b/voicemeeter/kinds_test.go @@ -0,0 +1,40 @@ +package voicemeeter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetKindBasic(t *testing.T) { + //t.Skip("skipping test") + __kind := newBasicKind() + t.Run("Should return a basic kind", func(t *testing.T) { + assert.NotNil(t, __kind) + }) + t.Run("Should equal 'Basic'", func(t *testing.T) { + assert.Equal(t, "Basic", __kind.String()) + }) +} + +func TestGetKindBanana(t *testing.T) { + //t.Skip("skipping test") + __kind := newBananaKind() + t.Run("Should return a banana kind", func(t *testing.T) { + assert.NotNil(t, __kind) + }) + t.Run("Should return 'Banana'", func(t *testing.T) { + assert.Equal(t, "Banana", __kind.String()) + }) +} + +func TestGetKindPotato(t *testing.T) { + //t.Skip("skipping test") + __kind := newPotatoKind() + t.Run("Should return a potato kind", func(t *testing.T) { + assert.NotNil(t, __kind) + }) + t.Run("Should return 'Potato'", func(t *testing.T) { + assert.Equal(t, "Potato", __kind.String()) + }) +} diff --git a/voicemeeter/path_test.go b/voicemeeter/path_test.go new file mode 100644 index 0000000..ab40d17 --- /dev/null +++ b/voicemeeter/path_test.go @@ -0,0 +1,15 @@ +package voicemeeter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetVMPath(t *testing.T) { + //t.Skip("skipping test") + _, err := dllPath() + t.Run("Should return err as nil", func(t *testing.T) { + assert.Nil(t, err) + }) +} diff --git a/voicemeeter/remote.go b/voicemeeter/remote.go index fcd53aa..c21cca6 100644 --- a/voicemeeter/remote.go +++ b/voicemeeter/remote.go @@ -52,19 +52,19 @@ func NewRemote(kindId string) *remote { } _strip := make([]t_strip, _kind.numStrip()) - for i := 0; i < _kind.physIn+_kind.virtIn; i++ { + for i := 0; i < _kind.numStrip(); i++ { if i < _kind.physIn { - _strip[i] = newPhysicalStrip(i, _kind) + _strip[i] = newPhysicalStrip(i) } else { - _strip[i] = newVirtualStrip(i, _kind) + _strip[i] = newVirtualStrip(i) } } _bus := make([]t_bus, _kind.numBus()) - for i := 0; i < _kind.physOut+_kind.virtOut; i++ { + for i := 0; i < _kind.numBus(); i++ { if i < _kind.physOut { - _bus[i] = newPhysicalBus(i, _kind) + _bus[i] = newPhysicalBus(i) } else { - _bus[i] = newVirtualBus(i, _kind) + _bus[i] = newVirtualBus(i) } } _button := make([]button, 80) diff --git a/voicemeeter/remote_test.go b/voicemeeter/remote_test.go new file mode 100644 index 0000000..211005e --- /dev/null +++ b/voicemeeter/remote_test.go @@ -0,0 +1,58 @@ +package voicemeeter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetBasicRemote(t *testing.T) { + //t.Skip("skipping test") + __rem := NewRemote("basic") + t.Run("Should return a remote basic type", func(t *testing.T) { + assert.NotNil(t, __rem) + }) + t.Run("Should equal 'Voicemeeter Basic'", func(t *testing.T) { + assert.Equal(t, "Voicemeeter Basic", __rem.String()) + }) + t.Run("Should strip length equal 3", func(t *testing.T) { + assert.Equal(t, 3, len(__rem.Strip)) + }) + t.Run("Should bus length equal 2", func(t *testing.T) { + assert.Equal(t, 2, len(__rem.Bus)) + }) +} + +func TestGetBananaRemote(t *testing.T) { + //t.Skip("skipping test") + __rem := NewRemote("banana") + t.Run("Should return a remote banana type", func(t *testing.T) { + assert.NotNil(t, __rem) + }) + t.Run("Should equal 'Voicemeeter Banana'", func(t *testing.T) { + assert.Equal(t, "Voicemeeter Banana", __rem.String()) + }) + t.Run("Should strip length equal 5", func(t *testing.T) { + assert.Equal(t, 5, len(__rem.Strip)) + }) + t.Run("Should bus length equal 5", func(t *testing.T) { + assert.Equal(t, 5, len(__rem.Bus)) + }) +} + +func TestGetPotatoRemote(t *testing.T) { + //t.Skip("skipping test") + __rem := NewRemote("potato") + t.Run("Should return a remote basic type", func(t *testing.T) { + assert.NotNil(t, __rem) + }) + t.Run("Should equal 'Voicemeeter Potato'", func(t *testing.T) { + assert.Equal(t, "Voicemeeter Potato", __rem.String()) + }) + t.Run("Should strip length equal 8", func(t *testing.T) { + assert.Equal(t, 8, len(__rem.Strip)) + }) + t.Run("Should bus length equal 8", func(t *testing.T) { + assert.Equal(t, 8, len(__rem.Bus)) + }) +} diff --git a/voicemeeter/strip.go b/voicemeeter/strip.go index c0295a3..12ca860 100644 --- a/voicemeeter/strip.go +++ b/voicemeeter/strip.go @@ -5,6 +5,7 @@ import ( ) type t_strip interface { + String() string GetMute() bool SetMute(val bool) GetMono() bool @@ -33,14 +34,6 @@ type strip struct { iRemote } -// implement stringer interface in fmt -func (s *strip) String() string { - if s.index < s.kind.physIn { - return fmt.Sprintf("PhysicalStrip%d\n", s.index) - } - return fmt.Sprintf("VirtualStrip%d\n", s.index) -} - // GetMute returns the value of the Mute parameter func (s *strip) GetMute() bool { return s.getter_bool("Mute") @@ -105,11 +98,16 @@ type physicalStrip struct { strip } -func newPhysicalStrip(i int, k *kind) t_strip { - ps := physicalStrip{strip{iRemote{"strip", i, k}}} +func newPhysicalStrip(i int) t_strip { + ps := physicalStrip{strip{iRemote{"strip", i}}} return t_strip(&ps) } +// implement stringer interface in fmt +func (p *physicalStrip) String() string { + return fmt.Sprintf("PhysicalStrip%d", p.index) +} + // GetComp returns the value of the Comp parameter func (p *physicalStrip) GetComp() bool { return p.getter_bool("Comp") @@ -154,11 +152,16 @@ type virtualStrip struct { strip } -func newVirtualStrip(i int, k *kind) t_strip { - vs := virtualStrip{strip{iRemote{"strip", i, k}}} +func newVirtualStrip(i int) t_strip { + vs := virtualStrip{strip{iRemote{"strip", i}}} return t_strip(&vs) } +// implement stringer interface in fmt +func (v *virtualStrip) String() string { + return fmt.Sprintf("VirtualStrip%d", v.index) +} + // GetMc returns the value of the MC parameter func (v *virtualStrip) GetMc() bool { return v.getter_bool("MC") diff --git a/voicemeeter/strip_test.go b/voicemeeter/strip_test.go new file mode 100644 index 0000000..a2a3b2c --- /dev/null +++ b/voicemeeter/strip_test.go @@ -0,0 +1,29 @@ +package voicemeeter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetPhysStrip(t *testing.T) { + //t.Skip("skipping test") + __strip := newPhysicalStrip(0) + t.Run("Should return a physical strip type", func(t *testing.T) { + assert.NotNil(t, __strip) + }) + t.Run("Should return 'PhysicalStrip0'", func(t *testing.T) { + assert.Equal(t, "PhysicalStrip0", __strip.String()) + }) +} + +func TestGetVirtStrip(t *testing.T) { + //t.Skip("skipping test") + __strip := newVirtualStrip(4) + t.Run("Should return a basic kind", func(t *testing.T) { + assert.NotNil(t, __strip) + }) + t.Run("Should return 'VirtualStrip4'", func(t *testing.T) { + assert.Equal(t, "VirtualStrip4", __strip.String()) + }) +} diff --git a/voicemeeter/vban.go b/voicemeeter/vban.go index 457b3db..174c530 100644 --- a/voicemeeter/vban.go +++ b/voicemeeter/vban.go @@ -23,8 +23,8 @@ type vbanInStream struct { vbanStream } -func newVbanInStream(i int, k *kind) t_vban { - vbi := vbanInStream{vbanStream{iRemote{"vban.instream", i, k}}} +func newVbanInStream(i int) t_vban { + vbi := vbanInStream{vbanStream{iRemote{"vban.instream", i}}} return t_vban(&vbi) } @@ -32,8 +32,8 @@ type vbanOutStream struct { vbanStream } -func newVbanOutStream(i int, k *kind) t_vban { - vbo := vbanOutStream{vbanStream{iRemote{"vban.outstream", i, k}}} +func newVbanOutStream(i int) t_vban { + vbo := vbanOutStream{vbanStream{iRemote{"vban.outstream", i}}} return t_vban(&vbo) } @@ -45,11 +45,11 @@ type vban struct { func newVban(k *kind) *vban { _vbanIn := make([]t_vban, k.vbanIn) for i := 0; i < k.vbanIn; i++ { - _vbanIn[i] = newVbanInStream(i, k) + _vbanIn[i] = newVbanInStream(i) } _vbanOut := make([]t_vban, k.vbanOut) for i := 0; i < k.vbanOut; i++ { - _vbanOut[i] = newVbanOutStream(i, k) + _vbanOut[i] = newVbanOutStream(i) } return &vban{ InStream: _vbanIn, diff --git a/voicemeeter/vban_test.go b/voicemeeter/vban_test.go new file mode 100644 index 0000000..05827ba --- /dev/null +++ b/voicemeeter/vban_test.go @@ -0,0 +1,23 @@ +package voicemeeter + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetVbanInStream(t *testing.T) { + //t.Skip("skipping test") + __vbi := newVbanInStream(0) + t.Run("Should return a vban instream type", func(t *testing.T) { + assert.NotNil(t, __vbi) + }) +} + +func TestGetVbanOutStream(t *testing.T) { + //t.Skip("skipping test") + __vbo := newVbanOutStream(0) + t.Run("Should return a vban outstream type", func(t *testing.T) { + assert.NotNil(t, __vbo) + }) +}