use of com.xenoage.zong.musiclayout.spacer.beam.Slant in project Zong by Xenoage.
the class SingleStaffBeamPlacerTest method computeForOneStaffTestRoss.
/**
* Tests with examples from Ross.
*/
@Test
public void computeForOneStaffTestRoss() {
List<Example> examples = new RossBeamSlant().getExamples();
List<ExampleResult> results = alist();
for (Example example : examples) {
// collect data
BeamedStems stems = example.getStems();
Slant slant = singleStaffBeamSlanter.compute(stems, 5);
// run test
Placement offset = testee.compute(slant, stems, 1, StaffLines.Companion.getStaff5Lines());
// check result
ExampleResult result = check(offset, example);
results.add(result);
}
// success, when 100% of the examples are perfect or at least accepted
// print accepted and failed results
int perfect = 0, accepted = 0, failed = 0;
for (ExampleResult result : results) {
if (result.getResult() != Result.Perfect) {
System.out.print(result.getExample().getName() + ": ");
if (result.getResult() == Result.Accepted) {
accepted++;
System.out.print("not perfect, but accepted");
} else {
failed++;
System.out.print("FAILED");
}
if (result.getComment() != null)
System.out.print("; " + result.getComment());
System.out.println();
} else {
perfect++;
}
}
System.out.println(SingleStaffBeamPlacerTest.class.getSimpleName() + ": " + perfect + " perfect, " + accepted + " accepted, " + failed + " failed");
if (failed > 0)
fail();
}
use of com.xenoage.zong.musiclayout.spacer.beam.Slant in project Zong by Xenoage.
the class SingleStaffBeamSlanterTest method computeTest.
@Test
public void computeTest() {
// use tests from Ross and Chlapik
for (Suite<Example> suite : alist(new RossBeamSlant(), new ChlapikBeamSlant())) {
for (Example example : suite.getExamples()) {
float expectedSlant = example.getSlantIs();
Slant slant = testee.compute(example.getStems(), example.staffLines);
assertSlantContains(expectedSlant, slant, suite.getName() + ": " + example.name);
}
}
}
use of com.xenoage.zong.musiclayout.spacer.beam.Slant in project Zong by Xenoage.
the class SlantTest method limitQsTest.
@Test
public void limitQsTest() {
Slant slant = slant(0).limitQs(1);
assertEquals(0, slant.getMinIs(), df);
assertEquals(0, slant.getMaxIs(), df);
slant = slantIs(0, 2, Ascending).limitQs(1 * 4);
assertEquals(0, slant.getMinIs(), df);
assertEquals(1, slant.getMaxIs(), df);
slant = slantIs(2, 3, Ascending).limitQs(1 * 4);
assertEquals(1, slant.getMinIs(), df);
assertEquals(1, slant.getMaxIs(), df);
slant = slantIs(0, 1, Descending).limitQs(1 * 4);
assertEquals(-1, slant.getMinIs(), df);
assertEquals(0, slant.getMaxIs(), df);
slant = slantIs(2, 3, Descending).limitQs(1 * 4);
assertEquals(-1, slant.getMinIs(), df);
assertEquals(-1, slant.getMaxIs(), df);
}
use of com.xenoage.zong.musiclayout.spacer.beam.Slant in project Zong by Xenoage.
the class SingleStaffBeamSlanter method compute.
public Slant compute(BeamedStems stems, int staffLines) {
// Ross, p. 115, row 1: use horizontal beam, if first and last note is on the same LP
if (stems.leftNoteLp == stems.rightNoteLp)
return horizontalSlant;
// unification of the rules in Ross, p. 115-117:
// a horizontal beam may be correct if all middle notes are lower/higher or equal than
// outer notes for a downstem/upstem beam
val stemDir = stems.getFirst().dir;
if (containsMiddleExtremeNote(stems, stemDir)) {
// Ross, p. 97, row 3: 3 notes with middle note equal to outer note: normal slant
if (is3NotesMiddleEqualsOuter(stems))
return computeNormal(stems.leftNoteLp, stems.rightNoteLp);
// Ross, p. 97, row 4: 4 notes in special constellation: half space slant
int rossSpecialDir = get4NotesRossSpecialDir(stems, stemDir);
if (rossSpecialDir != 0)
return slant(rossSpecialDir * 0.5f);
// Ross, p. 97, rows 5 and 6: inner run with half space slant
int innerRunDir = getInnerRunDir(stems);
if (innerRunDir != 0)
return slant(innerRunDir * 0.5f);
// no exception. horizontal is correct.
return horizontalSlant;
}
// otherwise, compute slant dependent on the horizontal spacing
Slant slant;
if (isCloseSpacing(stems))
slant = computeClose(stems, stemDir);
else
slant = computeNormal(stems.leftNoteLp, stems.rightNoteLp);
// limit slant
slant = limitSlantForExtremeNotes(slant, stems, stemDir, staffLines);
return slant;
}
use of com.xenoage.zong.musiclayout.spacer.beam.Slant in project Zong by Xenoage.
the class SingleStaffBeamSlanterTest method computeNormalTest.
@Test
public void computeNormalTest() {
Examples.test(Example.all, "interval", 14, (suite, example) -> {
float expectedSlant = example.getSlantIs();
Slant slant = testee.computeNormal(example.leftNoteLp, example.rightNoteLp);
assertSlantContains(expectedSlant, slant, example.name);
});
}
Aggregations