Search in sources :

Example 1 with Symbol

use of com.xenoage.zong.symbols.Symbol in project Zong by Xenoage.

the class TextLayoutTools method create.

/**
 * Creates a {@link TextLayout} for the given {@link FormattedTextParagraph},
 * including both {@link FormattedTextString}s and {@link FormattedTextSymbol}s.
 * If impossible (e.g. because the paragraph is empty), null is returned.
 */
private static TextLayout create(FormattedTextParagraph p, FontRenderContext frc) {
    // get the raw string
    AttributedString as = new AttributedString(p.getText());
    // set attributes
    int pos = 0;
    int count = 0;
    for (FormattedTextElement e : p.getElements()) {
        int len = e.getLength();
        if (len > 0) {
            if (e instanceof FormattedTextString) {
                as.addAttributes(createAttributesMap(e.getStyle()), pos, pos + len);
                count++;
            } else if (e instanceof FormattedTextSymbol) {
                FormattedTextSymbol fts = (FormattedTextSymbol) e;
                Symbol symbol = fts.getSymbol();
                if (symbol instanceof PathSymbol) {
                    as.addAttribute(TextAttribute.FOREGROUND, toAwtColor(fts.getStyle().getColor()), pos, pos + 1);
                    as.addAttribute(TextAttribute.CHAR_REPLACEMENT, new PathSymbolGraphicAttribute((PathSymbol) symbol, fts.getScaling()), pos, pos + 1);
                    count += 2;
                }
            }
            pos += len;
        }
    }
    if (count == 0)
        // creating a TextLayout would fail
        return null;
    else
        return new TextLayout(as.getIterator(), frc);
}
Also used : AttributedString(java.text.AttributedString) PathSymbolGraphicAttribute(com.xenoage.zong.renderer.awt.symbol.PathSymbolGraphicAttribute) PathSymbol(com.xenoage.zong.symbols.PathSymbol) Symbol(com.xenoage.zong.symbols.Symbol) PathSymbol(com.xenoage.zong.symbols.PathSymbol) TextLayout(java.awt.font.TextLayout)

Example 2 with Symbol

use of com.xenoage.zong.symbols.Symbol in project Zong by Xenoage.

the class ChordStamper method stampCore.

/**
 * Draws the given chord, including noteheads, stem, flags, accidentals, dots,
 * articulations and leger lines.
 */
