Thursday, February 15, 2007

Off the Scheme-OSA topic

Yes, I seem to be drifting slowly off the main topic: Scheme-OSA = Scheme + OSA = Scheme + Open Scripting Architecture = Scheme + Applescript. Well, this is still the main goal for my current activities and this blog supposes to reflect it. However, I do get distracted from time to time for variety of reasons. So this post will be all about excuses.

Squeak and Seaside
A week ago I was asked to investigate this: given a XYZ program, which prints its data to a printer, redirect the printer input to a Squeak-based scheduling program UVW, parse and modify the data and then spit it out to the printer - using a similar format to the one used by the original XYZ program. Well, the UVW is not a Command Line Unix program -- it is a GUI universe on its own. You cannot just redirect stdin to UVW, then manipulate the data and finally print the results out to stdout and force UVW to exit. Well, you can do it in principle but there is no easy way to implemented it.
The obvious alternative solution is to embed a HTTP server within UVW - which brought me to Seaside framework -- a nice, several years old technology, combining a Comanche web server with a 'servlet' support, CSS and Ajax.
In my view Seaside has three major selling points: it understands and supports continuations, it completely separates flow control from user interface and it provides remote support for browsing and debugging. The latter means that you can connect to a live Seaside server, inspect and modify data using Squeak-like inspectors embedded in a web page, and browse or modify offending methods using tools, such as Class Hierachy Browser, which look almost identical as standard Squeak tools. When doing those modifications you do not need to kill any session or the server itself - all the operations can be made on the "living organism".
The Seaside's home page offers several demo videos. One such demo was evidently given to a Lisp user group; the Lispers had many technical questions and suggestions, but apparently the Seaside concept was taken seriously by them.
All of this has nothing to do with Scheme in general (with the exception of continuation jargon), and Scheme-OSA in particular. This was just a distraction, but since I was paid for that, I do not complain. Oh, yes, I used to program in Smalltalk, and I have some experience with Squeak.

Presentation of the world's first commercial quantum computer
Few days ago D-wavesys company from British Columbia, Canada announced its first public presentation of a 16-qubit quantum computer, Orion. Some details leading to the presentation are available at Geordie Rose's blog -- a technical person from D-wavesys. To the credit of Dr. Rose, his blog contains permanent links to the blogs of some active quantum physicists, and who are not always overly enthusiastic about the event. But in average the response of the QC community is ambivalent but not damning: "give us more data to analyze the system first". If you want to learn something about Orion read blogs of physicists, watch some U-tube videos produced by participants of the events (Vancouver and San Francisco), but avoid regular press as a plague: too much hype and very little understanding of QC concept.
What does it have to do with Scheme-OSA? Nothing, but it affects the author of this blog somehow. In 2001 I wrote Haskell Simulator of Quantum Computer, which is cited in several Haskell publication produced ever since. There are also several Scheme-based papers on the subject published in recent years. For some reasons I have not followed the topic of Quantum Computing, but I wish I had. Much has happened in the recent years in this field and it took me several days to familiarize myself with major accomplishements of QC.

Thursday, February 1, 2007

Visualizing music

No, no, this is not about visualizing music in your iTunes by animating some pretty images. It is about visualization of structure of music.

Staking the ground
In this post I am going to prepare the background for another potential application of Scheme-OSA: transcription and visualization of different music formats. I should start with the link to MusicXML tutorial and advice you to look at their first lesson: "Hello World" in MusicXML. Surely, XML is the best way for exchanging information between incompatible systems. But XML is not designed for human consumption, it is designed for machine consumption.

Somewhere in between is a place for Scheme-based application, which would be able to handle both: human and machine interface. From the high level perspective, Scheme-OSA should be able to learn from two good applications: compo and Haskore. The first one is written in Lisp, the second in Haskell. The advantage of Scheme-OSA is in its ability in interfacing to variety of existing music notation programs available on Mac OS X platform.
I am particularly interested in various non-standard ways of music notation.

Folk music
The music score and the audio below have been produced by BarFly from a fragment of the wooodenflute.abc file.







Listen to Sound Symposium Jig

The file woodenflute.abc comprises the ABC tunes posted to the woodenflute mailing list betweenOctober 1998 and April 2000. The list exists to discuss all aspects of the wooden flute - music, history, technique, players, making, workshops, festivals, new CDs, and gossip.
The ABC music language was originally invented by Chris Walshaw to transcribe folk music in plain ASCII. It has now developed to such an extent that it can be used for many other musical purposes.
BarFly is an integrated environment for Mac OS X, developed by Phil Taylor, for working with abc music files. It can play, check, transpose and display tunes in abc notation.

The original ABC code, from which the above was created, is shown below.
X:157
T:Sound Symposium Jig
R:Jig
C:Emile Benoit
M:6/8
L:1/8
Z:Gerry Strong
K:G
|:eaa eaa| eaa baf | gag fed | gag fed| eaa eaa| eaa baf | gag edB| 1A3 A3:| 2A3|
|:efe ~A3| efe A2 e| dBA GAB | dBA GBd| efe ~A3| efe A2 e| dBA GBg| edB A3:|


Polyphonic music
ABC notation can go way beyond simple folk music. Here is Johann Bach at the height of his powers in the stupendous Fugue in C#m from the first book of the Well-Tempered Clavier, converted from ABC to audio format. As Phil Taylor, designer of BarFly, writes:

Five voices, in three subjects, coming and going all through with never a note out of place. My son, who is a keyboard player, calls this a "Real Man's Fugue", and would give his eye teeth to be able to play it. He says you would need hands the size of a bunch of bananas, for a start. I haven't set an instrument for this, and merging the voices onto two staves is still far beyond the capabilities of the program. Actually, it's much easier to read on five staves anyway. For greatest authenticity use a harpsichord, but piano sounds good too.

