Skip to content

Commit

Permalink
don't inject a bass note when chords change mid-measure if the patter…
Browse files Browse the repository at this point in the history
…n doesn't start on a bass note.
  • Loading branch information
paulrosen committed Jun 18, 2024
1 parent bdbc461 commit 296221a
Show file tree
Hide file tree
Showing 2 changed files with 164 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/synth/chord-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,11 @@ ChordTrack.prototype.resolveChords = function (startTime, endTime) {
firstBoom = true
var type = thisPattern[p]
var isBoom = type.indexOf('boom') >= 0
// If we changed chords at a time when we're not expecting a bass note, then add an extra bass note in.
var newBass = !isBoom && p !== 0 && (!currentChordsExpanded[p-1] || currentChordsExpanded[p-1].boom !== currentChordsExpanded[p].boom)
// If we changed chords at a time when we're not expecting a bass note, then add an extra bass note in if the first thing in the pattern is a bass note.
var newBass = !isBoom &&
p !== 0 &&
thisPattern[0].indexOf('boom') >= 0 &&
(!currentChordsExpanded[p-1] || currentChordsExpanded[p-1].boom !== currentChordsExpanded[p].boom)
var pitches = resolvePitch(currentChordsExpanded[p], type, firstBoom, newBass)
if (isBoom)
firstBoom = false
Expand Down
164 changes: 159 additions & 5 deletions tests/synth/flattener.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,9 @@ describe("Audio flattener", function() {
'%%MIDI chordprog 72\n' +
'%%MIDI chordvol 23\n' +
'K:C\n' +
'"C"z4|"G7"z4|\n'
'"C"z4|"G7"z2z"C"z|\n' +
'%%MIDI gchord GHIHghih\n' +
'"C"z4|"G7"z2z"C"z|\n'

var expectedChordArpeggio =
{
Expand Down Expand Up @@ -2875,7 +2877,16 @@ describe("Audio flattener", function() {
},
{
"cmd": "note",
"pitch": 74,
"pitch": 36,
"volume": 125,
"start": 1.75,
"duration": 0.125,
"gap": 0,
"instrument": 10
},
{
"cmd": "note",
"pitch": 67,
"volume": 23,
"start": 1.75,
"duration": 0.125,
Expand All @@ -2884,18 +2895,161 @@ describe("Audio flattener", function() {
},
{
"cmd": "note",
"pitch": 71,
"pitch": 64,
"volume": 23,
"start": 1.875,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 48,
"volume": 23,
"start": 2,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 52,
"volume": 23,
"start": 2.125,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 55,
"volume": 23,
"start": 2.25,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 52,
"volume": 23,
"start": 2.375,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 60,
"volume": 23,
"start": 2.5,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 64,
"volume": 23,
"start": 2.625,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 67,
"volume": 23,
"start": 2.75,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 64,
"volume": 23,
"start": 2.875,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 55,
"volume": 23,
"start": 3,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 59,
"volume": 23,
"start": 3.125,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 62,
"volume": 23,
"start": 3.25,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 59,
"volume": 23,
"start": 3.375,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 67,
"volume": 23,
"start": 3.5,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 71,
"volume": 23,
"start": 3.625,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 67,
"volume": 23,
"start": 3.75,
"duration": 0.125,
"gap": 0,
"instrument": 72
},
{
"cmd": "note",
"pitch": 64,
"volume": 23,
"start": 3.875,
"duration": 0.125,
"gap": 0,
"instrument": 72
}
]
],
"totalDuration": 2
"totalDuration": 4
}

//////////////////////////////////////////////////////////

var abcChordSwing = 'X: 1\n' +
Expand Down

0 comments on commit 296221a

Please sign in to comment.