Search in sources :

Example 1 with BeamedStems

use of com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems in project Zong by Xenoage.

the class SingleStaffBeamPlacerTest method getDictatorStemIndexTest_Descending.

@Test
public void getDictatorStemIndexTest_Descending() {
    val stemsDown = new BeamedStems(ilist(beamedStem(2, 13, Down), beamedStem(4, 11, Down), beamedStem(6, 10, Down)));
    val stemsUp = new BeamedStems(ilist(beamedStem(2, 13, Up), beamedStem(4, 11, Up), beamedStem(6, 10, Up)));
    // descending line, downstem (find min LP)
    assertEquals(2, testee.getDictatorStemIndex(Down, stemsDown, -0.95f));
    assertEquals(1, testee.getDictatorStemIndex(Down, stemsDown, -1.05f));
    assertEquals(1, testee.getDictatorStemIndex(Down, stemsDown, -1.95f));
    assertEquals(0, testee.getDictatorStemIndex(Down, stemsDown, -2.05f));
    // descending line, upstem (find max LP)
    assertEquals(0, testee.getDictatorStemIndex(Up, stemsUp, -0.95f));
    assertEquals(0, testee.getDictatorStemIndex(Up, stemsUp, -1.05f));
    assertEquals(2, testee.getDictatorStemIndex(Up, stemsUp, -1.95f));
    assertEquals(2, testee.getDictatorStemIndex(Up, stemsUp, -2.05f));
}
Also used : lombok.val(lombok.val) BeamedStems(com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems) Test(org.junit.Test)

Example 2 with BeamedStems

use of com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems 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 3 with BeamedStems

use of com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems in project Zong by Xenoage.

the class SingleStaffBeamPlacerTest method getDictatorStemIndexTest_HorizontalOrAscending.

@Test
public void getDictatorStemIndexTest_HorizontalOrAscending() {
    val stemsDown = new BeamedStems(ilist(beamedStem(2, 10, Down), beamedStem(4, 11, Down), beamedStem(6, 13, Down)));
    val stemsUp = new BeamedStems(ilist(beamedStem(2, 10, Up), beamedStem(4, 11, Up), beamedStem(6, 13, Up)));
    // horizontal line, downstem (find min LP)
    assertEquals(0, testee.getDictatorStemIndex(Down, stemsDown, 0));
    // horizontal line, upstem (find max LP)
    assertEquals(2, testee.getDictatorStemIndex(Up, stemsUp, 0));
    // ascending line, downstem (find min LP)
    assertEquals(0, testee.getDictatorStemIndex(Down, stemsDown, 0.95f));
    assertEquals(1, testee.getDictatorStemIndex(Down, stemsDown, 1.05f));
    assertEquals(1, testee.getDictatorStemIndex(Down, stemsDown, 1.95f));
    assertEquals(2, testee.getDictatorStemIndex(Down, stemsDown, 2.05f));
    // ascending line, upstem (find max LP)
    assertEquals(2, testee.getDictatorStemIndex(Up, stemsUp, 0.95f));
    assertEquals(2, testee.getDictatorStemIndex(Up, stemsUp, 1.05f));
    assertEquals(0, testee.getDictatorStemIndex(Up, stemsUp, 1.95f));
    assertEquals(0, testee.getDictatorStemIndex(Up, stemsUp, 2.05f));
}
Also used : lombok.val(lombok.val) BeamedStems(com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems) Test(org.junit.Test)

Example 4 with BeamedStems

use of com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems 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 5 with BeamedStems

use of com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems in project Zong by Xenoage.

the class Example method getStems.

public BeamedStems getStems() {
    val stems = new CList<BeamedStem>();
    int[] notesLp = getNotesLp();
    val stemDir = getStemDir();
    float distance = getStemsDistanceIs();
    for (int i : range(notesLp)) {
        float stemXIs = i * distance;
        float stemLengthIs;
        if (i == 0)
            stemLengthIs = leftStemLengthIs;
        else if (i == notesLp.length - 1)
            stemLengthIs = rightStemLengthIs;
        else
            stemLengthIs = stemDrawer.getPreferredStemLengthIs(new ChordLps(notesLp[i]), stemDir, Companion.getStaff5Lines());
        float stemEndLp = notesLp[i] + stemDir.getSign() * stemLengthIs * 2;
        stems.add(new BeamedStem(stemXIs, stemDir, slp(0, notesLp[i]), slp(0, stemEndLp)));
    }
    return new BeamedStems(stems.close());
}
Also used : lombok.val(lombok.val) BeamedStems(com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems) CList(com.xenoage.utils.collections.CList) ChordLps(com.xenoage.zong.musiclayout.notation.chord.ChordLps) BeamedStem(com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStem)

Aggregations

BeamedStems (com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStems)5 Test (org.junit.Test)4 lombok.val (lombok.val)3 Placement (com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement)2 CList (com.xenoage.utils.collections.CList)1 ChordLps (com.xenoage.zong.musiclayout.notation.chord.ChordLps)1 Slant (com.xenoage.zong.musiclayout.spacer.beam.Slant)1 BeamedStem (com.xenoage.zong.musiclayout.spacer.beam.stem.BeamedStem)1 ExampleResult (material.ExampleResult)1 Example (material.beam.slant.Example)1 RossBeamSlant (material.beam.slant.RossBeamSlant)1 TouchExample (material.beam.stafftouch.TouchExample)1