sointu/song.go
vsariola 6d2b63a5e9 feat(sointu, vm): implement pure-Go interpreter for bytecode
The old "native" compiler bridged version is now started with cmd/sointu-nativetrack,
while the new pure-Go bytecode implemented bytecode interpreter is started with
cmd/sointu-track

Thus, you do not need any of the CMake / cgo stuff to run cmd/sointu-track
2021-03-03 23:55:58 +02:00

36 lines
751 B
Go

package sointu
import (
"errors"
)
type Song struct {
BPM int
RowsPerBeat int
Score Score
Patch Patch
}
func (s *Song) Copy() Song {
return Song{BPM: s.BPM, RowsPerBeat: s.RowsPerBeat, Score: s.Score.Copy(), Patch: s.Patch.Copy()}
}
func (s *Song) SamplesPerRow() int {
return 44100 * 60 / (s.BPM * s.RowsPerBeat)
}
// TBD: Where shall we put methods that work on pure domain types and have no dependencies
// e.g. Validate here
func (s *Song) Validate() error {
if s.BPM < 1 {
return errors.New("BPM should be > 0")
}
if len(s.Score.Tracks) == 0 {
return errors.New("song contains no tracks")
}
if s.Score.NumVoices() > s.Patch.NumVoices() {
return errors.New("Tracks use too many voices")
}
return nil
}