Konubinix' opinionated web of thoughts

Midi to Music Sheet Using Lilypond

fleeting

midi to music sheet using lilypond

create music sheet for my kids.

For example, using “le petit cochon pendu au plafond”.

cochon.mid

Using midi2ly.

midi2ly cochon.mid

Then, using the snippet to color notes, changing the staff to make it more piano like and removing the silences.

I get this source code.

% Lily was here -- automatically converted by /usr/bin/midi2ly from b.mid
\version "2.14.0"

%LSR Thanks a LOT to Damian leGassick, Steven Weber and Jay Anderson for this snippet

%Association list of pitches to colors.
#(define color-mapping
   (list
    (cons (ly:make-pitch 0 0 NATURAL) (x11-color 'red))
    (cons (ly:make-pitch 0 0 SHARP) (x11-color 'green))
    (cons (ly:make-pitch 0 1 FLAT) (x11-color 'yellow))
    (cons (ly:make-pitch 0 1 NATURAL) (x11-color 'blue))
    (cons (ly:make-pitch 0 2 NATURAL) (x11-color 'red))
    (cons (ly:make-pitch 0 2 SHARP) (x11-color 'green))
    (cons (ly:make-pitch 0 3 FLAT) (x11-color 'red))
    (cons (ly:make-pitch 0 3 NATURAL) (x11-color 'yellow))
    (cons (ly:make-pitch 0 3 SHARP) (x11-color 'blue))
    (cons (ly:make-pitch 0 4 FLAT) (x11-color 'blue))
    (cons (ly:make-pitch 0 4 SHARP) (x11-color 'red))
    (cons (ly:make-pitch 0 4 NATURAL) (x11-color 'red))
    (cons (ly:make-pitch 0 5 FLAT) (x11-color 'red))
    (cons (ly:make-pitch 0 5 NATURAL) (x11-color 'yellow))
    (cons (ly:make-pitch 0 5 SHARP) (x11-color 'blue))
    (cons (ly:make-pitch 0 6 FLAT) (x11-color 'blue))
    (cons (ly:make-pitch 0 6 SHARP) (x11-color 'red))
    (cons (ly:make-pitch 0 6 NATURAL) (x11-color 'red))
    ))

%Compare pitch and alteration (not octave).
#(define (pitch-equals? p1 p2)
   (and
    (= (ly:pitch-alteration p1) (ly:pitch-alteration p2))
    (= (ly:pitch-notename p1) (ly:pitch-notename p2))))

#(define (pitch-to-color pitch)
   (let ((color (assoc pitch color-mapping pitch-equals?)))
     (if color
         (cdr color))))

#(define (color-notehead grob)
   (pitch-to-color
    (ly:event-property (event-cause grob) 'pitch)))


\layout {
  \context {
    \Voice
    \remove "Note_heads_engraver"
    \consists "Completion_heads_engraver"
    \remove "Rest_engraver"
    \consists "Completion_rest_engraver"
  }
}

trackAchannelA = {

  \time 2/4

  \tempo 4 = 100

}

trackA = <<
  \context Voice = voiceA \trackAchannelA
>>


trackBchannelA = {
  \skip 4*6432/240
}

trackBchannelB = \relative c {
    \override NoteHead.color = #color-notehead

g''4*96/240 g4*96/240 a4*96/240 a4*96/240

  g4*192/240

  g4*96/240 g4*96/240 a4*96/240 a4*96/240

  g4*192/240
  g4*96/240 g4*96/240 a4*96/240 a4*96/240

  g4*192/240
  g4*96/240 g4*96/240 a4*96/240 a4*96/240

  g4*192/240
  g4*96/240 g4*96/240 a4*96/240 a4*96/240

  a4*192/240
  g4*96/240 g4*96/240 a4*96/240 d4*96/240

  g,4*192/240 g4*96/240
  a4*96/240 g4*96/240 a4*96/240 d4*96/240

  g,4*192/240
}

trackB = <<
  \context Voice = voiceA \trackBchannelA
  \context Voice = voiceB \trackBchannelB
>>


\score {
  <<
    \context Staff=trackB \trackA
    \context Staff=trackB \trackB
  >>
  \layout {}
  \midi {}
}

And it generates the following image.

lilypond -o cochon --png cochon-midi.ly

play some of my favorite musics

For instance, cosmo canyon.

By playing a bit with the generated lilypond score, I get this result.

canyon-midi.ly

And it generates this sheet.

canyon-page1.png

canyon-page2.png

canyon-page3.png

canyon-page4.png

canyon-page5.png

I colored the tracks to that I can see which notes I want to put in the clef F and which ones in the clef G. Unfortunately, some tracks should be split into both. That means that I should identify the notes interval to capture from one track and to put into another track.

I found a sheet of Aeris’ theme.

Aeris-Theme-Aerith-piano-sheet-music.pdf

It helps having a reference to find out whether the conversion works well. On the other hand, the sheet is about the music reworked to be played in a piano, while the midi is not.

aeris.mid

aeris-midi.ly

Just taking the few first pages

🤔

conclusion

It looks to me like going from midi to piano note sheets it harder than looking for the piano sheet in the first place. It was a nice introduction to understanding a bit more about music and how one can write piano sheets with LilyPond.