package jmsltestsuite; import com.softsynth.jmsl.JMSLRandom; import com.softsynth.jmsl.MusicShape; import com.softsynth.jmsl.score.Clef; import com.softsynth.jmsl.score.Score; import com.softsynth.jmsl.score.ScoreFrame; import com.softsynth.jmsl.score.transcribe.BeatDivisionSchemeList; import com.softsynth.jmsl.score.transcribe.ElementMissedException; import com.softsynth.jmsl.score.transcribe.SearchPathListExpansionException; import com.softsynth.jmsl.score.transcribe.Transcriber; /** * * Transcribe two MusicShapes and generate a Score. * * Dim 0 of MusicShapes must be absolute time. Use musicShape.integrate(0) to convert durations to * abs time * * @author Nick Didkovsky, (c) 2002 Nick Didkovsky, All Rights reserved. */ public class TestTranscribeSimple { public static void main(String args[]) { // set up allowed subdivisions BeatDivisionSchemeList.defaultSetup(); // create musicshape data somehow MusicShape melody1 = new MusicShape(4); for (int i = 0; i < 17; i++) { double duration = JMSLRandom.choose(3.0); double pitch = JMSLRandom.choose(60, 84); double amp = JMSLRandom.choose(0.2, 0.7); double hold = duration * 0.8; melody1.add(duration, pitch, amp, hold); } MusicShape melody2 = new MusicShape(4); for (int i = 0; i < 17; i++) { double duration = JMSLRandom.choose(2.0); double pitch = JMSLRandom.choose(48, 60); double amp = JMSLRandom.choose(0.2, 0.7); double hold = duration * 0.8; melody2.add(duration, pitch, amp, hold); } // Prepare a Score, 2 staves, width, height final Score score = new Score(2, 1024, 800); score.addMeasure(); score.getMeasure(0).getStaff(1).setClef(Clef.BASS_CLEF); Transcriber transcriber = new Transcriber(); transcriber.setScore(score); // Set up time signatures. Only need to give it one 4/4 bar and transcriber will continue // with 4/4 throughout // NEW: The following code is done by default in Transcriber() constructor. // Uncomment and change if you want 5/4 for example, or a sequence of time sigs // TimeSignature ts = new TimeSignature(4, 4); // Vector tsVector = new Vector(); // tsVector.addElement(ts); // transcriber.setTimeSignatures(tsVector); try { // transcribe first melody score.setCurrentStaffNumber(0); score.rewind(); transcriber.setSourceMusicShape(melody1); melody1.integrate(0); transcriber.transcribe(); // transcribe second melody score.setCurrentStaffNumber(1); score.rewind(); transcriber.setSourceMusicShape(melody2); melody2.integrate(0); transcriber.transcribe(); } catch (ElementMissedException e) { e.printStackTrace(); System.out.println("ERROR: " + e); } catch (SearchPathListExpansionException e) { e.printStackTrace(); System.out.println("ERROR: " + e); } final ScoreFrame myScoreFrame = new ScoreFrame(); myScoreFrame.addScore(score); //myScoreFrame.loadPrefs(); myScoreFrame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { myScoreFrame.quit(); } }); myScoreFrame.setVisible(true); } }