Search in sources :

Example 1 with NoteDisplacement

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

the class ArticulationsNotator method compute.

/**
 * Computes the notations of the articulations of the given chord.
 * If there are no articulations, {@link ArticulationsNotation#empty} is returned.
 */
public ArticulationsNotation compute(Chord chord, StemDirection stemDirection, NotesNotation notesAlignment, int linesCount) {
    // depending on the stem direction, place the articulation on the other side.
    // if there is no stem direction, always place at the top
    VSide side = (stemDirection == StemDirection.Up ? VSide.Bottom : VSide.Top);
    // dependent on the side of the articulation, take the top or bottom note
    NoteDisplacement outerNote = (side == VSide.Top ? notesAlignment.getTopNote() : notesAlignment.getBottomNote());
    // compute alignment of articulations
    return compute(chord.getArticulations(), outerNote, side, linesCount);
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) VSide(com.xenoage.utils.math.VSide)

Example 2 with NoteDisplacement

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

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

the class ThreeAccidentals method compute.

@Override
AccidentalsNotation compute(Params p) {
    float width, xBottom, xMiddle, xTop;
    NoteDisplacement bottomNote = p.accsNote[0];
    NoteDisplacement middleNote = p.accsNote[1];
    NoteDisplacement topNote = p.accsNote[2];
    Accidental bottomAcc = p.accs[0];
    Accidental middleAcc = p.accs[1];
    Accidental topAcc = p.accs[2];
    float bottomWidth = p.chordWidths.get(bottomAcc);
    float middleWidth = p.chordWidths.get(middleAcc);
    float topWidth = p.chordWidths.get(topAcc);
    float accToAccGap = p.chordWidths.accToAccGap;
    float accToNoteGap = p.chordWidths.accToNoteGap;
    // interval of at least a seventh?
    if (topNote.lp - bottomNote.lp >= 6) {
        // interval of at least a seventh. can be rule 1, 3 or 4
        if (topNote.suspension == Right) {
            // top note is suspended on the right side of the stem.
            // this is rule 4. (same code as rule 1)
            xBottom = xTop = middleWidth + accToAccGap;
            xMiddle = 0;
            width = xBottom + p.chordWidths.getMaxWidth(bottomAcc, topAcc) + accToNoteGap;
        } else if (middleNote.suspension == Right) {
            // middle note is suspended on the right side of the stem.
            // (bottom note is never suspended on the right)
            // this is rule 3.
            xBottom = 0;
            xMiddle = bottomWidth + accToAccGap + topWidth + accToAccGap;
            xTop = bottomWidth + accToAccGap;
            width = xMiddle + middleWidth + accToNoteGap;
        } else {
            // there are no accidental notes suspended on the right side of the stem.
            // this is rule 1.
            xBottom = xTop = middleWidth + accToAccGap;
            xMiddle = 0f;
            width = xBottom + p.chordWidths.getMaxWidth(bottomAcc, topAcc) + accToNoteGap;
        }
    } else {
        // interval of less than a seventh. can be rule 2, 5 or 6
        if (topNote.suspension == Right) {
            // top note is suspended on the right side of the stem.
            // this is rule 5. (same code as rule 2)
            xBottom = middleWidth + accToAccGap;
            xMiddle = 0f;
            xTop = xBottom + bottomWidth + accToAccGap;
            width = xTop + topWidth + accToNoteGap;
        } else if (middleNote.suspension == Right) {
            // middle note is suspended on the right side of the stem.
            // (bottom note is never suspended on the right)
            // this is rule 6. (same code as rule 3)
            xBottom = 0f;
            xMiddle = bottomWidth + accToAccGap + topWidth + accToAccGap;
            xTop = bottomWidth + accToAccGap;
            width = xMiddle + middleWidth + accToNoteGap;
        } else {
            // there are no accidental notes suspended on the right side of the stem.
            // this is rule 2.
            xBottom = middleWidth + accToAccGap;
            xMiddle = 0f;
            xTop = middleWidth + accToAccGap + bottomWidth + accToAccGap;
            width = xTop + topWidth + accToNoteGap;
        }
    }
    return create(p, width, xBottom, xMiddle, xTop);
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) Accidental(com.xenoage.zong.core.music.chord.Accidental)

Example 4 with NoteDisplacement

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

the class AccidentalsNotatorTest method testNoAcc.

/**
 * Tests some chords with no accidentals.
 */
@Test
public void testNoAcc() {
    // C5
    AccidentalsNotation accs = testee.compute(alist(Companion.pi(0, 0, 5)), new NoteDisplacement[] { note(5) }, cw, contextC);
    assertEmpty(accs);
    // C4, D4, G4
    accs = testee.compute(alist(Companion.pi(0, 0, 4), Companion.pi(1, 0, 4), Companion.pi(4, 0, 4)), new NoteDisplacement[] { note(-2), note(-1, noteOffset, susRight), note(2) }, cw, contextC);
    assertEmpty(accs);
    // Eb4, Ab4, G##5 with contextEb
    accs = testee.compute(alist(Companion.pi(2, -1, 4), Companion.pi(5, -1, 4), Companion.pi(4, 2, 5)), new NoteDisplacement[] { note(0), note(3), note(9) }, cw, contextEb);
    assertEmpty(accs);
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) AccidentalsNotation(com.xenoage.zong.musiclayout.notation.chord.AccidentalsNotation) Test(org.junit.Test)

Example 5 with NoteDisplacement

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

Aggregations

NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)10 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)5 Test (org.junit.Test)5 Chord (com.xenoage.zong.core.music.chord.Chord)4 Accidental (com.xenoage.zong.core.music.chord.Accidental)2 VSide (com.xenoage.utils.math.VSide)1 AccidentalsNotation (com.xenoage.zong.musiclayout.notation.chord.AccidentalsNotation)1 ChordLps (com.xenoage.zong.musiclayout.notation.chord.ChordLps)1 NoteSuspension (com.xenoage.zong.musiclayout.notation.chord.NoteSuspension)1