public ChordStampings stampCore(ChordNotation chord, float chordXMm, StamperContext context) {
    val staff = context.getCurrentStaffStamping();
    Chord element = chord.element;
    boolean grace = element.isGrace();
    LayoutSettings settings = context.getSettings();
    float scaling = (grace ? settings.scalingGrace : 1);
    ChordWidths chordWidths = (grace ? settings.graceChordWidths : settings.chordWidths);
    float leftNoteXMm = getLeftNoteXMm(chordXMm, chord.notes, staff.is);
    // stem
    StemStamping stem = stampStem(chord, leftNoteXMm, context);
    // type of notehead
    CommonSymbol noteheadSymbol = CommonSymbol.NoteWhole;
    Duration.Type symbolType = Duration.INSTANCE.getNoteheadSymbolType(element.getDisplayedDuration());
    if (symbolType == Duration.INSTANCE.Type.Half)
        noteheadSymbol = CommonSymbol.NoteHalf;
    else if (symbolType == Duration.INSTANCE.Type.Quarter)
        noteheadSymbol = CommonSymbol.NoteQuarter;
    // noteheads
    NotesNotation notes = chord.notes;
    NoteheadStamping[] noteheads = new NoteheadStamping[notes.getNotesCount()];
    for (int iNote : range(noteheads)) {
        NoteDisplacement note = notes.getNote(iNote);
        Symbol noteSymbol = context.getSymbol(noteheadSymbol);
        float noteXMm = getNoteheadXMm(leftNoteXMm + note.xIs * staff.is, scaling, staff, noteSymbol);
        NoteheadStamping noteSt = new NoteheadStamping(chord, iNote, noteSymbol, Color.Companion.getBlack(), staff, sp(noteXMm, note.lp), scaling);
        noteheads[iNote] = noteSt;
    }
    // flags (only drawn if there is no beam)
    int flagsCount = Duration.INSTANCE.getFlagsCount(element.getDisplayedDuration());
    Beam beam = element.getBeam();
    StemDirection stemDir = chord.stemDirection;
    FlagsStamping flags = null;
    if (beam == null && flagsCount > 0 && chord.stem != null) /* can happen when no stem is used */
    {
        FlagsStamping.FlagsDirection flag = (stemDir == StemDirection.Up ? FlagsStamping.FlagsDirection.Down : FlagsStamping.FlagsDirection.Up);
        Symbol flagSymbol = context.getSymbol(CommonSymbol.NoteFlag);
        flags = new FlagsStamping(chord, staff, flag, flagsCount, flagSymbol, scaling, sp(leftNoteXMm + notes.stemOffsetIs * staff.is, chord.stem.endSlp.lp));
    }
    // accidentals
    AccidentalsNotation accs = chord.accidentals;
    AccidentalStamping[] accsSt = new AccidentalStamping[0];
    if (accs != null) {
        accsSt = new AccidentalStamping[accs.accidentals.length];
        for (int iAcc : range(accsSt)) {
            AccidentalDisplacement acc = accs.accidentals[iAcc];
            AccidentalStamping accSt = new AccidentalStamping(chord, iAcc, staff, sp(chordXMm + (acc.xIs - chord.width.frontGap + 0.5f) * staff.is, acc.yLp), 1, context.getSymbol(CommonSymbol.getAccidental(acc.accidental)));
            accsSt[iAcc] = accSt;
        }
    }
    // dots
    int[] dotPositions = notes.dotsLp;
    int dotsPerNote = notes.getDotsPerNoteCount();
    ProlongationDotStamping[] dots = new ProlongationDotStamping[dotPositions.length * dotsPerNote];
    Symbol dotSymbol = context.getSymbol(CommonSymbol.NoteDot);
    for (int iNote : range(dotPositions)) {
        for (int iDot : range(dotsPerNote)) {
            ProlongationDotStamping dotSt = new ProlongationDotStamping(chord, staff, dotSymbol, sp(leftNoteXMm + notes.getDotsOffsetIs(iDot) * staff.is, dotPositions[iNote]));
            dots[iNote * dotsPerNote + iDot] = dotSt;
        }
    }
    // articulations
    ArticulationsNotation arts = chord.articulations;
    ArticulationStamping[] artsSt = new ArticulationStamping[0];
    if (arts != null) {
        artsSt = new ArticulationStamping[arts.articulations.length];
        float noteheadWidth = chordWidths.get(element.getDuration());
        for (int iArt : range(artsSt)) {
            ArticulationDisplacement art = arts.articulations[iArt];
            ArticulationStamping artSt = new ArticulationStamping(chord, iArt, staff, sp(leftNoteXMm + (art.xIs + (noteheadWidth / 2)) * staff.is, art.yLp), 1, context.getSymbol(CommonSymbol.getArticulation(art.articulation)));
            artsSt[iArt] = artSt;
        }
    }
    // leger lines
    LegerLineStamping[] legerLines = legerLinesStamper.stamp(chord, chordXMm, staff);
    return new ChordStampings(element, chordXMm, staff, noteheads, dots, accsSt, legerLines, artsSt, flags, stem);
}
Also used : LayoutSettings(com.xenoage.zong.musiclayout.settings.LayoutSettings) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) Symbol(com.xenoage.zong.symbols.Symbol) Beam(com.xenoage.zong.core.music.beam.Beam) Chord(com.xenoage.zong.core.music.chord.Chord) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) StemDirection(com.xenoage.zong.core.music.chord.StemDirection) ChordStampings(com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.ChordStampings) lombok.val(lombok.val) Duration(com.xenoage.zong.core.music.util.Duration) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) ChordWidths(com.xenoage.zong.musiclayout.settings.ChordWidths)

Example 3 with Symbol

use of com.xenoage.zong.symbols.Symbol in project Zong by Xenoage.

the class DirectionStamper method createDynamics.

/**
 * Creates a {@link StaffTextStamping} for the given {@link Dynamic}s
 * below the given {@link Chord} and its {@link ChordStampings}.
 */
public StaffTextStamping createDynamics(Dynamic dynamics, Chord chord, ChordStampings chordStampings, SymbolPool symbolPool) {
    StaffStamping staff = chordStampings.staff;
    // positioning
    // below (default): 3 IS below the base line, or 2 IS below the lowest note
    // above: 2 IS above the top line, or 1 IS above the highest note
    float defaultLPBelow = -3f * 2;
    float defaultLPAbove = (staff.linesCount - 1) * 2 + 2 * 2;
    if (chordStampings.noteheads.length > 0) {
        defaultLPBelow = Math.min(defaultLPBelow, chordStampings.getFirstNotehead().position.lp - 2 * 2);
        defaultLPAbove = Math.max(defaultLPAbove, chordStampings.getLastNotehead().position.lp + 1 * 2);
    }
    SP sp = computePosition(dynamics, staff, defaultLPBelow, defaultLPAbove, defaultLPBelow);
    // create text
    CList<FormattedTextElement> elements = clist();
    for (CommonSymbol s : CommonSymbol.getDynamics(dynamics.getValue())) {
        Symbol symbol = symbolPool.getSymbol(s);
        elements.add(new FormattedTextSymbol(symbol, staff.is * FONT_SIZE_IN_IS, FormattedTextStyle.Companion.getDefaultColor()));
    }
    elements.close();
    FormattedTextParagraph paragraph = new FormattedTextParagraph(elements, Alignment.Center);
    FormattedText text = Companion.fText(paragraph);
    // create stamping
    return new StaffTextStamping(text, sp, staff, dynamics);
}
Also used : CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) Symbol(com.xenoage.zong.symbols.Symbol) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) SP(com.xenoage.zong.core.music.format.SP) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol)

