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

@ -3,6 +3,11 @@
package main
import (
"crypto/rand"
"encoding/hex"
"os"
"path/filepath"
"github.com/vsariola/sointu/cmd"
"github.com/vsariola/sointu/tracker"
"github.com/vsariola/sointu/tracker/gioui"
@ -49,10 +54,13 @@ func init() {
vst2.PluginAllocator = func(h vst2.Host) (vst2.Plugin, vst2.Dispatcher) {
modelMessages := make(chan interface{}, 1024)
playerMessages := make(chan tracker.PlayerMessage, 1024)
model, err := tracker.LoadRecovery(modelMessages, playerMessages)
if err != nil {
model = tracker.NewModel(modelMessages, playerMessages)
recoveryFile := ""
if configDir, err := os.UserConfigDir(); err == nil {
randBytes := make([]byte, 16)
rand.Read(randBytes)
recoveryFile = filepath.Join(configDir, "Sointu", "sointu-vsti-recovery-"+hex.EncodeToString(randBytes))
}
model := tracker.NewModel(modelMessages, playerMessages, recoveryFile)
player := tracker.NewPlayer(cmd.DefaultService, playerMessages, modelMessages)
tracker := gioui.NewTracker(model, cmd.DefaultService)
tracker.SetInstrEnlarged(true) // start the vsti with the instrument editor enlarged
@ -102,6 +110,12 @@ func init() {
tracker.Quit(true)
tracker.WaitQuitted()
},
GetChunkFunc: func(isPreset bool) []byte {
return tracker.SafeMarshalRecovery()
},
SetChunkFunc: func(data []byte, isPreset bool) {
tracker.SafeUnmarshalRecovery(data)
},
}
}