tests/examples updated with v2 changes

getCmd in vm-cli always prints value.
This commit is contained in:
onyx-and-iris 2022-12-08 10:52:15 +00:00
parent c4f00a3dbd
commit 7f2646ca6e
6 changed files with 150 additions and 114 deletions

View File

@ -6,7 +6,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/eiannone/keyboard"
"github.com/onyx-and-iris/voicemeeter"
"github.com/onyx-and-iris/voicemeeter/v2"
)
func init() {
@ -39,9 +39,9 @@ Loop:
case '0':
fmt.Printf("Logged into Voicemeeter %s, version %s\n", vm.Type(), vm.Version())
case '1':
vm.Strip[0].SetMute(!vm.Strip[0].GetMute())
vm.Strip[0].SetMute(!vm.Strip[0].Mute())
case '2':
if vm.Strip[3].GetGain() == -12.8 {
if vm.Strip[3].Gain() == -12.8 {
vm.Strip[3].FadeBy(-8.3, 500)
} else {
vm.Strip[3].FadeTo(-12.8, 500)

View File

@ -7,7 +7,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/onyx-and-iris/voicemeeter"
"github.com/onyx-and-iris/voicemeeter/v2"
"github.com/andreykaipov/goobs"
"github.com/andreykaipov/goobs/api/events"

View File

@ -2,46 +2,38 @@ package main
import (
"fmt"
"time"
log "github.com/sirupsen/logrus"
"github.com/onyx-and-iris/voicemeeter"
"github.com/onyx-and-iris/voicemeeter/v2"
)
// observer represents a single receiver of updates
type observer struct {
vm *voicemeeter.Remote
events chan string
}
// newObserver add ldirty events to the eventlist and returns an observer type
func newObserver(vm *voicemeeter.Remote) *observer {
vm.EventAdd("ldirty")
return &observer{vm}
}
// register registers this observer to receive updates
func (o observer) register() {
o.vm.Register(o)
}
// deregister deregisters this observer to receive updates
func (o observer) deregister() {
o.vm.Deregister(o)
o := &observer{vm, make(chan string)}
return o
}
// OnUpdate satisfies the observer interface defined in publisher.go
// for each event type an action is triggered when the event occurs.
func (o observer) OnUpdate(subject string) {
if subject == "pdirty" {
fmt.Println("pdirty!")
} else if subject == "mdirty" {
fmt.Println("mdirty!")
} else if subject == "midi" {
func (o observer) Listen() {
o.vm.Register(o.events)
for s := range o.events {
switch s {
case "pdirty", "mdirty":
fmt.Println(s)
case "midi":
var current = o.vm.Midi.Current()
var val = o.vm.Midi.Get(current)
fmt.Printf("Value of midi button %d: %d\n", current, val)
} else if subject == "ldirty" {
case "ldirty":
for _, bus := range o.vm.Bus {
if bus.Levels().IsDirty() {
fmt.Println(bus, bus.Levels().All())
@ -49,11 +41,17 @@ func (o observer) OnUpdate(subject string) {
}
}
}
}
func init() {
log.SetLevel(log.InfoLevel)
}
func runObserver(vm *voicemeeter.Remote) {
o := newObserver(vm)
o.Listen()
}
// main connects to Voiceemeter, registers observer for updates
// runs updates for 30 seconds and then deregisters observer.
func main() {
@ -63,15 +61,12 @@ func main() {
}
defer vm.Logout()
o := newObserver(vm)
o.register()
time.Sleep(30 * time.Second)
o.deregister()
runObserver(vm)
}
// vmConnect connects to Voicemeeter potato and logs into the API
func vmConnect() (*voicemeeter.Remote, error) {
vm, err := voicemeeter.NewRemote("potato", 0)
vm, err := voicemeeter.NewRemote("basic", 0)
if err != nil {
return nil, err
}
@ -80,6 +75,7 @@ func vmConnect() (*voicemeeter.Remote, error) {
if err != nil {
return nil, err
}
vm.EventAdd("ldirty")
return vm, nil
}

View File

@ -8,7 +8,7 @@ import (
"os"
"strings"
"github.com/onyx-and-iris/voicemeeter"
"github.com/onyx-and-iris/voicemeeter/v2"
)
type (
@ -168,9 +168,9 @@ func getCmd(vm *voicemeeter.Remote, cmd string) error {
err = fmt.Errorf("unable to get %s", cmd)
return err
}
vPrinter.printf("Value of %s is: %s", cmd, valS)
fmt.Printf("Value of %s is: %s", cmd, valS)
} else {
vPrinter.printf("Value of %s is: %v", cmd, valF)
fmt.Printf("Value of %s is: %v", cmd, valF)
}
return nil
}

View File

@ -1,13 +1,16 @@
package voicemeeter_test
import (
"log"
"bytes"
"testing"
"github.com/onyx-and-iris/voicemeeter"
log "github.com/sirupsen/logrus"
"github.com/onyx-and-iris/voicemeeter/v2"
)
var (
logstring bytes.Buffer
vm, err = voicemeeter.NewRemote("potato", 30)
)
@ -22,5 +25,7 @@ func TestMain(m *testing.M) {
}
defer vm.Logout()
log.SetOutput(&logstring)
m.Run()
}

View File

@ -9,39 +9,39 @@ import (
func TestStrip0Mute(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[0].SetMute(true)
t.Run("Should return true when SetMute(true)", func(t *testing.T) {
assert.True(t, vm.Strip[0].GetMute())
t.Run("Should return true when Strip[0].SetMute(true)", func(t *testing.T) {
assert.True(t, vm.Strip[0].Mute())
})
vm.Strip[0].SetMute(false)
t.Run("Should return false when SetMute(false)", func(t *testing.T) {
assert.False(t, vm.Strip[0].GetMute())
t.Run("Should return false when Strip[0].SetMute(false)", func(t *testing.T) {
assert.False(t, vm.Strip[0].Mute())
})
}
func TestStrip3A1(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[3].SetA1(true)
t.Run("Should return true when SetA1(true)", func(t *testing.T) {
assert.True(t, vm.Strip[3].GetA1())
t.Run("Should return true when Strip[3].SetA1(true)", func(t *testing.T) {
assert.True(t, vm.Strip[3].A1())
})
vm.Strip[3].SetA1(false)
t.Run("Should return false when SetA1(false)", func(t *testing.T) {
assert.False(t, vm.Strip[3].GetA1())
t.Run("Should return false when Strip[3].SetA1(false)", func(t *testing.T) {
assert.False(t, vm.Strip[3].A1())
})
}
func TestStrip2Limit(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[2].SetLimit(-8)
t.Run("Should return -8 when SetLimit(-8)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].GetLimit(), -8)
t.Run("Should return -8 when Strip[2].SetLimit(-8)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].Limit(), -8)
})
vm.Strip[2].SetLimit(-32)
t.Run("Should return -32 when SetLimit(-8)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].GetLimit(), -32)
t.Run("Should return -32 when Strip[2].SetLimit(-32)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].Limit(), -32)
})
}
@ -49,162 +49,197 @@ func TestStrip2Limit(t *testing.T) {
func TestStrip4Label(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[4].SetLabel("test0")
t.Run("Should return test0 when SetLimit('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Strip[4].GetLabel())
t.Run("Should return test0 when Strip[4].SetLabel('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Strip[4].Label())
})
vm.Strip[4].SetLabel("test1")
t.Run("Should return test1 when SetLimit('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Strip[4].GetLabel())
t.Run("Should return test1 when Strip[4].SetLabel('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Strip[4].Label())
})
}
func TestStrip5Gain(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[4].SetGain(-20.8)
t.Run("Should return -20.8 when SetGain(-20.8)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].GetGain(), -20.8)
t.Run("Should return -20.8 when Strip[4].SetGain(-20.8)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].Gain(), -20.8)
})
vm.Strip[4].SetGain(-3.6)
t.Run("Should return -3.6 when SetGain(-3.6)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].GetGain(), -3.6)
t.Run("Should return -3.6 when Strip[4].SetGain(-3.6)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].Gain(), -3.6)
})
}
func TestStrip3Comp(t *testing.T) {
func TestStrip3CompKnob(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[4].SetComp(8.1)
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].Comp().SetKnob(8.1)
t.Run("Should return 8.1 when Strip[4].SetComp(8.1)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].Comp().Knob(), 8.1)
})
vm.Strip[4].SetComp(1.6)
t.Run("Should return 1.6 when SetGain(1.6)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].GetComp(), 1.6)
vm.Strip[4].Comp().SetKnob(1.6)
t.Run("Should return 1.6 when Strip[4].SetComp(1.6)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].Comp().Knob(), 1.6)
})
}
func TestStrip0CompGainIn(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[0].Comp().SetGainIn(3.4)
t.Run("Should return 3.4 when Strip[0].Comp().SetGainIn(3.4)", func(t *testing.T) {
assert.Equal(t, vm.Strip[0].Comp().GainIn(), 3.4)
})
vm.Strip[0].Comp().SetGainIn(-19.3)
t.Run("Should return -19.3 when Strip[0].Comp().SetGainIn(-19.3)", func(t *testing.T) {
assert.Equal(t, vm.Strip[0].Comp().GainIn(), -19.3)
})
}
func TestStrip3GateKnob(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[4].Gate().SetKnob(8.1)
t.Run("Should return 8.1 when Strip[4].SetComp(8.1)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].Gate().Knob(), 8.1)
})
vm.Strip[4].Gate().SetKnob(1.6)
t.Run("Should return 1.6 when Strip[4].SetComp(1.6)", func(t *testing.T) {
assert.Equal(t, vm.Strip[4].Gate().Knob(), 1.6)
})
}
func TestStrip0GateAttack(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[0].Comp().SetAttack(3.4)
t.Run("Should return 3.4 when Strip[0].Comp().SetAttack(3.4)", func(t *testing.T) {
assert.Equal(t, vm.Strip[0].Comp().Attack(), 3.4)
})
vm.Strip[0].Comp().SetAttack(190.3)
t.Run("Should return -19.3 when Strip[0].Comp().SetAttack(-19.3)", func(t *testing.T) {
assert.Equal(t, vm.Strip[0].Comp().Attack(), 190.3)
})
}
func TestStrip5Mc(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[5].SetMc(true)
t.Run("Should return true when SetMc(true)", func(t *testing.T) {
assert.True(t, vm.Strip[5].GetMc())
t.Run("Should return true when Strip[5].SetMc(true)", func(t *testing.T) {
assert.True(t, vm.Strip[5].Mc())
})
vm.Strip[5].SetMc(false)
t.Run("Should return false when SetMc(false)", func(t *testing.T) {
assert.False(t, vm.Strip[5].GetMc())
t.Run("Should return false when Strip[5].SetMc(false)", func(t *testing.T) {
assert.False(t, vm.Strip[5].Mc())
})
}
func TestStrip2GainLayer3(t *testing.T) {
//t.Skip("skipping test")
vm.Strip[2].GainLayer()[3].Set(-18.3)
t.Run("Should return -18.3 when SetMc(true)", func(t *testing.T) {
t.Run("Should return -18.3 when Strip[2].GainLayer()[3].Set(-18.3)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].GainLayer()[3].Get(), -18.3)
})
vm.Strip[2].GainLayer()[3].Set(-25.6)
t.Run("Should return -25.6 when SetMc(true)", func(t *testing.T) {
t.Run("Should return -25.6 when Strip[2].GainLayer()[3].Set(-25.6)", func(t *testing.T) {
assert.Equal(t, vm.Strip[2].GainLayer()[3].Get(), -25.6)
})
}
func TestBus3Eq(t *testing.T) {
func TestBus3EqOn(t *testing.T) {
//t.Skip("skipping test")
vm.Bus[3].SetEq(true)
t.Run("Should return true when SetEq(true)", func(t *testing.T) {
assert.True(t, vm.Bus[3].GetEq())
vm.Bus[3].Eq().SetOn(true)
t.Run("Should return true when Bus[3].Eq().SetOn(true)", func(t *testing.T) {
assert.True(t, vm.Bus[3].Eq().On())
})
vm.Bus[3].SetEq(false)
t.Run("Should return false when SetEq(false)", func(t *testing.T) {
assert.False(t, vm.Bus[3].GetEq())
vm.Bus[3].Eq().SetOn(false)
t.Run("Should return false when Bus[3].SetEq(false)", func(t *testing.T) {
assert.False(t, vm.Bus[3].Eq().On())
})
}
func TestBus4Label(t *testing.T) {
//t.Skip("skipping test")
vm.Bus[4].SetLabel("test0")
t.Run("Should return test0 when SetEq('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Bus[4].GetLabel())
t.Run("Should return test0 when Bus[4].SetLabel('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Bus[4].Label())
})
vm.Bus[4].SetLabel("test1")
t.Run("Should return test1 when SetEq('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Bus[4].GetLabel())
t.Run("Should return test1 when Bus[4].SetLabel('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Bus[4].Label())
})
}
func TestBus3ModeAmix(t *testing.T) {
//t.Skip("skipping test")
vm.Bus[3].Mode().SetAmix(true)
t.Run("Should return true when Mode().SetAmix(true)", func(t *testing.T) {
assert.True(t, vm.Bus[3].Mode().GetAmix())
t.Run("Should return true when Bus[3].Mode().SetAmix(true)", func(t *testing.T) {
assert.True(t, vm.Bus[3].Mode().Amix())
})
}
func TestVbanInStream0On(t *testing.T) {
//t.Skip("skipping test")
vm.Vban.InStream[0].SetOn(true)
t.Run("Should return true when SetOn(true)", func(t *testing.T) {
assert.True(t, vm.Vban.InStream[0].GetOn())
t.Run("Should return true when Vban.InStream[0].SetOn(true)", func(t *testing.T) {
assert.True(t, vm.Vban.InStream[0].On())
})
vm.Vban.InStream[0].SetOn(false)
t.Run("Should return false when SetOn(false)", func(t *testing.T) {
assert.False(t, vm.Vban.InStream[0].GetOn())
t.Run("Should return false when Vban.InStream[0].SetOn(false)", func(t *testing.T) {
assert.False(t, vm.Vban.InStream[0].On())
})
}
func TestVbanOutStream6On(t *testing.T) {
//t.Skip("skipping test")
vm.Vban.OutStream[6].SetOn(true)
t.Run("Should return true when SetOn(true)", func(t *testing.T) {
assert.True(t, vm.Vban.OutStream[6].GetOn())
t.Run("Should return true when Vban.OutStream[6].SetOn(true)", func(t *testing.T) {
assert.True(t, vm.Vban.OutStream[6].On())
})
vm.Vban.OutStream[6].SetOn(false)
t.Run("Should return false when SetOn(false)", func(t *testing.T) {
assert.False(t, vm.Vban.OutStream[6].GetOn())
t.Run("Should return false when Vban.OutStream[6].SetOn(false)", func(t *testing.T) {
assert.False(t, vm.Vban.OutStream[6].On())
})
}
func TestVbanOutStream3Name(t *testing.T) {
t.Skip("skipping test")
//t.Skip("skipping test")
vm.Vban.OutStream[3].SetName("test0")
t.Run("Should return test0 when SetName('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Vban.OutStream[3].GetName())
t.Run("Should return test0 when Vban.OutStream[3].SetName('test0')", func(t *testing.T) {
assert.Equal(t, "test0", vm.Vban.OutStream[3].Name())
})
vm.Vban.OutStream[3].SetName("test1")
t.Run("Should return test1 when SetName('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Vban.OutStream[3].GetName())
t.Run("Should return test1 when Vban.OutStream[3].SetName('test1')", func(t *testing.T) {
assert.Equal(t, "test1", vm.Vban.OutStream[3].Name())
})
}
func TestVbanInStream4Bit(t *testing.T) {
t.Skip("skipping test")
t.Run("Should panic when instream SetBit(16)", func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Error("expected panic")
}
}()
//t.Skip("skipping test")
vm.Vban.InStream[4].SetBit(16)
t.Run("Should log 'bit is readonly for vban instreams' when instream Vban.InStream[4].SetBit(16)", func(t *testing.T) {
assert.Contains(t, logstring.String(), "bit is readonly for vban instreams")
})
}
func TestVbanOutStream4Bit(t *testing.T) {
//t.Skip("skipping test")
vm.Vban.OutStream[4].SetBit(16)
t.Run("Should return 16 when SetBit(16)", func(t *testing.T) {
assert.Equal(t, vm.Vban.OutStream[4].GetBit(), 16)
t.Run("Should return 16 when Vban.OutStream[4].SetBit(16)", func(t *testing.T) {
assert.Equal(t, vm.Vban.OutStream[4].Bit(), 16)
})
vm.Vban.OutStream[4].SetBit(24)
t.Run("Should return 24 when SetBit(24)", func(t *testing.T) {
assert.Equal(t, vm.Vban.OutStream[4].GetBit(), 24)
t.Run("Should return 24 when Vban.OutStream[4].SetBit(24)", func(t *testing.T) {
assert.Equal(t, vm.Vban.OutStream[4].Bit(), 24)
})
}