Skip to content

Commit

Permalink
Adding proper init of the pod with switch to the current preset
Browse files Browse the repository at this point in the history
  • Loading branch information
StarAurryon committed Aug 25, 2020
1 parent 3d19ef3 commit f9a91c1
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 16 deletions.
47 changes: 41 additions & 6 deletions controller/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func (c *Controller) InitPOD() {
f := func() {
c.QueryAllSets(false)
c.QueryAllPresets(false)
c.QueryCurrentSetID(false)
c.QueryCurrentPresetID(false)
c.QueryCurrentPreset(false)
c.notify(nil, sg.StatusInitDone(), nil)
}
go f()
Expand Down Expand Up @@ -87,9 +90,41 @@ func (c *Controller) QueryAllSets(async bool) {
}
}

func (c *Controller) QueryCurrentPreset() {
func (c *Controller) QueryCurrentPreset(async bool) {
if !c.started { return }
c.QueryPreset(true, message.CurrentPreset, message.CurrentSet)
c.QueryPreset(async, message.CurrentPreset, message.CurrentSet)
}

func (c *Controller) QueryCurrentPresetID(async bool) {
f := func() {
if !c.started { return }
m := message.GenStatusQueryPresetID()
c.syncMode = true
c.writeMessage(m, 0, 0)
<- c.syncModeChan
c.syncMode = false
}
if async {
go f()
} else {
f()
}
}

func (c *Controller) QueryCurrentSetID(async bool) {
f := func() {
if !c.started { return }
m := message.GenStatusQuerySetID()
c.syncMode = true
c.writeMessage(m, 0, 0)
<- c.syncModeChan
c.syncMode = false
}
if async {
go f()
} else {
f()
}
}

func (c *Controller) QueryPreset(async bool, presetID uint16, setID uint16) {
Expand Down Expand Up @@ -124,7 +159,7 @@ func (c *Controller) SavePreset() {
if !c.started { return }

c.syncMode = true
c.QueryCurrentPreset()
c.QueryCurrentPreset(false)
<- c.syncModeChan
c.syncMode = false

Expand Down Expand Up @@ -379,7 +414,7 @@ func (c *Controller) SetPedalBoardItemPosition(id uint32, pos uint16, posType ui
if !c.started { return }

c.syncMode = true
c.QueryCurrentPreset()
c.QueryCurrentPreset(false)
<- c.syncModeChan
c.syncMode = false

Expand Down Expand Up @@ -487,7 +522,7 @@ func (c *Controller) SetCurrentPresetName(name string) {
if !c.started { return }

c.syncMode = true
c.QueryCurrentPreset()
c.QueryCurrentPreset(false)
<- c.syncModeChan
c.syncMode = false

Expand All @@ -496,7 +531,7 @@ func (c *Controller) SetCurrentPresetName(name string) {

c.pb.SetCurrentPresetName2(name)
c.setCurrentPreset(c.pb)
c.QueryCurrentPreset()
c.QueryCurrentPreset(false)
}
go f()
}
7 changes: 1 addition & 6 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ func (c *Controller) parseMessage(rm *message.RawMessage) {
c.pb.UnlockData()
c.notify(err, ct, obj)
if c.syncMode {
switch ct {
case sg.StatusPresetLoad():
c.syncModeChan <- 0
case sg.StatusSetLoad():
c.syncModeChan <- 0
}
c.syncModeChan <- 0
}
}

Expand Down
19 changes: 19 additions & 0 deletions model/pod/message/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,22 @@ func GenTypeChange(pbi pod.PedalBoardItem) IMessage {

return m
}

func genStatusQuery(statusID uint32) IMessage {
var m *StatusQuery
m = newMessage2(reflect.TypeOf(m)).(*StatusQuery)

buf := genHeader(m)
binary.Write(buf, binary.LittleEndian, statusID)
m.data = buf.Bytes()

return m
}

func GenStatusQueryPresetID() IMessage {
return genStatusQuery(statusIDPreset)
}

func GenStatusQuerySetID() IMessage {
return genStatusQuery(statusIDSet)
}
25 changes: 25 additions & 0 deletions model/pod/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const (
setupMessageCab1Thump uint32 = 0x5c
setupMessageCab0Decay uint32 = 0x5d
setupMessageCab1Decay uint32 = 0x5e

statusIDSet uint32 = 0x09
statusIDPreset uint32 = 0x08
)

type IMessage interface {
Expand Down Expand Up @@ -251,6 +254,26 @@ func (m *SetupChange) Copy() IMessage {
return _m
}

type StatusResponse struct {
Message
}

func (m *StatusResponse) Copy() IMessage {
_m := new(StatusResponse)
*_m = *m
return _m
}

type StatusQuery struct {
Message
}

func (m *StatusQuery) Copy() IMessage {
_m := new(StatusQuery)
*_m = *m
return _m
}

var messages = []IMessage{
&ActiveChange{Message: Message{mtype: 0x0004, smtype: 4864, msize: 20, mname: "Item Active Change"}},
&TypeChange{Message: Message{mtype: 0x0004, smtype: 4352, msize: 20, mname: "Item Type Change"}},
Expand All @@ -268,6 +291,8 @@ var messages = []IMessage{
&SetLoad{Message: Message{mtype: 0x0006, smtype: 10496, msize: 12, mname: "Set Query"}},
&SetQuery{Message: Message{mtype: 0x0002, smtype: 10240, msize: 12, mname: "Set Query"}},
&SetupChange{Message: Message{mtype: 0x0005, smtype: 5632, msize: 24, mname: "Setup Change"}},
&StatusResponse{Message: Message{mtype: 0x0004, smtype: 0x2200, msize: 20, mname: "Status Response"}},
&StatusQuery{Message: Message{mtype: 0x0002, smtype: 0x2100, msize: 12, mname: "Status Query"}},
}

func newMessage(mtype uint16, smtype uint16) IMessage {
Expand Down
16 changes: 16 additions & 0 deletions model/pod/message/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,19 @@ func (m TypeChange) Parse(pb *pod.PedalBoard) (error, int, interface{}) {
}
return nil, ct.StatusTypeChange(), p
}

func (m StatusResponse) Parse(pb *pod.PedalBoard) (error, int, interface{}) {
status := binary.LittleEndian.Uint32(m.data[12:16])
value := binary.LittleEndian.Uint32(m.data[16:])

switch status {
case statusIDPreset:
pb.SetCurrentPreset(uint8(value))
return nil, ct.StatusPresetChange(), pb
case statusIDSet:
pb.SetCurrentSet(uint8(value))
return nil, ct.StatusSetChange(), pb
}

return nil, ct.StatusNone(), nil
}
3 changes: 3 additions & 0 deletions qtctrl/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Controller struct {
_ func(string) `signal:"LoopError"`
_ func() `signal:InitDone`
_ func(pod.Parameter) `signal:ParameterChange`
_ func(*pod.PedalBoard) `signal:PresetChange`
_ func(*pod.PedalBoard) `signal:PresetLoad`
_ func(int) `signal:Progress`
_ func(*pod.PedalBoard) `signal:SetChange`
Expand All @@ -60,6 +61,8 @@ func (c *Controller) notif(err error, n int, obj interface{}) {
c.InitDone()
case sg.StatusParameterChange():
c.ParameterChange(obj.(pod.Parameter))
case sg.StatusPresetChange():
c.PresetChange(obj.(*pod.PedalBoard))
case sg.StatusPresetLoad():
c.PresetLoad(obj.(*pod.PedalBoard))
case sg.StatusProgress():
Expand Down
11 changes: 7 additions & 4 deletions ui/lpedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,12 @@ func (l *LPEdit) initUI() {
}

func (l *LPEdit) connectSignal() {
pb := l.ctrl.GetPedalBoard()
l.updateSets()
l.updatePresets(0)
l.updatePedalBoard(l.ctrl.GetPedalBoard())
l.updateSet(pb)
l.updatePresets(l.SetList.CurrentIndex())
l.updatePreset(pb)
l.updatePedalBoard(pb)

//UI Connections
l.DiscardChanges.ConnectClicked(l.discardPresetChanges)
Expand All @@ -95,6 +98,7 @@ func (l *LPEdit) connectSignal() {
//PedalBoard Connections
l.ctrl.ConnectActiveChange(l.updateActive)
l.ctrl.ConnectParameterChange(l.updateParameter)
l.ctrl.ConnectPresetChange(l.updatePreset)
l.ctrl.ConnectPresetLoad(l.updatePedalBoard)
l.ctrl.ConnectSetChange(l.updateSet)
l.ctrl.ConnectTempoChange(l.updateTempo)
Expand All @@ -112,7 +116,6 @@ func (l *LPEdit) connectSignal() {

for _, p := range l.parameters {
p.value.ConnectActivated2(p.vfunc)
p.value.SetEditable(true)
}
}

Expand All @@ -126,6 +129,7 @@ func (l *LPEdit) disconnectSignal() {
//PedalBoard Connections
l.ctrl.DisconnectActiveChange()
l.ctrl.DisconnectParameterChange()
l.ctrl.DisconnectPresetChange()
l.ctrl.DisconnectPresetLoad()
l.ctrl.DisconnectSetChange()
l.ctrl.DisconnectTempoChange()
Expand Down Expand Up @@ -322,7 +326,6 @@ func (l *LPEdit) updateParameters(pb *pod.PedalBoard) {
func (l *LPEdit) updatePedalBoard(pb *pod.PedalBoard) {
pb.LockData()
defer pb.UnlockData()
l.updatePreset(pb)
l.updatePedalBoardView(pb)
l.updateParameters(pb)
for i, a := range l.amps {
Expand Down

0 comments on commit f9a91c1

Please sign in to comment.