Category Archives: Programming

Sprint 72 “Bullroarer” finished

The next version of Zong! is online! Sprint 72 features the first prototype of a pure HTML5/JS score renderer, a complete rewrite of the midi-out module and improved layout for cross-staff beams.

2017-03-03 WebApp Screenshot

The above screenshot shows the first prototype of the Zong! WebApp. It is a pure HTML5/JS implementation and should run in every modern browser, including mobile devices. The great thing is that it is actually using the original Java codebase and is then cross-compiled to JS using the fantastic GWT framework. Currently our webapp supports loading and rendering MusicXML files. Later, we will add more features like playback. We will also provide it as a web component that can easily be integrated into other websites and apps written by other developers. If you are interested in using this component in your project, please contact us so we can take the first steps together.

Another feature is the completely rewritten MIDI export module. It now supports all kinds of repetitions, voltas and jumps (like da capo, dal segno or coda), even in complicated scenarios. But there is still much work to do, like better support for dynamics, instruments and articulations.

We also fixed the layout of cross-staff beams. This turned out to be even more complicated than expected, especially if different staff sizes are supported (as we do!). There is also some room for discussion: Should the short beam flags at the 32nd stems always be placed on the chord side, or should all flags be placed on the same side within a beam? Other than Sibelius and MuseScore we decided to use the second solution because of better readability. Compare the two possibilities below and have a look at the last note. What do you think?

Cross-staff beams in MuseScore:

2017-03-03 Cross-staff beams MuseScore

Cross-staff beams in Zong!:

2017-03-03 Cross-staff beams Zong


Sprint 71 โ€œLurโ€ finished

After nearly two years, which should have been only four weeks according to the original plan, we finally released Sprint 71 today. The last two years were full of work, including the construction of my new home (see my blog, in German), so I had nearly no time left for Zong!. Fortunately, the last weeks I found time again to work on it, and I (again…) intend to continue with it during the coming year.

The goal of Spring 71 was to improve the stability of the MusicXML import and of the layout engine. Indeed, we managed to collect lots of MusicXML files from all over the web (about 12.000 pieces), some with great quality, some with little errors and poor quality, and now we are able to load and layout them all. Of course, the layout quality is still not good enough to publish a version of Zong! for real end users, but at least we can now focus on specific problems, one after the other. We can not publish the test files because of copyright issues, but we run the tests internally.

Another good – and public – overview of the current MusicXML import and layout progress is provided by our implementation of the Unofficial MusicXML Test Suite. There is a status report and a visual report, which brings our layout results face to face with the Lilypond renderings.

2016-12-31 Test Suite

For the next sprint, we are planning to improve the stability of midi-out and the rendering on Android devices and with HTML/JS. Happy new year! ๐Ÿ™‚

Demo apps available

Today we pushed Sprint 70 “Bow” to our server. As more and more developers get interested in the Zong! project, we started to write little demo apps which show how Zong! components can be used within other software projects:

  • The Minimal demo simply converts a MusicXML file to a PDF file
  • The little more advanced Simple GUI demo includes a score viewer with a moving cursor and MIDI playback

In this sprint, we created the JavaFX based renderer. We refactorized the musicxml and musicxml-in projects as well as the renderer project, which is now a universal base for all platform-specific renderers (JavaFX, AWT/Java2D, GWT and Android is on the way). We will continue by improving the layout project, including tests based on the Inofficial MusicXML Test Suite.

Zong! Player ready for Java Web Start

The Zong! Player is an open source audio player for MusicXML scores. It is also possible to convert MusicXML files to other audio formats like MIDI, OGG, WAV and MP3 (if LAME is installed). The program is now based on JavaFX 8 and can be started by clicking on the following button:

Oracle has spent some effort to increase the security of Java applets and applications. Therefor, Java Web Start applications have now to be signed using a trusted certificate. Being an open source project, Zong! got a free certificate from Certum. Thank you very much for your support!

Sprint 68 finished

Today, iteration 68, codename “Flute”, was pushed to the git server. After a long summer break, Zong! is finally back in active development. Within the last sprints, we started to create the GWT-based web viewer (pure HTML5/JS score viewer) and finally switched from AWT/Swing to JavaFX 8. We have also rewritten all the IO stuff from blocking to asynchronous processing for better support of single-threaded environments like the web browser. As always, our progress is documented in our public tracker and in the wiki.

