Skip to content
Feb 28 / kkrizka

GO CANADA GO!

Feb 28 / kkrizka

Symphony of Science – The Poetry of Reality

Yesterday John Boswell released a new song in his Symphony Of Science series called The Poetry of Reality. This one stars scientists like Michael Shermer, Jacob Bronowski, Carl Sagan, Neil deGrasse Tyson, Richard Dawkins, Jill Tarter, Lawrence Krauss, Richard Feynman, Brian Greene, Stephen Hawking, Carolyn Porco, and PZ Myers. You can download the MP3 here.

Feb 8 / kkrizka

LEGO Domino Row Building Machine

Now someone just has to create that robot with an NXT brick inside it and have follow preprogrammed paths.

[via: Woodgears]

Jan 5 / kkrizka

Announcing libmidi, A Very Simple MIDI File Library

I spent the last few days of my winter vacation experimenting with generating random music. This was inspired by my simple NXT Dancer robot, which currently just plays random tones. The idea behind this latest experiment is that (1) I build a probability density function of played notes from well known music and (2) I use that PDF to pick the notes to be played next, based on the previous note. I will post more details about this in a few days. But the important part is that I used MIDI files, which contain commands like “play this note” and “use this volume” to recreate the actual music.

Being lazy, I decided not to search a lot (I trie a bit) for a pre-made library for reading MIDI files and instead I decided to create my own. The result is libmidi, a very simple MIDI reading and writing library. To parse a MIDI file, just do this:

MIDI::File file("/path/to/file.mid");
file.open();

Then the contents of that file are available as they were found in the MIDI file. For example, to get a track and print out all of the events (the commands that tell the MIDI synchronizer what to do), do this:

MIDI::Track* track=file.track(0);
for(int j=0;j<track->numEvents();j++)
{
   MIDI::Event* event=track->event(j);
   event->debug();
}

Also libmidi contains a basic write support. You can add new events to the end of a track and call the MIDI::File::write() function to save the file that the track represents. See the randommusic example, included in the libmidi-0.1 package, on how to do this.

The downside to using the libmidi library right now is that it is not well developed yet. For example, there are only a few functions to modify the MIDI file (ei: tracks can only be appended to the end of the track) and not all meta event types have a nice define yet. Of course, I plan to fix this in the future.

But for now, you can download version 0.1 or checkout the latest development code at GitHUB. The API documentation is available here.

For more information about MIDI files, check out these websites:

Jan 1 / kkrizka

Fix WordPress’ Over-zealous XHTML Compliance Interfering With wp-syntax

Over the last few days, I’ve noticed that WordPress started converting all of the special HTML characters into their proper HTML entities (ei: & will be translated into &amp;), even though I explicitly specified that I do want the character itself. This interfered with the wp-syntax plugin that I use when I post snippets of code, because the plugin assumes that non-HTML encoded code is being used. It applied the conversion to HTML entities after all that is done. But now because of WordPress’ over-zealous compliance to XHTML specs, when the following is part of a post:

<pre lang=”php”>if(true && false) echo “Hello World”;</pre>

You will see the following:

if(true &amp;&amp; false) echo "Hello World";

Luckily, the fix is quite simple. It does not even involve using the seemingly abandoned role-manager plugin as suggested by wp-syntax’s FAQ. Just add the escaped=”true” argument to the pre tag, and wp-syntax will decode the HTML entities for you automatically. Now

<pre lang=”php” escaped=”true”>if(true && false) echo “Hello World”;</pre>

turns into

if(true && false) echo "Hello World";

To make things easier, I suggest that you install the wp-syntax-button plugin. This plugin adds a “Code” button to the visual WordPress editor, using which you can automatically highlight any code without having to switch to the HTML editor. And of course, the wp-syntax-button plugin automatically adds the escaped=”true” argument.