feat: save recovery data to disk and/or DAW project

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-10-15 15:28:35 +03:00
parent 97a1b2f766
commit 462faf5f4e
7 changed files with 126 additions and 95 deletions

View File

@ -57,16 +57,20 @@ type Tracker struct {
lastVolume tracker.Volume
wavFilePath string
quitChannel chan struct{}
quitWG sync.WaitGroup
errorChannel chan error
quitted bool
synthService sointu.SynthService
wavFilePath string
quitChannel chan struct{}
quitWG sync.WaitGroup
errorChannel chan error
quitted bool
unmarshalRecoveryChannel chan []byte
marshalRecoveryChannel chan (chan []byte)
synthService sointu.SynthService
*tracker.Model
*trackerModel
}
type trackerModel = tracker.Model
func (t *Tracker) UnmarshalContent(bytes []byte) error {
var units []sointu.Unit
if errJSON := json.Unmarshal(bytes, &units); errJSON == nil {
@ -143,7 +147,10 @@ func NewTracker(model *tracker.Model, synthService sointu.SynthService) *Tracker
errorChannel: make(chan error, 32),
synthService: synthService,
Model: model,
trackerModel: model,
marshalRecoveryChannel: make(chan (chan []byte)),
unmarshalRecoveryChannel: make(chan []byte),
}
t.Theme.Palette.Fg = primaryColor
t.Theme.Palette.ContrastFg = black
@ -213,6 +220,10 @@ mainloop:
}
case <-recoveryTicker.C:
t.SaveRecovery()
case retChn := <-t.marshalRecoveryChannel:
retChn <- t.MarshalRecovery()
case bytes := <-t.unmarshalRecoveryChannel:
t.UnmarshalRecovery(bytes)
}
}
w.Perform(system.ActionClose)
@ -220,6 +231,18 @@ mainloop:
t.quitWG.Done()
}
// thread safe, executed in the GUI thread
func (t *Tracker) SafeMarshalRecovery() []byte {
retChn := make(chan []byte)
t.marshalRecoveryChannel <- retChn
return <-retChn
}
// thread safe, executed in the GUI thread
func (t *Tracker) SafeUnmarshalRecovery(data []byte) {
t.unmarshalRecoveryChannel <- data
}
func (t *Tracker) sendQuit() {
select {
case t.quitChannel <- struct{}{}: