package jmslexamples.simple; import com.softsynth.jmsl.JMSLRandom; import com.softsynth.jmsl.MusicShape; import com.softsynth.jmsl.score.*; import com.softsynth.jmsl.score.transcribe.*; /** * * 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 * * Melody 2 uses quarter tones * * @author Nick Didkovsky, (c) 2002 Nick Didkovsky, All Rights reserved. */ public class TranscribeAndNotate { MusicShape melody1; MusicShape melody2; Score score; public TranscribeAndNotate() { } void buildScore() { // Prepare a Score, 2 staves, width, height score = new Score(2, 1024, 800); score.addMeasure(); score.getMeasure(0).getStaff(1).setClef(Clef.BASS_CLEF); } void buildMusicShapes() { // create musicshape data algorithmically melody1 = new MusicShape(4); for (int i = 0; i < 6; i++) { double duration = JMSLRandom.choose(3, 6); double pitch = JMSLRandom.choose(60, 84); double amp = JMSLRandom.choose(0.2, 0.7); double hold = duration; melody1.add(duration, pitch, amp, hold); } melody2 = new MusicShape(4); for (int i = 0; i < 17; i++) { double duration = JMSLRandom.choose(2.0); double pitch = JMSLRandom.choose(48, 60); // let's add a qtr tone roughly half the time if (JMSLRandom.choose() < 0.5) pitch += 0.5; double amp = JMSLRandom.choose(0.2, 0.7); double hold = duration * 0.8; melody2.add(duration, pitch, amp, hold); } } void transcribe() throws SearchPathListExpansionException, ElementMissedException { // set up allowed subdivisions BeatDivisionSchemeList.defaultSetup(); 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); // 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(); } /** * @return Returns the score. * @throws ElementMissedException * @throws SearchPathListExpansionException */ public Score generateScore() throws SearchPathListExpansionException, ElementMissedException { buildScore(); buildMusicShapes(); transcribe(); return score; } public static void main(String args[]) { JMSLRandom.randomize(); TranscribeAndNotate transcribeAndNotate = new TranscribeAndNotate(); Score score = null; try { score = transcribeAndNotate.generateScore(); } catch (SearchPathListExpansionException e1) { e1.printStackTrace(); } catch (ElementMissedException e1) { e1.printStackTrace(); } final ScoreFrame myScoreFrame = new ScoreFrame(); myScoreFrame.addScore(score); myScoreFrame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { myScoreFrame.quit(); } }); myScoreFrame.setVisible(true); } }