use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class StretchMeasuresTest method createSystemWith1MeasureGrace.
/**
* Creates and returns a simple {@link SystemSpacing} with only one
* measure and three notes: two main notes and two grace notes between them.
*/
public static SystemSpacing createSystemWith1MeasureGrace(float offsetChord1, float offsetChord2, float offsetMeasureEnd, float graceDistance) {
Chord chord1 = chord(Companion.pi(0, 0, 4), Companion.fr(2, 4));
Chord chord2grace = graceChord(Companion.pi(1, 0, 4));
Chord chord3grace = graceChord(Companion.pi(2, 0, 4));
Chord chord4 = chord(Companion.pi(3, 0, 4), Companion.fr(2, 4));
Voice voice = new Voice(alist(chord1, chord2grace, chord3grace, chord4));
List<BeatOffset> beatOffsets = alist(new BeatOffset(Companion.fr(0, 4), offsetChord1), new BeatOffset(Companion.fr(2, 4), offsetChord2), new BeatOffset(Companion.fr(4, 4), offsetMeasureEnd));
float is = 1;
List<VoiceSpacing> voiceSpacings = alist(new VoiceSpacing(voice, is, alist(new ChordSpacing(new ChordNotation(chord1), beatOffsets.get(0).getBeat(), beatOffsets.get(0).getOffsetMm()), new ChordSpacing(new ChordNotation(chord2grace), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm() - 2 * graceDistance), new ChordSpacing(new ChordNotation(chord3grace), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm() - 1 * graceDistance), new ChordSpacing(new ChordNotation(chord4), beatOffsets.get(1).getBeat(), beatOffsets.get(1).getOffsetMm()))));
MeasureSpacing measureSpacing = new MeasureSpacing(atMeasure(0, 0), is, voiceSpacings, empty, null);
ColumnSpacing mcs = new ColumnSpacing(-1, alist(measureSpacing), beatOffsets, alist(new BeatOffset(Companion.fr(0, 4), 0), new BeatOffset(Companion.fr(4, 4), offsetMeasureEnd)));
SystemSpacing system = new SystemSpacing(alist(mcs), 0, 0, offsetMeasureEnd, null, 0);
return system;
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class Base24f method getExpectedChords.
static Chord[] getExpectedChords() {
Chord[] ret = { ch(Companion.fr(2, 4), Companion.pi('E', 0, 5)), gr(Companion.fr(1, 16), false, Companion.pi('G', 0, 5)), ch(Companion.fr(2, 4), Companion.pi('E', 0, 5)) };
new SlurAdd(slur(ret[1], ret[2])).execute();
return ret;
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class ChordStamper method stampAll.
/**
* Returns all the stampings for the given {@link Chord}, including beams,
* tuplets, slurs and other attachments.
*
* The given {@link OpenSlursCache},
* {@link OpenLyricsCache}, {@link LastLyrics} and {@link OpenTupletsCache} may be modified.
*/
public List<Stamping> stampAll(ChordNotation chord, float xMm, BeamSpacing beam, StaffStampings staffStampings, StamperContext context, FormattedTextStyle defaultLyricStyle, OpenSlursCache openSlursCache, OpenLyricsCache openLyricsCache, LastLyrics lastLyrics, OpenTupletsCache openTupletsCache) {
List<Stamping> ret = alist();
Chord element = chord.getElement();
int staffIndex = context.staffIndex;
int systemIndex = context.systemIndex;
// noteheads, leger lines, dots, accidentals, stem, flags, articulations
ChordStampings chordSt = stampCore(chord, xMm, context);
chordSt.addAllTo(ret);
// beam
if (beam != null) {
// stamp the whole beam (when we find the beginning of the beam)
// TIDY: create/store beam stampings elsewhere?
Beam beamElement = beam.notation.element;
int chordIndex = beamElement.getWaypointIndex(element);
if (chordIndex == 0) {
ret.addAll(beamStamper.stamp(beam, context.getCurrentStaffStamping()));
}
}
// ties and slurs
for (Slur slur : element.getSlurs()) {
SlurWaypoint wp = slur.getWaypoint(element);
WaypointPosition pos = slur.getWaypointPosition(element);
// TODO: choose top/bottom
int noteIndex = notNull(wp.getNoteIndex(), 0);
NoteheadStamping notehead = chordSt.noteheads[noteIndex];
// define the placement: above or below (TODO: better strategy)
VSide side = slurStamper.getSide(slur);
// compute position
val staff = staffStampings.get(systemIndex, notehead.parentStaff.staffIndex);
val slurCache = openSlursCache.getOrCreate(slur);
float distanceIs = slurStamper.getAdditionalDistanceIs(chord, slur.getSide());
SP defaultSp = sp(notehead.position.xMm, notehead.position.lp + side.getDir() * distanceIs * 2);
if (pos == WaypointPosition.Start)
slurCache.setStart(defaultSp, staff, systemIndex);
else
slurCache.setStop(defaultSp, staff, systemIndex);
}
// lyric
List<Lyric> lyrics = element.getLyrics();
if (lyrics.size() > 0) {
float baseLine = -10;
for (Lyric lyric : lyrics) {
if (lyric != null) {
SyllableType lyricType = lyric.getSyllableType();
StaffTextStamping lastLyric = lastLyrics.get(staffIndex, lyric.getVerse());
if (lyricType == SyllableType.Extend) {
// extend
if (// TODO: frame breaks...
lastLyric != null) {
// remember it
openLyricsCache.setUnderscore((Lyric) lastLyric.getElement(), lastLyric, chordSt.noteheads[0], /* TODO*/
staffIndex);
}
} else {
// normal lyric
// create text stamping
StaffTextStamping sts = lyricStamper.createSyllableStamping(lyric, defaultLyricStyle, context.getCurrentStaffStamping(), chordSt.noteheads[0].position.xMm, baseLine);
ret.add(sts);
// when middle or end syllable, add a hypen between the preceding syllable and this syllable
if (// TODO: frame breaks...
lastLyric != null) {
if (lyricType == SyllableType.Middle || lyricType == SyllableType.End) {
StaffTextStamping hyphenStamping = lyricStamper.createHyphenStamping(lastLyric, sts, defaultLyricStyle);
ret.add(hyphenStamping);
}
}
// remember this lyric as the currently last one in the current staff and verse
lastLyrics.set(staffIndex, lyric.getVerse(), sts);
}
}
baseLine += -5;
}
}
// directions
ret.addAll(directionStamper.stampForChord(chordSt, context.layouter.symbols));
// tuplet
Tuplet tuplet = element.getTuplet();
if (tuplet != null) {
openTupletsCache.addChord(element, tuplet, chordSt);
}
return ret;
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class NotesNotatorTest method testChordG4B5.
/**
* Tests a G4-B5, 1/4. Stem: left, down. Width: 1x quarter.
*/
@Test
public void testChordG4B5() {
Chord chord = chord(new Pitch[] { Companion.pi(4, 0, 4), Companion.pi(6, 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);
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);
}
use of com.xenoage.zong.core.music.chord.Chord 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);
}
Aggregations