Search in sources :

Example 1 with ChordLps

use of com.xenoage.zong.musiclayout.notation.chord.ChordLps 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 ChordLps

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

the class OneMeasureOneStaff method compute.

public StemDirection[] compute(ChordLps[] chordsLps, int staffLinesCount) {
    int staffMiddleLp = staffLinesCount - 1;
    int upCount = 0;
    int downCount = 0;
    int furthestDistance = 0;
    StemDirection furthestDistanceDir = Up;
    // the chord with the note furthest away from the middle staff line
    for (ChordLps chordLps : chordsLps) {
        StemDirection preferredDir = singleStemDirector.compute(chordLps, staffLinesCount);
        int distance;
        if (preferredDir == Up) {
            upCount++;
            distance = staffMiddleLp - chordLps.getTop();
        } else {
            downCount++;
            distance = chordLps.getBottom() - staffMiddleLp;
        }
        if (// new furthest distance found
        distance > furthestDistance || // equal furthest distance found, but Down wins (Ross, p. 95):
        (distance == furthestDistance && preferredDir == Down)) {
            furthestDistance = distance;
            furthestDistanceDir = preferredDir;
        }
    }
    // the mostly used stem direction wins  (Ross, p. 95)
    // if both directions are equally distributed, the stem direction of
    // the chord with the note furthest away from the staff middle line wins (Ross, p. 95)
    StemDirection finalStemDir;
    if (upCount != downCount)
        finalStemDir = (upCount > downCount ? Up : Down);
    else
        finalStemDir = furthestDistanceDir;
    // use same direction for all stems
    StemDirection[] dirs = new StemDirection[chordsLps.length];
    for (int i : range(dirs)) dirs[i] = finalStemDir;
    return dirs;
}
Also used : ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) StemDirection(com.xenoage.zong.core.music.chord.StemDirection)

Example 3 with ChordLps

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

the class StemDrawerTest method getPreferredStemLengthTest.

@Test
public void getPreferredStemLengthTest() {
    test(Example.all, (suite, example) -> {
        float expectedLengthIs = example.stemLengthIs;
        float lengthIs = testee.getPreferredStemLengthIs(new ChordLps(example.noteLp), example.stemDir, example.staffLines);
        assertEquals(suite.getName() + ": " + example.name + " expected stem length of " + expectedLengthIs + ", but was " + lengthIs, expectedLengthIs, lengthIs, df);
    });
}
Also used : ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) Test(org.junit.Test)

Example 4 with ChordLps

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

the class StemDrawerTest method isStemLengthenedToMiddleLineTest.

@Test
public void isStemLengthenedToMiddleLineTest() {
    test(Example.all, (suite, example) -> {
        boolean expected = example.isLengthenedToMiddleLine;
        boolean lengthened = testee.isStemExtendedToMiddleLine(new ChordLps(example.noteLp), example.stemDir, example.staffLines);
        assertEquals(suite.getName() + ": " + example.name + " expected " + (expected ? "" : "NO ") + "stem lengthening but it was " + (lengthened ? "" : "NOT ") + "lengthened.", expected, lengthened);
    });
}
Also used : ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) Test(org.junit.Test)

Example 5 with ChordLps

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

the class OneMeasureOneStaff method compute.

@Override
public StemDirection[] compute(Beam beam, Score score) {
    int staffLinesCount = getStaffLinesCount(beam.getChord(0), score);
    ChordLps[] chordsLps = new ChordLps[beam.size()];
    for (int iChord : range(chordsLps)) {
        Chord chord = beam.getChord(iChord);
        MP mp = MP.getMP(chord);
        MusicContext mc = score.getMusicContext(mp, BeforeOrAt, Before);
        chordsLps[iChord] = new ChordLps(chord, mc);
    }
    return compute(chordsLps, staffLinesCount);
}
Also used : MP(com.xenoage.zong.core.position.MP) ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) Chord(com.xenoage.zong.core.music.chord.Chord) MusicContext(com.xenoage.zong.core.music.MusicContext)

Aggregations

ChordLps (com.xenoage.zong.musiclayout.notation.chord.ChordLps)8 MusicContext (com.xenoage.zong.core.music.MusicContext)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)2 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)2 Test (org.junit.Test)2 CList (com.xenoage.utils.collections.CList)1 Fraction (com.xenoage.utils.math.Fraction)1 Stem (com.xenoage.zong.core.music.chord.Stem)1 MP (com.xenoage.zong.core.position.MP)1 NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)1 StemNotation (com.xenoage.zong.musiclayout.notation.chord.StemNotation)1 BeamedStem (com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStem)1 BeamedStems (com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems)1 lombok.val (lombok.val)1