mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-14 02:54:37 -04:00
refactor!: rename SynthService to Synther and related types
The -er suffix is more idiomatic for single method interfaces, and the interface is not doing much more than converting the patch to a synth. Names were updated throughout the project to reflect this change. In particular, the "Service" in SynthService was not telling anything helpful.
This commit is contained in:
parent
e4a2ed9f32
commit
0a67129a0c
@ -13,17 +13,17 @@ import (
|
||||
"github.com/vsariola/sointu/vm"
|
||||
)
|
||||
|
||||
type BridgeService struct {
|
||||
type NativeSynther struct {
|
||||
}
|
||||
|
||||
type BridgeSynth C.Synth
|
||||
type NativeSynth C.Synth
|
||||
|
||||
func (s BridgeService) Compile(patch sointu.Patch, bpm int) (sointu.Synth, error) {
|
||||
func (s NativeSynther) Synth(patch sointu.Patch, bpm int) (sointu.Synth, error) {
|
||||
synth, err := Synth(patch, bpm)
|
||||
return synth, err
|
||||
}
|
||||
|
||||
func Synth(patch sointu.Patch, bpm int) (*BridgeSynth, error) {
|
||||
func Synth(patch sointu.Patch, bpm int) (*NativeSynth, 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)
|
||||
@ -55,7 +55,7 @@ func Synth(patch sointu.Patch, bpm int) (*BridgeSynth, error) {
|
||||
s.NumVoices = C.uint(comPatch.NumVoices)
|
||||
s.Polyphony = C.uint(comPatch.PolyphonyBitmask)
|
||||
s.RandSeed = 1
|
||||
return (*BridgeSynth)(s), nil
|
||||
return (*NativeSynth)(s), nil
|
||||
}
|
||||
|
||||
// Render renders until the buffer is full or the modulated time is reached, whichever
|
||||
@ -79,7 +79,7 @@ func Synth(patch sointu.Patch, bpm int) (*BridgeSynth, error) {
|
||||
// time > maxtime, as it is modulated and the time could advance by 2 or more, so the loop
|
||||
// exit condition would fire when the time is already past maxtime.
|
||||
// Under no conditions, nsamples >= len(buffer)/2 i.e. guaranteed to never overwrite the buffer.
|
||||
func (bridgesynth *BridgeSynth) Render(buffer sointu.AudioBuffer, maxtime int) (int, int, error) {
|
||||
func (bridgesynth *NativeSynth) Render(buffer sointu.AudioBuffer, maxtime int) (int, int, error) {
|
||||
synth := (*C.Synth)(bridgesynth)
|
||||
// TODO: syncBuffer is not getting passed to cgo; do we want to even try to support the syncing with the native bridge
|
||||
if len(buffer)%1 == 1 {
|
||||
@ -95,7 +95,7 @@ func (bridgesynth *BridgeSynth) Render(buffer sointu.AudioBuffer, maxtime int) (
|
||||
}
|
||||
|
||||
// Trigger is part of C.Synths' implementation of sointu.Synth interface
|
||||
func (bridgesynth *BridgeSynth) Trigger(voice int, note byte) {
|
||||
func (bridgesynth *NativeSynth) Trigger(voice int, note byte) {
|
||||
s := (*C.Synth)(bridgesynth)
|
||||
if voice < 0 || voice >= len(s.SynthWrk.Voices) {
|
||||
return
|
||||
@ -106,7 +106,7 @@ func (bridgesynth *BridgeSynth) Trigger(voice int, note byte) {
|
||||
}
|
||||
|
||||
// Release is part of C.Synths' implementation of sointu.Synth interface
|
||||
func (bridgesynth *BridgeSynth) Release(voice int) {
|
||||
func (bridgesynth *NativeSynth) Release(voice int) {
|
||||
s := (*C.Synth)(bridgesynth)
|
||||
if voice < 0 || voice >= len(s.SynthWrk.Voices) {
|
||||
return
|
||||
@ -115,7 +115,7 @@ func (bridgesynth *BridgeSynth) Release(voice int) {
|
||||
}
|
||||
|
||||
// Update
|
||||
func (bridgesynth *BridgeSynth) Update(patch sointu.Patch, bpm int) error {
|
||||
func (bridgesynth *NativeSynth) Update(patch sointu.Patch, bpm int) error {
|
||||
s := (*C.Synth)(bridgesynth)
|
||||
if n := patch.NumDelayLines(); n > 64 {
|
||||
return fmt.Errorf("native bridge has currently a hard limit of 64 delaylines; patch uses %v", n)
|
@ -40,7 +40,7 @@ func TestOscillatSine(t *testing.T) {
|
||||
}}}
|
||||
tracks := []sointu.Track{{NumVoices: 1, Order: []int{0}, Patterns: []sointu.Pattern{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}}}}
|
||||
song := sointu.Song{BPM: 100, RowsPerBeat: 4, Score: sointu.Score{RowsPerPattern: 16, Length: 1, Tracks: tracks}, Patch: patch}
|
||||
buffer, err := sointu.Play(bridge.BridgeService{}, song, false)
|
||||
buffer, err := sointu.Play(bridge.NativeSynther{}, song, false)
|
||||
if err != nil {
|
||||
t.Fatalf("Render failed: %v", err)
|
||||
}
|
||||
@ -95,7 +95,7 @@ func TestAllRegressionTests(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("could not parse the .yml file: %v", err)
|
||||
}
|
||||
buffer, err := sointu.Play(bridge.BridgeService{}, song, false)
|
||||
buffer, err := sointu.Play(bridge.NativeSynther{}, song, false)
|
||||
buffer = buffer[:song.Score.LengthInRows()*song.SamplesPerRow()] // extend to the nominal length always.
|
||||
if err != nil {
|
||||
t.Fatalf("Play failed: %v", err)
|
Reference in New Issue
Block a user