The English Hymnal - Wiki Music Experiment/midiconversion

From DPWiki
Jump to navigation Jump to search

How to Convert Midi to Lilypond

The midi2ly program is included in Lilypond and can be found in \usr\bin. It is a command line utility which can be used to convert midi files to Lilypond format. It has been used with some success as a method of quickly typesetting the hymns in this project. However there are a few peculiarities to beware of.

First of all, the conversion program tends to insert a lot of extra code. The computer understands it just fine, and it will compile correctly, but it is very unreadable. Here is an example of Lilypond format straight after conversion from midi:

trackAchannelA =  {
  
  \time 4/4 
  

  \key g \major
  
  \tempo 4 = 120 
  
  \tempo 4 = 92 
  
}

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


trackBchannelA = \relative c {
  
  % [SEQUENCE_TRACK_NAME] Church Organ
  s2 d'4 g |
  % 2
  g s8 fis g4 b |
  % 3
  b a d d |
  % 4
  d4. c8 b4 a |
  % 5
  b2 d,4 g |

It can be tidied up quite quickly but you need a good text editor which can search by regular expressions. A few nifty global search and replace operations, a few renaming of identifiers and the code will be human-readable within minutes. Here's some of the things that need to be changed:


  • Changes in tempo or time signature. Remove extraneous ones, and just keep one which best matches the measure divisions in the image.


  • Remove unnecessary blocks of data like the "trackA" above.


  • Rename wanted blocks of notation to more standard names. E.g. rename "trackBchannelA" to "soprano". You probably want relative c' instead of relative c for soprano and alto.


  • Notice that the import program inserts a linebreak at every measure, and inserts a comment like "% 2" to every other line. Remove these comments with search and replace. For example search for "% \d\n" and replace it with "".


  • The notation has a linebreak at every bar. It is usable, but it is easier to check if the measures are split so that they match the notation on the original image. I tend to join all the measures together and reinsert the linebreaks.


  • The score block is probably not usable because it uses the original voice identifier names. Simply copy and paste a score block from a previously done piece.
  • That's about it. It is still faster than entering notes yourself.