Sunday, March 28, 2010

Odd 1366x768 LCD res on Nvidia

I bought a LCD monitor (LG Flatron W1943S) months ago for my mother. This desktop PC runs Kubuntu 9.04 with an NVidia 6600 card. I had never been able to fix a problem: about 60 pixels of overscan to the right, which is very awful and annoying specially when you need to move scrollbar...

(My mother with infinite patience has moved too many windows to the left to pick these missing buttons... I would have already thrown the monitor out the window.)

Some further debugging today let me find this:

First, the native resolution 1366x768 is not supported by nvida (the card? the driver?). You need exact 16:9, or multiples of 8, I igore it -- the point is that you need to get the modeline for 1368 horizontal pixels; I used this to generate it and put it on xorg.conf:

$ gtf 1366 768 60
# 1368x768 @ 60.00 Hz (GTF) hsync: 47.70 kHz; pclk: 85.86 MHz
Modeline "1368x768_60.00" 85.86 1368 1440 1584 1800 768 769 772 795

(In Screen section, under a Display subsection, added Modes "1368x768_60.00")
It also works with 1360x768, I still don't know which one is better.

Then, the most important part was in the monitor itself: I read in a forum (about different hardware I think) that there was a "reset to factory defaults" in the monitor. So, afer setting this resolution, I navigated through the unintuitive OSD monitor menu, under Setup - in the last screen - last option is Factory Reset. That simply accomodated all the pixels within the screen! And easier: There is an "auto/set" button that appears to be the same! All this time I was looking for a xorg vs. drivers vs. monitor configuration issue, I never thought it would be that simple.

I am still trying to get a real 1:1 sampling, I see some pixels appearing as "blurred" horizontally. Suggestions are welcome...

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.