So I did set the instrument to harpsichord - as the man adviced.


Listen to Bach's Fugue in C#m



Music Animation Machine
Here are few first measures from Bach's Fugue No. 5 in D Major [Well Tempered Clavier, book II] shown in classical notation and visualized according to Stephen Malinowski's Music Animation Machine. If you have Apple's GarageBand installed on your Mac OS X Stephen's visualization should look familiar: notes are distributed vertically according to their pitch classes, note lengths are proportional to lengths of the pitch bars. But in addition to these two concepts, Music Animation Machine uses colors: each pitch class has its own color.


According to Stephen:
I applied the color wheel to the "circle of fifth", so that pitches which were closely related by perfect fifths would be close in color[...] This turned out to be useful for showing things about tonality. For example, all the notes in a major scale are grouped together. This means that if you're playing a piece that stays in one key, it stays in one area of the circle. If the key changes, the notes are in a new area. Also, notes which are not in the key stand out.
By the way, this method of coloring pitches is used in the Sibelius music notation software.


Here is Music Animation Machine in action; it visualizes Debussy's Clair de lune:



Critique of Classical Western Music Notation
Why is the standard music notation so complex - with all those clefs, sharps, flats, flags, scales, etc.? Serious articles would give you serious answers; I just say this: it is due to international conspiracy of great and lesser musicians of all times who had to support themselves by teaching dumb pupils. It was not in their interest to make their notation any simpler. :-)

But whatever the reason — serious or not — the CWMN does not have to be as complex as it is. When I was learning the basics of guitar I was lucky enough to come across one of those alternative notation methods, which — I know it now, after some googling — related somehow to some obscure Dutch school of music, known as Klavar, or Klavarscribo. The only difference was in direction of staves: in Klavar they are vertical, while in my source they were horizontal, more appropriate for a guitar student.
From there I learned that if I focus on relative pitches, rather than on absolute pitches, everything would become simple and mathematically pleasing.

If you took a look at the above link you should recognize some similarities between Klavar and the Music Animation Machine. Old ideas (1931) of Cornelis Pot die hard. :-)
From a programmer's perspective, scores of sophisticated music look like old-fashioned BASIC spaghetti code — with all those GOTO's statements and multi-level IF-ELSEs' thrown in. But even BASIC has become modernized, and there are many better languages than BASIC that people use nowadays.

Alternative Music Notations
It appears that I am not alone in my assessment. The Music Notation Modernization Association MNMA is in a process of elimination and selection of alternative proposals to Classical Western Music Notation. So far over 500 alternative music notation schemes have been considered, and a subset of those have been selected for further consideration. Many are somehow related to the good old Klavarscribo.

Will it ever be a consensus for a new notation? None of these proposals to MNMA has provided a sufficiently-compelling benefit to become broadly popular (except for guitar tablature). What would it take for a new notation method to become acceptable? One strong argument against any new music notation is the existing vast archive of CWMN. However, with all those score reading optical recognition programs this should not be a problem nowadays. Another argument against a new notation is lack of sheet music for the new style. Afficionados of Klavarscribo claim that there are 25,000 pieces of music transcribed into that format. Yet, Klavar did not make any dent in general attitude towards music notation.

When I was recently watching a video presentation of iPhone by Steve Jobs, one of his quotes of Allan Key (of the Smalltalk fame) struck me as applicable to this situation. He was saying something in effect that people will readily accept your new idea only if you offer them a totally unique solution, not just an alternative. In the iPhone context that meant a combination of unique sophisticated software and hardware.

And such a total solution for alternative music notation might be just around the corner, in the form of musical instrument Thummer from an obscure programmer-turned-businessman from Australia. After reading his Thummer documents the man did not struck me as one of those coocoos who want to replace List/Scheme parentheses by something else; he evidently has something to offer. Not that I like the look of his product - it would require Apple geniuses to style it to look really ergonomic and "pretty".
Thummer concepts are quite similar to those of iPhone in a way: simplify basic notation, layout the buttons to match the software, eliminate inconsistencies, add touch/gesture controls.

But predictions are just best guesses; nobody knows what would happen with the Thummer. People come with very good ideas all the time. For example, there is Paul Hirsch's interesting site dealing with instrument 'modernization' and music theory :Intuitive Instruments for Improvisors. Paul provides few interesting on screen instruments, which you can try on his web site. He also delivers several hardware gadgets that handle music in intuitive way.
You may also want to look at Blumberg's Music Theory Cipher — a chromatic approach to interval notation on guitar and other stringed instruments.

Not just simplicity
A need for a new music notation is not dictated by simplicity alone. Any introduction to the subject will point out that CWMN is not able to handle other scales, as invented by cultures other than Western European. Many modern composers, such as Arnold Schoenberg or John Cage, also felt a need for new kind of musical notation. Schoenberg is often quoted from his "A New Twelve-Tone Notation"[1924]:
The need for a new notation, or a radical improvement of the old, is greater than it seems, and the number of ingenious minds that have tackled the problem is greater than one might think.


Others seek new form of expressions in microtonal music. Here is an excerpt from Microtonal Projects Ltd:
Microtonal Music uses pitches other than the 12 equally spaced semitones normally heard in western music or their close relations (such as the ones found in the tmperaments used in Baroque music). Such music is not particularly rare. The ancient Greeks used structured intervals as small as a quarter-tone, so do many folk music from around the world and Indian classical music.