Search in sources :

Example 6 with Chord

use of com.xenoage.zong.core.music.chord.Chord 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 7 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class Test72b method testNotatedPitches.

@Test
public void testNotatedPitches() {
    for (int iStaff : range(expectedNotatedPitches.length)) {
        MP mp = MP.atElement(iStaff, 0, 0, 0);
        Chord chord = getChordAt(score, mp);
        Pitch pitch = chord.getNotes().get(0).getPitch();
        assertEquals("" + mp, expectedNotatedPitches[iStaff], pitch);
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 8 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class Test72c method testNotatedPitches.

@Test
public void testNotatedPitches() {
    for (int iMeasure : range(expectedTransposes.length)) {
        MP mp = MP.atElement(0, iMeasure, 0, 0);
        Chord chord = getChordAt(score, mp);
        Pitch pitch = chord.getNotes().get(0).getPitch();
        assertEquals("" + mp, expectedNotatedPitch, pitch);
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 9 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class Test61c method test.

@Test
public void test() {
    for (int iStaff : range(2)) {
        for (int iElement : range(4)) {
            MP mp = MP.atElement(iStaff, 0, 0, iElement);
            Chord chord = ChordTest.getChordAt(score, mp);
            assertEqualsChordLyrics(expectedLyrics[iStaff][iElement], chord, mp);
        }
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) Chord(com.xenoage.zong.core.music.chord.Chord) ChordTest(musicxmltestsuite.tests.utils.ChordTest) Test(org.junit.Test)

Example 10 with Chord

use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.

the class Test61d method test.

@Test
public void test() {
    for (int iMeasure : range(2)) {
        for (int iElement : range(4)) {
            MP mp = MP.atElement(0, iMeasure, 0, iElement);
            Chord chord = ChordTest.getChordAt(score, mp);
            assertEqualsChordLyrics(expectedLyrics[iMeasure * 4 + iElement], chord, mp);
        }
    }
}
Also used : MP(com.xenoage.zong.core.position.MP) Chord(com.xenoage.zong.core.music.chord.Chord) ChordTest(musicxmltestsuite.tests.utils.ChordTest) Test(org.junit.Test)

Aggregations

Chord (com.xenoage.zong.core.music.chord.Chord)63 Test (org.junit.Test)34 MP (com.xenoage.zong.core.position.MP)16 Pitch (com.xenoage.zong.core.music.Pitch)12 Score (com.xenoage.zong.core.Score)11 Voice (com.xenoage.zong.core.music.Voice)10 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)10 VoiceElement (com.xenoage.zong.core.music.VoiceElement)8 Note (com.xenoage.zong.core.music.chord.Note)6 Rest (com.xenoage.zong.core.music.rest.Rest)6 ChordTest (musicxmltestsuite.tests.utils.ChordTest)6 Fraction (com.xenoage.utils.math.Fraction)5 Staff (com.xenoage.zong.core.music.Staff)4 Beam (com.xenoage.zong.core.music.beam.Beam)4 Grace (com.xenoage.zong.core.music.chord.Grace)4 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)4 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)4 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)4 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)4 NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)4