Skip to content
Jun 11 / kkrizka

AutoRotate 0.4.1 Released

Today I took some time to update the AutoRotate daemon to work with Ubuntu Lucid. There were a few small changes that I had to make, so I decided to slightly increment the version of the package. You can download the source code here. Also Ubuntu users can install it automatically from my PPA.

Change Log

  • Use xsetwacom –list to get a list of all WACOM devices

The next addition I am planning to work on next is to write a simple indicator menu to control the daemon. I’ve created a post on the Ubuntu Forums asking for suggestions.

Jun 7 / kkrizka

Symphony of Science – The Case For Mars

This is the sixth installment in the Symphony of Science musical series. This one includes Robert Zubrin, Carl Sagan, Brian Cox, and Penelope Boston. The topic is the exploration … or colonization… of Mars!

The MP3 version can be downloaded from the Symphony of Science website.

Apr 20 / kkrizka

Converting Between kCGWindowBounds and NSWindow#frame

kCGWindowBounds is a field in a dictionary returned by the CGWindowListCopyWindowInfo function. This fields lists the dimensions of a window displayed by the Quartz Window System (Mac OS X’s analogue of X11). I was trying to use this field to resize a NSWindow object that I was controlling, with the idea to create a window picker. The problem is that kCGWindowBounds’ coordinates are not the same ones as used by NSWindow’s frame property, and it took me a while to realize this. Which is why I am sharing what I found out.

Both kCGWindowBounds and NSWindow’s frame property are instances of CGRect (technically, NSWindow uses a NSRect but all literature I found says it is equivalent to CGRect). This object has two attributes; a point (origin) and dimensions (size). The difference between the CGRect returned by kCGWindowBounds and NSWindow’s frame property is that:

  • kCGWindowBounds measures the origin as the top-left corner of the rectangle relative to the top-left corner of the screen
  • NSWindow’s frame property measures the origin as the bottom-left corner of the rectangle relative to the bottom-left corner of the screen

So if you want to convert between the two representations of the same information, you have to do the following. It is the same conversion if you are going from kCGWindowBounds to NSWindow#frame or in the other direction.

bounds.origin.y=[[NSScreen mainScreen] frame].size.height-bounds.origin.y-bounds.size.height;
Apr 19 / kkrizka

Installing a Hard Drive Into The Antec 900 Case

My main desktop computer, tiny101, recently run out of hard disk space. Instead of clearing out everything, I decided to visit NCIX and purchase 2 new 2 TB drives (Western Digital). However when I started installing them, I realized that my previous storage disk (1 TB, Samsung) was not installed properly. It was just placed into one of the trays and connected to the motherboard. As you can imagine, this is not good for it. In this tutorial, I plan to go over how I rectified this problem by properly installing the hard drive into my Antec Nine Hundred Gaming Case.

Before I begin with the tutorial, I want to say that Antec has great customer support. The Antec 900 case requires special hard drive screws, which I did not have. But when I asked them where I can buy those screws, this was their response:

We can send the part/s out to you. Please reply back with your postal address.

They did not charge for the parts or even ask to see a receipt to prove that I own an Antec case. After this experience, I am quite glad that three years ago I chose an Antec case.

Requirements

  • Antec 900 Case, but I would imagine that the other cases in the family have similar instructions.
  • 4 Antec 900 hard drive screws, per disk. These are special long screws and not the standard short screws. You should have received as spare set with your case, but if you lost them you can always contact Antec support and ask for more.
  • 1 SATA cable, per disk. I am assuming that your bought a SATA disk. If you have a different type of disk, you can still follow these instructions to install the disk into into the case. However you are on your own when it comes connecting the disk to the mother board.
  • 1 hard disk (DUh?)
  • Phillips head screw-driver, for the hard drive screws.
  • A vaccum cleaner. Since your case is open, I recommend that you take some time to clean out some of the dust.

