Search in sources :

Example 6 with NoteDisplacement

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

Example 7 with NoteDisplacement

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

the class NotesNotator method computeNotes.

private NoteDisplacement[] computeNotes(ChordLps lps, StemDirection sd, float stemOffset) {
    NoteDisplacement[] notes = new NoteDisplacement[lps.getNotesCount()];
    // if stem direction is down or none, begin with the highest note,
    // otherwise with the lowest
    int dir = (sd == StemDirection.Up) ? 1 : -1;
    int startIndex = (dir == 1) ? 0 : lps.getNotesCount() - 1;
    int endIndex = lps.getNotesCount() - 1 - startIndex;
    // default side of the stem. 1 = right, 0 = left
    int stemSide = (sd == StemDirection.Up) ? 1 : 0;
    int lastSide = stemSide;
    for (int i = startIndex; dir * i <= dir * endIndex; i += dir) {
        int side = 1 - stemSide;
        NoteSuspension suspension = NoteSuspension.None;
        if (i == startIndex) {
        // first note: use default side
        } else {
            // following note: change side, if last note is 1 or 0 LPs away
            if (abs(lps.get(i) - lps.get(i - dir)) <= 1) {
                // change side
                side = 1 - lastSide;
                if (side != 1 - stemSide) {
                    if (side == 0)
                        suspension = NoteSuspension.Left;
                    else
                        suspension = NoteSuspension.Right;
                }
            }
        }
        notes[i] = new NoteDisplacement(lps.get(i), side * stemOffset, suspension);
        lastSide = side;
    }
    return notes;
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) NoteSuspension(com.xenoage.zong.musiclayout.notation.chord.NoteSuspension)

Example 8 with NoteDisplacement

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

the class TwoAccidentals method compute.

@Override
AccidentalsNotation compute(Params p) {
    float width, xTop, xBottom;
    NoteDisplacement bottomNote = p.accsNote[0];
    NoteDisplacement topNote = p.accsNote[1];
    Accidental bottomAcc = p.accs[0];
    Accidental topAcc = p.accs[1];
    float accToAccGap = p.chordWidths.accToAccGap;
    // interval of at least a seventh?
    if (topNote.lp - bottomNote.lp >= 6) {
        // placed on the same horizontal position x = 0
        xTop = xBottom = 0;
        width = p.chordWidths.getMaxWidth(p.accs) + p.chordWidths.accToNoteGap;
    } else {
        // placed on different horizontal positions
        // normally begin with the bottom accidental
        boolean bottomFirst = true;
        // is not, then the bottom accidental is nearer to the stem (Ross p.12, 3rd row)
        if (bottomNote.suspension == Right && topNote.suspension != Right)
            bottomFirst = false;
        // is not, then the bottom accidental is nearer to the stem (Ross p.12, 4th row)
        if (topNote.suspension == Left && bottomNote.suspension != Left)
            bottomFirst = false;
        // horizontal position
        float bottomWidth = p.chordWidths.get(bottomAcc);
        float topWidth = p.chordWidths.get(topAcc);
        if (bottomFirst) {
            // bottom accidental is leftmost
            xBottom = 0;
            xTop = bottomWidth + accToAccGap;
        } else {
            // top accidental is leftmost
            xBottom = topWidth + accToAccGap;
            xTop = 0;
        }
        // width
        width = bottomWidth + accToAccGap + topWidth + p.chordWidths.accToNoteGap;
    }
    return create(p, width, xBottom, xTop);
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) Accidental(com.xenoage.zong.core.music.chord.Accidental)

Example 9 with NoteDisplacement

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

the class NotesNotatorTest method testChordC5C5.

/**
 * Tests a C5/C5 (unison) chord, 1/4. Stem: left, down. Width: 2x quarter.
 */
@Test
public void testChordC5C5() {
    Chord chord = chord(new Pitch[] { Companion.pi(0, 0, 5), Companion.pi(0, 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(5, 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)

Example 10 with NoteDisplacement

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

the class NotesNotatorTest method testSingleNoteC5.

/**
 * Tests a C5, 1/4. Stem: left, down. Width: 1x quarter.
 */
@Test
public void testSingleNoteC5() {
    Chord chord = chord(Companion.pi(0, 0, 5), Companion.fr(1, 4));
    NotesNotation notes = testee.compute(chord, StemDirection.Down, cw, context);
    assertEquals(0, notes.stemOffsetIs, Df);
    assertEquals(n, notes.widthIs, Df);
    NoteDisplacement note = notes.getNote(0);
    assertEquals(5, 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