From 61437db0d67d270aaf903c98131b2e26428dd864 Mon Sep 17 00:00:00 2001 From: vsariola <5684185+vsariola@users.noreply.github.com> Date: Thu, 21 Jan 2021 13:16:41 +0200 Subject: [PATCH] refactor(sointu): add explicit RowsPerPattern to the song --- bridge/bridge_test.go | 2 +- compiler/patterns.go | 2 +- compiler/patterns_test.go | 3 +++ sointu.go | 17 +++++++---------- templates/amd64-386/player.h | 2 +- tests/test_add.yml | 1 + tests/test_add_stereo.yml | 1 + tests/test_addp.yml | 1 + tests/test_addp_stereo.yml | 1 + tests/test_aux.yml | 1 + tests/test_aux_stereo.yml | 1 + tests/test_chords.yml | 1 + tests/test_clip.yml | 1 + tests/test_clip_stereo.yml | 1 + tests/test_compressor.yml | 1 + tests/test_compressor_stereo.yml | 1 + tests/test_crush.yml | 1 + tests/test_crush_stereo.yml | 1 + tests/test_delay.yml | 1 + tests/test_delay_dampmod.yml | 1 + tests/test_delay_drymod.yml | 1 + tests/test_delay_feedbackmod.yml | 1 + tests/test_delay_flanger.yml | 1 + tests/test_delay_notetracking.yml | 1 + tests/test_delay_pregainmod.yml | 1 + tests/test_delay_reverb.yml | 1 + tests/test_delay_stereo.yml | 1 + tests/test_distort.yml | 1 + tests/test_distort_mod.yml | 1 + tests/test_distort_stereo.yml | 1 + tests/test_envelope.yml | 1 + tests/test_envelope_mod.yml | 1 + tests/test_envelope_stereo.yml | 1 + tests/test_filter_band.yml | 1 + tests/test_filter_freqmod.yml | 1 + tests/test_filter_high.yml | 1 + tests/test_filter_low.yml | 1 + tests/test_filter_peak.yml | 1 + tests/test_filter_resmod.yml | 1 + tests/test_filter_stereo.yml | 1 + tests/test_gain.yml | 1 + tests/test_gain_stereo.yml | 1 + tests/test_hold.yml | 1 + tests/test_hold_mod.yml | 1 + tests/test_hold_stereo.yml | 1 + tests/test_in.yml | 1 + tests/test_in_stereo.yml | 1 + tests/test_invgain.yml | 1 + tests/test_invgain_stereo.yml | 1 + tests/test_loadnote.yml | 1 + tests/test_loadnote_stereo.yml | 1 + tests/test_loadval.yml | 1 + tests/test_loadval_stereo.yml | 1 + tests/test_mul.yml | 1 + tests/test_mul_stereo.yml | 1 + tests/test_mulp.yml | 1 + tests/test_mulp_stereo.yml | 1 + tests/test_multiple_instruments.yml | 1 + tests/test_noise.yml | 1 + tests/test_noise_stereo.yml | 1 + tests/test_oscillat_colormod.yml | 1 + tests/test_oscillat_detunemod.yml | 1 + tests/test_oscillat_gainmod.yml | 1 + tests/test_oscillat_gate.yml | 1 + tests/test_oscillat_lfo.yml | 1 + tests/test_oscillat_phasemod.yml | 1 + tests/test_oscillat_pulse.yml | 1 + tests/test_oscillat_sample.yml | 1 + tests/test_oscillat_sample_stereo.yml | 1 + tests/test_oscillat_shapemod.yml | 1 + tests/test_oscillat_sine.yml | 1 + tests/test_oscillat_stereo.yml | 1 + tests/test_oscillat_transposemod.yml | 1 + tests/test_oscillat_trisaw.yml | 1 + tests/test_oscillat_unison.yml | 1 + tests/test_oscillat_unison_stereo.yml | 1 + tests/test_outaux.yml | 1 + tests/test_outaux_stereo.yml | 1 + tests/test_panning.yml | 1 + tests/test_panning_stereo.yml | 1 + tests/test_polyphony.yml | 1 + tests/test_pop.yml | 1 + tests/test_pop_stereo.yml | 1 + tests/test_push.yml | 1 + tests/test_push_stereo.yml | 1 + tests/test_receive.yml | 1 + tests/test_receive_stereo.yml | 1 + tests/test_send.yml | 1 + tests/test_send_global.yml | 1 + tests/test_send_stereo.yml | 1 + tests/test_speed.yml | 1 + tests/test_xch.yml | 1 + tests/test_xch_stereo.yml | 1 + tracker/defaultsong.go | 3 ++- tracker/keyevent.go | 4 ++-- tracker/songpoint.go | 12 ++++++------ tracker/track.go | 4 ++-- tracker/tracker.go | 8 ++++---- 98 files changed, 117 insertions(+), 28 deletions(-) diff --git a/bridge/bridge_test.go b/bridge/bridge_test.go index a39694b..5e07b95 100644 --- a/bridge/bridge_test.go +++ b/bridge/bridge_test.go @@ -40,7 +40,7 @@ func TestOscillatSine(t *testing.T) { sointu.Unit{Type: "out", Parameters: map[string]int{"stereo": 1, "gain": 128}}, }}}} tracks := []sointu.Track{{NumVoices: 1, Sequence: []byte{0}, Patterns: [][]byte{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}}}} - song := sointu.Song{BPM: 100, Tracks: tracks, Patch: patch} + song := sointu.Song{BPM: 100, RowsPerPattern: 16, Tracks: tracks, Patch: patch} synth, err := bridge.Synth(patch) if err != nil { t.Fatalf("Compiling patch failed: %v", err) diff --git a/compiler/patterns.go b/compiler/patterns.go index b0ed2fc..a877ac7 100644 --- a/compiler/patterns.go +++ b/compiler/patterns.go @@ -167,7 +167,7 @@ func bytesToInts(array []byte) []int { } func ConstructPatterns(song *sointu.Song) ([][]byte, [][]byte, error) { - patLength := song.PatternRows() + patLength := song.RowsPerPattern sequences := make([][]byte, len(song.Tracks)) var patterns [][]int for i, t := range song.Tracks { diff --git a/compiler/patterns_test.go b/compiler/patterns_test.go index 8d37094..425c355 100644 --- a/compiler/patterns_test.go +++ b/compiler/patterns_test.go @@ -10,6 +10,7 @@ import ( func TestPatternReusing(t *testing.T) { song := sointu.Song{ + RowsPerPattern: 8, Tracks: []sointu.Track{{ Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 0, 0}, {72, 0, 0, 0, 0, 0, 0, 0}}, Sequence: []byte{0, 1}, @@ -34,6 +35,7 @@ func TestPatternReusing(t *testing.T) { func TestUnnecessaryHolds(t *testing.T) { song := sointu.Song{ + RowsPerPattern: 8, Tracks: []sointu.Track{{ Patterns: [][]byte{{64, 1, 1, 1, 0, 1, 0, 0}, {72, 0, 1, 0, 1, 0, 0, 0}}, Sequence: []byte{0, 1}, @@ -58,6 +60,7 @@ func TestUnnecessaryHolds(t *testing.T) { func TestDontCares(t *testing.T) { song := sointu.Song{ + RowsPerPattern: 8, Tracks: []sointu.Track{{ Patterns: [][]byte{{64, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}}, Sequence: []byte{0, 1}, diff --git a/sointu.go b/sointu.go index 6d1bffe..9f1094f 100644 --- a/sointu.go +++ b/sointu.go @@ -254,9 +254,10 @@ var UnitTypes = map[string]([]UnitParameter){ } type Song struct { - BPM int - Tracks []Track - Patch Patch + BPM int + RowsPerPattern int + Tracks []Track + Patch Patch } func (s *Song) Copy() Song { @@ -267,16 +268,12 @@ func (s *Song) Copy() Song { return Song{BPM: s.BPM, Tracks: tracks, Patch: s.Patch.Copy()} } -func (s *Song) PatternRows() int { - return len(s.Tracks[0].Patterns[0]) -} - func (s *Song) SequenceLength() int { return len(s.Tracks[0].Sequence) } func (s *Song) TotalRows() int { - return s.PatternRows() * s.SequenceLength() + return s.RowsPerPattern * s.SequenceLength() } func (s *Song) SamplesPerRow() int { @@ -350,8 +347,8 @@ func Play(synth Synth, song Song) ([]float32, error) { buffer := make([]float32, 0, initialCapacity) rowbuffer := make([]float32, song.SamplesPerRow()*2) for row := 0; row < song.TotalRows(); row++ { - patternRow := row % song.PatternRows() - pattern := row / song.PatternRows() + patternRow := row % song.RowsPerPattern + pattern := row / song.RowsPerPattern for t := range song.Tracks { patternIndex := song.Tracks[t].Sequence[pattern] note := song.Tracks[t].Patterns[patternIndex][patternRow] diff --git a/templates/amd64-386/player.h b/templates/amd64-386/player.h index 5811671..35ebcbc 100644 --- a/templates/amd64-386/player.h +++ b/templates/amd64-386/player.h @@ -7,7 +7,7 @@ #define SU_SAMPLE_RATE 44100 #define SU_BPM {{.Song.BPM}} -#define SU_PATTERN_SIZE {{.Song.PatternRows}} +#define SU_PATTERN_SIZE {{.Song.RowsPerPattern}} #define SU_MAX_PATTERNS {{.Song.SequenceLength}} #define SU_TOTAL_ROWS (SU_MAX_PATTERNS*SU_PATTERN_SIZE) #define SU_SAMPLES_PER_ROW (SU_SAMPLE_RATE*4*60/(SU_BPM*16)) diff --git a/tests/test_add.yml b/tests/test_add.yml index 3d5f264..98de67d 100644 --- a/tests/test_add.yml +++ b/tests/test_add.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_add_stereo.yml b/tests/test_add_stereo.yml index 61b144e..58bebad 100644 --- a/tests/test_add_stereo.yml +++ b/tests/test_add_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_addp.yml b/tests/test_addp.yml index 16cc459..1cdae02 100644 --- a/tests/test_addp.yml +++ b/tests/test_addp.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_addp_stereo.yml b/tests/test_addp_stereo.yml index b38a4d1..8407593 100644 --- a/tests/test_addp_stereo.yml +++ b/tests/test_addp_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_aux.yml b/tests/test_aux.yml index 3f9749f..317571b 100644 --- a/tests/test_aux.yml +++ b/tests/test_aux.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_aux_stereo.yml b/tests/test_aux_stereo.yml index 5bb5470..e21e0fd 100644 --- a/tests/test_aux_stereo.yml +++ b/tests/test_aux_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_chords.yml b/tests/test_chords.yml index e3b794b..3977cfc 100644 --- a/tests/test_chords.yml +++ b/tests/test_chords.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_clip.yml b/tests/test_clip.yml index 3dc2df2..74e71e8 100644 --- a/tests/test_clip.yml +++ b/tests/test_clip.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_clip_stereo.yml b/tests/test_clip_stereo.yml index 2542364..8cef67a 100644 --- a/tests/test_clip_stereo.yml +++ b/tests/test_clip_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_compressor.yml b/tests/test_compressor.yml index ec3351a..121ff6d 100644 --- a/tests/test_compressor.yml +++ b/tests/test_compressor.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_compressor_stereo.yml b/tests/test_compressor_stereo.yml index fd377d5..eead46c 100644 --- a/tests/test_compressor_stereo.yml +++ b/tests/test_compressor_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_crush.yml b/tests/test_crush.yml index 5f1a18f..fc05acb 100644 --- a/tests/test_crush.yml +++ b/tests/test_crush.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_crush_stereo.yml b/tests/test_crush_stereo.yml index 6ec3e4e..a417085 100644 --- a/tests/test_crush_stereo.yml +++ b/tests/test_crush_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay.yml b/tests/test_delay.yml index c0ad7d9..9e7146a 100644 --- a/tests/test_delay.yml +++ b/tests/test_delay.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay_dampmod.yml b/tests/test_delay_dampmod.yml index e4144e4..a2968c4 100644 --- a/tests/test_delay_dampmod.yml +++ b/tests/test_delay_dampmod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay_drymod.yml b/tests/test_delay_drymod.yml index 13c42c2..733a58a 100644 --- a/tests/test_delay_drymod.yml +++ b/tests/test_delay_drymod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay_feedbackmod.yml b/tests/test_delay_feedbackmod.yml index 5e63bfe..8e07db8 100644 --- a/tests/test_delay_feedbackmod.yml +++ b/tests/test_delay_feedbackmod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay_flanger.yml b/tests/test_delay_flanger.yml index 4711808..3e5b815 100644 --- a/tests/test_delay_flanger.yml +++ b/tests/test_delay_flanger.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay_notetracking.yml b/tests/test_delay_notetracking.yml index 9e3146e..f9747fe 100644 --- a/tests/test_delay_notetracking.yml +++ b/tests/test_delay_notetracking.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay_pregainmod.yml b/tests/test_delay_pregainmod.yml index fd21177..6edc98d 100644 --- a/tests/test_delay_pregainmod.yml +++ b/tests/test_delay_pregainmod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay_reverb.yml b/tests/test_delay_reverb.yml index 4aa2df7..1a9aa36 100644 --- a/tests/test_delay_reverb.yml +++ b/tests/test_delay_reverb.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_delay_stereo.yml b/tests/test_delay_stereo.yml index a40d95d..985cea3 100644 --- a/tests/test_delay_stereo.yml +++ b/tests/test_delay_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_distort.yml b/tests/test_distort.yml index 783b4cb..e8ef272 100644 --- a/tests/test_distort.yml +++ b/tests/test_distort.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_distort_mod.yml b/tests/test_distort_mod.yml index 5971be5..7bcf09d 100644 --- a/tests/test_distort_mod.yml +++ b/tests/test_distort_mod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_distort_stereo.yml b/tests/test_distort_stereo.yml index 33320b7..7fe6f84 100644 --- a/tests/test_distort_stereo.yml +++ b/tests/test_distort_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_envelope.yml b/tests/test_envelope.yml index 47eee6a..44f8725 100644 --- a/tests/test_envelope.yml +++ b/tests/test_envelope.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_envelope_mod.yml b/tests/test_envelope_mod.yml index 3d2250b..07f2d88 100644 --- a/tests/test_envelope_mod.yml +++ b/tests/test_envelope_mod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_envelope_stereo.yml b/tests/test_envelope_stereo.yml index 6ae333f..9bf8894 100644 --- a/tests/test_envelope_stereo.yml +++ b/tests/test_envelope_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_filter_band.yml b/tests/test_filter_band.yml index 39ee2b4..2e24afe 100644 --- a/tests/test_filter_band.yml +++ b/tests/test_filter_band.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_filter_freqmod.yml b/tests/test_filter_freqmod.yml index 469410c..9b130b9 100644 --- a/tests/test_filter_freqmod.yml +++ b/tests/test_filter_freqmod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_filter_high.yml b/tests/test_filter_high.yml index 9e965d7..2d89af8 100644 --- a/tests/test_filter_high.yml +++ b/tests/test_filter_high.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_filter_low.yml b/tests/test_filter_low.yml index d697851..f632c72 100644 --- a/tests/test_filter_low.yml +++ b/tests/test_filter_low.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_filter_peak.yml b/tests/test_filter_peak.yml index c3f8b7d..2ea2a0f 100644 --- a/tests/test_filter_peak.yml +++ b/tests/test_filter_peak.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_filter_resmod.yml b/tests/test_filter_resmod.yml index 69b54bc..e5a1c39 100644 --- a/tests/test_filter_resmod.yml +++ b/tests/test_filter_resmod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_filter_stereo.yml b/tests/test_filter_stereo.yml index 4e353b2..cdf77fc 100644 --- a/tests/test_filter_stereo.yml +++ b/tests/test_filter_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_gain.yml b/tests/test_gain.yml index 33e4a89..9a66b9f 100644 --- a/tests/test_gain.yml +++ b/tests/test_gain.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_gain_stereo.yml b/tests/test_gain_stereo.yml index c00c2f5..5659eda 100644 --- a/tests/test_gain_stereo.yml +++ b/tests/test_gain_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_hold.yml b/tests/test_hold.yml index 00d3fcb..6bbf6b5 100644 --- a/tests/test_hold.yml +++ b/tests/test_hold.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_hold_mod.yml b/tests/test_hold_mod.yml index 6c0641c..cd69f54 100644 --- a/tests/test_hold_mod.yml +++ b/tests/test_hold_mod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_hold_stereo.yml b/tests/test_hold_stereo.yml index 274e3b6..1bdec88 100644 --- a/tests/test_hold_stereo.yml +++ b/tests/test_hold_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_in.yml b/tests/test_in.yml index b77fe0e..f37e7c3 100644 --- a/tests/test_in.yml +++ b/tests/test_in.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_in_stereo.yml b/tests/test_in_stereo.yml index 0b8ffbe..44961fb 100644 --- a/tests/test_in_stereo.yml +++ b/tests/test_in_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_invgain.yml b/tests/test_invgain.yml index 629a065..0408666 100644 --- a/tests/test_invgain.yml +++ b/tests/test_invgain.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_invgain_stereo.yml b/tests/test_invgain_stereo.yml index 554faf6..0aa0025 100644 --- a/tests/test_invgain_stereo.yml +++ b/tests/test_invgain_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_loadnote.yml b/tests/test_loadnote.yml index 0497f9d..6d86821 100644 --- a/tests/test_loadnote.yml +++ b/tests/test_loadnote.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_loadnote_stereo.yml b/tests/test_loadnote_stereo.yml index 25fcec0..96226f2 100644 --- a/tests/test_loadnote_stereo.yml +++ b/tests/test_loadnote_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_loadval.yml b/tests/test_loadval.yml index e30c3fb..963d0fa 100644 --- a/tests/test_loadval.yml +++ b/tests/test_loadval.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_loadval_stereo.yml b/tests/test_loadval_stereo.yml index a27d3e4..2635f0c 100644 --- a/tests/test_loadval_stereo.yml +++ b/tests/test_loadval_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_mul.yml b/tests/test_mul.yml index ad104d9..3b4b9f1 100644 --- a/tests/test_mul.yml +++ b/tests/test_mul.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_mul_stereo.yml b/tests/test_mul_stereo.yml index 3ade7f2..d0af25c 100644 --- a/tests/test_mul_stereo.yml +++ b/tests/test_mul_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_mulp.yml b/tests/test_mulp.yml index 5960d9b..921d6f9 100644 --- a/tests/test_mulp.yml +++ b/tests/test_mulp.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_mulp_stereo.yml b/tests/test_mulp_stereo.yml index 9689083..7d8d4a9 100644 --- a/tests/test_mulp_stereo.yml +++ b/tests/test_mulp_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_multiple_instruments.yml b/tests/test_multiple_instruments.yml index c3e26e7..892326a 100644 --- a/tests/test_multiple_instruments.yml +++ b/tests/test_multiple_instruments.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_noise.yml b/tests/test_noise.yml index 833471a..43bda20 100644 --- a/tests/test_noise.yml +++ b/tests/test_noise.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_noise_stereo.yml b/tests/test_noise_stereo.yml index bdcf6a6..34e136f 100644 --- a/tests/test_noise_stereo.yml +++ b/tests/test_noise_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_colormod.yml b/tests/test_oscillat_colormod.yml index 2e28013..4d8fe5f 100644 --- a/tests/test_oscillat_colormod.yml +++ b/tests/test_oscillat_colormod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_detunemod.yml b/tests/test_oscillat_detunemod.yml index 24aa841..273cdf4 100644 --- a/tests/test_oscillat_detunemod.yml +++ b/tests/test_oscillat_detunemod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_gainmod.yml b/tests/test_oscillat_gainmod.yml index 7dbdeab..9cee4a7 100644 --- a/tests/test_oscillat_gainmod.yml +++ b/tests/test_oscillat_gainmod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_gate.yml b/tests/test_oscillat_gate.yml index fd3f89e..28e1307 100644 --- a/tests/test_oscillat_gate.yml +++ b/tests/test_oscillat_gate.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_lfo.yml b/tests/test_oscillat_lfo.yml index 494527b..4d7d6ea 100644 --- a/tests/test_oscillat_lfo.yml +++ b/tests/test_oscillat_lfo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_phasemod.yml b/tests/test_oscillat_phasemod.yml index 6d99ae0..abd0fc1 100644 --- a/tests/test_oscillat_phasemod.yml +++ b/tests/test_oscillat_phasemod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_pulse.yml b/tests/test_oscillat_pulse.yml index 95333f6..b91978e 100644 --- a/tests/test_oscillat_pulse.yml +++ b/tests/test_oscillat_pulse.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_sample.yml b/tests/test_oscillat_sample.yml index f5cb00b..175641b 100644 --- a/tests/test_oscillat_sample.yml +++ b/tests/test_oscillat_sample.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 8 tracks: - numvoices: 1 sequence: [1, 0, 2, 0, 3, 0, 4, 0] diff --git a/tests/test_oscillat_sample_stereo.yml b/tests/test_oscillat_sample_stereo.yml index faac4cc..beebdb4 100644 --- a/tests/test_oscillat_sample_stereo.yml +++ b/tests/test_oscillat_sample_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 8 tracks: - numvoices: 1 sequence: [1, 0, 2, 0, 3, 0, 4, 0] diff --git a/tests/test_oscillat_shapemod.yml b/tests/test_oscillat_shapemod.yml index 108f3df..27a69cc 100644 --- a/tests/test_oscillat_shapemod.yml +++ b/tests/test_oscillat_shapemod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_sine.yml b/tests/test_oscillat_sine.yml index 35e566f..ae07570 100644 --- a/tests/test_oscillat_sine.yml +++ b/tests/test_oscillat_sine.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_stereo.yml b/tests/test_oscillat_stereo.yml index ff53466..f571492 100644 --- a/tests/test_oscillat_stereo.yml +++ b/tests/test_oscillat_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_transposemod.yml b/tests/test_oscillat_transposemod.yml index da4e07c..dc00e56 100644 --- a/tests/test_oscillat_transposemod.yml +++ b/tests/test_oscillat_transposemod.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_trisaw.yml b/tests/test_oscillat_trisaw.yml index 7bcd1f4..8906078 100644 --- a/tests/test_oscillat_trisaw.yml +++ b/tests/test_oscillat_trisaw.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_unison.yml b/tests/test_oscillat_unison.yml index f28a39e..fd6a159 100644 --- a/tests/test_oscillat_unison.yml +++ b/tests/test_oscillat_unison.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_oscillat_unison_stereo.yml b/tests/test_oscillat_unison_stereo.yml index 4c00681..5bf1032 100644 --- a/tests/test_oscillat_unison_stereo.yml +++ b/tests/test_oscillat_unison_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_outaux.yml b/tests/test_outaux.yml index dc1c980..d1f779e 100644 --- a/tests/test_outaux.yml +++ b/tests/test_outaux.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_outaux_stereo.yml b/tests/test_outaux_stereo.yml index 0cd549b..28bdc84 100644 --- a/tests/test_outaux_stereo.yml +++ b/tests/test_outaux_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_panning.yml b/tests/test_panning.yml index ffa044e..3b505b3 100644 --- a/tests/test_panning.yml +++ b/tests/test_panning.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_panning_stereo.yml b/tests/test_panning_stereo.yml index 1cf6041..b41abc5 100644 --- a/tests/test_panning_stereo.yml +++ b/tests/test_panning_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_polyphony.yml b/tests/test_polyphony.yml index f7a375e..3b1a93c 100644 --- a/tests/test_polyphony.yml +++ b/tests/test_polyphony.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 2 sequence: [0] diff --git a/tests/test_pop.yml b/tests/test_pop.yml index fc8ca5e..460bfb8 100644 --- a/tests/test_pop.yml +++ b/tests/test_pop.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_pop_stereo.yml b/tests/test_pop_stereo.yml index 343c51f..04e662d 100644 --- a/tests/test_pop_stereo.yml +++ b/tests/test_pop_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_push.yml b/tests/test_push.yml index 6d7cba9..9449a8c 100644 --- a/tests/test_push.yml +++ b/tests/test_push.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_push_stereo.yml b/tests/test_push_stereo.yml index 9e7198f..ad096e8 100644 --- a/tests/test_push_stereo.yml +++ b/tests/test_push_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_receive.yml b/tests/test_receive.yml index a65bd95..b731a79 100644 --- a/tests/test_receive.yml +++ b/tests/test_receive.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_receive_stereo.yml b/tests/test_receive_stereo.yml index f84b3c9..c0c2254 100644 --- a/tests/test_receive_stereo.yml +++ b/tests/test_receive_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_send.yml b/tests/test_send.yml index f52880b..7b2b00e 100644 --- a/tests/test_send.yml +++ b/tests/test_send.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_send_global.yml b/tests/test_send_global.yml index f0fedb1..666193d 100644 --- a/tests/test_send_global.yml +++ b/tests/test_send_global.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_send_stereo.yml b/tests/test_send_stereo.yml index cf0a9cf..5095d9e 100644 --- a/tests/test_send_stereo.yml +++ b/tests/test_send_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_speed.yml b/tests/test_speed.yml index 09ba207..c49f66f 100644 --- a/tests/test_speed.yml +++ b/tests/test_speed.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0, 0] diff --git a/tests/test_xch.yml b/tests/test_xch.yml index ed84837..eff947c 100644 --- a/tests/test_xch.yml +++ b/tests/test_xch.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tests/test_xch_stereo.yml b/tests/test_xch_stereo.yml index 6b6ff07..ca12ece 100644 --- a/tests/test_xch_stereo.yml +++ b/tests/test_xch_stereo.yml @@ -1,4 +1,5 @@ bpm: 100 +rowsperpattern: 16 tracks: - numvoices: 1 sequence: [0] diff --git a/tracker/defaultsong.go b/tracker/defaultsong.go index 5138071..c4b269f 100644 --- a/tracker/defaultsong.go +++ b/tracker/defaultsong.go @@ -13,7 +13,8 @@ var defaultInstrument = sointu.Instrument{ } var defaultSong = sointu.Song{ - BPM: 100, + BPM: 100, + RowsPerPattern: 16, Tracks: []sointu.Track{ {NumVoices: 2, Sequence: []byte{0, 0, 0, 1}, Patterns: [][]byte{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}, {64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 75, 0, 75, 0, 80, 0}}}, {NumVoices: 2, Sequence: []byte{0, 0, 0, 1}, Patterns: [][]byte{{0, 0, 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0}, {32, 0, 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 68, 0, 68, 0}}}, diff --git a/tracker/keyevent.go b/tracker/keyevent.go index bfd3cde..ffa3d83 100644 --- a/tracker/keyevent.go +++ b/tracker/keyevent.go @@ -75,7 +75,7 @@ func (t *Tracker) KeyEvent(e key.Event) bool { case key.NameUpArrow: delta := -1 if e.Modifiers.Contain(key.ModCtrl) { - delta = -t.song.PatternRows() + delta = -t.song.RowsPerPattern } t.Cursor.Row += delta t.Cursor.Clamp(t.song) @@ -87,7 +87,7 @@ func (t *Tracker) KeyEvent(e key.Event) bool { case key.NameDownArrow: delta := 1 if e.Modifiers.Contain(key.ModCtrl) { - delta = t.song.PatternRows() + delta = t.song.RowsPerPattern } t.Cursor.Row += delta t.Cursor.Clamp(t.song) diff --git a/tracker/songpoint.go b/tracker/songpoint.go index 52a52c1..e5f105c 100644 --- a/tracker/songpoint.go +++ b/tracker/songpoint.go @@ -18,21 +18,21 @@ type SongRect struct { } func (r *SongRow) Wrap(song sointu.Song) { - totalRow := r.Pattern*song.PatternRows() + r.Row - r.Row = mod(totalRow, song.PatternRows()) - r.Pattern = mod((totalRow-r.Row)/song.PatternRows(), song.SequenceLength()) + totalRow := r.Pattern*song.RowsPerPattern + r.Row + r.Row = mod(totalRow, song.RowsPerPattern) + r.Pattern = mod((totalRow-r.Row)/song.RowsPerPattern, song.SequenceLength()) } func (r *SongRow) Clamp(song sointu.Song) { - totalRow := r.Pattern*song.PatternRows() + r.Row + totalRow := r.Pattern*song.RowsPerPattern + r.Row if totalRow < 0 { totalRow = 0 } if totalRow >= song.TotalRows() { totalRow = song.TotalRows() - 1 } - r.Row = totalRow % song.PatternRows() - r.Pattern = ((totalRow - r.Row) / song.PatternRows()) % song.SequenceLength() + r.Row = totalRow % song.RowsPerPattern + r.Pattern = ((totalRow - r.Row) / song.RowsPerPattern) % song.SequenceLength() } func (p *SongPoint) Wrap(song sointu.Song) { diff --git a/tracker/track.go b/tracker/track.go index e51b3dd..dae2cd8 100644 --- a/tracker/track.go +++ b/tracker/track.go @@ -26,7 +26,7 @@ func (t *Tracker) layoutTrack(trackNo int) layout.Widget { op.Offset(f32.Pt(0, float32(gtx.Constraints.Max.Y/2)-trackRowHeight)).Add(gtx.Ops) // TODO: this is a time bomb; as soon as one of the patterns is not the same length as rest. Find a solution // to fix the pattern lengths to a constant value - cursorSongRow := t.Cursor.Pattern*t.song.PatternRows() + t.Cursor.Row + cursorSongRow := t.Cursor.Pattern*t.song.RowsPerPattern + t.Cursor.Row op.Offset(f32.Pt(0, (-1*trackRowHeight)*float32(cursorSongRow))).Add(gtx.Ops) patternRect := SongRect{ Corner1: SongPoint{SongRow: SongRow{Pattern: t.Cursor.Pattern}, Track: t.Cursor.Track}, @@ -38,7 +38,7 @@ func (t *Tracker) layoutTrack(trackNo int) layout.Widget { } for i, s := range t.song.Tracks[trackNo].Sequence { if patternRect.Contains(SongPoint{Track: trackNo, SongRow: SongRow{Pattern: i}}) { - paint.FillShape(gtx.Ops, activeTrackColor, clip.Rect{Max: image.Pt(trackWidth, trackRowHeight*t.song.PatternRows())}.Op()) + paint.FillShape(gtx.Ops, activeTrackColor, clip.Rect{Max: image.Pt(trackWidth, trackRowHeight*t.song.RowsPerPattern)}.Op()) } for j, c := range t.song.Tracks[trackNo].Patterns[s] { songRow := SongRow{Pattern: i, Row: j} diff --git a/tracker/tracker.go b/tracker/tracker.go index 0c24854..0f43277 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -188,7 +188,7 @@ func (t *Tracker) AddTrack() { t.SaveUndo() if t.song.TotalTrackVoices() < t.song.Patch.TotalVoices() { seq := make([]byte, t.song.SequenceLength()) - patterns := [][]byte{make([]byte, t.song.PatternRows())} + patterns := [][]byte{make([]byte, t.song.RowsPerPattern)} t.song.Tracks = append(t.song.Tracks, sointu.Track{ NumVoices: 1, Patterns: patterns, @@ -233,7 +233,7 @@ func (t *Tracker) SetCurrentPattern(pat byte) { if int(pat) >= length { tail := make([][]byte, int(pat)-length+1) for i := range tail { - tail[i] = make([]byte, t.song.PatternRows()) + tail[i] = make([]byte, t.song.RowsPerPattern) } t.song.Tracks[t.Cursor.Track].Patterns = append(t.song.Tracks[t.Cursor.Track].Patterns, tail...) } @@ -261,8 +261,8 @@ func (t *Tracker) SetSongLength(value int) { } func (t *Tracker) getSelectionRange() (int, int, int, int) { - r1 := t.Cursor.Pattern*t.song.PatternRows() + t.Cursor.Row - r2 := t.SelectionCorner.Pattern*t.song.PatternRows() + t.SelectionCorner.Row + r1 := t.Cursor.Pattern*t.song.RowsPerPattern + t.Cursor.Row + r2 := t.SelectionCorner.Pattern*t.song.RowsPerPattern + t.SelectionCorner.Row if r2 < r1 { r1, r2 = r2, r1 }