Monthly Archives: October 2009

Modularizing Zong!

Project Jigsaw is one of the most important features of JDK 7: Instead of a huge monolithic package the JDK will consist of smaller moduls, that can be loaded on demand and can thus decrease the download size, startup time and memory footprint. I thought that this is a good idea, and it should be applied to Zong! too:

splitproject

Of course Zong! is way smaller than the JDK, but with now more than 50.000 lines of code it is quite complex already (and there is much more to come, I guess we will need more than 150.000 lines of code for all planned features). But I see two advantages in modularization:

  1. A programmer is forced to write cleaner code, that doesn’t have dependencies between arbitrary packages. For example, the util package can not use classes from the viewer package and is thus easier to test and to share with other projects. Of course, these dependencies were avoided before too (at least more or less. It really took me some time to remove the few ones, and I must say, this was really dirty code before!), but now there is a technical barrier that forbids them.
  2. The sources, which will be free software, are strictly separated from our proprietary code. This is a very important step for releasing them to the public soon (already this winter!).

Intonation Ear Training

As the conductor of a bavarian brass band I often have to intonate the different instruments in the orchestra. Because I found no website or free program where you can practice your intonation hearing I decided to write a little applet:

Intonation Ear Training Applet

Have fun practicing 🙂

Because I’m getting more familiar to Clojure and like the language very much, I decided to write it in this language. It worked quite well despite of some teething troubles which Clojure still has. Because of that I’ve written a little tutorial how to create applets, and I hope it will encourage more developers in giving it a try.

Experimenting with Clojure

In former days, Visual Basic 6 was the language of my choice. A lot of people tried to convince me that VB is crap and I should learn a “real” language like C++. Nevertheless, I was happy with VB and even built some nice stuff with it.

Later, when I switched from Windows to Linux, I was looking for a new language and found Java. I like Java still very much, and it is great to write and compile code only one time and it runs on all platforms (at least in theory. Bolzplatz 2006 was more complex, but anyway it was a good decision to choose Java). But when you become a more experienced developer, you soon notice that Java has several severe limitations (the project where I encountered these problems in particular was CUP2, a parser generator for Java, which was the topic of my Bachelor’s Thesis. There, I had lots of “fun” with reflection and such things).

Some days ago I read Paul Graham’s article called Beating the Averages, which I really recommend reading. He states, that every programmer is happy with his favourite language and is more or less restricted in his thinking. This prevents him from switching to the really most powerful language (which is, as he thinks, LISP).

For already two years I am trying to learn LISP, so far without success (mostly because lack of time). This week I took the time and started some experiments with Clojure, a modern LISP for the JVM. My goal was to replace the Java-SLE-solver of the slur layout engine by Clojure code.

My experiences so far:

  • Clojure is not very easy to understand for a programmer that only worked with imperative languages before
  • Anyway it is possible to learn the basics quite fast, that means, using the features without exactly knowing why or how it works
  • Clojure opens up a new dimension of programming. LISP as a “programmable programming language” allows you to do things that you will never be able to do in Java (for example, please don’t wait for Sun until they finally add closures to Java. They won’t do it ever, I guess).

Actually, I could finish my Gauß-solver, and I like the code. However, since I am a newbie in functional programming, I guess there are lots of things I could optimize. My Java solution needed 300 ms for solving 1.000.000 3×3 SLEs, but my Clojure version needs 33 seconds (ouch!). Here is the code – if you have any suggestions, please tell me 😉

This experiment has encouraged me to gain more experience in LISP now, perhaps we can use some Clojure code in Zong! in the future (it integrates nearly seamlessly into Java!). If not, LISP will at least make me a better programmer.

The math behind slurs

After two weeks of summer school in South Tyrol I am back at home and can continue working on Zong!. Today I finished the first version of an automatic layout engine for slurs. I thought that this would be an easy task, but instead of plain if-then-else-code it turned out that I would need some math to solve this task. There are some requirements which have to be fulfilled:

  • The slur may not touch note heads
  • The slur must have a certain amount of curvature
  • The slur should cling to the notes as close as possible
  • And of course the slur should look nice

After some discussion, also with mathematicians and physicist (thanks to Uli, Christian, Phil, Daniel), I finally found a first solution that looks fine for most cases. Here is the result (simplified display):

» Demo-Applet

Play around with it too see how it works. These are the basic ideas:

  • Compute a polygon over the notes and convert it to a convex one
  • Find a quadratic curve that minimizes the area between the curve and the polygon (using linear programming and solving some SLEs)
  • Approximate this curve by a cubic bezier curve. If it is too flat, increase its curvature.

The result must be a cubic bezier curve to ensure compatibility to other notation programs and MusicXML.