mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 21:14:31 -04:00
feat(tracker): add menu item to export .wav
Also refactor the common functions for .wav export into base package so that both sointu-play and tracker can use same functions.
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"gioui.org/app"
|
||||
"gopkg.in/yaml.v3"
|
||||
@ -82,3 +83,33 @@ func (t *Tracker) saveSong(filename string) bool {
|
||||
t.SetChangedSinceSave(false)
|
||||
return true
|
||||
}
|
||||
|
||||
func (t *Tracker) exportWav(pcm16 bool) {
|
||||
filename, err := dialog.File().Filter(".wav file", "wav").Title("Export .wav").Save()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var extension = filepath.Ext(filename)
|
||||
if extension == "" {
|
||||
filename = filename + ".wav"
|
||||
}
|
||||
synth, err := t.synthService.Compile(t.Song().Patch)
|
||||
if err != nil {
|
||||
t.Alert.Update(fmt.Sprintf("Error compiling the patch during export: %v", err), Error, time.Second*3)
|
||||
return
|
||||
}
|
||||
for i := 0; i < 32; i++ {
|
||||
synth.Release(i)
|
||||
}
|
||||
data, _, err := sointu.Play(synth, t.Song()) // render the song to calculate its length
|
||||
if err != nil {
|
||||
t.Alert.Update(fmt.Sprintf("Error rendering the song during export: %v", err), Error, time.Second*3)
|
||||
return
|
||||
}
|
||||
buffer, err := sointu.Wav(data, pcm16)
|
||||
if err != nil {
|
||||
t.Alert.Update(fmt.Sprintf("Error converting to .wav: %v", err), Error, time.Second*3)
|
||||
return
|
||||
}
|
||||
ioutil.WriteFile(filename, buffer, 0644)
|
||||
}
|
||||
|
Reference in New Issue
Block a user