Software over the rainbow

desearch and revelopment

Penner Easing for C++

As I said last week, I’m also using robert penner’s easing equations in openFrameworks, so I’ve ported them to c++.

This has been relatively straightforward, but, as with the actionscript to java conversion, I’ve run into some nuances between languages and I’ve definitely learned the hard way (read “wasting some hours of my life”) why pre and post increment operators can be evil.

Grab them here

For usage, you can have a look at the openFrameworks app provided. If you want to have a quick glance at the types of movement, see the easing applet (p5 version).

Being this a programming exercise, it will have improvable things for sure. I’m thinking of some, but if you know anything, please let me know.

Taking Notes About What You Are Listening to on The Hacky Way

Some time ago, I wondered how could I take some notes about the music I was listening to.

After having a look at the player source code* I instantly saw what a stupid thing I had suggested. In no way I’d be able to figure out that bunch of c++ classes (not that it made any sense to try, just to implement such a simple thing).

I thought of some other alternatives, mostly involving desktop widgets, but as far as I could see, none of the options could cover both my local music and the player (for when I’m listening to radio). I gave up the idea.

But one day, while sending a recommendation to a friend via the player I realized that I could write some text in that text box. Could I send recommendations to myself? Yes. And how could I take those recommendations out of Luckily, they offer an rss feed for manual recommendations in their web services.

auto recommendation on

So I hacked together some code that parsed my recommendations and sent the ones with my username to my helipad notebook (not public, so I don’t have much to show). I set up a cron job and… You can see that I still use it in my rss feed.

The code is so trivial (and so tied to helipad in my case) that I’m sure you can do it better quickly, but in case you are interested, I could try to clean some of the php mess and send it upon request.

Although they are kind of personal, I’ve been thinking of publishing the notes directly here, since the rss feed is public anyway (and explicit sharing can improve your personal content, I think)

As a side note, I think could get some value of implementing such a thing. On one hand users could get some sort of musical microblogging, like a contextual twitter. On the other hand, since the info is always from, it could really enrich artists, songs and album pages, and more seamlesly than the current shoutbox, in my humble opinion.

* yes, I learned how to use subversion. Now I can’t live without it.

Penner’s Easing Equations Processing Library

Being an actionscript head, I’ve frequently used rober penner’s easing equations in processing*. To avoid copy/paste each time I’ve packed them as a processing library.

While I was at it, I discovered a couple of implementations (1, 2), but I was almost done, and wanted to learn how to make processing libraries anyway.

So in the hope that it is useful to somebody, here it is:

*I’m also using them in openFrameworks, so I’ve begun porting them to c++ too. They’ll be here when I’m done.

Actionscript 3 Syntax Highlighting for jEdit

Still happily living on jEdit for most of my scripting. I haven’t found an actionscript 3 edit mode, so I’ve made one. It is based on the original actionscript.xml and the Flash CS3 AsColorSyntax_3.xml file so it should have everything you can see colored on the IDE.

This edit mode doesn’t have any as2 specific keywords, so if you have to work on as2 don’t delete the original. Otherwise, you can just replace your original actionscript.xml file (you’ll find it problably in “c:\program files\jEdit\modes” if you’re on win xp) with this one. Make a backup of the original, just in case.

Grab the actionscript 3 edit mode for jEdit

Php and Mysql in Different Time Zones

Just a quick code tip for working with dates in mysql and php.

I’m building a script to regularly mirror my recent tracks to a mysql database of my own. I’m interested in experimenting with daily and hourly statistics.

One problem that has taken me some head scratching has been the fact that the recentracks web service gives me the date a given track was played in a timestamp of my current timezone (+02:00 , Europe/Paris, as I’ve just learnt), but my web server is on a different timezone (-05:00, America/Los_Angeles), so when I try to insert a date in the database, even though I’m giving it a timestamp, it gets interpreted as being 7 hours less than it actually is. So a track played at let’s say 31 Mar 2007, 23:55 would be stored as having been played at 31 Mar 2007, 16:55. Not good.

