Dots and Dashes 6

In this tutorial there are some modest changes to the class. There is some reorganisation of code and small changes which are best characterised as "tidying up". Also the composition is extended by reusing the phrase data arrays and a specific tempo is set.

Here is the source file for this class.

Dot06.java

Have a look through the code and see if you can spot the difference from the previous Dot05 class.

Let's have a closer look.
import jm.music.data.*;
import jm.JMC;
import jm.util.*;
import qt.QTPlayer;
import jm.music.tools.*;
 
public class Dot06 implements JMC {
    private Score aScore = new Score("Composition and Arrangement");
    private int partCounter = 0;
    
    public static void main(String[] args) { 
        new Dot06();
    }
    
    // the constructor method
    public Dot06() {
        // musical material
        double[] phraseOneData = {C4, QUARTER_NOTE};
        double[] phraseTwoData= {REST, EIGHTH_NOTE, E4, EIGHTH_NOTE, 
                REST, QUARTER_NOTE};        
        double[] phraseThreeData= {REST, QUARTER_NOTE, F4, EIGHTH_NOTE, 
                REST, EIGHTH_NOTE};
        // arrangement and orchestration
        notesToPart( phraseOneData, 0.0, 48, CLARINET);
        notesToPart( phraseTwoData, 4.0, 9, FLUTE);
        notesToPart( phraseThreeData, 8.0, 7, NYLON_GUITAR);
        notesToPart( phraseTwoData, 30.0, 7, FLUTE);
        notesToPart( phraseThreeData, 32.0, 7, HORN);
 
        aScore.setTempo(140.0);
        
        View.sketch(aScore);
        
        QTPlayer.display(aScore);
        
    }
    
    private void notesToPart(double[] notes, double startTime, 
                              int repeats, int instrument) {
        // create a new phrase from the notes and loop it
        Phrase aPhrase = new Phrase(startTime);
        aPhrase.addNoteList(notes);
        Mod.repeat(aPhrase, repeats);
        // create a new part and add the phrase to it
        Part aPart = new Part("Part "+partCounter, 
                                instrument, partCounter);
        aPart.addPhrase(aPhrase);
        // keep track of how many parts have been created
        partCounter++;
        // add the part to the score
        aScore.addPart(aPart);
    }
}

After the marathon of the previous Dot05 tutorial, this one should be used as consolidation of the concepts of reusing code. In this class not only do we re-use code through invoking it repeatedly as a method, but the musical phrase data is reused for reiterations of the phrases within the composition. That is, the phrases are played again later on in the piece.

The main() method code has been reorganised into data and part generation sections. This reflects the compositional decision to treat phrases as reusable musical material. It also means that the arrangement of the phrases can been scanned at a glance, and reorganised with little reference to the phrase data directly. Notice that to position a phrase later in the piece the startTime value is changed.

A new Score method, setTempo(), is used to specify the speed of the composition. Notice that tempo is specified as a double value (fractional). This may seem overkill, but jMusic is nothing if not accurate - and there will come a time when you need that accuracy, so it's better to have it.

The rest of this class is as it was for the Dot05 tutorial.

You should try changing the arrangement and orchestration of the phrases in this piece to get a feel for how easy this is.


jMusic Tutorial Index