StaffDrawer Component for .NET

Purpose

For the SeekWell project, I am designing a StaffDrawer component that takes as input a description of a simple, monophonic musical passage and draws the appropriate musical notation on a provided graphics context. Future improvements will allow for multiple staves to be displayed at once. The component will be written in C#, using the .NET framework with GDI+ for drawing. I am using a shareware font for music notation called Fughetta, developed by Blake Hodgetts (of Eugene, Oregon), who also developed Finale's Maestro font.

Features

Input

Besides providing a Graphics object on which to draw, the input consists of a MusicPassage object, which represents the essential features of the notation as well as providing straightforward conversion to and from my own XML format. This format for music passages, SeekWellXML (see the Schema file) , can be used to store music examples and to facilitate processing of simple music. I will eventually write converters between SeekWellXML and MusicXML to provide access to a wide range of musical data and other utilities, such as a music player application.

Output

The output is simply a rendered version of the music on a .NET Graphics object; this is essentially a bitmap representation of the music. It can be used with a separate ASP.NET control I am working on to render music on a web page. It can also be used by a WIndows Forms control I have designed to provide music notation in client-side Windows applicaitons.

Notation features

Motivation

This component is intended to represent a simple subset of musical notation that is relevant to my research in the creative microdomain SeekWell. In particular, this microdomain is restricted to:

Despite the seemingly severe restrictions imposed by these constraints, melodies in the SeekWell microdomain can be suprisingly interesting and complicated -- consider some of Bach's suites for solo instruments, for example. Even in single melodies conposed entirely of fixed note durations, principles of harmony, voice leading, and compound melody play active roles.

In spite of my short-term goals for rendering SeekWell melodies with this component, I would like to expand it to handle more complex music at a later time.

Requirements and Desired Features

The following features should be provided by the component:

Algorithm

Automatic layout of music notation is a notoriously difficult problem, and for good results it is necessary to spend a very large amount of time and to use techniques such as constraint-satisfaction to find a resonable solution to a given rendering problem. In this simple domain, however, it should be possible to generate passable results. The inclusion of chords, multiple voices on a staff, non-uniform durations, rests, and additional notation features such as expression markings and articulations lead to most of the complications. My algorithm will follow the following approach for one staff. Layout of multiple staffs linked in one system would proceed a bit differently.

  1. Determine the horizontal space required by each component, at some arbitrary font point size (like 24 point). In a simple case, the horizontal components are:
  2. Tally the total horizontal space, and compare with the total horizontal space available. Adjust the note-spacing algebraically (it will be like a simple linear programming problem with minimum-distance and max-distance constraints). This will fit notes in if possible.
  3. Calculate a scale factor for the point size: HorizontalPointSizeFactor = actual space / required space.
  4. Calculate a vertical space requirement by subtracting the top staff line used by the bottom staff line used and multiplying by the line distance. Staff lines 1,2,3,4, and 5 are always used, but additional ones can be used due to ledger lines. Calculate a vertical scale factor for the point size: VerticalPointSizeFactor = actual vertical / required vertical.
  5. Pick the minimum of the vertical and horizontal factors.
  6. Multiply the default point size 24 by the minimum scaler.
  7. Round the new point size down.
  8. Calculate the exact scale factor = new point size / 24. Scale the amount of horizontal space between notes by this factor.
  9. Recalculate spacing constants using the new point size, and rerun the horizontal space determination algorithm, but this time include actual rendering of the graphics.

Architecture

There are several major .NET components I am developing for music research. These include: