[jmsl] Adding MyNote when Loading an XML file to the score.

jmsl at music.columbia.edu jmsl at music.columbia.edu
Fri Feb 3 12:39:50 EST 2006

Dear Mr Nick,

More problems. I am really sorry that I am not gathering all questions together.

I have created the following class which extends Note.

import com.softsynth.jmsl.score.*;

 * @author pav
public class MyNote extends Note{
    private double[] performanceData;
    private double durationData;
    private double pitchData;
    private double amplitudeData;
    private double holdData;
    /** Creates a new instance of MyNote */
    public MyNote() {
        super(0,0,0, 0);                
    public double[] getPerformanceData(){
        performanceData = super.getPerformanceData();
        performanceData[0] = durationData;
        performanceData[1] = pitchData;
        performanceData[2] = amplitudeData;
        performanceData[3] = holdData;    
        return performanceData;
    public void setDurationData(double duration){
        this.durationData = duration;
    public void setPitchData(double pitch){
        this.pitchData = pitch;
    public void setApmlituteData(double amplitude){
        this.amplitudeData = amplitude;
    public void setHoldData(double hold){
        this.holdData = hold;

What I have in mind is as you said to use my own class for handling performance
of a note. Another problem that I have come across now is that, because I am using 
existing XML files that I have created ( created and generated with ScoreFrame demos) 
I can't capture a note from the score with the type 'MyNote'. The system does not let me to do that 
and gives me the following error.

           Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.softsynth.jmsl.score.Note

I suppose that this is because when I say

         score = Score.load(myFile.getPath());
catch(IOException e){System.out.println("Loading XML File: " + e);};

then the XML file is read and notes are added as of type 'Note' to the score.
What I am trying to do is:
    Enumeration en = tempScore.getSelectionBuffer().elements();
     while (en.hasMoreElements()){            
             MyNote note = (MyNote)en.nextElement();
             // .........code to modify note.........

but the system does not let me since it does not accept the type MyNote for
the element contained in the 'enumeration' . 

Is there a way when I load a score from an XML file to add 'MyNote'  type of notes
instead of 'Note' type of notes by overwriting some class again.

At the moment I am trying to do something different but it does not work for me.
After I load a score I am trying to get all notes, copy them as MyNote in a new Vector,
then remove the current notes of type 'Note' form the score and add the new ones of type
'MyNote'. Part of my code is following:

                  this.score = score.load(myFile.getPath());
             } catch(IOException e){System.out.println("Loading XML File: " + e);};

         tempBuf = new SelectionBuffer();
         tempBuf = score.getSelectionBuffer();
         Enumeration en = tempBuf.elements();        
         Vector newEnum = new Vector();

         // Copy all selected notes to vector newEnum.
         while (en.hasMoreElements()){                         
             Note note = (Note)en.nextElement();            
             MyNote myNote = new MyNote();
             Note.copyProperties((Note)note, myNote);
         // Trying to remove all current notes of type 'Note' from the score.
         Enumeration enumeration = newEnum.elements();
         // Add notes of type 'MyNote' to the score.
         while (enumeration.hasMoreElements()) {
             MyNote note = (MyNote) enumeration.nextElement();
         // Of course later I set orchestra and other settings for the score.

What I get as an output from this code is the first measure of the score not 
changed but of type 'Note' as it was, and the rest of the score's notes are changed to
type 'MyNote' but notes of the left hand (piano piece) and intrval notes of the right hand 
are missing.

Thank you.   
Pavlos Marios

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://music.columbia.edu/pipermail/jmsl/attachments/20060203/e3ac9f83/attachment.html

More information about the jmsl mailing list