Sunday, April 13, 2008

Math Makes Music

I've written before about the intersection of art and technology. As a musician and an engineer, I'm always interested in art that is techie and tech thats artful. Last week I had the distinct pleasure of discovering a little piece of technology that I think is one of the coolest things I've ever seen in my life, ever. It's a software-based piano synthesizer that turns the whole world of digital piano technology on it's head.

Piano players can't really lug a piano around easily, so you never know when you show up at a gig what kind of instrument you'll have to play on. I've seen everything from a Bosendorfer to a beat up electronic Casio with the sustain pedal polarity wired in reverse. The notes wouldn't stop until you stepped down on the pedal, exactly the opposite of how it normally works. It was like trying to drive down the freeway backwards.

Like a lot of other pianists, I sprung for a decent digital stage piano that I can take to gigs with me. It's also good for recording, because miking a recording on an acoustic piano is hard to do properly. With digital, you can go back and fix your mistakes! For a number of reasons, a digital piano is really useful. But they have never been able to fully replicate the sound of a real acoustic grand piano.

In recent years, software based "sampled" digital pianos have gotten really good. Some take up hundreds of megabytes or gigabytes of disk space, with each note on the piano recorded at different velocities for up to 60 seconds, with and without the sustain pedal. Playing a moderately polyphonic piece of music requires a ton of memory and CPU power. If you have too many notes sustaining at once you can get clips and drop-outs. No matter how good they sound they are just not the same as playing a real piano.

Pianoteq takes a totally different approach. Rather than trying to record every nuance of an acoustic piano and replay the sound samples in software, Pianoteq builds a mathematical model of the physics of a piano. Everything from the length of the strings to the hardness of the felt hammers to the impedence of the soundboard is taken into consideration... and presented in the clean user interface so you can tweak it. You can build a10-meter long piano if you want to! As a bonus, there are no gigabytes of sampled data to download; the whole program was less than 14 megabytes! It mathematically calculates what the waveform of the sound will be, taking all the parameters into consideration, and then constructs the sound image in real-time.

At some point in their musical development, an instrumentalist comes to the realization that a truly fine instrument can actually make them play better. After you've spent years working on your chops, you sit down with a really great instrument and notice all sorts of ideas and techniques suddenly bubbling out of your creative reservoir. That's when you can really tell a great instrument from the mediocre. And you know, nothing is going to compare with a 9ft Bosendorfer, but after playing just about every model of grand piano out there, and dozens of digital pianos and software synths, I sat down with this Pianoteq software and was blown away. It made me play better. In one evening of jamming with it I came up with more ideas, changes and riffs than I have in months.

After keeping a careful eye on a dozen or so digital sampled piano packages, waiting for something truly convincing to come along, the wait is over. Pianoteq has what it takes.

Although I agree with another reviewer that some of the preset piano models sounded a little bit flat in the mid-range right out-of-the-box, I'll be quick to point out that the onboard EQ and reverb settings, not to mention the individual harmonic overtone settings, let you tweak the tone color to your heart's content. Actually, I suspect whats happening is that Pianoteq is almost too realistic, and those of us who've gotten used to the heavily-processed sampled piano sound just are not used to the natural purity of tone coming out of our headphones. And no other piano software gives you the range of configurable parameters to construct any type of piano model from a 9ft concert grand to a1980's vintage Yamaha CP80 electric stage piano.

Created by a pianist-turned-mathematician, Pianoteq is a great example of the combination of art and technology to produce something brilliant.

Tuesday, March 25, 2008

Gospel Goes Green

CBC Radio, The Current, 24 March 2008 featured an interview with Rev. Richard Cizik, Vice President for Government Policy with the National Association of Evangelicals, the most powerful religious organization in the United States with over 30 million members. He is encouraging his flock of 30 million to "proselytize in the fight against climate change as well as the battle to save souls."

On a trip last August, he along with other evangelicals and scientists went to Alaska to see the effects of climate change. Asked about the impact of the trip, he said it was "an extraordinary experience for me personally as well as for all evangelicals."

The group saw first hand the impact of climate change, habitat destruction, and species extinction. Stressing the need for cooperation between the religious and scientific communities, Cizik recounted "...all these things that we together believe threaten the planet."

