This post has been imported from the old blog and has not yet been converted to the new syntax yet.
Time for some Monday morning fun... These days we got so many religions, why not add another one? I give you the Bits & Bytes Religion!

Unlike a lot of the single god religions, this one is polytheist, like the old Greek Gods. It's a religion focused to the IT-business. Let's take a look at the gods.

OlympiansGod of Software
Watches over every piece of software ever written, and being written at the moment. If you want to keep your software running and want to write quality software, pray to this one.

God of Hardware
The guardian of all hardware related things. Responsible for your HD crashes, but also for nano-technology.

God of Users
The 'simple' god. Responsible for the common knowledge and actions of all users. If you want users to get smart, ask him a favor.

God of Performance
The Speed God. He knows to tweak every millisecond from a piece of software or hardware, but when you make him anger he can also take revenge by making everything run so slowly you decide to start over from scratch again.

God of Maintenance
Also known as 'The Handyman'. Make him happy and you'll be able to fix everything you encounter. Make him angry and your life will be turned into a living maintenance hell.

God of Bugs
Responsible for every bug ever created, but simultaneous also in charge of 'Luck'. You'll find yourself asking favors of him a lot, to prevent you from writing accidental bugs.

And the most important one:

God of Electricity!
He who commands all other gods. Without him, there is nothing. Mostly he is a very caring god, but when he is angry, it's very very bad. Electricity outage, electrical interference. He can destroy hardware and bring every piece of software to a halt.

Now, on to the worshipping.

There's no need to go to a special building to worship them, or wear special clothes. The only thing they take into account is your motivation and happiness. When you create something and it works, be extremely happy, and when you are making something, try to make the best of it. Doing those things will please them, if you aren't motivated and you create something bad, they can get angry with you.

And here we are, a new religion :)
 
This post has been imported from the old blog and has not yet been converted to the new syntax yet.
Yesterday I explained how you could manage your iPod through Windows Explorer. Having this ability opens up more powerful ways of managing your iPod. One of these ways for example is the ability to automatically sync your master archive stored on your computer, with your iPod. In my case it's stored in FLAC format to retain all it's quality, since FLAC is a lossless format.

Armed with TagLib#, LAME, FLAC and a nice function to recursively search through a directory for files, I slapped together a small synchronization application for myself.

On my iPod I have the following batch file, EncodeLibrary.bat, stored:

[code]@ECHO OFF
ECHO Running: '%~d0\LibrarySync.exe %~d0\ C:\Media\Music %~d0\Music'
ECHO Encodes to MP3 with: -V 4 --vbr-new
%~d0\LibrarySync.exe %~d0\ C:\Media\Music %~d0\Music
ECHO Done.[/code]

This file simply calls my utility, LibrarySync.exe, and passes in the drive it is running on (%~d0), The Archive and the target directory. In my application I then simply scan for all available FLAC files, through a wildcard search, in the archive and trigger an action whenever a file is found.

[csharp]static void Main(string[] args)
{
/* Note to blog reader: These used to be constants, never properly refactored it since it was a quick and dirty personal app. */
DRIVE = args[0];
FROMDIR = args[1];
TODIR = args[2];

ScanDirectory scanDirectory = new ScanDirectory();

scanDirectory.FileEvent += new ScanDirectory.FileEventHandler(scanDirectory_FileEvent);
scanDirectory.SearchPattern = "*.flac";

scanDirectory.WalkDirectory(FROMDIR);
}
[/csharp]

Whenever a FLAC file is found, I check if the target MP3 already exists, and in case it doesn't exist yet, I call a Convert.bat file. I've chosen to use an external batch file to handle the copying, this way I can simply open it up in a text editor and change the encoding quality or the paths to the encoder.

After encoding the file, I take the meta data from the original FLAC file and place it in the target MP3 ID3v1 and ID3v2 tags. This way my iPod can read out the file details and organize it easily in it's catalog.