Not wanting to fiddle with configurations or anything beyond my knowledge, I discovered that I could set the timezone in both php and mysql for a given script or db query.

Setting the timezone in php

If you want to know which timezone your server is in, you can guess it with

<br /> date_default_timezone_get();<br />

Which should give you a string like “America/Los_Angeles” or any other of the supported timezones list

If it is different than your desired timezone, look for the one you want in the list and before doing any time operation, call:

<br /> // set your timezone as gmt +02:00<br /> date_default_timezone_set("Europe/Paris");<br />

From then on, all your php code should understand timestamps and dates in that timezone.

Then for mysql use CONVERT_TZ

Even though it is corrected in php, you’ll have to do it also when inserting information on you mysql db, because it will interpret timestamps again in its time zone. You can guess which is it by having a look at the system time zone variable.

In my case, after trying some hacky alternatives I discovered CONVERT_TZ in one of the latest comments in this post

From the mysql manual

<br /> CONVERT_TZ(dt,from_tz,to_tz)<br />

CONVERT_TZ() converts a datetime value dt from the time zone given by from_tz to the time zone given by to_tz and returns the resulting value.

You have to pass it the timestamp, current timezone (‘SYSTEM’ is the server time zone) and target timezone and it happily converts between them.

So now my query would look like this:

$query = "INSERT INTO recenttracks (artist, name, url, date, type) 
    VALUES ( '$lastFmTrack->artist', 
    <strong>CONVERT_TZ(FROM_UNIXTIME('$lastFmTrack->playDate'), 'SYSTEM', '+02:00'), </strong>

Basically that’s it. Hope it is useful for someone.

Mind you, I’m nothing of an expert in php or mysql, this is just a method which worked for me. Corrections are welcome.

Suspects: Easy

Like, for example:

A 20th century problem is that technology has become too “easy”. When it was hard to do anything, whether good or bad, enough time was taken so that the result was usually good. Now we can make things almost trivially, especially in software, but most of the designs are trivial as well. This is inverse vandalism: the making of things because you can.”

It’s Alan Kay, summing up in his wonderful “Early history of Smalltalk”

Music and Memory: A Small (Frustrated) Project


A couple of months ago, having a look at some old stats in my profile, I realised how much I could remember a given time by just seeing the music I used to listen to (that old (unfinished?) project by marcos weskamp and didier hilhorst came to mind inmediately).

The source: keeps weekly data about what we listen to. We also can (could) construct a radio link based on various artists. For example:


The application

A web page that, given some artists that I used to listen to in a given time (e.g: december 2005), constructs the url of a radio with those bands, so I can somehow “transport” myself to that time by listening to similar music…

And I’ve done it, but…

Last friday, the multiple artists station feature stopped working. In fact, I had some suspicion, but I thought that… nothing. I didn’t think of it and kept working.

So it is basically useless in its actual form, but it was finished (as a proof of concept, at least), so here it is: time machine (if it had worked i’d have looked for a better name).

I’m not sure if the idea can take another direction to become useful. I’ve thought of having a look at xspf to see if I can generate playlists instead of radios, but by now I don’t really know. If you have any ideas…

At the very least, it’s been useful to clean the dust over my php, use the webservices, a little bit of ajax (thanks mr.sofa naranja) and above all, to finish something.

By the way, avidos let me stay in their hosting to do some tests while mine hadn’t php5, and ignasi tudela tried to help me with the design, but apart from using Georgia and taking his colors for the different seasons, I didn’t pay him much (deserved) attention, and you can see the results. Thanks to both.

Magic Words

There are some words I’ve put under suspicion. They’re like magic. When they appear everything seems better, more pleasant, more adequate…

I still don’t know what it is, but I’m somehow annoyed. Perphaps they appear too frequently in advertising, products, speeches… I think they hide some… swindle.

3 come to mind now:

  • New
  • Easy
  • Original

do you have more? do you know what it is?