"It's one of the most important conversations that has to occur if we're going to be able to merge the concerns of these two worlds of religion and science on behalf of something that is surely one of the greatest challenges facing the planet - that of climate change."

In Alaska, the group saw melting of glaciers, rising sea levels of Shishmaref and the "great ghost" fir trees destroyed by bark beetles on the Kenai peninsula. Cizik said the impact of climate change is hitting close to home and that seeing it in the US is "critical" for Americans to understand.

It's clear he is passionate about the issue. "People are impacted too! Inupik Indians forced to consider leaving and losing entire way of life... the impacts are human!"

Although the group members didn't shy away from topics of creation and evolution, according to Cizik the debate is not how the earth was created (God is already well aware of that, he quips) but rather, what we do with the earth He created. He cites the Genesis 2:15 mandate to protect and care for the earth. "More import than how it all came to be is what is happening to it NOW."

The enmity between religious and scientific communities is a thing of the past, according to Cizik. "Science helps us to know what creation is telling us about itself - science is our partner in this. Science has been viewed as an enemy of the faith... that view has frankly gone by wayside for most people."

He admits that there is residual impact from the fundamentalist attitude, saying it is why large segments of the American public are skeptical about climate change, and why the GOP congress has been reluctant to act.

"This is new territory for a lot of people", he added.

Having demonstrated a much more forward-looking attitude than the religious right in recent times, it nevertheless surprised many when the Vatican revised its 1500 year-old list of Seven Mortal Sins to include "causing damage to the environment". The revised list :

1.) genetic modification
2.) carrying out experiments on humans
3.) polluting the environment
4.) causing social injustice
5.) causing poverty
6.) becoming obscenely wealthy
7.) taking drugs


Cizik calls it "a reappraisal of theology itself," and says that evangelicals have been slowest to this. Times are changing, however.

"The mainline has been on the sidelines... the irony is the community that has been least equipped has become the go-to religious community in Washington on policy changes with respect to climate change.

Cizik believes the influence of the religious community is the only way that the republicans are going to move in the policy debate. It has, he says, moved George W Bush from barely even recognizing it to saying, in his last State of the Union address "it is here".

Speaking of the beginnings of his own environmentalism, Cizik said he made a turn about face at a conference in Oxford, UK several years ago.

"I thought I was well positioned as a mugwump... don't push me, the science is split; I dont need to make decision, I don't have to engage evangelicals in this."

But the scientific evidence he saw at that conference swayed him.

"Wow... I saw with my own eyes the impacts that climate change is having upon the world. It's like I had a St. Paul's conversion. It was not by looking at the earth per se... I had it looking at the science."

He recalls thinking, "How can this be? That I myself in this case for 18 years a representative of the association here in Washington, that I could decide based on whatever evidence we had that I had no dog in this fight, so to speak? And yet I couldn't have been more wrong!"

"We all have blind spots. We evangelicals have been the blindest of all. It was a conversion for me at Oxford in England that brought me to this place. Well, I turned around and went in another direction. Yes, In some cases we evangelicals need to repent and turn around. I don't apologize for that term. I say, what is it if you turn around and go another direction except a conversion?"

Cizik insists that principles of caring for the earth are taught all the way from Genesis to Revelation, and says the religious community has been misguided by political interests.

"We've participated in an unholy alliance with big business. Those are the two components of the Republican party, the conservative moralists, the evangelicals, fundamentalists... along with big business. We're the two wings of this political party. We're 40 to 50 percent at least if not more. And we've participated in an unholy alliance over the years in which we've gotten very little andthey've gotten a lot. And one of the things they've gotten is a free run over our energy policy and our environmental policy. This is what's got to change."

Cizik is encouraging people not to put politics ahead of faith by "focusing on one or two hot-button issues". He criticizes the religious right for putting their tent in the wrong camp, and says that pro-lifers who say abortion is the main issue need to have a broader agenda. "We see hundreds of millions of lives at stake because of climate change today. I say broaden your understanding of what it means to be pro-life." The younger generation, he says, is keenly aware of these issues that will be among the most important issues they face throughout their lives. Many have been left politically homeless. Cizik sounds as if he may be among them. "I don't know who I would vote for," he admits. But he claims he predicted years ago that no non-green candidate would be elected to the republican party in 2008.

