package jmsltestsuite; import java.awt.FontFormatException; import java.awt.Graphics; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.*; import java.util.Enumeration; import java.util.Hashtable; import com.didkovsky.portview.swing.ViewFactorySwing; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.score.*; import com.softsynth.jmsl.score.musicglyphrenderers.SonataMusicGlyphRenderer; /** * JMSL Score lets you add custom music glyph renderers, that might use a real music font for * example. Here we test two such renderers, one that uses Sonata music font for most glyphs, but * gives the priority to another renderer for microtonal accidentals (Accidentals font by Matthew * Hindson, see http://www.hindson.com.au/wordpress/free-fonts-available-for-download/ * * The order you add MusicGlyphRenderers to JMSL determines the priority. The first renderer to * successfully render a glyph returns true and stops the chain. If they all fall through or if none * exist, JMSL uses line drawing routines. * * * * Test SonataMusicGlyphRenderer and AccidentalsMusicGlyphRenderer */ public class MusicGlyphRendererTest implements MusicGlyphRendererProxyListener, MusicCurveRenderer { PrintWriter log; public MusicGlyphRendererTest() { try { log = new PrintWriter(new FileWriter(new File("logs/MusicGlyphProxyOutput.txt")), true); } catch (IOException e) { e.printStackTrace(); } } public void notifyRenderMusicGlyph(String msg) { if (log != null) { log.println(msg); } else { System.out.println("\t\t\t" + msg); } } public void draw(Graphics g, String graphicsCommand, Hashtable properties) { log.println("\nGraphics Command: " + graphicsCommand); Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); log.println(key + ": " + properties.get(key)); } } public static void main(String[] args) { JMSL.setViewFactory(new ViewFactorySwing()); MusicGlyphRendererTest musicGlyphRendererTest = new MusicGlyphRendererTest(); boolean USE_LINE_DRAWING = !true; boolean USE_PROXY = !false; Score score = new Score(1, 1200, 600); if (USE_PROXY && !USE_LINE_DRAWING) { System.out.println("Using proxy renderer"); MusicGlyphRendererProxy proxyRenderer = new MusicGlyphRendererProxy(); proxyRenderer.addMusicGlyphRendererProxyListener(musicGlyphRendererTest); score.addMusicGlyphRenderer(proxyRenderer); score.setMusicCurveRenderer(musicGlyphRendererTest); } else if (!USE_LINE_DRAWING) { MusicGlyphRenderer sonataMusicGlyphRenderer = new SonataMusicGlyphRenderer(); MusicGlyphRenderer accidentalsMusicGlyphRenderer = new AccidentalsMusicGlyphRenderer(); try { if (accidentalsMusicGlyphRenderer.isFontFound()) { score.addMusicGlyphRenderer(accidentalsMusicGlyphRenderer); } else { System.out.println( "\"Accidentals\" Font not found on your system\nGet it from http://www.hindson.com.au/wordpress/free-fonts-available-for-download/"); } if (sonataMusicGlyphRenderer.isFontFound()) { score.addMusicGlyphRenderer(sonataMusicGlyphRenderer); } else { System.out.println("Sonata font not found on your system. Get it from http://www.adobe.com"); } } catch (FontFormatException e1) { System.err.println("FontFormatException, music font cannot be loaded"); e1.printStackTrace(); } catch (IOException e1) { System.err.println("IOException, music font cannot be loaded"); e1.printStackTrace(); } } score.addMeasure(); score.setCurrentTrackNumber(0); Note n1 = score.addNote(1, 60, 0.5, 0.8); Note n2 = score.addNote(1, 60, 0.5, 0.8); Note n3 = score.addNote(1, 60, 0.5, 0.8); n1.setCrescOut(true); n2.setCrescOut(true); // score.addNote(0.5, 0, 0, 0.4); score.setCurrentTrackNumber(1); n1 = score.addNote(1, 72, 0.5, 0.8); n2 = score.addNote(1, 72, 0.5, 0.8); n3 = score.addNote(1, 72, 0.5, 0.8); n1.setCrescOut(true); n2.setCrescOut(true); // score.addNote(0.5, 0, 0, 0.4); /* * score.addMeasure(3, 4); score.addMeasure(13, 8); double dur = .25; * * score.addNote(dur, 60, 0.5, 0.8).setBeamedOut(true); score.addNote(dur, 63 - 12, 0.5, * 0.8).setAccPref(Note.ACC_PREFER_FLAT); score.addNote(dur, 66, 0.5, * 0.8).setAccPref(Note.ACC_PREFER_FLAT); score.addNote(dur, 67, 0.5, * 0.8).setAccPref(Note.ACC_PREFER_FLAT); * * dur = .5; Note n = score.addNote(dur, 12 + 61, 0.5, 0.8); n.setBeamedOut(true); * score.addNote(dur, 12 + 63, 0.5, 0.8); * * n = score.addNote(dur, 24 + 66, 0.5, 0.8); // n.setBeamedOut(true); score.addNote(dur, 24 * + 68, 0.5, 0.8); * * dur = 1; score.addNote(dur, 60.5, 0.5, 0.8).setAccPref(Note.ACC_PREFER_FLAT); * score.addNote(dur, 61.5, 0.5, 0.8).setAccPref(Note.ACC_PREFER_FLAT); * * score.addNote(dur, 60.5, 0.5, 0.8); * * score.addNote(dur, 61.5, 0.5, 0.8).addMark(Note.MARK_TRILL); score.addNote(dur, 63.5, * 0.5, 0.8).addMark(Note.MARK_TRILL); * * // SECOND STAFF score.setCurrentMeasureNumber(0); score.setCurrentStaffNumber(1); * * dur = 0.5; int[] dynamics = { Note.DYNAMIC_PPP, Note.DYNAMIC_PP, Note.DYNAMIC_P, * Note.DYNAMIC_MP, Note.DYNAMIC_MF, Note.DYNAMIC_F, Note.DYNAMIC_FF, Note.DYNAMIC_FFF }; * for (int i = 0; i < dynamics.length; i++) { score.addNote(dur, 60, 0.5, dur * * 0.8).setDynamic(dynamics[i]); // score.addNote(dur, 72, 0.5, dur * * 0.8).setDynamic(dynamics[i]); } * * dur = 2; score.addNote(dur, 12 + 61, 0.5, 0.8).addMark(Note.MARK_TRILL_FLAT); * score.addNote(dur, 61, 0.5, 0.8).addMark(Note.MARK_TRILL_SHARP); * * dur = 4; n = score.addNote(dur, 41, 0.5, 0.8); n.setMark(Note.MARK_TRILL_NATURAL); * n.setNoteheadColor(java.awt.Color.green); // System.out.println("CORE DUR OF WHOLE NOTE=" * + n.getCoreDuration()); * * // THIRD STAFF score.setCurrentMeasureNumber(0); score.setCurrentStaffNumber(2); double * restDur = 1.0; for (int i = 0; i < 7; i++) { score.addNote(restDur, 0, 0, 0); if (i == 6) * { score.addNote(restDur, 0, 0, 0); } restDur /= 2; } int[] marks = { Note.MARK_TENUTO, * Note.MARK_ACCENT, Note.MARK_STACCATO, Note.MARK_ACCENT_STACCATO, * Note.MARK_WEDGE_STACCATO, Note.MARK_ACCENT_TENUTO, Note.MARK_FERMATA, Note.MARK_HARMONIC, * Note.MARK_INVERTED_MORDANT, Note.MARK_MORDANT, Note.MARK_WEDGE }; for (int i = 0; i < * marks.length; i++) { int mark = marks[i]; score.addNote(0.25, 60, 0.5, * 0.2).addMark(mark); score.addNote(0.25, 72, 0.5, 0.2).addMark(mark); } * score.addNote(0.25, 60, 0.5, 0.2); score.addNote(0.25, 72, 0.5, 0.2); * * score.getMeasure(1).getStaff(0).setClef(Clef.ALTO_CLEF); * score.getMeasure(0).getStaff(1).setClef(Clef.TENOR_CLEF); * score.getMeasure(1).getStaff(1).setClef(Clef.BASS_CLEF); * score.getMeasure(2).getStaff(1).setClef(Clef.BASS_CLEF); */ ScoreFrame scoreFrame = new ScoreFrame(); scoreFrame.addScore(score); scoreFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { JMSL.closeMusicDevices(); System.exit(0); } }); scoreFrame.setVisible(true); } }