This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-12-30 22:43:35 +02:00
parent f765d75fde
commit 2303e89bbd
10 changed files with 330 additions and 110 deletions

View File

@ -73,9 +73,13 @@ type (
signalAnalyzer *ScopeModel
detectorResult DetectorResult
spectrum *Spectrum
weightingType WeightingType
oversampling bool
specAnSettings SpecAnSettings
alerts []Alert
dialog Dialog
@ -185,6 +189,7 @@ func (m *Model) Dialog() Dialog { return m.dialog }
func (m *Model) Quitted() bool { return m.quitted }
func (m *Model) DetectorResult() DetectorResult { return m.detectorResult }
func (m *Model) Spectrum() Spectrum { return *m.spectrum }
// NewModelPlayer creates a new model and a player that communicates with it
func NewModel(broker *Broker, synthers []sointu.Synther, midiContext MIDIContext, recoveryFilePath string) *Model {
@ -195,6 +200,7 @@ func NewModel(broker *Broker, synthers []sointu.Synther, midiContext MIDIContext
m.d.Octave = 4
m.linkInstrTrack = true
m.d.RecoveryFilePath = recoveryFilePath
m.spectrum = broker.GetSpectrum()
m.resetSong()
if recoveryFilePath != "" {
if bytes2, err := os.ReadFile(m.d.RecoveryFilePath); err == nil {
@ -205,7 +211,7 @@ func NewModel(broker *Broker, synthers []sointu.Synther, midiContext MIDIContext
}
}
TrySend(broker.ToPlayer, any(m.d.Song.Copy())) // we should be non-blocking in the constructor
m.signalAnalyzer = NewScopeModel(broker, m.d.Song.BPM)
m.signalAnalyzer = NewScopeModel(m.d.Song.BPM)
m.updateDeriveData(SongChange)
m.presets.load()
m.updateDerivedPresetSearch()
@ -372,6 +378,7 @@ func (m *Model) ProcessMsg(msg MsgToModel) {
}
if msg.Reset {
m.signalAnalyzer.Reset()
TrySend(m.broker.ToDetector, MsgToDetector{Reset: true}) // chain the messages: when the signal analyzer is reset, also reset the detector
}
switch e := msg.Data.(type) {
case func():
@ -394,6 +401,18 @@ func (m *Model) ProcessMsg(msg MsgToModel) {
m.playing = e.bool
case *sointu.AudioBuffer:
m.signalAnalyzer.ProcessAudioBuffer(e)
// chain the messages: when we have a new audio buffer, send them to the detector and the spectrum analyzer
clone := m.broker.GetAudioBuffer()
*clone = append(*clone, *e...)
if !TrySend(m.broker.ToDetector, MsgToDetector{Data: e}) {
m.broker.PutAudioBuffer(e)
}
if !TrySend(m.broker.ToSpecAn, MsgToSpecAn{Data: clone}) {
m.broker.PutAudioBuffer(clone)
}
case *Spectrum:
m.broker.PutSpectrum(m.spectrum)
m.spectrum = e
}
}