use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class Test01c method test.
@Test
public void test() {
Voice voice = getScore().getVoice(mp0);
for (VoiceElement e : voice.getElements()) {
if (e instanceof Chord) {
Chord chord = (Chord) e;
// check pitch
assertEquals(Companion.pi('G', 0, 4), chord.getNotes().get(0).getPitch());
// check lyric
assertEquals(1, chord.getLyrics().size());
assertEquals("A", chord.getLyrics().get(0).getText().toString());
return;
}
}
fail("note not found");
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class Test33b method test.
@Test
public void test() {
Score score = getScore();
Chord chord1 = (Chord) score.getVoice(atVoice(0, 0, 0)).getElement(0);
Chord chord2 = (Chord) score.getVoice(atVoice(0, 1, 0)).getElement(0);
assertEquals(1, chord1.getSlurs().size());
Slur tie = chord1.getSlurs().get(0);
assertEquals(SlurType.Tie, tie.getType());
List<SlurWaypoint> waypoints = tie.getWaypoints();
assertEquals(2, waypoints.size());
assertEquals(chord1, waypoints.get(0).getChord());
assertEquals(chord2, waypoints.get(1).getChord());
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class StemDirector method compute.
/**
* Computes the {@link StemDirection} of the given chord (and maybe connected
* ones) and returns them. The chord must be part of a score.
*/
public Map<Chord, StemDirection> compute(Chord chord) {
Map<Chord, StemDirection> ret = map();
Beam beam = chord.getBeam();
Score score = chord.getScore();
if (beam != null) {
// compute stem directions for all chords of the beam
StemDirection[] beamedStems = beamedStemDirector.compute(beam, score);
for (int iChord : range(beam.size())) ret.put(beam.getChord(iChord), beamedStems[iChord]);
} else {
// compute stem direction for single chord
MP mp = MP.getMP(chord);
StemDirection stem = singleStemDirector.compute(chord, score.getMusicContext(mp, BeforeOrAt, Before));
ret.put(chord, stem);
}
// but it was bad and outdated, so we removed it.
return ret;
}
use of com.xenoage.zong.core.music.chord.Chord in project Zong by Xenoage.
the class BeamFragmenter method compute.
/**
* Computes the fragments for the given line (1: 16th line, 2: 32th line, ...).
* Use an algorithm based on the rules in Chlapik, page 45, rule 6.
*
* Begin with the highest line (e.g. 32th before 16th), and use the result of line n
* as a parameter to compute line n-1 (for the first computation, use null).
* This is needed to support Chlapik, page 45, rule 6, example of row 3, column 6.
* Without that, the 16th line would go from the second note to the fourth one.
*/
Fragments compute(Beam beam, int line, Fragments higherLine) {
if (line < 1)
throw new IllegalArgumentException("This method only works for 16th lines or higher");
// in this algorithm, we go from note to note, looking for "groups".
// groups are consecutive chords/stems with the same number of flags (or
// a higher number inbetween) and not divided by a subdivision break.
// initialize return array with none-waypoints
Fragments ret = new Fragments(beam.size());
int lastFlagsCount = -1;
// start chord of the last group, or -1 if no group is open
int startChord = -1;
// stop chord of the last group, or -1 if group is open
int stopChord = -1;
for (int iChord : range(beam.size() + 1)) {
if (iChord < beam.getWaypoints().size()) {
// another chord within the beam
Chord chord = beam.getChord(iChord);
int flagsCount = INSTANCE.getFlagsCount(chord.getDuration());
// enough flags for the given line? (e.g. a 8th beam has no 16th line)
if (flagsCount >= line + 1) {
// yes, we need a line of the given line for this stem
if (startChord == -1) {
if (higherLine == null || higherLine.get(iChord) != HookLeft) {
// start new group
startChord = iChord;
lastFlagsCount = flagsCount;
} else {
// example mentioned in the method documentation (Chlapik, page 45, row 3, col 6)
// we place a hook. this is not explicitly mentioned in the text, but seems to
// be right when looking at the example.
startChord = iChord;
stopChord = iChord;
}
} else if (lastFlagsCount > -1 && (// less flags than previous stem
flagsCount < flagsCount || beam.isEndOfSubdivision(iChord))) {
// forced subdivision break
// end the group here
stopChord = iChord - 1;
}
} else {
// no, we need no line of the given line for this stem
// so, close the last group
stopChord = iChord - 1;
}
} else {
// no more chord in the beam, so we have to close
stopChord = iChord - 1;
}
// if a group was closed, create it
if (startChord > -1 && stopChord > -1) {
// type of line is dependent on number of chords in the group
int chordsCount = stopChord - startChord + 1;
if (chordsCount > 1) {
// simple case: more than one chord. create a normal line
// between those stems
ret.set(startChord, Start);
ret.set(stopChord, Stop);
} else {
// more difficult case: exactly one chord.
if (startChord == 0) {
// first chord in beam has always hook to the right
ret.set(startChord, HookRight);
} else if (startChord == beam.getWaypoints().size() - 1) {
// last chord in beam has always hook to the left
ret.set(startChord, HookLeft);
} else {
// middle chords have left hook, if the preceding chord
// has a longer or equal duration than the following chord,
// otherwise they have a right hook
Fraction left = beam.getChord(startChord - 1).getDuration();
Fraction right = beam.getChord(startChord + 1).getDuration();
if (left.compareTo(right) >= 0)
ret.set(startChord, HookLeft);
else
ret.set(startChord, HookRight);
}
}
// reset group data
startChord = -1;
stopChord = -1;
lastFlagsCount = -1;
}
}
return ret;
}
use of com.xenoage.zong.core.music.chord.Chord 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);
}
Aggregations