package jmsltestsuite; import java.util.Vector; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.MusicShape; import com.softsynth.jmsl.score.Score; import com.softsynth.jmsl.score.ScoreFrame; import com.softsynth.jmsl.score.transcribe.*; import com.softsynth.jmsl.util.TimeSignature; /** * * JMSL's com.softsynth.jmsl.score.transcribe package enables the transcription of arbitrary * MusicShape data into common music notation. This example uses a melody generated by Larry * Polansky, used with permission * * @author Nick Didkovsky, (c) 2002 Nick Didkovsky, All Rights reserved. * */ public class TranscribeScoreLP1 { public static void main(String args[]) { JMSL.clock.setAdvance(0.1); BeatDivisionSchemeList.defaultSetup(); MusicShape musicShape_1 = new MusicShape(4); musicShape_1.setDimensionName( 0, "duration"); musicShape_1.setLimits(0, 0.0, 8.0); musicShape_1.setDefault(0, 1.0); musicShape_1.setDimensionName( 1, "pitch"); musicShape_1.setLimits(1, 0.0, 127.0); musicShape_1.setDefault(1, 60.0); musicShape_1.setDimensionName( 2, "amplitude"); musicShape_1.setLimits(2, 0.0, 1.0); musicShape_1.setDefault(2, 0.5); musicShape_1.setDimensionName( 3, "hold"); musicShape_1.setLimits(3, 0.0, 8.0); musicShape_1.setDefault(3, 0.8); musicShape_1.add( 0.25, 70.0, 0.5, 0.25 ); musicShape_1.add( 0.5, 63.0, 0.5, 0.5 ); musicShape_1.add( 0.16666, 65.0, 0.5, 0.124995 ); musicShape_1.add( 0.16666, 68.0, 0.5, 0.08333 ); musicShape_1.add( 0.16666, 62.0, 0.5, 0.08333 ); musicShape_1.add( 0.5, 64.0, 0.5, 0.5 ); musicShape_1.add( 0.25, 68.0, 0.5, 0.1875 ); musicShape_1.add( 0.25, 72.0, 0.5, 0.1875 ); musicShape_1.add( 0.375, 65.0, 0.5, 0.140625 ); musicShape_1.add( 0.375, 71.0, 0.5, 0.28125 ); musicShape_1.add( 0.25, 64.0, 0.5, 0.1875 ); musicShape_1.add( 0.5, 69.0, 0.5, 0.25 ); musicShape_1.add( 0.1875, 66.0, 0.5, 0.123046875 ); musicShape_1.add( 0.1875, 68.0, 0.5, 0.123046875 ); musicShape_1.add( 0.125, 73.0, 0.5, 0.166015625 ); musicShape_1.add( 0.0625, 0.0, 0.0, 0.041015625 ); musicShape_1.add( 0.0625, 64.0, 0.5, 0.14453125 ); musicShape_1.add( 0.125, 0.0, 0.0, 0.08203125 ); musicShape_1.add( 0.125, 67.0, 0.5, 0.166015625 ); musicShape_1.add( 0.0625, 0.0, 0.0, 0.041015625 ); musicShape_1.add( 0.0625, 70.0, 0.5, 0.14453125 ); musicShape_1.add( 0.125, 0.0, 0.0, 0.08203125 ); musicShape_1.add( 0.25, 73.0, 0.5, 0.33203125 ); musicShape_1.add( 0.125, 0.0, 0.0, 0.08203125 ); musicShape_1.add( 0.25, 70.0, 0.5, 0.33203125 ); musicShape_1.add( 0.125, 0.0, 0.0, 0.08203125 ); musicShape_1.add( 0.125, 67.0, 0.5, 0.16015625 ); musicShape_1.add( 0.0625, 0.0, 0.0, 0.03515625 ); musicShape_1.add( 0.0625, 70.0, 0.5, 0.1328125 ); musicShape_1.add( 0.125, 0.0, 0.0, 0.0703125 ); musicShape_1.add( 0.25, 75.0, 0.5, 0.390625 ); musicShape_1.add( 0.125, 0.0, 0.0, 0.140625 ); musicShape_1.add( 0.375, 69.0, 0.5, 0.421875 ); // HEY LOOK HERE!!!!!!!!!!!!!!!!!!!!!!!!!!! // GO FROM RELTIVE DURATIONS TO ABSOLULTE TIME!!!!!!!!!!!!!!!!!!!!!!!!! musicShape_1.integrate(0); // 1 staff, width, height Score score = new Score(1, 1024, 800); score.addMeasure(); Transcriber transcriber = new Transcriber(); transcriber.setScore(score); transcriber.setSourceMusicShape(musicShape_1); TimeSignature ts = new TimeSignature(4, 4); Vector tsVector = new Vector(); tsVector.addElement(ts); transcriber.setTimeSignatures(tsVector); score.setCurrentStaffNumber(0); double timebefore = JMSL.realTime(); try { transcriber.transcribe(); } catch (ElementMissedException e) { e.printStackTrace(); System.out.println("ERROR: " + e); System.exit(0); } catch (SearchPathListExpansionException e) { e.printStackTrace(); System.out.println("ERROR: " + e); System.exit(0); } double timeafter = JMSL.realTime(); double duration = timeafter - timebefore; System.out.println("That took " + duration + " sec to transcribe"); final ScoreFrame f = new ScoreFrame(); f.addScore(score); // f.loadPrefs(); f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { f.quit(); } }); f.setVisible(true); } } /** * 4/4 takes 0.25 sec * 5/4 takes 0.25 sec * 6/4 takes 0.297 sec * 7/4 takes 0.687 sec * 8/4 takes 1.156 sec * 9/4 takes 8.359 sec * 10/4 takes 10.031 sec * 11/4 takes 126.59 sec * * */