Instructions

  1. Disconnect all of the external cables from the case and move the somewhere with a lot of space.
  2. Remove 4 of the big, black screws on the back of the case. There are two on each side, holding down the side panels. You do not need a screw-driver for them, instead use your hands. After you remove them, place them in a place where you won’t loose them.
  3. Remove the two side panels by moving them towards the back of the case for one centimeter, and then pulling them toward you.
  4. Disconnect any already connected hard drives. Make sure to remember how they were connected, because you will have to reconnect them later. If you are installing your hard drive in a cage different from the current hard drive, you can skip this step. The hard drive can be put into any of the two cages located in the front (each cage holds up to 3 hard drives). A cage is just a small box that can be pulled out from the case. Take a quick look at the picture in step 8 to see what a cage looks like.
  5. Disconnect the fans of the cage that you will be installing the hard drive into. Each fan is connected only to the power supply by a two thin wires. You can find those wires at the back of the case, as demonstrated in one of the pictures above. Then just follow the two wires until you reach the power cable. Both wires are connected to the power supply via the same plug. Unplug that plug, but remember which one it was! You will have to reconnect the fans after you are done!
  6. Unscrew the thumb grayscrews from the cage that you will be using. There are two screws on each side of the cage (thus 4 in total). Place those screws somewhere safe, but make sure not to mix them up with the black screws from the side panels. They are different!
  7. Gently pull out the cage through the front. Start by pushing it from inside the cage and end by pulling it from the outside after you can get a good grip. If for some reason you get stuck, investigate why! Maybe you forgot to unplug some wires. One more friendly warning: If you have not cleaned your computer in some time, make sure to have a vacuum cleaner turned on when you do this step. A handful of dust is guaranteed to come out.
  8. Put the cage somewhere where you can see it.
  9. Place your disk inside one of the free compartments inside the cage. Look at the picture above to see what a free compartment looks like.
  10. Make sure you place the disk in a way such that the connectors stick out. In the picture, I placed my new disk into the second compartment from bottom.
  11. Look for holes on the side of the cage. After you found them, screw the long hard drive screws into them. They should go through the cage and into the hard drive. Remember that there are 2 screws per side of the cage (4 in total). You will need a Phillips head screw driver for this.
  12. Slide the cage back into the case. Make sure to put in the fan wires first. This is essentially step 7 in reverse.
  13. Reconnect the fans (and any old disks) you disconnected earlier.
  14. Connect the new hard drive to the motherboard. I described how to do it in the next section of this tutorial.
  15. Put in the gray thumbscrews to hold the cage in place. If you forgot where they came from, then look at the picture above. They go through the wide slits.
  16. Slide the two side panels back by doing step 3 in reverse. This step can be quite tricky, because there are slits in the side panels that the case has go through. After you are done, the panels should fit snuggly into the case.
  17. Fasten the side panels by screwing in the black thumbscrews on the back.
  18. Now you have successfully installed a hard drive in the Antec 900 case! In the next few steps, I will guide you through how to connect it to the motherboard (which you should already have done in step 14…). I assume your disk was SATA (very common for personal computers).

Connecting A SATA Hard Drive to the Motherboard

  1. Familiarize yourself with the important ports on your hard drive. I described them above.
  2. Find an empty SATA power plug comming from your power supply. They look something like this. In my case, the plugs have “S-ATA 3” written on them.
  3. Connect the plug to the power port on the hard drive. The plug goes in at a specific orentation. The yellow cable should point toward the motherboard. You should have located the port in step 1.
  4. Find an empty SATA plug on your motherboard. They look something like in the picture above.
  5. Connect one end of the SATA cable into that plug. It does not matter which end of the cable you plug in, because both ends are the same. But there is a specific orientation at which the cable goes into the plug. Look at the shape of the plug and the cable to figure out which way it should go in. Sadly, there are no easy markings to describe it.
  6. Connect the other end of the SATA cable into the SATA port on your hard disk. You should have located the port in step 1.
  7. Turn on your computer and enter the BIOS. It should have detected your hard drive, if you have done everything correctly.

Further Resources

Mar 9 / kkrizka

Generating Random Music

A while ago, I wrote a tutorial on how to get the NBC/NXC running on Linux in order to program an Mindstorm NXT brick. In the tutorial, I posted an example script that turns the robot into a dancer and plays some music. The only problem is that the music was just set of random frequencies and thus was unbearable to listen to. So I though, is there a way to make it less random without the need to make it play the same thing over and over again?

Experimenting with this idea lead me to write the libmidi library. MIDI files are a collection of notes, so it seemed as the best format to use. It allowed me to just generate random notes and tell the MIDI player to play them in some order. The library also includes an example called randommusic, but just does the same thing as the dancing robot. It just plays 128 random notes. This is what it sounds like:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

I am no expert on music theory, but from what I understand most songs contain only notes in one scale. And the idea also works the other way, playing notes in a scale can result in a song. The song won’t be a masterpiece, but it will be bearable. Since I am too lazy to pre-program every possible scale, I decided that I will only limit notes to ones found in an existing song instead of a scale.

After analyzing Piano Sonata No.1, that I grabbed from Kunst der Fuge some time ago, I get the following result:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

It sounds much better than before, but it still sounds like it is all over the place. To fix this, I applied one more change to how the next note is picked by looking at one more piece of information when analyzing the song; the note that was played previously. That is if note B never follows note A in the existing song, then it should never do so in the random music. Here is the result:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

That was a big improvement! I think that is where I will stop working on this. But more tweaks could be done in the future:

  • Add random rhythm
  • Analyze multiple songs

Of course, the code still needs to be ported to NXT to make a much more improved dancer robot.

The script that I wrote to do this can be downloaded here and is released under the GPL3 license. To use it, you need to have libmidi and ROOT installed. This is how it works:

  1. Analyze the song
    ./analyze input.mid output.root
  2. Generate a random tune.
    • The first argument is the track of the orignal song to analyze, and should be set as track1, track2 and so on. Also you can set it to song, which uses all tracks.
    • The second argument is the ROOT file with the analyzed song created in step 1
    • The third argument is the output MIDI where the result will be saved
    • The fourth argument is optional. Specifying it will ignore any previous note conditional probability.
    ./generate track input.root output.mid [unconditional]