mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-25 18:00:37 -04:00
refactor(tracker): split NewModelPlayer into NewModel, NewPlayer
This commit is contained in:
parent
37769fcc9c
commit
8074fd71d3
@ -49,7 +49,8 @@ func main() {
|
||||
defer midiContext.Close()
|
||||
midiContext.TryToOpenBy(*defaultMidiInput, *firstMidiInput)
|
||||
broker := tracker.NewBroker()
|
||||
model, player := tracker.NewModelPlayer(broker, cmd.MainSynther, midiContext, recoveryFile)
|
||||
model := tracker.NewModel(broker, cmd.MainSynther, midiContext, recoveryFile)
|
||||
player := tracker.NewPlayer(broker, cmd.MainSynther)
|
||||
detector := tracker.NewDetector(broker)
|
||||
go detector.Run()
|
||||
|
||||
|
@ -75,7 +75,8 @@ func init() {
|
||||
recoveryFile = filepath.Join(configDir, "sointu", "sointu-vsti-recovery-"+hex.EncodeToString(randBytes))
|
||||
}
|
||||
broker := tracker.NewBroker()
|
||||
model, player := tracker.NewModelPlayer(broker, cmd.MainSynther, NullMIDIContext{}, recoveryFile)
|
||||
model := tracker.NewModel(broker, cmd.MainSynther, NullMIDIContext{}, recoveryFile)
|
||||
player := tracker.NewPlayer(broker, cmd.MainSynther)
|
||||
detector := tracker.NewDetector(broker)
|
||||
go detector.Run()
|
||||
|
||||
|
@ -181,7 +181,7 @@ func (m *Model) Quitted() bool { return m.quitted }
|
||||
func (m *Model) DetectorResult() DetectorResult { return m.detectorResult }
|
||||
|
||||
// NewModelPlayer creates a new model and a player that communicates with it
|
||||
func NewModelPlayer(broker *Broker, synther sointu.Synther, midiContext MIDIContext, recoveryFilePath string) (*Model, *Player) {
|
||||
func NewModel(broker *Broker, synther sointu.Synther, midiContext MIDIContext, recoveryFilePath string) *Model {
|
||||
m := new(Model)
|
||||
m.synther = synther
|
||||
m.MIDI = midiContext
|
||||
@ -199,15 +199,9 @@ func NewModelPlayer(broker *Broker, synther sointu.Synther, midiContext MIDICont
|
||||
}
|
||||
}
|
||||
}
|
||||
trySend(broker.ToPlayer, any(m.d.Song.Copy())) // we should be non-blocking in the constructor
|
||||
m.signalAnalyzer = NewScopeModel(broker, m.d.Song.BPM)
|
||||
p := &Player{
|
||||
broker: broker,
|
||||
synther: synther,
|
||||
song: m.d.Song.Copy(),
|
||||
loop: m.loop,
|
||||
}
|
||||
p.compileOrUpdateSynth()
|
||||
return m, p
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Model) change(kind string, t ChangeType, severity ChangeSeverity) func() {
|
||||
|
@ -265,7 +265,8 @@ func FuzzModel(f *testing.F) {
|
||||
reader := bytes.NewReader(slice)
|
||||
synther := vm.GoSynther{}
|
||||
broker := tracker.NewBroker()
|
||||
model, player := tracker.NewModelPlayer(broker, synther, NullContext{}, "")
|
||||
model := tracker.NewModel(broker, synther, NullContext{}, "")
|
||||
player := tracker.NewPlayer(broker, synther)
|
||||
buf := make([][2]float32, 2048)
|
||||
closeChan := make(chan struct{})
|
||||
go func() {
|
||||
|
@ -73,6 +73,13 @@ const (
|
||||
|
||||
const numRenderTries = 10000
|
||||
|
||||
func NewPlayer(broker *Broker, synther sointu.Synther) *Player {
|
||||
return &Player{
|
||||
broker: broker,
|
||||
synther: synther,
|
||||
}
|
||||
}
|
||||
|
||||
// Process renders audio to the given buffer, trying to fill it completely. If
|
||||
// the buffer is not filled, the synth is destroyed and an error is sent to the
|
||||
// model. context tells the player which MIDI events happen during the current
|
||||
|
Loading…
Reference in New Issue
Block a user