[csharp]static void scanDirectory_FileEvent(object sender, FileEventArgs e)
{
string from = e.Info.FullName;
string to = TODIR + e.Info.FullName.Remove(0, FROMDIR.Length).Replace(".flac", ".mp3");
string toDir = TODIR + e.Info.DirectoryName.Remove(0, FROMDIR.Length);

if (!IO.File.Exists(to))
{
if (!IO.Directory.Exists(toDir))
{
IO.Directory.CreateDirectory(toDir);
}

Console.WriteLine("Writing " + to);

Process convertFile = new Process();
convertFile.StartInfo.UseShellExecute = false;
convertFile.StartInfo.RedirectStandardOutput = false;

convertFile.StartInfo.FileName = DRIVE + "Convert.bat";
convertFile.StartInfo.Arguments = "\"" + from + "\" \"" + to + "\"";
convertFile.Start();

convertFile.WaitForExit();

Flac.File flacFile = new Flac.File(from);
TagLib.Tag flacTag = flacFile.GetTag(TagLib.TagTypes.FlacMetadata, false);

TagLib.File mp3File = TagLib.File.Create(to);
MP3.Tag mp3Tag = mp3File.GetTag(TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag;
MP3Old.Tag mp3OldTag = mp3File.GetTag(TagLib.TagTypes.Id3v1) as TagLib.Id3v1.Tag;

if (flacTag.Album != null) { mp3Tag.Album = flacTag.Album; }
if (flacTag.FirstPerformer != null) { mp3Tag.Performers = new string [] { flacTag.FirstPerformer }; }
if (flacTag.Title != null) { mp3Tag.Title = flacTag.Title; }
if (flacTag.Year != 0) { mp3Tag.Year = flacTag.Year; }
if (flacTag.FirstGenre != null) { mp3Tag.Genres = new string [] { flacTag.FirstGenre }; }
if (flacTag.Track != 0) { mp3Tag.Track = flacTag.Track; }

if (flacTag.Album != null) { mp3OldTag.Album = flacTag.Album; }
if (flacTag.FirstPerformer != null) { mp3OldTag.Performers = new string [] { flacTag.FirstPerformer }; }
if (flacTag.Title != null) { mp3OldTag.Title = flacTag.Title; }
if (flacTag.Year != 0) { mp3OldTag.Year = flacTag.Year; }
if (flacTag.FirstGenre != null) { mp3OldTag.Genres = new string [] { flacTag.FirstGenre }; }
if (flacTag.Track != 0) { mp3OldTag.Track = flacTag.Track; }

mp3File.Save();

Console.WriteLine();
}
}[/csharp]

The content of my Convert.bat file looks like this:

[code]@ECHO OFF
"%~d0\Tools\FLAC\flac.exe" --decode --stdout --silent %1 | "%~d0\Tools\LAME\latest\lame.exe" -V 4 --vbr-new - %2[/code]

It simply encodes the FLAC file to a VBR MP3 with a target bitrate of 165kbps.

All said and done, this is how the tool looks like in action:

Encoding FLAC files to MP3

When I connect my iPod, I usually follow these steps from now on:

  • Run reTune to manage my songs in Windows Explorer.

  • Run EncodeLibrary to encode possible missing songs.

  • Run reTune to organize them back into my iPod.

  • Disconnect and listen to music.


I created a small zip file for anyone who would like to set something like this up for himself as well. To use it, simply follow the following steps:

  • Extract the zip file to the root of your iPod.

  • Edit EncodeLibrary.bat to point to your master archive, and the target folder.

  • Get the FLAC and LAME files and place them in a folder called Tools. Look at Convert.bat to determine the exact paths.

  • Run EncodeLibrary.bat from a command prompt, and with a bit of luck it'll work for you. If not, leave a comment and I'll see what I can do for you.


Do you know of other cool things I could create for my iPod? Comment and let me know!
 
This post has been imported from the old blog and has not yet been converted to the new syntax yet.
Do you own an iPod? Are you tired of using iTunes? If you answered positive to both questions, read on! reTune is your solution.

reTune is a very small, but useful, tool which you store on your iPod and every time you connect to your computer (or any computer for that matter, since you'll be free of iTunes), you double click just one file and you will be able to manage your iPod music collection through Windows Explorer!

When you run it for the first time, it will scan your iPod for MP3 files, read out the artist, title and album information and store it in Apple's proprietary iPod format. I advise to start using reTune from an empty iPod, since it will not magically extract music already on your iPod. Read these detailed instructions before using it.

reTune keeps a kind of mapping file between the location where the music file initially was located, and where it is stored after syncing. When you plug your iPod back in, and rerun reTune, it will move the file back out of the iPod, making it visible in the file system and allowing you to manage your collection, just remember to sync them back into the iPod afterwards :)

Here's a sample session of using reTune:

I connect my iPod, which holds a copy of The Archive in MP3 format, from some time ago, and run reTune.

iPod connected - reTune

From this point on, I can manage the files on my iPod through Windows Explorer and add or remove music.

iPod Windows Explorer

When I'm done organizing my files, I run reTune again, which moves everything back into the iPod.

iPod before disconnect - reTune

After this I simply remove my iPod and off I go, ready to hit the road again, but now with my updated music collection. And at no single point I needed iTunes or was I bothered by DRM restrictions, I should be able to play all the music I bought in my local music store on all devices I own. And I can.

iTunes fanboy? Anti-DRM? Speak up and spark the discussion!
 
This post has been imported from the old blog and has not yet been converted to the new syntax yet.
You're an audiophile, and you wish to listen to music in the highest possible quality, but on the other hand, you don't have that much disk space at your disposal to store everything as wave files. What are you to do?

Meet Free Lossless Audio Codec, or FLAC for the friends. A codec which allows you to store your music digitally without any loss of quality from the original source, but not as big as storing huge wave files. Unlike as with MP3 where data is discarded, resulting in an audible quality loss. MP3 is called a lossy format, while FLAC is lossless.

FLAC is a reasonably unknown player among the general public, but it's here to stay and become mainstream. There is a reasonable selection of hardware devices out there already who can playback FLAC files, while most respectable music players will play them on your PC, Winamp being one of them.

A small summary of the most important features of the FLAC format:

  • Lossless, no quality is lost when compressing the sound.

  • Fast, the algorithm was designing to support very fast playback.

  • Metadata, you can store all sorts of information in it to display when playing.

  • Archiving, since a flac file is of the exact quality, you can convert it easily to lossy formats, like MP3.

  • No DRM, there is no DRM on all flac files out there, for now.


You can already buy FLAC music from smaller record companies, or find some free music recorded as FLAC files. Or you could simply store your own CD collection as FLAC files with this nice guide. Storing these files needs a bit more space than storing MP3 files however. To give you a small idea, these are the sizes and compression ratios (lower is better) after I archived my own CD collection:

TransporterI noticed that 'sung' music usually ends up with smaller files. I'm not sure why, but my guess is that there are more moments of silence when a person sings and grasps for breath, unlike electronic music where it's a constant stream. On the other hand, you'd expect electronic music to have recurring patterns and compress better. I'd have to withhold giving a good explanation for this, because I don't know either.

My personal approach towards FLAC is to have all the discs I have physically in the house, stored digitally on a central file server. After which I will stream the FLAC files itself to a high-end Hi-Fi setup, as if the disc itself would be playing on a normal CD player. But I will also be writing some automation tools to easily convert The Archive to other formats when needed, for example to play on my iPod.

If you're serious about music, I'd strongly recommend having a look at the FLAC format, the devices, software and possibilities, you won't regret it, even if you don't use it. Knowledge is power after all!

Are you using FLAC already? Leave some feedback on how you use it, and possible nice tools.
 
This post has been imported from the old blog and has not yet been converted to the new syntax yet.
Visual Studio is a great editor! But when editing other file formats I miss the coloring.

When working with PHP files, it's great to be able to make a solution to organize php sources, and having code open in tabs, but when they all look black and white, I find it requires more focus on my part when coding.

Long ago, I wrote a piece on getting coloring to work in Visual Studio 2002 and 2003. Somehow I managed to skip doing any PHP development during the entire lifetime of Visual Studio 2005, but recently I had to create something small, and I missed my nice colors. I tried to apply my old method in Visual Studio 2008 (Orcas), and this is the result:

Visual Studio 2008 - PHP

Looks pretty appetizing, doesn't it?

To get this in Visual Studio 2008, do the following:

  • Download vs-php.zip and extract it somewhere.

  • Execute the preferred registry file (php_edit2008.reg for Visual Studio 2008 ofcourse).

  • This will create a File Extension association for PHP files, treating them as C++ files.

  • Copy the usertype.dat to your VS.NET directory. (default C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE)

  • Restart Visual Studio if it was opened.

  • Open a .php file and admire the colors!


For this to work, you need to have C++ support installed! Otherwise the usertype.dat file will not work, since this is specific to .cpp files. You don't need to install everything for C++, only the following will already work:

Visual Studio 2008 - Setup C++

When you look in the registry, you will see that the .php extension looks exactly like the .cpp one, you can also try experimenting with applying the .cs or .html filter to a .php file, but I found them both lacking. Using the .cs value, you will get coloring from C#, but it will also give you lots of syntax warnings. When using the .html one, it doesn't always color the entire file.

If you want to color more keywords, open up the usertype.dat file in a text editor, and simply add more words to it.

Enjoy the extra productivity gain!