Package com.softsynth.jmsl.score
Class MusicGlyphRendererProxy
java.lang.Object
com.softsynth.jmsl.score.MusicGlyphRenderer
com.softsynth.jmsl.score.MusicGlyphRendererProxy
public class MusicGlyphRendererProxy extends MusicGlyphRenderer
This MusicGlyph renderer builds text messages that can be sent to Max for
rendering in MaxScore, or anywhere else for that matter.
render() returns true for glyphs that can be rendered in the proxy renderer
and in so doing, passes a text message to its
MusicGlyphRendererProxyListeners
The first token will always be "RenderMusicGlyph" The second token is the name of the font (it will be either "Sonata" or "Accidentals") The third token is the name of the GlyphToken itself The fourth token is the character of the font that will make the desired glyph (for example "J" in Sonata makes the black notehead). The fifth token is the X position of the glyph The sixth token is the Y position of the glyph The seventh token is the zoom. To convert from zoom to font point size use this formula and logic (however this translates to font manipulation in Max): if (zoom != lastZoom || myFont == null) { int point = (int) (zoom * Staff.SPACE_INTERVAL * FONT_SIZE_FACTOR); // see below myFont = new Font(getFontName(), Font.PLAIN, point); lastZoom = zoom; } ...where: Staff.SPACE_INTERVAL = 12 and FONT_SIZE_FACTOR = 4 The eighth token is either "null" or the class name of parent object that he glyph belongs to (for example "Note" for glyph token "noteheadblack") The tokens that follow the 8th token depend on the parent's type: "Measure" is followed by measure index "Note" is followed by four integers: measure index, staff index, track index, note index "Clef" is followed by an integer constant signalling the clef type. not particularly useful since the music glyph itself already tells you if it's tr, al, te, or ba for treble, alto, tenor, or bass clef Some comments: Here's some of the stuff that will get rendered directly into your graphics environment using line drawing and rectangle drawing: percussion clef (no such glyph in Sonata) Staff lines bar lines, repeats, double bars, period double bars) slurs, ties, dots brackets over tuplets beams ledger lines cresc/decresc 8va/8vb brackets (but the text token itself uses the font) The happily naive way that you could proceed with this is straightforward: For each message set the font and the font size according to the zoom and print token #4 to the x, y position ie you can ignore the meta information and just print and see what you get. It should be identical to the layout I get in pure Java/JMSL. Then for extended tricks you can examine the glyph token and the parent object and start messing around creatively! RenderMusicGlyph tempoqtrequals 20.0 29.0 1.0 Measure 0 RenderMusicGlyph tr 24.0 136.92000000000002 1.0 Clef 0 RenderMusicGlyph noteheadblack 147.0 147.0 1.0 Note 0 0 0 0 RenderMusicGlyph noteheadblack 192.0 177.0 1.0 Note 0 0 0 1 RenderMusicGlyph flat 182.0 177.0 1.0 null RenderMusicGlyph stem 147.0 149.0 1.0 Note 0 0 0 0 RenderMusicGlyph stem 147.0 132.0 1.0 Note 0 0 0 0 RenderMusicGlyph stem 192.0 179.0 1.0 Note 0 0 0 1 RenderMusicGlyph stem 192.0 140.0 1.0 Note 0 0 0 1 RenderMusicGlyph stem 192.0 132.0 1.0 Note 0 0 0 1 RenderMusicGlyph noteheadblack 237.0 123.0 1.0 Note 0 0 0 2 RenderMusicGlyph flat 227.0 123.0 1.0 null RenderMusicGlyph stem 237.0 125.0 1.0 Note 0 0 0 2 RenderMusicGlyph stem 237.0 113.0 1.0 Note 0 0 0 2 RenderMusicGlyph eighthflagdown 237.0 111.0 1.0 Note 0 0 0 2 RenderMusicGlyph eighthflagdown 237.0 123.0 1.0 Note 0 0 0 2 RenderMusicGlyph noteheadblack 282.0 123.0 1.0 Note 0 0 0 3 RenderMusicGlyph natural 272.0 123.0 1.0 null RenderMusicGlyph stem 282.0 125.0 1.0 Note 0 0 0 3 RenderMusicGlyph stem 282.0 113.0 1.0 Note 0 0 0 3 RenderMusicGlyph eighthflagdown 282.0 111.0 1.0 Note 0 0 0 3 RenderMusicGlyph eighthflagdown 282.0 123.0 1.0 Note 0 0 0 3 etc
- Author:
- Nick Didkovsky, March 2009, programmed during the Ice Cream Time European Tour mostly in the van.
-
Constructor Summary
Constructors Constructor Description MusicGlyphRendererProxy()
-
Method Summary
Modifier and Type Method Description void
addMusicGlyphRendererProxyListener(MusicGlyphRendererProxyListener listener)
java.lang.String
getFontName()
double
getGlyphWidth(java.awt.Graphics g, java.lang.String glyphToken, double zoom)
void
removeMusicGlyphRendererProxyListener(MusicGlyphRendererProxyListener listener)
boolean
render(java.lang.String glyphToken, java.lang.Object parent, double x, double y, double zoom, java.awt.Graphics g)
parent might be null, or might be a Note, Measure, or a ClefPositionedGlyph
selectGlyph(java.lang.String glyphToken, java.lang.Object parent, double x, double y, double zoom)
Methods inherited from class com.softsynth.jmsl.score.MusicGlyphRenderer
createBaseFont, getBaseFont, getFont_size_normalization_factor, isFontFound, printAvailableSystemFonts, setBaseFont, setFont_size_normalization_factor
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
MusicGlyphRendererProxy
public MusicGlyphRendererProxy()
-
-
Method Details
-
addMusicGlyphRendererProxyListener
-
removeMusicGlyphRendererProxyListener
-
getFontName
public java.lang.String getFontName()- Specified by:
getFontName
in classMusicGlyphRenderer
-
render
public boolean render(java.lang.String glyphToken, java.lang.Object parent, double x, double y, double zoom, java.awt.Graphics g)parent might be null, or might be a Note, Measure, or a Clef- Specified by:
render
in classMusicGlyphRenderer
- Returns:
- true if glyph is assigned and rendered
-
selectGlyph
public PositionedGlyph selectGlyph(java.lang.String glyphToken, java.lang.Object parent, double x, double y, double zoom)- Specified by:
selectGlyph
in classMusicGlyphRenderer
-
getGlyphWidth
public double getGlyphWidth(java.awt.Graphics g, java.lang.String glyphToken, double zoom)- Overrides:
getGlyphWidth
in classMusicGlyphRenderer
-