mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
reorganize things into different packages
This commit is contained in:
parent
e46ece3648
commit
a035845b81
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -67,4 +67,4 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CGO_LDFLAGS: ${{ matrix.config.cgo_ldflags }}
|
CGO_LDFLAGS: ${{ matrix.config.cgo_ldflags }}
|
||||||
run: |
|
run: |
|
||||||
go test ./bridge ./compiler ./oto
|
go test ./vm ./vm/compiler/bridge ./vm/compiler ./oto
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/vsariola/sointu"
|
"github.com/vsariola/sointu"
|
||||||
"github.com/vsariola/sointu/compiler"
|
"github.com/vsariola/sointu/vm/compiler"
|
||||||
)
|
)
|
||||||
|
|
||||||
func filterExtensions(input map[string]string, extensions []string) map[string]string {
|
func filterExtensions(input map[string]string, extensions []string) map[string]string {
|
||||||
|
@ -15,8 +15,8 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/vsariola/sointu"
|
"github.com/vsariola/sointu"
|
||||||
"github.com/vsariola/sointu/bridge"
|
|
||||||
"github.com/vsariola/sointu/oto"
|
"github.com/vsariola/sointu/oto"
|
||||||
|
"github.com/vsariola/sointu/vm/compiler/bridge"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -4,9 +4,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/vsariola/sointu/bridge"
|
|
||||||
"github.com/vsariola/sointu/oto"
|
"github.com/vsariola/sointu/oto"
|
||||||
"github.com/vsariola/sointu/tracker/gioui"
|
"github.com/vsariola/sointu/tracker/gioui"
|
||||||
|
"github.com/vsariola/sointu/vm/compiler/bridge"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package tracker
|
package tracker
|
||||||
|
|
||||||
import "github.com/vsariola/sointu/compiler"
|
import "github.com/vsariola/sointu/vm"
|
||||||
|
|
||||||
type GmDlsEntry struct {
|
type GmDlsEntry struct {
|
||||||
Start int
|
Start int
|
||||||
@ -10,11 +10,11 @@ type GmDlsEntry struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
var GmDlsEntryMap = make(map[compiler.SampleOffset]int)
|
var GmDlsEntryMap = make(map[vm.SampleOffset]int)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
for i, e := range GmDlsEntries {
|
for i, e := range GmDlsEntries {
|
||||||
key := compiler.SampleOffset{Start: uint32(e.Start), LoopStart: uint16(e.LoopStart), LoopLength: uint16(e.LoopLength)}
|
key := vm.SampleOffset{Start: uint32(e.Start), LoopStart: uint16(e.LoopStart), LoopLength: uint16(e.LoopLength)}
|
||||||
GmDlsEntryMap[key] = i
|
GmDlsEntryMap[key] = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/vsariola/sointu"
|
"github.com/vsariola/sointu"
|
||||||
"github.com/vsariola/sointu/compiler"
|
"github.com/vsariola/sointu/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Model implements the mutable state for the tracker program GUI.
|
// Model implements the mutable state for the tracker program GUI.
|
||||||
@ -812,7 +812,7 @@ func (m *Model) Param(index int) (Parameter, error) {
|
|||||||
return Parameter{Type: typ, Min: min, Max: max, Name: name, Hint: text, Value: val}, nil
|
return Parameter{Type: typ, Min: min, Max: max, Name: name, Hint: text, Value: val}, nil
|
||||||
}
|
}
|
||||||
if unit.Type == "oscillator" && index == 0 {
|
if unit.Type == "oscillator" && index == 0 {
|
||||||
key := compiler.SampleOffset{Start: uint32(unit.Parameters["samplestart"]), LoopStart: uint16(unit.Parameters["loopstart"]), LoopLength: uint16(unit.Parameters["looplength"])}
|
key := vm.SampleOffset{Start: uint32(unit.Parameters["samplestart"]), LoopStart: uint16(unit.Parameters["loopstart"]), LoopLength: uint16(unit.Parameters["looplength"])}
|
||||||
val := 0
|
val := 0
|
||||||
hint := "0 / custom"
|
hint := "0 / custom"
|
||||||
if v, ok := GmDlsEntryMap[key]; ok {
|
if v, ok := GmDlsEntryMap[key]; ok {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package compiler
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/vsariola/sointu"
|
"github.com/vsariola/sointu"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EncodedPatch struct {
|
type BytePatch struct {
|
||||||
Commands []byte
|
Commands []byte
|
||||||
Values []byte
|
Values []byte
|
||||||
DelayTimes []uint16
|
DelayTimes []uint16
|
||||||
@ -22,8 +22,8 @@ type SampleOffset struct {
|
|||||||
LoopLength uint16
|
LoopLength uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
func Encode(patch sointu.Patch, featureSet FeatureSet) (*EncodedPatch, error) {
|
func Encode(patch sointu.Patch, featureSet FeatureSet) (*BytePatch, error) {
|
||||||
var c EncodedPatch
|
var c BytePatch
|
||||||
sampleOffsetMap := map[SampleOffset]int{}
|
sampleOffsetMap := map[SampleOffset]int{}
|
||||||
globalAddrs := map[int]uint16{}
|
globalAddrs := map[int]uint16{}
|
||||||
globalFixups := map[int]([]int){}
|
globalFixups := map[int]([]int){}
|
@ -1,7 +1,7 @@
|
|||||||
package bridge
|
package bridge
|
||||||
|
|
||||||
// #cgo CFLAGS: -I"${SRCDIR}/../build/"
|
// #cgo CFLAGS: -I"${SRCDIR}/../../../build/"
|
||||||
// #cgo LDFLAGS: "${SRCDIR}/../build/libsointu.a"
|
// #cgo LDFLAGS: "${SRCDIR}/../../../build/libsointu.a"
|
||||||
// #include <sointu.h>
|
// #include <sointu.h>
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/vsariola/sointu"
|
"github.com/vsariola/sointu"
|
||||||
"github.com/vsariola/sointu/compiler"
|
"github.com/vsariola/sointu/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BridgeService struct {
|
type BridgeService struct {
|
||||||
@ -23,7 +23,7 @@ func (s BridgeService) Compile(patch sointu.Patch) (sointu.Synth, error) {
|
|||||||
|
|
||||||
func Synth(patch sointu.Patch) (*C.Synth, error) {
|
func Synth(patch sointu.Patch) (*C.Synth, error) {
|
||||||
s := new(C.Synth)
|
s := new(C.Synth)
|
||||||
comPatch, err := compiler.Encode(patch, compiler.AllFeatures{})
|
comPatch, err := vm.Encode(patch, vm.AllFeatures{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error compiling patch: %v", err)
|
return nil, fmt.Errorf("error compiling patch: %v", err)
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ func (s *C.Synth) Release(voice int) {
|
|||||||
|
|
||||||
// Update
|
// Update
|
||||||
func (s *C.Synth) Update(patch sointu.Patch) error {
|
func (s *C.Synth) Update(patch sointu.Patch) error {
|
||||||
comPatch, err := compiler.Encode(patch, compiler.AllFeatures{})
|
comPatch, err := vm.Encode(patch, vm.AllFeatures{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error compiling patch: %v", err)
|
return fmt.Errorf("error compiling patch: %v", err)
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/vsariola/sointu"
|
"github.com/vsariola/sointu"
|
||||||
"github.com/vsariola/sointu/bridge"
|
"github.com/vsariola/sointu/vm/compiler/bridge"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
// TODO: test the song using a mocks instead
|
// TODO: test the song using a mocks instead
|
||||||
)
|
)
|
||||||
@ -78,7 +78,7 @@ func TestRenderSamples(t *testing.T) {
|
|||||||
|
|
||||||
func TestAllRegressionTests(t *testing.T) {
|
func TestAllRegressionTests(t *testing.T) {
|
||||||
_, myname, _, _ := runtime.Caller(0)
|
_, myname, _, _ := runtime.Caller(0)
|
||||||
files, err := filepath.Glob(path.Join(path.Dir(myname), "..", "tests", "*.yml"))
|
files, err := filepath.Glob(path.Join(path.Dir(myname), "..", "..", "..", "tests", "*.yml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot glob files in the test directory: %v", err)
|
t.Fatalf("cannot glob files in the test directory: %v", err)
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ func TestDivideByZero(t *testing.T) {
|
|||||||
|
|
||||||
func compareToRawFloat32(t *testing.T, buffer []float32, rawname string) {
|
func compareToRawFloat32(t *testing.T, buffer []float32, rawname string) {
|
||||||
_, filename, _, _ := runtime.Caller(0)
|
_, filename, _, _ := runtime.Caller(0)
|
||||||
expectedb, err := ioutil.ReadFile(path.Join(path.Dir(filename), "..", "tests", "expected_output", rawname))
|
expectedb, err := ioutil.ReadFile(path.Join(path.Dir(filename), "..", "..", "..", "tests", "expected_output", rawname))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("cannot read expected: %v", err)
|
t.Fatalf("cannot read expected: %v", err)
|
||||||
}
|
}
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/Masterminds/sprig"
|
"github.com/Masterminds/sprig"
|
||||||
"github.com/vsariola/sointu"
|
"github.com/vsariola/sointu"
|
||||||
|
"github.com/vsariola/sointu/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Compiler struct {
|
type Compiler struct {
|
||||||
@ -30,7 +31,7 @@ func New(os string, arch string, output16Bit bool) (*Compiler, error) {
|
|||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("compiler.New failed, because only amd64, 386 and wasm archs are supported (targeted architecture was %v)", arch)
|
return nil, fmt.Errorf("compiler.New failed, because only amd64, 386 and wasm archs are supported (targeted architecture was %v)", arch)
|
||||||
}
|
}
|
||||||
templateDir := filepath.Join(path.Dir(myname), "..", "templates", subdir)
|
templateDir := filepath.Join(path.Dir(myname), "..", "..", "templates", subdir)
|
||||||
compiler, err := NewFromTemplates(os, arch, output16Bit, templateDir)
|
compiler, err := NewFromTemplates(os, arch, output16Bit, templateDir)
|
||||||
return compiler, err
|
return compiler, err
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ func (com *Compiler) Library() (map[string]string, error) {
|
|||||||
return nil, fmt.Errorf(`compiling as a library is supported only on 386 and amd64 architectures (targeted architecture was %v)`, com.Arch)
|
return nil, fmt.Errorf(`compiling as a library is supported only on 386 and amd64 architectures (targeted architecture was %v)`, com.Arch)
|
||||||
}
|
}
|
||||||
templates := []string{"library.asm", "library.h"}
|
templates := []string{"library.asm", "library.h"}
|
||||||
features := AllFeatures{}
|
features := vm.AllFeatures{}
|
||||||
retmap := map[string]string{}
|
retmap := map[string]string{}
|
||||||
for _, templateName := range templates {
|
for _, templateName := range templates {
|
||||||
compilerMacros := *NewCompilerMacros(*com)
|
compilerMacros := *NewCompilerMacros(*com)
|
||||||
@ -80,13 +81,13 @@ func (com *Compiler) Song(song *sointu.Song) (map[string]string, error) {
|
|||||||
} else if com.Arch == "wasm" {
|
} else if com.Arch == "wasm" {
|
||||||
templates = []string{"player.wat"}
|
templates = []string{"player.wat"}
|
||||||
}
|
}
|
||||||
features := NecessaryFeaturesFor(song.Patch)
|
features := vm.NecessaryFeaturesFor(song.Patch)
|
||||||
retmap := map[string]string{}
|
retmap := map[string]string{}
|
||||||
encodedPatch, err := Encode(song.Patch, features)
|
encodedPatch, err := vm.Encode(song.Patch, features)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(`could not encode patch: %v`, err)
|
return nil, fmt.Errorf(`could not encode patch: %v`, err)
|
||||||
}
|
}
|
||||||
patterns, sequences, err := ConstructPatterns(song)
|
patterns, sequences, err := vm.ConstructPatterns(song)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(`could not encode song: %v`, err)
|
return nil, fmt.Errorf(`could not encode song: %v`, err)
|
||||||
}
|
}
|
||||||
@ -103,7 +104,7 @@ func (com *Compiler) Song(song *sointu.Song) (map[string]string, error) {
|
|||||||
FeatureSetMacros
|
FeatureSetMacros
|
||||||
X86Macros
|
X86Macros
|
||||||
SongMacros
|
SongMacros
|
||||||
*EncodedPatch
|
*vm.BytePatch
|
||||||
Patterns [][]byte
|
Patterns [][]byte
|
||||||
Sequences [][]byte
|
Sequences [][]byte
|
||||||
PatternLength int
|
PatternLength int
|
||||||
@ -118,7 +119,7 @@ func (com *Compiler) Song(song *sointu.Song) (map[string]string, error) {
|
|||||||
FeatureSetMacros
|
FeatureSetMacros
|
||||||
WasmMacros
|
WasmMacros
|
||||||
SongMacros
|
SongMacros
|
||||||
*EncodedPatch
|
*vm.BytePatch
|
||||||
Patterns [][]byte
|
Patterns [][]byte
|
||||||
Sequences [][]byte
|
Sequences [][]byte
|
||||||
PatternLength int
|
PatternLength int
|
@ -1,7 +1,9 @@
|
|||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
|
import "github.com/vsariola/sointu/vm"
|
||||||
|
|
||||||
type FeatureSetMacros struct {
|
type FeatureSetMacros struct {
|
||||||
FeatureSet
|
vm.FeatureSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *FeatureSetMacros) HasOp(instruction string) bool {
|
func (p *FeatureSetMacros) HasOp(instruction string) bool {
|
@ -4,6 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/vsariola/sointu/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type X86Macros struct {
|
type X86Macros struct {
|
||||||
@ -17,10 +19,10 @@ type X86Macros struct {
|
|||||||
intConsts []int
|
intConsts []int
|
||||||
calls map[string]bool
|
calls map[string]bool
|
||||||
stackframes map[string][]string
|
stackframes map[string][]string
|
||||||
features FeatureSet
|
features vm.FeatureSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewX86Macros(os string, Amd64 bool, features FeatureSet, DisableSections bool) *X86Macros {
|
func NewX86Macros(os string, Amd64 bool, features vm.FeatureSet, DisableSections bool) *X86Macros {
|
||||||
return &X86Macros{
|
return &X86Macros{
|
||||||
calls: map[string]bool{},
|
calls: map[string]bool{},
|
||||||
usesFloatConst: map[float32]bool{},
|
usesFloatConst: map[float32]bool{},
|
@ -1,4 +1,4 @@
|
|||||||
package compiler
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
@ -1,4 +1,4 @@
|
|||||||
package compiler
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
@ -1,11 +1,11 @@
|
|||||||
package compiler_test
|
package vm_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/vsariola/sointu"
|
"github.com/vsariola/sointu"
|
||||||
"github.com/vsariola/sointu/compiler"
|
"github.com/vsariola/sointu/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPatternReusing(t *testing.T) {
|
func TestPatternReusing(t *testing.T) {
|
||||||
@ -21,7 +21,7 @@ func TestPatternReusing(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
patterns, sequences, err := compiler.ConstructPatterns(&song)
|
patterns, sequences, err := vm.ConstructPatterns(&song)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("erorr constructing patterns: %v", err)
|
t.Fatalf("erorr constructing patterns: %v", err)
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func TestUnnecessaryHolds(t *testing.T) {
|
|||||||
Order: []int{0, 1},
|
Order: []int{0, 1},
|
||||||
}}},
|
}}},
|
||||||
}
|
}
|
||||||
patterns, sequences, err := compiler.ConstructPatterns(&song)
|
patterns, sequences, err := vm.ConstructPatterns(&song)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("erorr constructing patterns: %v", err)
|
t.Fatalf("erorr constructing patterns: %v", err)
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ func TestDontCares(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
patterns, sequences, err := compiler.ConstructPatterns(&song)
|
patterns, sequences, err := vm.ConstructPatterns(&song)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("erorr constructing patterns: %v", err)
|
t.Fatalf("erorr constructing patterns: %v", err)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user