blog archive contact about feed

Rob's Blog - August 2006

Contents

Here are Rob's Blog entries for August 2006.

Blog entries for other months can be found in the main blog index.

Links for 2006-08-30

Bookmarks from del.icio.us
Entered: 2006-08-31 00:15:11
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=818

Links for 2006-08-25

Bookmarks from del.icio.us
Entered: 2006-08-26 00:15:02
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=817

Links for 2006-08-24

Bookmarks from del.icio.us
Entered: 2006-08-25 00:15:02
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=816

Links for 2006-08-23

Bookmarks from del.icio.us
Entered: 2006-08-24 00:15:07
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=815

iTunes Auto Updating Now Playing in VB2005

Previously I've covered how to link into the iTunes COM library from VB 2005 to show now playing information. This article assumes you have already read that, or have it to hand.

Taking this application further, wouldn't it be useful for our application to automatically update itself when a track changes takes place on iTunes?

Well I hope you are saying yes, as it's what I'm going to cover now.

iTunes can inform our application of changes of track if we choose to listen for it's OnPlayerPlayEvent event.

If you are not sure what an event is, it's basically a way for one program to tell another that something has happened in that program and the other program may wish to react to it. In this case, a different track has started playing in iTunes.

So how can we get our application to listen out for this? Well firstly we need to say that our programme is interested in these events. We do this by using VB 2005's WithEvents keyword when we create our interface into iTunes.

So previously we did this using the following code.

Dim app As New iTunesApp()

Now we have to add in the WithEvents keyword as follows.

Private WithEvents app As New iTunesApp

Now our program can listen out for events from iTunes. You may have noticed I've changed Dim to Private. This is because for this example I'm going to use a Windows Application and not a Console application as before.

Next we have to create our event handler so we can react to the events iTunes is sending us.

The easiest way to do this is use the method generator at the top of the code view in Visual Basic 2005 Express Edition. My iTunes object is called app so we select this, then OnPlayerPlayEvent to create our event handler stub.

Creating an iTunes event in VB2005

This passes in the variable iTrack as an Object. We know this is really an IITTrack object, so we need to cast it as such.

Dim track As IITTrack track = CType(iTrack, IITTrack)
This creates a new varible called track and casts the existing iTrack variable as an IITTrack using CType. Doing this, we have easy access to the track data passed to us by iTunes in the event. We need to do something with this information seeing as we've gone to all the trouble of asking iTunes for it. The easiest thing to do is to just display a small window with the name of the current track.
MsgBox(track.name)

Obviously this is a simplified version of a real program, but it should give you an idea of how to get events from a remote program into your VB2005 application.

Entered: 2006-08-23 21:18:52
Modified: 2006-08-23 21:26:45
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=814

Links for 2006-08-22

Bookmarks from del.icio.us
Entered: 2006-08-23 00:15:06
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=813

iTunes Now Playing in VB 2005

As I've been using VB 2005 a lot more a work the past few weeks, I thought I'd rewrite my iTunes Now Playing console app in VB.

It does the same as the previous C# example, and again I've chosen to use the free version of the language and Microsoft's Visual Basic 2005 Express Edition.

The first thing to do, is to make sure you have downloaded the iTunes SDK from Apple.

In Visual Basic, create a new Console Application. We need to add a reference to the iTunes COM library, so we do this by right clicking over our application in the Solution Explorer, and selecting "Add Reference...". Select the COM tab, and scroll down to find the iTunes library. Mine was called "iTunes 1.7 Type Library".

adding the iTunes COM object to VB 2005

Now for some code.

Firstly, like all good programmers we turn on VB's strict mode to make sure we're not using too many bad programming practices.

Option Strict On

Next we need to import the libraries we want to use. In this case, System> and iTunesLib.

Imports System Imports iTunesLib

As we've created a Console App in VB, we can just drop the following code into the Main sub.

Firstly we need to create an iTunesApp object so we can get talk to iTunes. After that we need to get the current track.

Dim app As New iTunesApp() Dim track As IITTrack = app.CurrentTrack

We should now have the details of the current track in the track object so we just need to print these to the console.

Console.WriteLine("Current Track: {0}", track.Name) Console.WriteLine("Current Artist: {0}", track.Artist)

Finally, just so we can see the result we need to wait for the user to press return before we exit.

Console.ReadLine()

Fire up iTunes if it's not already on and start a track playing. Now start your VB program, and it should tell you the current track title and artist as shown below.

iTunes now playing script

It's as simple as that. Obviously I'm not checking for exceptions and errors as this is just an basic example.

Your final code should look something like this.

Option Strict On Imports System Imports iTunesLib Module Module1 Sub Main() Dim app As New iTunesApp() Dim track As IITTrack = app.CurrentTrack Console.WriteLine("Current Track: {0}", track.Name) Console.WriteLine("Current Artist: {0}", track.Artist) Console.ReadLine() End Sub End Module

