Search in sources :

Example 1 with NotesNotation

use of com.xenoage.zong.musiclayout.notation.chord.NotesNotation in project Zong by Xenoage.

the class NotesNotator method compute.

/**
 * Computes the displacement of the notes of the given chord, which has a stem into
 * the given direction, using the given musical context.
 */
public NotesNotation compute(Chord chord, StemDirection stemDirection, ChordWidths chordWidths, MusicContext musicContext) {
    ChordLps lp = new ChordLps(chord, musicContext);
    ChordClass chordClass = computeChordClass(lp, stemDirection);
    float noteheadWidth = chordWidths.get(chord.getDisplayedDuration());
    float stemOffset = computeStemOffset(chordClass, noteheadWidth);
    float notesWidth = computeNotesWidth(chordClass, noteheadWidth);
    NoteDisplacement[] notes = computeNotes(lp, stemDirection, stemOffset);
    int dotsCount = computeDotsCount(chord.getDuration());
    float[] dotsOffsets = computeDotsOffsets(notesWidth, dotsCount, chordWidths);
    int[] dotsLp = (dotsCount > 0 ? computeDotsLp(lp) : emptyIntArray);
    boolean leftSuspended = isLeftSuspended(notes);
    float totalWidth;
    if (dotsCount > 0)
        totalWidth = dotsOffsets[dotsCount - 1];
    else
        totalWidth = notesWidth;
    return new NotesNotation(totalWidth, noteheadWidth, notes, dotsOffsets, dotsLp, stemOffset, leftSuspended);
}
Also used : ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation)

Example 2 with NotesNotation

use of com.xenoage.zong.musiclayout.notation.chord.NotesNotation in project Zong by Xenoage.

the class ChordNotator method compute.

public ChordNotation compute(Chord chord, Context context, @MaybeNull Notations notations) {
    Score score = context.score;
    float interlineSpace = score.getInterlineSpace(context.mp);
    FontInfo lyricsFont = score.getFormat().getLyricFont();
    MusicContext mc = score.getMusicContext(context.mp, BeforeOrAt, Before);
    // grace or normal chord?
    boolean grace = chord.isGrace();
    ChordWidths chordWidths = (grace ? context.settings.graceChordWidths : context.settings.chordWidths);
    ChordSpacings spacings = (grace ? context.settings.spacings.graceChordSpacings : context.settings.spacings.normalChordSpacings);
    // use or compute stem direction
    StemDirection stemDirection = chord.getStem().getDirection();
    if (stemDirection == StemDirection.Default) {
        // if stem direction was not computed yet, compute it now
        if (notations != null)
            stemDirection = notations.getChord(chord).stemDirection;
        if (stemDirection == StemDirection.Default) {
            Map<Chord, StemDirection> computedStems = stemDirector.compute(chord);
            stemDirection = computedStems.get(chord);
            // also remember the other computed stems
            if (notations != null)
                for (Chord computedChord : computedStems.keySet()) notations.getChord(computedChord).stemDirection = computedStems.get(computedChord);
        }
    }
    // notes displacement
    NotesNotation notes = notesNotator.compute(chord, stemDirection, chordWidths, mc);
    float leftSuspendedWidth = (notes.leftSuspended ? notes.noteheadWidthIs : 0);
    // accidentals
    AccidentalsNotation accs = accidentalsNotator.compute(chord, notes, chordWidths, mc);
    // symbol's width: width of the noteheads and dots
    float symbolWidth = notes.widthIs - leftSuspendedWidth;
    float frontGap = accs.widthIs + leftSuspendedWidth;
    // rear gap: empty duration-dependent space behind the chord minus the symbol's width
    float rearGap = spacings.getWidth(chord.getDisplayedDuration()) - symbolWidth;
    // lyric width
    float lyricWidth = 0;
    TextMeasurer textMeasurer = platformUtils().getTextMeasurer();
    for (Lyric lyric : chord.getLyrics()) {
        if (lyric != null && lyric.getText() != null) {
            // width of lyric in interline spaces
            FormattedText lyricText = styleText(lyric.getText(), new FormattedTextStyle(lyricsFont));
            float l = lyricText.getWidth() / interlineSpace;
            // for start and end syllable, request "-" more space, for middle syllables "--"
            // TODO: unsymmetric - start needs space on the right, end on the left, ...
            SyllableType lyricType = lyric.getSyllableType();
            if (lyricType == SyllableType.Begin || lyricType == SyllableType.End) {
                l += textMeasurer.measure(lyricsFont, "-").getWidth() / interlineSpace;
            } else if (lyricType == SyllableType.Middle) {
                l += textMeasurer.measure(lyricsFont, "--").getWidth() / interlineSpace;
            }
            // save width of the widest lyric
            lyricWidth = Math.max(lyricWidth, l);
        }
    }
    // compute length of the stem (if any)
    float scaling = grace ? context.settings.scalingGrace : 1;
    StemNotation stem = stemNotator.compute(chord.getStem(), notes.getLps(), stemDirection, context.mp.getStaff(), Companion.staffLines(mc.getLinesCount()), scaling);
    // compute articulations
    ArticulationsNotation arts = articulationsNotator.compute(chord, stemDirection, notes, mc.getLinesCount());
    return new ChordNotation(chord, chord.getMP(), new ElementWidth(frontGap, symbolWidth, rearGap, lyricWidth), context.mp.getStaff(), notes, stemDirection, stem, accs, arts);
}
Also used : ElementWidth(com.xenoage.zong.musiclayout.spacing.ElementWidth) ChordNotation(com.xenoage.zong.musiclayout.notation.ChordNotation) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) FormattedText(com.xenoage.zong.core.text.FormattedText) MusicContext(com.xenoage.zong.core.music.MusicContext) StemNotation(com.xenoage.zong.musiclayout.notation.chord.StemNotation) Score(com.xenoage.zong.core.Score) ArticulationsNotation(com.xenoage.zong.musiclayout.notation.chord.ArticulationsNotation) TextMeasurer(com.xenoage.utils.font.TextMeasurer) ChordWidths(com.xenoage.zong.musiclayout.settings.ChordWidths) AccidentalsNotation(com.xenoage.zong.musiclayout.notation.chord.AccidentalsNotation) Lyric(com.xenoage.zong.core.music.lyric.Lyric) ChordSpacings(com.xenoage.zong.musiclayout.settings.ChordSpacings) SyllableType(com.xenoage.zong.core.music.lyric.SyllableType) NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) FontInfo(com.xenoage.utils.font.FontInfo) StemDirection(com.xenoage.zong.core.music.chord.StemDirection) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 3 with NotesNotation

