[jmsl] Noteheads and NoteFactory bug

jmsl at music.columbia.edu jmsl at music.columbia.edu
Thu Feb 26 20:45:36 EST 2009


Nice bug report Peter! Here's a not so pretty fix which nevertheless 
works fine:
...
// store notehead type before duration change
        int noteHeadType = n.getNoteHeadType();
// change from quarter to half note for example
        n.setDurationData(2);  
        NoteFactory.update(n);   // notehead type is lost now!
// restore notehead type, but be careful this might be the wrong form of 
the notehead (in this case a quarter notehead x on a half note which 
should be oval-x)
        n.setNoteHeadType(noteHeadType);
        // now fix the form of the notehead, in this case oval-x
        NoteFactory.calcAndSetNoteHeadStemTailInfo(n, n.getCoreDuration());
...


Will this work for your application?

Thanks,
Nick Didkovsky

jmsl at music.columbia.edu wrote:
> It looks like there may be a bug in the way NoteFactory handles 
> noteheads.  NoteFactory.updateFromPitch(n) works properly, but these 
> methods wipe out the notehead info:
>
> NoteFactory.update(n);
> NoteFactory.updateFromDur(n);
>
> thanks,
> Peter McCulloch
>
> Here's sample code:
>
> import java.awt.BorderLayout;
> import java.awt.event.WindowAdapter;
> import java.awt.event.WindowEvent;
>
> import javax.swing.JFrame;
>
> import com.didkovsky.portview.swing.ViewFactorySwing;
> import com.softsynth.jmsl.JMSL;
> import com.softsynth.jmsl.score.Note;
> import com.softsynth.jmsl.score.NoteFactory;
> import com.softsynth.jmsl.score.Score;
>
> public class TestNoteHeads {
>
>     public static void main(String[] args) {
>         JMSL.setViewFactory(new ViewFactorySwing());
>         Score score = new Score(2);
>         score.addMeasures(10);
>
>         Note n = NoteFactory.makeNote(Note.QUARTER, 60., 0, 0);
>
>         JFrame frame = new JFrame();
>         frame.setLayout(new BorderLayout());
>
>         frame.add(score.getScoreCanvas().getComponent());
>
>         frame.addWindowStateListener(new WindowAdapter() {
>             @Override
>             public void windowClosed(WindowEvent e) {
>                 JMSL.closeMusicDevices();
>                 System.exit(0);
>             }
>         });
>
>         frame.pack();
>
>         frame.setVisible(true);
>
>         n.setNoteHeadType(Note.NOTEHEAD_X);
>
>         score.addNote(n);
>
>         // This one is okay
>         // NoteFactory.updateFromPitch(n);
>
>         // These two are not
>         NoteFactory.update(n);
>         // NoteFactory.updateFromDur(n);
>        
>         System.out.println(n.getNoteHeadType());
>
>     }
>
> }
>
> _______________________________________________
> jmsl mailing list
> jmsl at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/jmsl


More information about the jmsl mailing list