/* * Created on Jun 13, 2017 by Nick * */ package jmsltestsuite; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import com.softsynth.jmsl.JMSLRandom; import com.softsynth.jmsl.score.*; import com.softsynth.jmsl.score.util.*; import com.softsynth.jmsl.util.TimeSignature; /** test beam grouping, ie assigning groupings to a time signature (7/8 beamed as 2,2,3 versus 3,2,2 for example */ public class BeamGroupTest { public static void main(String[] args) { JMSLRandom.randomize(); Score score = new Score(1, 600, 400); int beats = 6; score.addMeasure(beats, 8); for (int i = 0; i < beats * 4; i++) { double duration = 0.25; // 0.333; // 0.25; // 0.6666; // 1; // JMSLRandom.choose() < 0.5 ? 0.5 : // 0.25; boolean makeRest = false; // JMSLRandom.choose() < 0.15; double pitch = makeRest ? 0 : 60 + 2 * i; Note n = score.addNote(duration, pitch, 0.5, 0.4); if (!makeRest) { // n.addInterval(80); } } ScoreFrame scoreFrame = new ScoreFrame(); scoreFrame.addScore(score); scoreFrame.pack(); scoreFrame.setVisible(true); scoreFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); try { BeamGroupCollection col = new BeamGroupCollection(); // int[] groups = { 1, 1, 1, 1, 1, 1 }; // int[] groups = { 2, 3, 2 }; // int[] groups = { 3, 2, 2 }; // int[] groups = { 2, 2, 2 }; // int[] groups = { 2, 2, 2 }; // int[] groups = { 2, 2, 3 }; // int[] groups = { 2, 3, 2 }; int[] groups = { 2, 1, 3 }; col.addBeamGroup(new BeamGroup(new TimeSignature(6, 8), groups)); int[] groups2 = { 3, 2, 2 }; // col.addBeamGroup(new BeamGroup(new TimeSignature(7, 4), groups2)); System.out.println(col); Track t = score.getMeasure(0).getStaff(0).getTrack(0); new BeamGrouper(t, col).beam(); score.render(); // write/read to/from file File f = new File("C:\\Users\\Nick\\Desktop\\temp\\ABEAMGROUP.TXT"); new BeamGroupCollectionIO().write(col, f); col = new BeamGroupCollectionIO().read(f); System.out.println("After reading\n" + col); } catch (Exception e) { e.printStackTrace(); } } }