Example 4 with Symbol

use of com.xenoage.zong.symbols.Symbol in project Zong by Xenoage.

the class DirectionStamper method createPedal.

/**
 * Creates a {@link StaffSymbolStamping} for the given {@link Pedal}.
 */
public StaffSymbolStamping createPedal(Pedal pedal, StamperContext context) {
    val staff = context.getCurrentStaffStamping();
    // positioning
    // below (default): 4 IS below the base line
    // above: 3 IS above the top line
    float defaultLPBelow = -4f * 2;
    float defaultLPAbove = (staff.linesCount - 1) * 2 + 3 * 2;
    SP sp = computePosition(pedal, staff, defaultLPBelow, defaultLPAbove, defaultLPBelow);
    // create stamping
    Symbol symbol = context.getSymbol(CommonSymbol.getPedal(pedal.getType()));
    return new StaffSymbolStamping(null, staff, symbol, null, sp, 1, false);
}
Also used : lombok.val(lombok.val) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) Symbol(com.xenoage.zong.symbols.Symbol) StaffSymbolStamping(com.xenoage.zong.musiclayout.stampings.StaffSymbolStamping) SP(com.xenoage.zong.core.music.format.SP)

Example 5 with Symbol

use of com.xenoage.zong.symbols.Symbol in project Zong by Xenoage.

the class TimeRenderer method draw.

/**
 * Draws the given {@link TimeStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    TimeStamping s = (TimeStamping) stamping;
    SymbolPool symbolPool = args.symbolPool;
    float interlineSpace = s.parentStaff.is;
    float linesCount = s.parentStaff.linesCount;
    // write numerator digits
    float offsetX = s.numeratorOffsetIs * interlineSpace;
    String num = Integer.toString(s.time.element.getType().getNumerator());
    for (int i = 0; i < num.length(); i++) {
        int d = num.charAt(i) - '0';
        Symbol symbol = symbolPool.getSymbol(CommonSymbol.getDigit(d));
        if (symbol != null) {
            float symbolWidth = symbol.getBoundingRect().size.width;
            StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + offsetX, linesCount + 1), 1, s.parentStaff, false, canvas, args);
            offsetX += (symbolWidth + s.digitGapIs) * interlineSpace;
        }
    }
    // write denominator digits
    offsetX = s.denominatorOffsetIs * interlineSpace;
    String den = Integer.toString(s.time.element.getType().getDenominator());
    for (int i = 0; i < den.length(); i++) {
        int d = den.charAt(i) - '0';
        Symbol symbol = symbolPool.getSymbol(CommonSymbol.getDigit(d));
        if (symbol != null) {
            float symbolWidth = symbol.getBoundingRect().size.width;
            StaffSymbolRenderer.drawWith(symbol, null, sp(s.xMm + offsetX, linesCount - 3), 1, s.parentStaff, false, canvas, args);
            offsetX += (symbolWidth + s.digitGapIs) * interlineSpace;
        }
    }
}
Also used : Symbol(com.xenoage.zong.symbols.Symbol) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) TimeStamping(com.xenoage.zong.musiclayout.stampings.TimeStamping) SymbolPool(com.xenoage.zong.symbols.SymbolPool)

Aggregations

Symbol (com.xenoage.zong.symbols.Symbol)13 CommonSymbol (com.xenoage.zong.symbols.common.CommonSymbol)12 lombok.val (lombok.val)5 SP (com.xenoage.zong.core.music.format.SP)4 Point2f (com.xenoage.utils.math.geom.Point2f)2 KeySignatureStamping (com.xenoage.zong.musiclayout.stampings.KeySignatureStamping)2 StaffSymbolStamping (com.xenoage.zong.musiclayout.stampings.StaffSymbolStamping)2 StaffTextStamping (com.xenoage.zong.musiclayout.stampings.StaffTextStamping)2 Beam (com.xenoage.zong.core.music.beam.Beam)1 Chord (com.xenoage.zong.core.music.chord.Chord)1 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)1 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)1 Duration (com.xenoage.zong.core.music.util.Duration)1 ChordStampings (com.xenoage.zong.musiclayout.layouter.scoreframelayout.util.ChordStampings)1 ChordWidths (com.xenoage.zong.musiclayout.settings.ChordWidths)1 LayoutSettings (com.xenoage.zong.musiclayout.settings.LayoutSettings)1 Spacings (com.xenoage.zong.musiclayout.settings.Spacings)1 FlagsStamping (com.xenoage.zong.musiclayout.stampings.FlagsStamping)1 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)1 TimeStamping (com.xenoage.zong.musiclayout.stampings.TimeStamping)1