[jmsl] ScorePainter problem
jmsl at music.columbia.edu
jmsl at music.columbia.edu
Mon Sep 8 20:47:21 EDT 2008
Hi Peter
Thanks for the working code example. It helps me troubleshoot and
reveals problems quickly.
Couple of things. ScorePainter already has a Score class variable, so
you do not want to re-declare that in the subclass.
But since you are providing your own ScorePainter (something that was
not anticipated in the original API), the score needs to be handed a
reference to it as well, since Score is not creating its own. Ugly, sorry.
So I paste a complete working example below. BUT it will not work until
you get a new prerelease which makes score.setScorePainter() public.
That's coming your way soon
Thanks
Nick Didkovsky
package com.petermcculloch.megalo.graphics;
import java.awt.Graphics;
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.*;
public class ScorePainterMegalo extends ScorePainter {
// Score score; no! superclass already has score class variable
public ScorePainterMegalo(Score score) {
super(score);
score.setScorePainter(this); // !!! ugly but necessary
// this.score = score; no! superclass already has score class
variable
}
// @Override
public void render(Graphics g, double playTime, boolean b) {
super.render(g, playTime, b);
g.drawLine(0, 0, 200, 200);
System.out.println("Called render...");
}
public static void main(String args[]) {
JFrame frame = new JFrame();
JMSL.setViewFactory(new ViewFactorySwing());
Score.useSharedCanvas(false); // !!!
ScoreCanvas canvas = new
ScoreCanvasFactory().createScoreCanvas(500, 500);
Score score = new Score(2, 700, 700, "Megalo Sabado", canvas);
ScorePainterMegalo painter = new ScorePainterMegalo(score);
score.addMeasures(10, 3, 4);
score.setCurrentMeasureNumber(0);
score.setCurrentStaffNumber(0);
score.setCurrentTrackNumber(0);
score.addNote(1., 60., 1., 1.);
frame.add(((ScoreCanvasSwing) canvas).getComponent());
frame.addWindowStateListener(new WindowAdapter() {
// @Override
public void windowClosed(WindowEvent e) {
JMSL.closeMusicDevices();
System.exit(0);
}
});
frame.pack();
score.ownCanvas();
frame.setVisible(true);
System.out.println("ScorePainter:\t" +
score.getScorePainter().getClass().toString());
}
}
jmsl at music.columbia.edu wrote:
>
> Hi all,
>
> I'm trying to test a new ScorePainter, and I can't get it to install.
> When I run it I get:
> ScorePainter: class com.softsynth.jmsl.score.ScorePainter
>
>
> Here's a demonstration of the problem. Am I missing something in the
> rendering sequence for a score?
>
> thanks,
> Peter McCulloch
>
> package com.petermcculloch.megalo.graphics;
>
> import java.awt.Graphics;
> 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.Score;
> import com.softsynth.jmsl.score.ScoreCanvasSwing;
> import com.softsynth.jmsl.score.ScorePainter;
>
> public class ScorePainterMegalo extends ScorePainter {
>
> Score score;
>
> public ScorePainterMegalo(Score score) {
> super(score);
> this.score = score;
> }
>
> @Override
> public void render(Graphics g, double playTime, boolean b) {
> super.render(g, playTime, b);
> System.out.println("Called render...");
> }
>
> public static void main(String args[]) {
>
> JFrame frame = new JFrame();
>
> JMSL.setViewFactory(new ViewFactorySwing());
>
> // Score.useSharedCanvas(false);
>
> Score score = new Score(2, 700, 700);
>
> score.addMeasures(10, 3, 4);
>
> score.setCurrentMeasureNumber(0);
> score.setCurrentStaffNumber(0);
> score.setCurrentTrackNumber(0);
> score.addNote(1., 60., 1., 1.);
>
> ScorePainterMegalo painter = new ScorePainterMegalo(score);
>
> ScoreCanvasSwing canvas = null;
>
>
> // if true, blank canvas, but same scorepainter. If false,
> score canvas and same scorepainter
> boolean createNew = false;
>
> if (createNew) {
> canvas = new ScoreCanvasSwing(500, 500);
>
> score.setScoreCanvas(canvas);
> canvas.setScorePainter(painter);
> score.getScoreCanvas().setScorePainter(painter);
> } else {
>
> score.getScoreCanvas().setScorePainter(painter);
>
> canvas = (ScoreCanvasSwing) score.getScoreCanvas();
>
> }
>
> frame.add(((ScoreCanvasSwing) canvas).getComponent());
>
> frame.addWindowStateListener(new WindowAdapter() {
> @Override
> public void windowClosed(WindowEvent e) {
> JMSL.closeMusicDevices();
> System.exit(0);
> }
> });
>
> frame.pack();
>
> score.ownCanvas();
>
> frame.setVisible(true);
>
> System.out.println("ScorePainter:\t" +
> score.getScorePainter().getClass().toString());
>
> }
>
> }
> _______________________________________________
> jmsl mailing list
> jmsl at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/jmsl
More information about the jmsl
mailing list