Nearly two years ago we found JavaFX not to be ready for real-world applications. Now, in version 8, JavaFX looks fantastic and is really fun to work with. For example, the SceneBuilder is a nice WYSIWYG editor for creating GUI in JavaFX, and connecting the controls and the actions to the Java controller class works straightforward. And, very important for Zong!, in a first test application for drawing lots of vector images (musical symbols) we observed very high performance. We are curious, if JavaFX will become more famous and bring Java applications back to the desktop. We already made our decision.

Swing component: Combobox for font selection

There are many great Swing components around, but we could not find a nice combobox for font selection, that includes not only the font names but also some preview characters and maybe a history of the recently selected fonts. You know such a combobox from and other word processors.

Well, here it is now. Our FontChooserComboBox offers font preview, customizable preview strings, optionally a list of the recent fonts and even auto completion for the font name. And best of all, the code is public domain, so you can use it for whatever you want. However, if you improve it, please share your work with us!

Here is a demo video:


A webstart demo:

Here are the files:

Comments are welcome ๐Ÿ™‚

Java Tip #5: Shorter singleton calls

If you are using the Singleton pattern, you often have code like this:

Object myValue = MySingleton.getInstance().getSomeValue();

Can this be shortened? Yes! Like in Java Tip #3, we can use public static methods and static import. But then, we do not see at a glance what getInstance() is actually returning, and if we use multiple Singletons within our class, we would have a naming problem. The easy solution: rename the getInstance() method to the (camelCase) name of its class. Now we can write:

Object myValue = mySingleton().getSomeValue();

Java Tip #4: Switch comments

During testing, you often want to make things simpler. For example, if you want to test your new printing routines, you might want to see only the print preview instead of getting real printouts. You can switch between two code blocks by using the following pattern and by simply inserting or removing a single character:


When removing the first slash, the second code block becomes active:



Java Tip #3: Shorter code with static factory methods

Java code can look much cleaner and shorter when using static factory methods combined with import static. These are methods, which return a new (or reused) instance of a class. Let’s say we have a HashMap which should use instances of KeyClass for the keys and a tuple of ValueClass1 and ValueClass2 as its values. Instead of writing lengthy code like

HashMap<KeyClass, Tuple<ValueClass1, ValueClass2>>
  myMap = new HashMap<KeyClass,
      Tuple2<ValueClass1, ValueClass2>>();

you could just use

HashMap<KeyClass, Tuple<ValueClass1, ValueClass2>>
  myMap = map();

Therefor, we need to create a static factory method named map somewhere with the following code:

public static <T1, T2> HashMap<T1, T2> map()
  return new HashMap<T1, T2>();

And then, when filling the HashMap, you can again make use of factory methods. Compared to

  new Tuple2<ValueClass1, ValueClass2>(
    value1, value2));

the following code is much shorter:

myMap.put(myKey, t(value1, value2));

Nice, how easy tuples (or triples, or quadrupels, …) can be created in Java! Remember, that import static is needed to make it really short. We do not want to write Tuple.t(...) everywhere where we instantiate a tuple, but really only t(...). This is nearly as short as in the programming languages which support tuples natively.

One other example, where we always use those methods, are fractions. Instead of new Fraction(1, 4); we always use fr(1, 4). Actually we made the constructor private, so that programmers must use the factory method. This leads to much cleaner code. One real example from Zong!: Instead of

new Chord(new Note(new Pitch(1, 0, 4)),
  new Fraction(1, 4))

we just have to write

chord(note(pi(1, 0, 4)), fr(1, 4))

Downloads: Fraction, Tuple2, Tuple3

Java Tip #2: foreach with index (2)

Time for another Java Tip. Last time I described the problem of losing a loop counter when using the foreach loop. I mentioned, that I have two solutions for this problem. Here is the second one:

I created a class named It (short for “iterator”). It is a Iterable Iterator (funny, but true: Not all Iterators are Iterable in Java…) which allows you to wrap any collection and use it within a foreach loop. Moreover, it contains the method getIndex() which returns the current value of the loop counter. For quick creation, there is the it factory method which you should import statically.

Here is an example:

It<Foo> fooIt = it(fooList);
for (Foo foo : fooIt) {
  //for each foo in fooList...
  //if you need the current index:

You can also write similar iterators, like ReverseIterator for an iterator which begins with the last element and ends with the first one. Enjoy ๐Ÿ™‚

Downloads: It, ReverseIterator