mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
refactor(tracker): use the Broker to communicate when exporting wav
This commit is contained in:
parent
ee3ab3bf86
commit
b73fc0b95b
@ -75,7 +75,7 @@ func (m *Model) WriteSong(w io.WriteCloser) {
|
|||||||
m.completeAction(false)
|
m.completeAction(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Model) WriteWav(w io.WriteCloser, pcm16 bool, execChan chan<- func()) {
|
func (m *Model) WriteWav(w io.WriteCloser, pcm16 bool) {
|
||||||
m.dialog = NoDialog
|
m.dialog = NoDialog
|
||||||
song := m.d.Song.Copy()
|
song := m.d.Song.Copy()
|
||||||
go func() {
|
go func() {
|
||||||
@ -83,21 +83,18 @@ func (m *Model) WriteWav(w io.WriteCloser, pcm16 bool, execChan chan<- func()) {
|
|||||||
rand.Read(b)
|
rand.Read(b)
|
||||||
name := fmt.Sprintf("%x", b)[2 : 32+2]
|
name := fmt.Sprintf("%x", b)[2 : 32+2]
|
||||||
data, err := sointu.Play(m.synther, song, func(p float32) {
|
data, err := sointu.Play(m.synther, song, func(p float32) {
|
||||||
execChan <- func() {
|
txt := fmt.Sprintf("Exporting song: %.0f%%", p*100)
|
||||||
m.Alerts().AddNamed(name, fmt.Sprintf("Exporting song: %.0f%%", p*100), Info)
|
trySend(m.broker.ToModel, MsgToModel{Data: Alert{Message: txt, Priority: Info, Name: name, Duration: defaultAlertDuration}})
|
||||||
}
|
|
||||||
}) // render the song to calculate its length
|
}) // render the song to calculate its length
|
||||||
if err != nil {
|
if err != nil {
|
||||||
execChan <- func() {
|
txt := fmt.Sprintf("Error rendering the song during export: %v", err)
|
||||||
m.Alerts().Add(fmt.Sprintf("Error rendering the song during export: %v", err), Error)
|
trySend(m.broker.ToModel, MsgToModel{Data: Alert{Message: txt, Priority: Error, Name: name, Duration: defaultAlertDuration}})
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
buffer, err := data.Wav(pcm16)
|
buffer, err := data.Wav(pcm16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
execChan <- func() {
|
txt := fmt.Sprintf("Error converting to .wav: %v", err)
|
||||||
m.Alerts().Add(fmt.Sprintf("Error converting to .wav: %v", err), Error)
|
trySend(m.broker.ToModel, MsgToModel{Data: Alert{Message: txt, Priority: Error, Name: name, Duration: defaultAlertDuration}})
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Write(buffer)
|
w.Write(buffer)
|
||||||
|
@ -253,7 +253,7 @@ func (t *Tracker) showDialog(gtx C) {
|
|||||||
filename = p[:len(p)-len(filepath.Ext(p))] + ".wav"
|
filename = p[:len(p)-len(filepath.Ext(p))] + ".wav"
|
||||||
}
|
}
|
||||||
t.explorerCreateFile(func(wc io.WriteCloser) {
|
t.explorerCreateFile(func(wc io.WriteCloser) {
|
||||||
t.WriteWav(wc, t.Dialog() == tracker.ExportInt16Explorer, t.execChan)
|
t.WriteWav(wc, t.Dialog() == tracker.ExportInt16Explorer)
|
||||||
}, filename)
|
}, filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user