use of com.xenoage.zong.musiclayout.notation.chord.NotesNotation in project Zong by Xenoage.

the class NotesNotatorTest method testSingleNoteF4.

/**
 * Tests a F4, 1/2. Stem: right, up. Width: 1x half.
 */
@Test
public void testSingleNoteF4() {
    Chord chord = chord(Companion.pi(3, 0, 4), Companion.fr(1, 2));
    NotesNotation notes = testee.compute(chord, StemDirection.Up, cw, context);
    assertEquals(n, notes.stemOffsetIs, Df);
    assertEquals(n, notes.widthIs, Df);
    NoteDisplacement note = notes.getNote(0);
    assertEquals(1, note.lp);
    assertEquals(0, note.xIs, Df);
    assertEquals(NoteSuspension.None, note.suspension);
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 4 with NotesNotation

use of com.xenoage.zong.musiclayout.notation.chord.NotesNotation in project Zong by Xenoage.

the class NotesNotatorTest method testChordC4E4G4.

/**
 * Tests a C4-E4-G4, 3/4. Stem: right, up. Width: 1x half + 1x dot.
 */
@Test
public void testChordC4E4G4() {
    Chord chord = chord(new Pitch[] { Companion.pi(0, 0, 4), Companion.pi(2, 0, 4), Companion.pi(4, 0, 4) }, Companion.fr(3, 4));
    NotesNotation notes = testee.compute(chord, StemDirection.Up, cw, context);
    assertEquals(n, notes.stemOffsetIs, Df);
    assertEquals(n + dg, notes.widthIs, Df);
    assertEquals(0, notes.getNote(0).xIs, Df);
    assertEquals(NoteSuspension.None, notes.getNote(0).suspension);
    assertEquals(0, notes.getNote(1).xIs, Df);
    assertEquals(NoteSuspension.None, notes.getNote(1).suspension);
    assertEquals(0, notes.getNote(2).xIs, Df);
    assertEquals(NoteSuspension.None, notes.getNote(2).suspension);
}
Also used : NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 5 with NotesNotation

use of com.xenoage.zong.musiclayout.notation.chord.NotesNotation in project Zong by Xenoage.

the class NotesNotatorTest method testChordC5D5.

/**
 * Tests a C5/D5, 1/4. Stem: left, down. Width: 1x quarter.
 */
@Test
public void testChordC5D5() {
    Chord chord = chord(new Pitch[] { Companion.pi(0, 0, 5), Companion.pi(1, 0, 5) }, Companion.fr(1, 4));
    NotesNotation notes = testee.compute(chord, StemDirection.Down, cw, context);
    assertEquals(n, notes.stemOffsetIs, Df);
    assertEquals(2 * n, notes.widthIs, Df);
    NoteDisplacement note = notes.getNote(0);
    assertEquals(5, note.lp);
    assertEquals(0, note.xIs, Df);
    assertEquals(NoteSuspension.Left, note.suspension);
    note = notes.getNote(1);
    assertEquals(6, note.lp);
    assertEquals(n, note.xIs, Df);
    assertEquals(NoteSuspension.None, note.suspension);
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Aggregations

NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)12 Chord (com.xenoage.zong.core.music.chord.Chord)10 Test (org.junit.Test)8 NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)5 MusicContext (com.xenoage.zong.core.music.MusicContext)2 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)2 ChordLps (com.xenoage.zong.musiclayout.notation.chord.ChordLps)2 StemNotation (com.xenoage.zong.musiclayout.notation.chord.StemNotation)2 FontInfo (com.xenoage.utils.font.FontInfo)1 TextMeasurer (com.xenoage.utils.font.TextMeasurer)1 Fraction (com.xenoage.utils.math.Fraction)1 Score (com.xenoage.zong.core.Score)1 Pitch (com.xenoage.zong.core.music.Pitch)1 Lyric (com.xenoage.zong.core.music.lyric.Lyric)1 SyllableType (com.xenoage.zong.core.music.lyric.SyllableType)1 FormattedText (com.xenoage.zong.core.text.FormattedText)1 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)1 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)1 AccidentalsNotation (com.xenoage.zong.musiclayout.notation.chord.AccidentalsNotation)1 ArticulationsNotation (com.xenoage.zong.musiclayout.notation.chord.ArticulationsNotation)1