Automatic charset detection for MIDI import (mozilla code)