Search in sources :

Example 1 with Placement

use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.

the class SingleStaffBeamPlacerTest method shortenTest.

@Test
public void shortenTest() {
    // the following tests use arbitrary horizontal positions, but normal spacing (not close spacing)
    // p104 r1 c1: could be 3.5/sit, but is 3.25/straddle
    Placement old = new Placement(5f, 5f);
    BeamedStems stems = new BeamedStems(ilist(beamedStem(5, -2, Up), beamedStem(10, -2, Up)));
    Placement shortened = testee.shorten(old, Up, stems, 1, Companion.getStaff5Lines());
    assertEquals(new Placement(4.5f, 4.5f), shortened);
    // p104 r6 c1: could be 3.75/straddle and 3.5/hang, but is 3.5/sit and 3.25/straddle
    old = new Placement(-2.5f, -3f);
    stems = new BeamedStems(ilist(beamedStem(10, 5, Down), beamedStem(15, 4, Down)));
    shortened = testee.shorten(old, Down, stems, 1, Companion.getStaff5Lines());
    assertEquals(new Placement(-2f, -2.5f), shortened);
    // p104 r7 c1: is not shortened, since then a stem would be shorter than 3 spaces
    old = new Placement(-1f, -0.5f);
    stems = new BeamedStems(ilist(beamedStem(0, 5, Down), beamedStem(5, 6, Down)));
    shortened = testee.shorten(old, Down, stems, 1, Companion.getStaff5Lines());
    assertEquals(old, shortened);
    // p105 r1 c1: not shortened, because beam line would be within white space
    old = new Placement(6f, 6f);
    stems = new BeamedStems(ilist(beamedStem(0, -1, Up), beamedStem(8, -1, Up)));
    shortened = testee.shorten(old, Up, stems, 1, Companion.getStaff5Lines());
    assertEquals(old, shortened);
    // p105 r1 c2: could be 3.5/hang, but is 3.25/staddle
    old = new Placement(-1f, -1f);
    stems = new BeamedStems(ilist(beamedStem(10, 6, Down), beamedStem(15, 6, Down)));
    shortened = testee.shorten(old, Down, stems, 1, Companion.getStaff5Lines());
    assertEquals(new Placement(-0.5f, -0.5f), shortened);
}
Also used : BeamedStems(com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems) Placement(com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement) Test(org.junit.Test)

Example 2 with Placement

use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement 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 3 with Placement

use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.

the class TouchExample method example32nd.

public static TouchExample example32nd(String name, double leftLp, double rightLp, StemDirection stemDir) {
    TouchExample ret = new TouchExample();
    ret.name = name;
    ret.placement = new Placement((float) leftLp, (float) rightLp);
    ret.stemDir = stemDir;
    // 3 lines, 2 gaps
    ret.beamHeightIs = 0.5f + 0.25f + 0.5f + 0.25f + 0.5f;
    return ret;
}
Also used : Placement(com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement)

Example 4 with Placement

use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.

the class SingleStaffBeamPlacerTest method getPlacementTest.

@Test
public void getPlacementTest() {
    // exact result: no rounding required
    assertEqualsPlacement(new Placement(2, 3.5f), testee.getPlacement(2, 7, 3, 2.3f, 0.75f));
    // 0.4 quarter spaces (= 0.2 LP) higher: should be rounded down to same result
    assertEqualsPlacement(new Placement(2, 3.5f), testee.getPlacement(2, 7, 3, 2.3f + 0.2f, 0.75f));
    // 0.6 quarter spaces (= 0.3 LP) higher: should be rounded up to the next quarter space
    assertEqualsPlacement(new Placement(2.5f, 4), testee.getPlacement(2, 7, 3, 2.3f + 0.3f, 0.75f));
}
Also used : Placement(com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement) Test(org.junit.Test)

Example 5 with Placement

use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.

the class TouchExample method example8th.

public static TouchExample example8th(String name, double leftLp, double rightLp, StemDirection stemDir) {
    TouchExample ret = new TouchExample();
    ret.name = name;
    ret.placement = new Placement((float) leftLp, (float) rightLp);
    ret.stemDir = stemDir;
    ret.beamHeightIs = 0.5f;
    return ret;
}
Also used : Placement(com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement)

Aggregations

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