feat: add ability to import 4klang patches and instruments

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-07-06 23:47:55 +03:00
parent c06ac6ea5e
commit 248ba483c6
87 changed files with 643 additions and 55 deletions

View File

@ -16,17 +16,17 @@ import (
type BridgeService struct {
}
func (s BridgeService) Compile(patch sointu.Patch) (sointu.Synth, error) {
synth, err := Synth(patch)
func (s BridgeService) Compile(patch sointu.Patch, bpm int) (sointu.Synth, error) {
synth, err := Synth(patch, bpm)
return synth, err
}
func Synth(patch sointu.Patch) (*C.Synth, error) {
func Synth(patch sointu.Patch, bpm int) (*C.Synth, error) {
s := new(C.Synth)
if n := patch.NumDelayLines(); n > 64 {
return nil, fmt.Errorf("native bridge has currently a hard limit of 64 delaylines; patch uses %v", n)
}
comPatch, err := vm.Encode(patch, vm.AllFeatures{})
comPatch, err := vm.Encode(patch, vm.AllFeatures{}, bpm)
if err != nil {
return nil, fmt.Errorf("error compiling patch: %v", err)
}
@ -109,11 +109,11 @@ func (s *C.Synth) Release(voice int) {
}
// Update
func (s *C.Synth) Update(patch sointu.Patch) error {
func (s *C.Synth) Update(patch sointu.Patch, bpm int) error {
if n := patch.NumDelayLines(); n > 64 {
return fmt.Errorf("native bridge has currently a hard limit of 64 delaylines; patch uses %v", n)
}
comPatch, err := vm.Encode(patch, vm.AllFeatures{})
comPatch, err := vm.Encode(patch, vm.AllFeatures{}, bpm)
if err != nil {
return fmt.Errorf("error compiling patch: %v", err)
}

View File

@ -54,7 +54,7 @@ func TestRenderSamples(t *testing.T) {
sointu.Unit{Type: "out", Parameters: map[string]int{"stereo": 1, "gain": 128}},
}}}
synth, err := bridge.Synth(patch)
synth, err := bridge.Synth(patch, 120)
if err != nil {
t.Fatalf("bridge compile error: %v", err)
}
@ -130,7 +130,7 @@ func TestStackUnderflow(t *testing.T) {
patch := sointu.Patch{sointu.Instrument{NumVoices: 1, Units: []sointu.Unit{
sointu.Unit{Type: "pop", Parameters: map[string]int{}},
}}}
synth, err := bridge.Synth(patch)
synth, err := bridge.Synth(patch, 120)
if err != nil {
t.Fatalf("bridge compile error: %v", err)
}
@ -146,7 +146,7 @@ func TestStackBalancing(t *testing.T) {
sointu.Instrument{NumVoices: 1, Units: []sointu.Unit{
sointu.Unit{Type: "push", Parameters: map[string]int{}},
}}}
synth, err := bridge.Synth(patch)
synth, err := bridge.Synth(patch, 120)
if err != nil {
t.Fatalf("bridge compile error: %v", err)
}
@ -179,7 +179,7 @@ func TestStackOverflow(t *testing.T) {
sointu.Unit{Type: "pop", Parameters: map[string]int{}},
sointu.Unit{Type: "pop", Parameters: map[string]int{}},
}}}
synth, err := bridge.Synth(patch)
synth, err := bridge.Synth(patch, 120)
if err != nil {
t.Fatalf("bridge compile error: %v", err)
}
@ -196,7 +196,7 @@ func TestDivideByZero(t *testing.T) {
sointu.Unit{Type: "invgain", Parameters: map[string]int{"invgain": 0}},
sointu.Unit{Type: "pop", Parameters: map[string]int{}},
}}}
synth, err := bridge.Synth(patch)
synth, err := bridge.Synth(patch, 120)
if err != nil {
t.Fatalf("bridge compile error: %v", err)
}

View File

@ -84,7 +84,7 @@ func (com *Compiler) Song(song *sointu.Song) (map[string]string, error) {
}
features := vm.NecessaryFeaturesFor(song.Patch)
retmap := map[string]string{}
encodedPatch, err := vm.Encode(song.Patch, features)
encodedPatch, err := vm.Encode(song.Patch, features, song.BPM)
if err != nil {
return nil, fmt.Errorf(`could not encode patch: %v`, err)
}