Cizik explains that historically, environmentalism has been associated with democratic blue state politics, leading many Evangelicals to view it with suspicion. Evangelicals who oppose evolution have also therefore opposed science, as a proponent of evolution, and have been skeptical of media. He calls it "a tribal kind of attitude", a "narrow fundamentalism" that is not based on sound principles of faith and wrongly ignores "undeniable realities."

The entire segment can be heard on CBC's web site at http://www.cbc.ca/thecurrent/2008/200803/20080324.html

Thursday, March 20, 2008

Selenium IDE Test Tips


Here are a few things to bear in mind when creating Selenium IDE tests.

Setting and Getting Variables

store | 10 | x

This obviously sets x=10. There are a couple of ways to reference it: ${x} or storedVars['x']. They're not the same.

The first, ${x}, is from Prototype. Its a shortcut and returns a copy of storedVars['x'], it doesn't actually point to the real value. The second, storedVars['x'] directly references the array of Selenium's stored user variables. I recommend using storedVars['x'] and not ${x} (even though it's shorter).

You can't assign anything to${x}. Within a single Selenium command, if you modify storedVars['x'], the value of ${x} won't get updated until the next command. Stick with storedVars and you'll be ok.

When you want to use a previously stored variable as an argument to a subsequent command, use the "javascript{...}" notation. For example:

assertElementPresent | javascript{storedVars['myElementsXpath']}

XPATH from Firebug

You tend to use xpath queries a lot in Selenium tests. Sometimes figuring out the xpath expression for an element is a real pain. Firebug can help. Just click on the "inspect" tab and highlight the element you want. Right-click on it in the HTML code display and select "Copy Xpath" from the context menu. Paste it and give it a try. You may have to replace "/html/body/" with "//" though.

Xpath can get interesting. I like Zvon's tutorial.

Using storeEval

There are ways of defining functions even in Selenium IDE, but a simple approach is to use storeEval to run some Javascript code and put the result in a variable you can use for subsequent commands. For example, say you need to click on ButtonA if its present, or else click on ButtonB if its present. If neither one is present you want to do something else.

In this example I've got my xpath expressions for ButtonA and ButtonB stored as variables (just to illustrate the aforementioned javascript{} syntax). I'm going to fetch them and use them in my evaluation.

storeElementPresent javascript{storedVars['ButtonA_Xpath']} ButtonA
storeElementPresent javascript{storedVars['ButtonB_Xpath']} ButtonA
storeEval (storedVars['ButtonA']==true)?storedVars['ButtonA_Xpath'] :((storedVars['ButtonB']==true)?storedVars['ButtonB_Xpath']:null); linkToClick



That's one way to do it. Another is to use conditional logic and flow control to set up an if-else structure. Check out the Selenium IDE FlowControl post for info on how to do conditional logic-based flow control.

In the end, if you're testing a web application you've designed and your test case is getting this ugly, you'd better re-evaluate your design. If you're testing something other than a web app though, for example a test case that spans multiple sites, you might need to get creative.

Tuesday, March 11, 2008

What I Don't Like About Google

As with all good things that must come to an end, the pure spartan simplicity that defined Google at the start has begun to cede ground to the ever-encroaching clutter.

Usability trouble comes in various guises but could be summed up in a word as "inconsistency". If I had a mantra for usability it would be "meet expectations". Which is impossible when your products set conflicting expectations. With all the additions, acquisitions, and new beta projects coming out of Google now we're starting to see the inevitable usability dragon rearing its ugly head.

It happens, for example, when you click on "My Account" in one application and it takes you to the app's dashboard, click it in another application and go to your Google account preferences. I don't want to have to remember that two identical-looking links in identical fonts in identical places on Google apps have completely different functionality.


Dear Google, please fix the inconsistency.

It snowed...

... a bit last night.

Monday, March 10, 2008

Selenium IDE Internals


When porting the original flowcontrol plugin for using goto and while loops in Selenium IDE (original Sideflow post) I found the following techniques useful for digging into the internals of Selenium IDE.

using getEval / storeEval

The functionality Selenium provides is great, but at times you may need to do something beyond the ordinary. One of the most useful commands in Selenium IDE for this is getEval. Get eval executes an arbitrary string of JavaScript code. If you've upgraded to the new Selenium IDE 1.0 Beta 1 you can also use the new "runScript" command.

getEval with alert

Most people will have tried this, I'm sure. Some say this is bad form, but I use this sort of thing all the time and it's usually the fastest way to get what I need for debugging.

|getEval | alert("simple is always better"); |
|getEval | alert("first command = "+testCase.commands[0].command); |
You'll want to remove these kinds of alerts once your test case is ready for production.

Selenium Internals

Selenium's greatest fault may be its poor documentation. Technical documentation is basically non-existent. These "can-opener" scripts can show you what's under Selenium's hood. They also show you how to open up a window and write stuff to it, an alternative to plumbing the depths of Selenium's inscrutable logging internals.

This will crack the Selenium object open for you:
|getEval| var result = "<h2>Selenium.prototype</h2><ul>"; for (var i in Selenium.prototype) { result += "<li>this." + i + " = " + Selenium.prototype[i] + " <br>";} result+="</ul>"; var debugWin = window.open("about:blank", "debugWin"); debugWin.document.open(); debugWin.document.write(result); debugWin.document.close();

Here's the browserbot object:
var result = "<h2>this.browserbot</h2><ul>"; for (var i in this.browserbot) { result += "<li>this." + i + " = " + this.browserbot[i] + " <br>";} result+="</ul>";var debugWin = window.open("about:blank", "debugWin"); debugWin.document.open(); debugWin.document.write(result); debugWin.document.close();

Try it with TestLoop.prototype, currentTest, testCase, and, of course, 'this'.

Looking at Constructors

Another handy trick is to check an object's constructor. It can be used sort of like a typeOf.
|getEval| alert(currentTest.currentCommand.constructor.toString());

How all these pieces fit together, and hacking new and nifty things out of them is left as an exercise for the reader (you).

Note: According to Matt Raible's blog post on the Selenium User's Meet-up, the next release of Selenium is going to feature some major changes including the merging of Google's webdriver code. So a lot of this is likely to change.

Wednesday, February 13, 2008

Selenium IDE Flow Control - Goto and While Loops

tldr; https://github.com/73rhodes/sideflow

This extension provides goto, gotoIf and while loop functionality in Selenium IDE. Selenium IDE is a plugin for Firefox that automates the testing of web-based applications. There is an excellent flow-control extension at wiki.openqa.org/display/SEL/flowControl for the Selenium RC and TestRunner components, but it does not work with Selenium IDE (the Firefox plugin) directly. This makes it difficult to develop controlled test cases within Selenium IDE, and there are times when the frame-based TestRunner cannot be used (such as when the website under test employs a frame-buster script).

I've ported the existing control-flow extension to work in the Selenium IDE Firefox add-on. The image below shows a sample test case using goto, gotoIf and a while loop, all running successfully in Selenium IDE.



The file can be downloaded from Github and should be saved as "sideflow.js" to your hard drive. Then the Options settings in Selenium IDE should set the Selenium Core extensions to include the path of this file, similar to the image below.

I've published the extension on github.  Go ahead and download it from there. 


github.com/73rhodes/sideflow

Update 26 February, 2008:
This mod of the FlowControl extension works only with the Selenium IDE Firefox add-on. If you want to use the TestRunner component or Selenium RC, please use the original FlowControl extension.

Update 19 February 2011

I've moved the extension over to github. 


Update 7 July 2011
I've updated the example to use the newer syntax required in the latest versions of Selenium IDE.

Please note that if you are using Selenium RC, you should use the original flow-control plugin here: wiki.openqa.org/display/SEL/flowControl



Unfortunately I haven't had the time or the need to make this compatible with both Selenium RC and Selenium IDE.  Please feel free to fork the code on github and make a pull request if you would like to help out.

Update 24 July 2012
I added a "push" command to the plugin, with a simple example on the Github page. This allows you to easily create a collection of items and implement "for each"-style functionality to iterate over it. Here's the original announcement. 

Productivity and Note-taking

I told a friend of mine that I wasn't really happy with the amount of time that gets taken up by Slack and "communication and sched...