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.

Thursday, February 25, 2010

Install Ubuntu from Alternate CD image; booting from USB flash drive

I recently tried a couple of ubuntu versions, installing them on a partition to play a few hours. In the process I re-discovered unetbootin, a wonderful tool for this: I burned the CD ISO images in a USB flash drive, instead of burning CDs (even if you use rewritable, it is slower than a USB key). UNetbootin let's you make a bootable pendrive from any ISO image; you can even download your favorite distro CD from there.

The main comment of this post is, however, not just the unetbootin process, but two tips that solved issues with these images.

First, the simpler one: You have to mark the partition in the USB drive as bootable, or you will not be able to boot... To do this, run fdisk /dev/sdb (or whichever your drive's device is), and add its boot flag.

The second on is subtler. With the Ubuntu 9.10 Desktop CD everything worked perfectly; I was able to boot. But later I tried the Alternate CD, which after booting it could not find the contents of the "CD" it was installing from. Somehow it missed the point it had boot from USB; so there would not be any contents on CD-ROM to read (in fact, that machine does not even have a CD drive). What I had to do was to add a flag to the kernel boot options: When UNetbootin starts, before pressing Enter on the "Default" option, press Tab to edit it. Edit the kernel line, to make it look like this one:
/ubnkern initrd=/ubninit vga=normal cdrom-detect/try-usb=true -- quiet

(Everything should be in a single line). Your line might not be identical; but the important part is to add "cdrom-detect/try-usb=true" before the "--". With this option the installer found the contents and was able to continue the rest of the install process.

Wednesday, February 24, 2010

Resizing a VirtualBox bootable WinXP drive

I have a couple of Windows images running in VirtualBox machines. (Yes I only boot linux, but still have a couple of windows images confined to their VMs). They ran out of diskspace; I created too small disks. I had attempted to solve this by adding increasingly larger secondary disks; but Windows does not like small "C:" partitions; sooner or later problems arise.

I found tips from several places about how to do this so I am going to compile my experience here. Since VDI images cannot be just resized (disk geometry can be altered), one needs to move the data to another VDI disk. The procedure is then: 1) Create a new (bigger) disk, 2) Clone the old disk into the new disk, 3) replace the disk in the virtual machine.

So far, that's more or less simple if the disk is not the primary, bootable disk. But I tried cloning with Acronis TrueImage, GParted and a couple of other tools, and they all resulted in an unbootable disk with "Disk reader error, press Ctrl+Alt+Del" message when trying to boot. I tried using the windows recovery console rebuild the MBR (fixmbr.exe) or the boot sector (fixboot.exe) but none of them worked. The extra tip was touching a parameter in the boot sector of the disk... find the details below.

Before you start, you might want to backup your entire VDI image; just in case (none of these steps will modify it... but there is always the case of selecting the wrong option).

All the steps then look like:
  1. Create the disk

    1. Shut down the virtual Windows machine
    2. From VirtualBox disk manager, create a new disk (bigger!), and attach it as secondary to that machine.

  2. Copy data. Use some cloning tool to copy the entire disk from the old disk to the new one. In my case, I found the simpler way was:

    1. Download a GParted LiveCD,
    2. Add it to the list of VirtualBox ISO images,
    3. Mount it on the virtual machine, and make sure the CDROM is first in boot order sequence.
    4. Boot GParted. Select the old disk/partition, click "Copy". Select the new disk, create on "Create Partition Table" (type "MSDOS"), then click "Paste" to bring the new data. In the resizing dialog, you can extend the partition to the end of the disk. Click "Apply" and it will take a while until the partition is copied. Then go to "Manage Flags" and enable the "Boot" flag.
    5. Shutdown the virtual machine; remove the ISO cd image.

  3. Enable the new disk (You might want to try seeing if the new disk just boots -- If you do not get a "Disk Read Error" message, skip next steps and you are done!).

    1. Start the virtual machine (still with the old disk as primary). You should be able to view the bigger, secondary disk, with the same contents as the old one.
    2. From within Windows, download Roadkil's Boot Builder. Then a) Read the boot sector of the NEW disk, b) change the "Heads" parameters to 255, c) write the sector back to the NEW disk. (Make sure not to screw up disk names! your old disk is still the backup.). See screenshot.
    3. Shutdown Windows. From VirtualBox, remove the old (smaller) disk, and leave only the new (larger) disk. Start up the VM, it will nicely boot up. (Well, Windows will boot up...)

I have no idea why that Heads parameter needs to be changed; but changing it from 128 to the magic 255 value worked for me (enlarging a 3Gb disk to 10Gb one) and others as well.

Happy cloning!

Sunday, October 11, 2009

Quick DVD authoring, with subtitles

Let's say you have a DivX movie (movie.avi) and a subtitles file (subtitles.srt) and you want to burn this into a DVD, which any player (non divx-capable) can play.

This is called DVD authoring, and there are many tools to do the job (though I have not found one that I really like, yet). For such a simple task, a few commands on the console are the simplest option.

1. Transcode move to MPEG-2

See the mencoder documentation at the end - it contains examples for other formats.
mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf \
-vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 \
-lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=5000:\
keyint=15:vstrict=0:acodec=ac3:abitrate=192:aspect=16/9 -ofps 25 \
-o movie.mpg movie.avi


2. Render and multiplex subtitles into movie

Create a file like this one, and save it as sub.xml:
<subpictures>
<stream>
<textsub filename="subtitles.srt" characterset="ISO-8859-1"
fontsize="22.0" font="devedesans.ttf"
horizontal-alignment="center"
vertical-alignment="bottom" left-margin="60"
right-margin="60"
top-margin="20" bottom-margin="40" subtitle-fps="25"
movie-fps="25" movie-width="720" movie-height="574"/>
</stream>
</subpictures>
Run spumux to create a new mpeg file with the subtitles stream:
spumux -s0 sub.xml < movie.mpg > m_subs.mpg


