paulrosen / abcjs

javascript for rendering abc music notation
Other
1.94k stars 285 forks source link

Add swing to the playback #1016

Closed dranidis closed 5 months ago

dranidis commented 6 months ago

The swing is added as a parameter in synth options:

synth: {
    el: "#audio",
    options: {
      displayRestart: true, displayPlay: true, displayProgress: true,
      options: {"swing":66}
    }

The swing is represented as a percentage of the duration of the first note to the duration of the pair of eighth notes. The default is 50%, which is no swing.

Try out editor-swing.html in the examples folder.

paulrosen commented 6 months ago

Wow! This looks great and something I've wanted for a while. I will have to study it a little bit to see how it acts in some edge cases.

paulrosen commented 6 months ago

Thanks for the example! That saves me time.

dranidis commented 6 months ago

Thanks for the example! That saves me time.

Let me know if you need something changed.

By the way, congrats on the library. Great work!

paulrosen commented 5 months ago

I did find one interesting thing. If there are an odd number of pickup notes there is something odd. For instance:

X: 1
T: The Frim Fram Sauce
M: 4/4
L: 1/8
C: 1945 Joe Ricardel/Redd Evans
Q:1/4=130
K:C
P:A
^D EG|:"C6"c2 A^D E G3|c2A^D EG3|

I haven't had a chance to research it yet. If I add a "z" to the beginning it works great.

paulrosen commented 5 months ago

I fixed the issue with the odd number of pickup beats. I am ready to release now. I do have a couple more questions, though, but they can be addressed in future versions:

1) I see volumeIncrease. I guess that should probably be exposed as a parameter, like swingVolumeIncrease, but it seems fine at zero to me. Can you post an example tune that sounds better with a non-zero value for that?

2) I am not sure about the non-4/4 key sigs. I haven't done much with needing swing on them. In particular, just from looking at the code, in 6/8 I think you are swinging every other 8th note, right? But the 4th 8th note should be right on the beat, I think? That is, there are two beats per measure in 6/8, not 6. Also, shouldn't cut time have swing, too?

3) I haven't tried it, but I think there might be a problem when the tempo changes - since you are determining the place in the measure by the start time.

paulrosen commented 5 months ago

Also, when the swing is written in, I think that more swing shouldn't be added. For instance, check this out at swing:75:

T:Ain't Got Nothing But the Blues
C:Duke Ellington
M:4/4
L:1/8
Q:1/4=70
K:C
P:Verse
GA>c edcc |: "C"A3G- G4 | zGA>c "C7"edcG|"F"A3A- A4 |zGG>G AGAG|
paulrosen commented 5 months ago

And, there should be a way to override the swing in the middle of a tune, with a %%MIDI swing 50 command. That will go in a future release, too.

dranidis commented 5 months ago

I fixed the issue with the odd number of pickup beats.

Indeed, the swing needed the beats to be even. I saw your changes. They look fine.

I am ready to release now. I do have a couple more questions, though, but they can be addressed in future versions:

  1. I see volumeIncrease. I guess that should probably be exposed as a parameter, like swingVolumeIncrease, but it seems fine at zero to me. Can you post an example tune that sounds better with a non-zero value for that?

In swing, the upbeats are usually accented slightly more than the downbeats. Thus, the suggested increase of volume. The swing is even more profound when the volume of the upbeats is slightly increased, especially when the swing is set to lower values such as 55-60. Try the following with swing at 55 which is relatively low. Changing the volumeIncrease to 0.2 brings out the swing even at that low value.

T:Ornithology
M:4/4
L:1/8
Q:1/4=180
K: G
D| GABc dBcd | BG z2 z3 D| GA_Bc de2=f- |
fGA_B- B3d |
  1. I am not sure about the non-4/4 key sigs. I haven't done much with needing swing on them. In particular, just from looking at the code, in 6/8 I think you are swinging every other 8th note, right? But the 4th 8th note should be right on the beat, I think? That is, there are two beats per measure in 6/8, not 6. Also, shouldn't cut time have swing, too?

In 6/8 the 16ths swing, so the 8ths are right on the beat. See for example "All Blues" as it is written in the Real Book:

T:All Blues
M:6/8
L:1/16
Q:1/8=140
K: G
G3ded =f3ded | G3ded =f3ded |

Although, I am not aware of any swing tunes in cut time, it could be added as well.

  1. I haven't tried it, but I think there might be a problem when the tempo changes - since you are determining the place in the measure by the start time.

That's true.

dranidis commented 5 months ago

Also, when the swing is written in, I think that more swing shouldn't be added. For instance, check this out at swing:75:

T:Ain't Got Nothing But the Blues
C:Duke Ellington
M:4/4
L:1/8
Q:1/4=70
K:C
P:Verse
GA>c edcc |: "C"A3G- G4 | zGA>c "C7"edcG|"F"A3A- A4 |zGG>G AGAG|

"Explicitly" adding the dotted-sixteenth swing beats the purpose, Unless one wishes to swing only specific notes. I would write the tune as in:

T:Ain't Got Nothing But the Blues
C:Duke Ellington
M:4/4
L:1/8
Q:1/4=70
K:C
P:Verse
zGAc _edcA- |: "C"AG3- G4 | zGAc "C7"_edcA-|"F"A8 |zGAG AG_BA|