paulrosen / abcjs

javascript for rendering abc music notation
Other
1.9k stars 281 forks source link

Plugin for generating custom pattern for jazz chords #879

Closed presidento closed 1 year ago

presidento commented 1 year ago

As I see in abcjs the jazz chords pattern cannot be set (see %%MIDI gchord option). Unfortunately the built-in pattern does not fit for me in most of the cases. I'm thinking of writing a plugin which translates the jazz chords after the parsing phase into abc notation. Do you think it is feasible? Can you give me a hint where to start?

For example I'd like to see this:

Q:70
L:1/8
M:4/4
K:Bb
"Gm"zFGB"Eb"d4 | "Bb"c3B"Dm7"c2d2 | "Gm"zFGB"Eb"d2e2 | "Bb"dcBd"Dm7"f4 ||

And I'd like to hear something similar:

%%MIDI drum dddd 76 77 77 77 90 90 90 90 
%%MIDI drumon
Q:70
L:1/8
M:4/4
K:Bb
V:T
zFGBd4 | c3Bc2d2 | zFGBd2e2 | dcBdf4 ||
V:B bass
%%MIDI program 76
!pppp! [G,,G,B,D]4 [E,,E,G,B,]4 | [B,,B,DF]4 [D,,D,F,A,]4 | [G,,G,B,D]4 [E,,E,G,B,]4 | [B,,B,DF]4 [D,,D,F,A,]4 ||
paulrosen commented 1 year ago

This isn't pretty, but you could set the callback for sequenceCallback and replace the chord track with whatever you want. I guess in your case you'd move the chords from the second and fourth beats to the first and third. This is an untested example:

function sequenceCallback(tracks) {
  var chordTrack = tracks[1]
  for (var i = 0; i < chordTrack.length; i++) {
    var note = chordTrack[i]
    var measurePosition = (''+note.start).split('.')[1]
    if (measurePosition === "25" || measurePosition === "75") {
      note.start -= 0.25
      note.end -= 0.25
    }
  }
}

I guess the real solution, though, is to support the %%MIDI gchord option. That could be done mostly in abc_midi_flattener.js in the resolveChords() function. That's a bit harder, though.

presidento commented 1 year ago

I see, thank you.