NewRemote now accepts delay param

getters clear dirty params sync enabled.

examples and tests updated
This commit is contained in:
onyx-and-iris 2022-09-14 16:05:15 +01:00
parent a4b84f289e
commit 8ca545b1c4
7 changed files with 41 additions and 57 deletions

15
base.go
View File

@ -151,6 +151,11 @@ func getVMType() (string, error) {
// getParameterFloat gets the value of a float parameter
func getParameterFloat(name string) (float64, error) {
if vmsync {
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
for pdirty() || mdirty() {
}
}
var value float32
b := append([]byte(name), 0)
res, _, _ := vmGetParamFloat.Call(
@ -181,6 +186,11 @@ func setParameterFloat(name string, value float64) error {
// getParameterString gets the value of a string parameter
func getParameterString(name string) (string, error) {
if vmsync {
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
for pdirty() || mdirty() {
}
}
b1 := append([]byte(name), 0)
var b2 [512]byte
res, _, _ := vmGetParamString.Call(
@ -225,6 +235,11 @@ func setParametersMulti(script string) error {
// getMacroStatus gets a macrobutton value
func getMacroStatus(id, mode int) (float64, error) {
if vmsync {
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
for pdirty() || mdirty() {
}
}
var state float32
res, _, _ := vmGetMacroStatus.Call(
uintptr(id),

View File

@ -44,7 +44,7 @@ func (o observer) OnUpdate(subject string) {
}
func main() {
vm, err := voicemeeter.NewRemote("potato")
vm, err := voicemeeter.NewRemote("potato", 0)
if err != nil {
log.Fatal(err)
}

View File

@ -4,11 +4,10 @@ import (
"log"
"os"
"testing"
"time"
)
var (
vm, err = NewRemote("potato")
vm, err = NewRemote("potato", 30)
)
func TestMain(m *testing.M) {
@ -21,9 +20,3 @@ func TestMain(m *testing.M) {
vm.Logout()
os.Exit(code)
}
func sync() {
time.Sleep(30 * time.Millisecond)
for vm.Pdirty() || vm.Mdirty() {
}
}

View File

@ -2,6 +2,7 @@ package voicemeeter
import (
"fmt"
"time"
)
// A Remote type represents the API for a kind
@ -76,6 +77,7 @@ func (r *Remote) Mdirty() bool {
// Sync is a helper method that waits for dirty parameters to clear
func (r *Remote) Sync() {
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
for r.Pdirty() || r.Mdirty() {
}
}
@ -316,14 +318,25 @@ func (potb *potatoBuilder) Build() remoteBuilder {
makeMidi()
}
var (
vmsync bool
vmdelay int
)
// NewRemote returns a Remote type for a kind
// this is the interface entry point
func NewRemote(kindId string) (*Remote, error) {
func NewRemote(kindId string, delay int) (*Remote, error) {
_kind, ok := kindMap[kindId]
if !ok {
err := fmt.Errorf("unknown Voicemeeter kind '%s'", kindId)
return nil, err
}
if delay < 0 {
err := fmt.Errorf("invalid delay value. should be >= 0")
return nil, err
}
vmsync = delay > 0
vmdelay = delay
director := director{}
switch _kind.Name {

View File

@ -8,7 +8,7 @@ import (
func TestGetBasicRemote(t *testing.T) {
//t.Skip("skipping test")
__rem, _ := NewRemote("basic")
__rem, _ := NewRemote("basic", 0)
t.Run("Should return a remote basic type", func(t *testing.T) {
assert.NotNil(t, __rem)
})
@ -34,7 +34,7 @@ func TestGetBasicRemote(t *testing.T) {
func TestGetBananaRemote(t *testing.T) {
//t.Skip("skipping test")
__rem, _ := NewRemote("banana")
__rem, _ := NewRemote("banana", 0)
t.Run("Should return a remote banana type", func(t *testing.T) {
assert.NotNil(t, __rem)
})
@ -60,7 +60,7 @@ func TestGetBananaRemote(t *testing.T) {
func TestGetPotatoRemote(t *testing.T) {
//t.Skip("skipping test")
__rem, _ := NewRemote("potato")
__rem, _ := NewRemote("potato", 0)
t.Run("Should return a remote basic type", func(t *testing.T) {
assert.NotNil(t, __rem)
})
@ -88,7 +88,6 @@ func TestSetAndGetFloatParameter(t *testing.T) {
//t.Skip("skipping test")
var param = "strip[0].mute"
vm.SetFloat(param, 1)
sync()
t.Run("Should get a float parameter", func(t *testing.T) {
assert.Equal(t, float64(1), vm.GetFloat(param))
})
@ -99,7 +98,6 @@ func TestSetAndGetStringParameter(t *testing.T) {
var param = "strip[0].label"
var val = "test0"
vm.SetString(param, val)
sync()
t.Run("Should get a string parameter", func(t *testing.T) {
assert.Equal(t, val, vm.GetString(param))
})

View File

@ -2,31 +2,25 @@ package voicemeeter_test
import (
"log"
"os"
"testing"
"time"
"github.com/onyx-and-iris/voicemeeter-api-go"
)
var (
vm, err = voicemeeter.NewRemote("potato")
vm, err = voicemeeter.NewRemote("potato", 30)
)
func TestMain(m *testing.M) {
if err != nil {
log.Fatal(err)
}
err = vm.Login()
if err != nil {
log.Fatal(err)
}
defer vm.Logout()
vm.Login()
code := m.Run()
vm.Logout()
os.Exit(code)
}
func sync() {
time.Sleep(30 * time.Millisecond)
for vm.Pdirty() || vm.Mdirty() {
}
m.Run()
}

View File

@ -9,13 +9,11 @@ import (
func TestStrip0Mute(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[0].SetMute(true)
sync()
t.Run("Should return true when SetMute(true)", func(t *testing.T) {
assert.True(t, vm.Strip[0].GetMute())
})
vm.Strip[0].SetMute(false)
sync()
t.Run("Should return false when SetMute(false)", func(t *testing.T) {
assert.False(t, vm.Strip[0].GetMute())
})
@ -24,13 +22,11 @@ func TestStrip0Mute(t *testing.T) {
func TestStrip3A1(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[3].SetA1(true)
sync()
t.Run("Should return true when SetA1(true)", func(t *testing.T) {
assert.True(t, vm.Strip[3].GetA1())
})
vm.Strip[3].SetA1(false)
sync()
t.Run("Should return false when SetA1(false)", func(t *testing.T) {
assert.False(t, vm.Strip[3].GetA1())
})
@ -39,13 +35,11 @@ func TestStrip3A1(t *testing.T) {
func TestStrip2Limit(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[2].SetLimit(-8)
sync()
t.Run("Should return -8 when SetLimit(-8)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].GetLimit(), -8)
})
vm.Strip[2].SetLimit(-32)
sync()
t.Run("Should return -32 when SetLimit(-8)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].GetLimit(), -32)
})
@ -55,13 +49,11 @@ func TestStrip2Limit(t *testing.T) {
func TestStrip4Label(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[4].SetLabel("test0")
sync()
t.Run("Should return test0 when SetLimit('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Strip[4].GetLabel())
})
vm.Strip[4].SetLabel("test1")
sync()
t.Run("Should return test1 when SetLimit('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Strip[4].GetLabel())
})
@ -70,13 +62,11 @@ func TestStrip4Label(t *testing.T) {
func TestStrip5Gain(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[4].SetGain(-20.8)
sync()
t.Run("Should return -20.8 when SetGain(-20.8)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].GetGain(), -20.8)
})
vm.Strip[4].SetGain(-3.6)
sync()
t.Run("Should return -3.6 when SetGain(-3.6)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].GetGain(), -3.6)
})
@ -85,13 +75,11 @@ func TestStrip5Gain(t *testing.T) {
func TestStrip3Comp(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[4].SetComp(8.1)
sync()
t.Run("Should return 8.1 when SetGain(8.1)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].GetComp(), 8.1)
})
vm.Strip[4].SetComp(1.6)
sync()
t.Run("Should return 1.6 when SetGain(1.6)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].GetComp(), 1.6)
})
@ -100,13 +88,11 @@ func TestStrip3Comp(t *testing.T) {
func TestStrip5Mc(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[5].SetMc(true)
sync()
t.Run("Should return true when SetMc(true)", func(t *testing.T) {
assert.True(t, vm.Strip[5].GetMc())
})
vm.Strip[5].SetMc(false)
sync()
t.Run("Should return false when SetMc(false)", func(t *testing.T) {
assert.False(t, vm.Strip[5].GetMc())
})
@ -115,13 +101,11 @@ func TestStrip5Mc(t *testing.T) {
func TestStrip2GainLayer3(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[2].GainLayer()[3].Set(-18.3)
sync()
t.Run("Should return -18.3 when SetMc(true)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].GainLayer()[3].Get(), -18.3)
})
vm.Strip[2].GainLayer()[3].Set(-25.6)
sync()
t.Run("Should return -25.6 when SetMc(true)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].GainLayer()[3].Get(), -25.6)
})
@ -130,13 +114,11 @@ func TestStrip2GainLayer3(t *testing.T) {
func TestBus3Eq(t *testing.T) {
//t.Skip("skipping test")
vm.Bus[3].SetEq(true)
sync()
t.Run("Should return true when SetEq(true)", func(t *testing.T) {
assert.True(t, vm.Bus[3].GetEq())
})
vm.Bus[3].SetEq(false)
sync()
t.Run("Should return false when SetEq(false)", func(t *testing.T) {
assert.False(t, vm.Bus[3].GetEq())
})
@ -145,13 +127,11 @@ func TestBus3Eq(t *testing.T) {
func TestBus4Label(t *testing.T) {
//t.Skip("skipping test")
vm.Bus[4].SetLabel("test0")
sync()
t.Run("Should return test0 when SetEq('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Bus[4].GetLabel())
})
vm.Bus[4].SetLabel("test1")
sync()
t.Run("Should return test1 when SetEq('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Bus[4].GetLabel())
})
@ -160,7 +140,6 @@ func TestBus4Label(t *testing.T) {
func TestBus3ModeAmix(t *testing.T) {
//t.Skip("skipping test")
vm.Bus[3].Mode().SetAmix(true)
sync()
t.Run("Should return true when Mode().SetAmix(true)", func(t *testing.T) {
assert.True(t, vm.Bus[3].Mode().GetAmix())
})
@ -169,13 +148,11 @@ func TestBus3ModeAmix(t *testing.T) {
func TestVbanInStream0On(t *testing.T) {
//t.Skip("skipping test")
vm.Vban.InStream[0].SetOn(true)
sync()
t.Run("Should return true when SetOn(true)", func(t *testing.T) {
assert.True(t, vm.Vban.InStream[0].GetOn())
})
vm.Vban.InStream[0].SetOn(false)
sync()
t.Run("Should return false when SetOn(false)", func(t *testing.T) {
assert.False(t, vm.Vban.InStream[0].GetOn())
})
@ -184,13 +161,11 @@ func TestVbanInStream0On(t *testing.T) {
func TestVbanOutStream6On(t *testing.T) {
//t.Skip("skipping test")
vm.Vban.OutStream[6].SetOn(true)
sync()
t.Run("Should return true when SetOn(true)", func(t *testing.T) {
assert.True(t, vm.Vban.OutStream[6].GetOn())
})
vm.Vban.OutStream[6].SetOn(false)
sync()
t.Run("Should return false when SetOn(false)", func(t *testing.T) {
assert.False(t, vm.Vban.OutStream[6].GetOn())
})
@ -199,13 +174,11 @@ func TestVbanOutStream6On(t *testing.T) {
func TestVbanOutStream3Name(t *testing.T) {
t.Skip("skipping test")
vm.Vban.OutStream[3].SetName("test0")
sync()
t.Run("Should return test0 when SetName('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Vban.OutStream[3].GetName())
})
vm.Vban.OutStream[3].SetName("test1")
sync()
t.Run("Should return test1 when SetName('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Vban.OutStream[3].GetName())
})
@ -226,13 +199,11 @@ func TestVbanInStream4Bit(t *testing.T) {
func TestVbanOutStream4Bit(t *testing.T) {
//t.Skip("skipping test")
vm.Vban.OutStream[4].SetBit(16)
sync()
t.Run("Should return 16 when SetBit(16)", func(t *testing.T) {
assert.Equal(t, vm.Vban.OutStream[4].GetBit(), 16)
})
vm.Vban.OutStream[4].SetBit(24)
sync()
t.Run("Should return 24 when SetBit(24)", func(t *testing.T) {
assert.Equal(t, vm.Vban.OutStream[4].GetBit(), 24)
})