Search in sources :

Example 1 with Slant

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();
}
Also used : BeamedStems(com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems) Placement(com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement) Example(material.beam.slant.Example) TouchExample(material.beam.stafftouch.TouchExample) RossBeamSlant(material.beam.slant.RossBeamSlant) Slant(com.xenoage.zong.musiclayout.spacer.beam.Slant) RossBeamSlant(material.beam.slant.RossBeamSlant) ExampleResult(material.ExampleResult) Test(org.junit.Test)

Example 2 with Slant

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);
        }
    }
}
Also used : Example(material.beam.slant.Example) RossBeamSlant(material.beam.slant.RossBeamSlant) ChlapikBeamSlant(material.beam.slant.ChlapikBeamSlant) RossBeamSlant(material.beam.slant.RossBeamSlant) Slant(com.xenoage.zong.musiclayout.spacer.beam.Slant) ChlapikBeamSlant(material.beam.slant.ChlapikBeamSlant) Test(org.junit.Test)

Example 3 with Slant

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);
}
Also used : Slant(com.xenoage.zong.musiclayout.spacer.beam.Slant) Test(org.junit.Test)

Example 4 with Slant

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;
}
Also used : lombok.val(lombok.val) Slant(com.xenoage.zong.musiclayout.spacer.beam.Slant)

Example 5 with 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);
    });
}
Also used : ChlapikBeamSlant(material.beam.slant.ChlapikBeamSlant) RossBeamSlant(material.beam.slant.RossBeamSlant) Slant(com.xenoage.zong.musiclayout.spacer.beam.Slant) Test(org.junit.Test)

Aggregations

Slant (com.xenoage.zong.musiclayout.spacer.beam.Slant)7 Test (org.junit.Test)6 RossBeamSlant (material.beam.slant.RossBeamSlant)4 ChlapikBeamSlant (material.beam.slant.ChlapikBeamSlant)3 Example (material.beam.slant.Example)2 Placement (com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement)1 BeamedStems (com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems)1 lombok.val (lombok.val)1 ExampleResult (material.ExampleResult)1 TouchExample (material.beam.stafftouch.TouchExample)1