Entered: 2006-08-22 20:45:35
Modified: 2006-08-22 20:48:39
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=812

Links for 2006-08-21

Bookmarks from del.icio.us
Entered: 2006-08-22 00:15:02
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=811

Homebrew Remote Switch For Canon EOS-350D

I've found myself needing a remote switch for my Canon EOS 350D camera recently. The official Canon product is the RS-060E3, but at 25 UKP that seems a bit steep.

A quick search on Google, and I came across Chantal Currid's page on making your own remote control.

It turns out it's actually really simple to build my own, so that's exactly what I've done.

The EOS 350D uses a 2.5mm stereo socket, the three connections being ground, shutter control and auto focus control.

A quick trip down to the radio studios are work produced an old stereo cable from their junk box. This had a 3.5mm stereo jack plug on it. Next was a trip to Maplin on Great Portland Street where I bought a 3.5mm to 2.5mm adaptor plug, a handheld box, a red push to make button, a black push to make button and a toggle switch.

components

The wiring is simple, and details are on Chantal's page on the theory of operation.

The toggle switch is used to latch the auto focus. The black push button is a momentary connection to the auto focus for when we don't want to use the latch. The red push button is used to trigger the shutter release. If the toggle switch is on, this keeps the shutter open until the toggle is switched back. Very handy for those long "bulb" exposures.

Here's the wired up box.

wired up canon switch

And here's the final finished (and working) remote switch.

finished switch 1

finished switch 2

finished switch 3

finished switch 4

It should be possible to do more interesting stuff with this. How about one of Maplin's IR beam kits, that we can use to trigger a shot if an invisible IR beam is crossed? Or even fitting in one of their remote control units? There are a lot of cool ideas to try.

Entered: 2006-08-15 22:59:22
Modified: 2006-08-23 14:24:43
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=810

Links for 2006-08-11

Bookmarks from del.icio.us
Entered: 2006-08-12 00:15:02
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=809

Links for 2006-08-10

Bookmarks from del.icio.us
Entered: 2006-08-11 00:15:02
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=808

Links for 2006-08-08

Bookmarks from del.icio.us
Entered: 2006-08-09 00:15:01
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=807

iTunes Now Playing In Perl

After working on the C# iTunes Now Playing program, I thought I'd give the Perl Win32::OLE module a try.

This module is Activestate Perl's COM interface for Microsoft Windows.

After using Perl for nearly 8 years, I've never given it a try before, and it turns out to be surprisingly easy to use.

The following script works exactly the same way as the C# version.

Firstly we need to create a new iTunes.Application object.

my $iTunesApp = new Win32::OLE("iTunes.Application");

Next we get the current track and print the name and artist.

my $track = $iTunesApp->CurrentTrack; print "Current Track: " . $track->Name . "\nCurrent Artist: " . $track->Artist . "\n"

And that's it. Obviously we should be checking to make sure the objects were create correctly, but this is just a simple example, not live code.

So to recap, here's the final working example code.

#!/usr/bin/perl

use strict; use Win32::OLE;

my $iTunesApp = new Win32::OLE("iTunes.Application"); my $track = $iTunesApp->CurrentTrack;

print "Current Track: " . $track->Name . "\nCurrent Artist: " . $track->Artist . "\n"

Entered: 2006-08-08 22:01:28
Modified: 2006-08-22 20:45:49
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=806

iTunes Now Playing In C#

I've been playing about with the COM interface to Apple's iTunes running on a windows machine with .NET installed.

My choice of language has been C# as it's a bit more Perl like than VB. I've used Microsoft's "free" Visual C# Express in this case.

The iTunes SDK is available from Apple and has all the documentation needed.

I'm going to run through how to get Now Playing information out of iTunes. The quickest way to do this is as a console application.

Start up Visual C# and create a new console application. I called mine NowPlaying.

You'll need to add a reference to the iTunes come library. Do this on the righthand side of the C# project window by right clicking and selecting "Add Reference...", selecting the COM tab, and finding the iTunes library.

The first thing you'll need to in your code is to import the iTunes namespace to make the code look a little cleaner. We'll also need the System interface for our console input and output.

using System; using iTunesLib;

In your Main method, the first thing we need to do is to create an instance of the iTunesAppClass. I've rather originally called mine, app.

// Create a new iTunesApp object to use iTunesApp app = new iTunesAppClass();

Next we need to get the current track. This is a simple attribute call to the app object.

// Get the current track from iTunes. ITTrack track = app.CurrentTrack;

Finally we need to show the current track. To do this we call two attributes on our track variable, name and artist. There are plenty of other attributes we could call, but these are the two most useful for this example. See the SDK for more choice.

Once we have displayed our name and artist, we need to wait for the user to hit return. This is useful if our program wasn't launched from a console window as it would end before we've had a chance to read any output.

// Display some info on the current track. Console.WriteLine("Current Track: {0}\r\nCurrent Artist: {1}" , track.Name, track.Artist); // Pause until we hit return. Console.ReadLine();

