Search in sources :

Example 1 with CommonSymbol

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

the class TupletStamper method createText.

private FormattedText createText(int digit, float fontSize, SymbolPool symbolPool) {
    if (digit < 0 || digit > 9)
        // TODO
        return null;
    CommonSymbol s = CommonSymbol.getDigit(digit);
    FormattedTextParagraph p = Companion.fPara(new FormattedTextSymbol(symbolPool.getSymbol(s), fontSize, FormattedTextStyle.Companion.getDefaultColor()));
    return Companion.fText(p);
}
Also used : FormattedTextParagraph(com.xenoage.zong.core.text.FormattedTextParagraph) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) FormattedTextSymbol(com.xenoage.zong.core.text.FormattedTextSymbol)

Example 2 with CommonSymbol

use of com.xenoage.zong.symbols.common.CommonSymbol 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 CommonSymbol

use of com.xenoage.zong.symbols.common.CommonSymbol 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 CommonSymbol

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

the class ElementStamper method getRestSymbol.

private Symbol getRestSymbol(Duration.Type duration, StamperContext context) {
    CommonSymbol cs = durationSymbolMapping.get(duration);
    SymbolPool symbols = context.layouter.symbols;
    if (cs != null)
        return symbols.getSymbol(cs);
    else
        return symbols.getWarningSymbol();
}
Also used : SymbolPool(com.xenoage.zong.symbols.SymbolPool) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol)

Example 5 with CommonSymbol

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

the class DirectionStamper method createDynamics.

/**
 * Creates a {@link StaffTextStamping} for the given {@link Dynamic}s.
 */
public StaffTextStamping createDynamics(Dynamic dynamics, StamperContext context) {
    val staff = context.getCurrentStaffStamping();
    // 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 = (context.getCurrentStaffStamping().linesCount - 1) * 2 + 2 * 2;
    SP sp = computePosition(dynamics, staff, defaultLPBelow, defaultLPAbove, defaultLPBelow);
    // create text
    CList<FormattedTextElement> elements = clist();
    for (CommonSymbol s : CommonSymbol.getDynamics(dynamics.getValue())) {
        Symbol symbol = context.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 : lombok.val(lombok.val) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol) Symbol(com.xenoage.zong.symbols.Symbol) StaffTextStamping(com.xenoage.zong.musiclayout.stampings.StaffTextStamping) SP(com.xenoage.zong.core.music.format.SP) CommonSymbol(com.xenoage.zong.symbols.common.CommonSymbol)

Aggregations

CommonSymbol (com.xenoage.zong.symbols.common.CommonSymbol)5 Symbol (com.xenoage.zong.symbols.Symbol)3 SP (com.xenoage.zong.core.music.format.SP)2 StaffTextStamping (com.xenoage.zong.musiclayout.stampings.StaffTextStamping)2 lombok.val (lombok.val)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 FormattedTextParagraph (com.xenoage.zong.core.text.FormattedTextParagraph)1 FormattedTextSymbol (com.xenoage.zong.core.text.FormattedTextSymbol)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 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)1 SymbolPool (com.xenoage.zong.symbols.SymbolPool)1