3. Author the DVD


Finally, we need to tell dvdauthor how to create a dvd. Create a file dvd.xml like this one:
<dvdauthor>
<vmgm>
<titleset>
<titles>
<subpicture lang="es">
<pgc>
<vob file="m_subs.mpg">
</pgc>
</titles>
</titleset>
</dvdauthor>
And run dvdauthor:
dvdauthor -o thedvd -x dvd.xml


4. Round up


Voila! The directory thedvd will contain the DVD structure (not an ISO image). You can test the results with mplayer:
mplayer dvd:// -dvd-device thedvd

and if it looks ok, just burn it into a dvd - k3b can burn this (use new Project -> movie DVD)

At the end you can delete *.mpg files, and the thedvd directory.

References:


  • mencoder on dvd authroing: http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-vcd-dvd.html
  • spumux: http://dvdauthor.sourceforge.net/doc/spumux.html

Wednesday, October 7, 2009

thunderbird: very small fonts, and links not opening in browser

I recently installed and new kubuntu on my mother's PC (yes!! finally, wiped out Windows completely!!), and of course I am the help desk support since then...

A few days ago I had the chance to solve to curious issues she was having with thunderbird. I had to google a little for both solutions:

Very small fonts: Almost everything in thunderbird had a very, very small font size: menus, message list, etc. I tried changing DPI resolution in KDE, setting global font preferences por KDE and GTK applications, with no avail. Finally the solution was to tweak a property within thunderbird:
layout.css.cpi = 0

(the default value was unset, or -1, I can't remember). So simple! I don't know what is the meaning of the property, but solved the issue and now all fonts are just like in any other application.



Clicking links does not open a browser: When reading an email with a URL, clicking on them did just nothing. I browsed every possible option in the Preferences windows, but there was nothing that fixed it. The solution, again, was hidden in the advanced preferences. I had to set a few variables:
network.protocol-handler.app.http = /usr/bin/firefox
network.protocol-handler.app.https = /usr/bin/firefox
(that can be done for ftp as well -- and any other protocol if needed).



Note: To edit the "advanced" preferences, go to Edit > Preferences > Advanced > Config Editor. Be aware that you can misconfigure it very easily from there!


Both are things far from what a regular end user could change. I wonder why the default install left things that way....

Wednesday, September 9, 2009

so many wifi clients!

Last night I ran a apt-get upgrade after some time updating anything -- over a month. It looked like mostly an update for many, many KDE packages (I think I got 4.3.1). Just in case, I rebooted -- I always do it after upgrading many packages in case something goes wrong, to make it evident. Well, something went wrong: the knetworkmanager would not connect again to my WPA-protected home wifi. As a result, I lost a couple of hours of sleep time last night... things are working again, after some fight.

I thought it would be interesting to remember how many wifi clients I used over the last year or so:
  • network manager from KDE3: I used this one for a long time. Even after starting using KDE4 (in those scary days of betas of the 4.0.x branch, where virtually nothing worked as expected), this rock-solid tool kept me connected to my wireless network. Its biggest problem was just that it was slated to die; it had the KDE3 look, and would be vanished soon. (Image from softpedia)


  • At some point, a plasmoid appeared as a replacement. This one was a nightmare at the beginning, but after some time it started to work. It never worked 100%, there where some inconsistencies (when editing networks' properties, or when showing the current state, some things did not reflect correct status). It worked for some time. (Image taken from here)


  • Just a couple of months ago (from KDE 4.3 betas?) the plasma applet changed is icon to something really ugly, and a tooltip message said that its development was incomplete and suggested to use "knetworkmanager" instead. So I moved... and well, this one worked nicely! I thought it was the end of the journey. Well integrated in KDE4, properties appearing in control panel too... some tiny features where appearing from time to time after upgrades. Very nice.
    Sadly, after yesterday's update, it did not connect anymore. I can click the network names I created, and nothing happens. Just that. I don't know how to debug it.


  • I should also mention that when these things fail, I also resort to wpa_supplicant, connecting from command line with a config file I already have pre-configured and a command line saved right there as I always, always forget the parameters. But again, this is working 100%. It keeps disconnecting, it shows a lot of errors in the console... It kind of works, and saved me sometimes. Last night it was not the exception, so I did not want to continue using it for work over weeks until finding a solution.
  • Looking for solutions last night I found wicd. I just thought 'yet another program to try'... and worse, it depended on gnome libraries so it looked like some gnome-only applet. But comments were very positive, so I tried it. Installing the package also uninstalled knetworkmanager, good job! The package also added a daemon, perfect.... and all I can say is it just works. Ok, the UI is not KDE4-ish. But I can configure everything I need, and it worked perfectly after a couple of reboots. (As a side comment: Ubuntu's repositories had a 1.5.x version, and after installing it and knowing it worked, I moved to wicd's repos which brought 1.6.2 version, which is even nicer).


This can be read as a rant against wifi support on linux. And it is, in part. ((Wireless connections have been more of a problem for me than anything else -- even more than 3d acceleration which has settled down reasonably many months (or years) ago for me. Wireless is still... a pain.)) The web is too confusing as it becomes quickly outdated; when you run a search you will find results for hundreds of methods, drivers, hardware, linux distribution, even different ubuntu versions, and none of them except one will work on your scenario.

My intention is to let others know wicd, and to receive feedback about these things, like: Am I too dumb, that I break my networking so often? Is this regular fight intended for every end user that just intends to keep his ubuntu updated? (I know I play beyond end-user-ness, and I enjoy it, but I also think ubuntu must be something an end user must be able to manage by itself).
Meanwhile... I will happily use wicd -- as long as it works :)