Tuesday, March 23, 2010

Rosegarden, Lilypond, Timidity and my sax lessons

I started trying to write some decent music sheets, for my sax lessons. I wanted to find some free, opensource linux alternatives to programs like Sibelius, and indeed I found them!

Fortunately, all of them are in Karmic repositories, so I just apt-get install rosegarden and this installed Lilypond, a latex-based music-typesetting (if that's a word) system, and Rosegarden, a very good stand alone GUI that not only serves to write the music, but also allows listening via MIDI (something I could do yet, but I will...)

So this post is actually about how to use Rosegarden to save a MIDI file that Timidity can play (my Timidity install just worked, while Jackd soundsystem did not). So go ahead and type some music in Rosegarden. Then export it as a .mid file. Then, timidity file.mid should already work.

Sound fonts But, the default piano sound of my cheap soundcard is far from nice. I wanted to install some sound banks ("sound fonts"). There are some of them here.

Unpacking? I downloaded a file 1276-Soft Tenor Sax.sfpack. Now, how to open it? First problem, there is no sfpack-unpacker for linux. There is a small DOS utility here that runs fine under Wine, so I used it: run wine SFPACK.EXE, click Add Files, select the .sfpack file, and click Go. This unpacks the file 1276-Soft Tenor Sax.sf2, which is something the sound card (or the midi system) can use.

Installing. To use the soundfont, you must give Timidity a config file. There are many config files for several fonts here, but my file was not there. So I created a very raw configuration for it. First, comment the enabled "source" line in /etc/timidity/timidity.cfg, and add a new line source /etc/timidity/my.cfg. Then, edit that new file /etc/timidity/my.cfg, adding just this content:
bank 0
0 %font "1276-Soft Tenor Sax.sf2" 0 0 tune=-14 amp=31 pan=0
Note: I am using "-12", not "-14", so other MIDIs are played on tune as well... but the reasoning is still useful so I am leaving this version in this article (See update at the end)

what this does is creating a single program "0" on bank "0", using the .sf2 file given. (Note: I put that file also in /etc/timidity, otherwise type the full path in there). The tune parameter is explained below (you can omit it). The amp tells how much to amplify, and the pan can be used to balance it to left/right (I use it in another example to send different instruments to left and right channels).

Save it wav/mp3. I wanted this as an easily playable sound file, so I ran timidity input.mid -Ow -o output.wav to convert it. My music file was just one instrument, number 0, bank 0, so it now vaguely resembles a sax (better than the original piano, at least). I later converted it to mp3 and put it on my player to study listening to it.

Tune to Bb! One caveat: I typed whas was supposed to be in C, while my tenor sax is Bb. I could have exported to Midi one tone down from Rosegarden, but I missed it. Also, the way it was originally exported it was one octave higher than the way I play that music in my sax. That's the reason of the tune=-14 parameter in my .cfg file: 14 semitones down (12 semitones = shift 1 octave down; and another tone to tune it in Bb). Note: There is an alternate, better method -- see the update at the end

Swing! One more thing -- the song I am practicing was supposed to be played with swing rithm -- that is, octaves lasts 2/3 and 1/3 of the time of a half -- but we just type them all the same way, as regular octaves. I imagined there should be an easy formula or script to apply to a Lilypond file, that could convert a regular rythm to swing... and there is! In Rosegarden, use the Quantize option (after selecting the whole file), use type=grid, base=eight, swing=100%, and make sure to check "quantize durations". That's it! I did not saved the result, but only exported it to .mid, but it sounds perfectly :)


That was my experience from last night -- while children sleep I cannot play the sax, so doing this was a funny alternative!

Update (Apr 20th): While tuning 1 tone down im timidity.cfg is possible, it does of course has side effects. Every MIDI will be shifted down... quite undesirable. Later I found that Rosegarden allows to shift instruments, so most of them in my partiture (written fo four saxophones) just appear as "-2" (one tone down) or "10" (one octave higher, but still 1 tone down) to be played in Bb.

No comments:

Post a Comment