That's it, nice and easy.

Here's the full .cs source code.

using System; using iTunesLib; namespace NowPlaying { class Program { static void Main(string[] args) { // Create a new iTunesApp object to use iTunesApp app = new iTunesAppClass(); // Get the current track from iTunes and return its artist and name. IITTrack track = app.CurrentTrack; Console.WriteLine("Current Track: {0}\r\nCurrent Artist: {1}" , track.Name, track.Artist); // Pause until we hit return. Console.ReadLine(); } } }
Entered: 2006-08-08 19:59:35
Modified: 2006-08-22 20:46:01
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=805

Acme::Terror::UK Update

I've updated the Acme::Terror::UK module to version 0.02 on CPAN and added a new method called level

The new level method returns the current UK terror alert status in an easily comparible format.

my $t = Acme::Terror::UK->new(); if ($t->level() == Acme::Terror::UK::SEVERE) { print "The current terror level is SEVERE\n"; }

See the documentation with the module for more information.

On the back of this, Andy Kennedy released Acme::Terror::AU. As the Australian government refuses to release this information, his module always returns Acme::Terror::AU::UNKNOWN. :-)

Entered: 2006-08-08 10:57:12
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=804

The Vintage Hot Five At The Terminus Eastbourne

The Vintage Hot Five have started a regular fortnightly spot at the Terminus in Eastbourne.

Now a bit about the band themselves, and who better than Johnny Muxlow (drums, Vintage Hot Five) to explain...

This is the Vintage Hot Five's first appearance at the Terminus. The band was formed in 1993, partly with a view to performing the lesser known and neglected "pop" tunes of the 1920s and 1930s, but also any other number which took our fancy as well. Hence a thankfully non-existent musical policy, which embraces a repertoire of 773 tunes (as at last Friday - it may have gone up since then!) but at the same time saves is from being drearily hidebound by any particular jazz "style" or "genre". We play what we want to play, the only band rule being that we have fun while doing so, which - as an overgrown schoolboy myself - semms to me an admirable philosophy. (If at 5' 6.5, I can truly describe myself as overgrown.) - Johnny Muxlow (drums, Vintage Hot Five).

Here are a few snaps of the night.

Vintage Hot Five 1

Vintage Hot Five 2

Vintage Hot Five 3

Vintage Hot Five 4

Vintage Hot Five 5

Entered: 2006-08-08 00:17:45
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=803

Links for 2006-08-07

  • BBC NEWS | Technology | Google warns on 'unsafe' websites Google has started warning users if they are about to visit a webpage that could harm their computer. The warning will pop up if users click on a link to a page known to host spyware or other malicious programs.
  • The Hello World of AJAX This tutorial will teach you how to create a hello world web page using AJAX technologies. Odds are if you found this tutorial, then you have created a "Hello World!" program before. Hello World is the most basic program that you can write, and every la
Bookmarks from del.icio.us
Entered: 2006-08-08 00:15:02
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=802

Links for 2006-08-05

Bookmarks from del.icio.us
Entered: 2006-08-06 00:15:02
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=801

Links for 2006-08-04

Bookmarks from del.icio.us
Entered: 2006-08-05 00:15:00
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=800

Links for 2006-08-03

Bookmarks from del.icio.us
Entered: 2006-08-04 00:15:01
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=799

Introducing Acme::Terror::UK

There is a lot of fuss in the press at present about the current terrorist threat to the UK.

The government has put the current threat level on a few of it's websites. These are...

The US government has had provided it's threat levels to the public for a while, and there are various ways to access this, incuding a Perl module called Acme::Terror.

Now the UK has this information online, I decided to provide the UK with it's own version of this Perl module, which I've rather originally decided to call Acme::Terror::UK.

It's really simple to use the module. For example, this small bit of code will fetch and display the current UK threat level.

use Acme::Terror::UK; my $t = Acme::Terror::UK->new(); # create new Acme::Terror::UK object my $level = $t->fetch; # fetch the current terror level print "Current terror alert level is: $level\n";

The code goes off to the home office site behind the scenes and screen scrapes the page to get the current UK threat level as the UK government doesn't currently provide and automated feed of this information. This makes the module vulnerable to any design changes on the page, but it works for now and that's the main thing.

There are 5 levels, these are...

  • CRITICAL - an attack is expected imminently
  • SEVERE - an attack is likely
  • SUBSTANTIAL - an attack is a strong possibility
  • MODERATE - an attack is possible but not likely
  • LOW - an attack is unlikely

At the time of writing, Acme::Terror::UK informs me the current threat level is SEVERE.

Entered: 2006-08-03 22:35:12
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=798

Links for 2006-08-02

Bookmarks from del.icio.us
Entered: 2006-08-03 00:15:01
TRACKBACK - http://www.robertprice.co.uk/cgi-bin/robblog/trackback.pl?id=797