Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

nx3 • 1. Data persistence object tree

Jonas Nyström edited this page Jan 12, 2014 · 2 revisions

As a starting point, the notation data is structured in a hierarchial tree representing the information neccessary to describe the enteties needed to build the score - the bars with its parts, the parts with their clefs and key signatures, the notes with their noteheads and accidentals etc.

These data classes are named with beginning N*:

  • a root level NScore that holds an array of NBar(s)
  • each NBar holds an array of NPart(s)
  • each NPart holds an array of NVoice(s)
  • each NVoice holds an array of NNote(s)
  • each NNote holds an array of NHead(s)

The relation between the elements is illustrated in the following overview, together with some example properties associated with each class:

My image

The relation between NBar, NPart, NVoice and NNote is illustrated here:

My image

Let's examine the following example to see how it's described in code:

My image

The upper part has two voices where the upper voice (NVoice0) has a single NNote with the note value of a dotted half note:

My image

This single dotted half note in the upper part's upper voice is created like the following:

var note0 = new NNote([new NHead(-1)], ENoteValue.Nv2dot);

The NNote is created with an array of one NHead(s) passed into the constructor as the first parameter. The NHead is passed an integer value reperesenting the note level relative to the middle line - in this case -1 wich translates to one position above the middle line. The second parameter passed into NNote represents the note value, in this case ENoteValue.Nv2dot.

Having created this single note we can pass it into an instace of NVoice:

var voiceUpper = new NVoice([note0], EDirectionUD.Up);

On to the lower voice of the upper part:

My image

It has three notes with note values of a dotted quarter note, an eight note and a quarter note respectively. The third of the notes has a sharp accidental, passed as second parameter into NHead:

var note0 = new NNote([new NHead(1)], ENoteValue.Nv4dot);
var note1 = new NNote([new NHead(2)], ENoteValue.Nv8);
var note2 = new NNote([new NHead(3, ESign.Sharp)] /*, ENoteValue.NV4 */); 

Please note the note value of quarter note is default, so we don't need to pass that into the third note above.

Now we can create the lower voice, passing an array of above notes into the constructor:

var voiceLower = new NVoice([note0, note1, note2], EDirectionUD.Down);

Now, when we have the two voices for the upper part, it's time to create the NPart itself. In the same manner as above, we pass the children (here the two voices) as an array into the NPart constructor:

var partUpper = new NPart([voiceUpper, voiceLower], EClef.ClefG, EKey.Flat1);

We also set the clef to EClef.ClefG (actually not needed as G-clef is default) and the key to EKey.Flat1.

Now for the lower part and its single voice:

My image

Please note that the first NNote has two noteheads, wich means that two NHead instances are passed into the NNote constructor:

var note0 = new NNote([new NHead(-2), new Head(5)], ENoteValue.Nv2);
var note1 = new NNote([new NHead(0)]); // No note value passed as quarter note is default
var voice = new NVoice([note0, note1]);

Here's the code for creating the lower NPart. Note the F-clef:

var partLower = new NPart([voice], EClef.ClefF, EKey.Flat1);	

Finally, we can create the NBar by passing the two NParts. We also set the time signature for the bar to 3/4:

var bar = new NBar([partUpper, partLower], ETime.Time3_4);

Done!