package jmsltutorial; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import com.softsynth.jmsl.*; import com.softsynth.jmsl.jsyn.JSynMusicDevice; import com.softsynth.jmsl.jsyn.TransposingSamplePlayingInstrument; /** A subclass of TransposingSamplePlayingInstrument which maps pitches to sound files, and transposes to fill in unmapped gaps, * * Does a simple loop to sustain the sample over time. You will hear a possibly clicky repeat loop. For smoother sustain, see CelloSampleSustainingIns * * Copy and rename this example, change the buildFromAttributes() method. * * This example only maps one cello soundfile to middle C, to serve as an example without shipping a huge sample bank. * * @author Nick Didkovsky, copyright 2004 Nick Didkovsky, all rights reserved * * */ public class CelloSampleIns extends TransposingSamplePlayingInstrument { static int insNum = 0; public CelloSampleIns() { super(); name = "CelloSampleIns_" + insNum++; } public CelloSampleIns(String sampleDirectory) { super(sampleDirectory); name = "CelloSampleIns_" + insNum++; } public void buildFromAttributes() { addSamplePitch("vcl_c4.wav", 60); // add more samples here, every minor third recommended super.buildFromAttributes(); } /** Create an instance of this class and write it out as an XML file */ public static void main(String args[]) { JSynMusicDevice.instance().open(); JMSL.clock.setAdvance(0.2); CelloSampleIns ins = new CelloSampleIns("E:/jwork/eclipse_projects/JMSL_Release/JMSL_v103/SAMPLES/"); ins.buildFromAttributes(); JMSLMixerContainer mixer = new JMSLMixerContainer(); mixer.start(); mixer.addInstrument(ins); MusicShape s = new MusicShape(4); s.add(3.0, 60, 0.45, 4.5); s.add(3.5, 63, 0.45, 4.0); s.add(4.5, 58, 0.45, 5.0); s.setInstrument(ins); s.setRepeats(10); s.addRepeatPlayable(new Playable() { public double play(double time, Composable parent) throws InterruptedException { MusicShape s = (MusicShape) parent; s.scramble(0, s.size() - 1, 0); s.scramble(0, s.size() - 1, 1); return time; } }); s.launch(JMSL.now()); Frame f = new Frame("Close to quit"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { JMSL.closeMusicDevices(); System.exit(0); } }); f.setSize(320, 200); f.setVisible(true); // try { // PrintWriter out = new PrintWriter(new FileOutputStream("CelloSampleIns.xml")); // (new SimpleXMLSaver(ins, "jmslscoreinstrument")).writeXML(out); // out.close(); // } // catch (Exception e) { // System.out.println("ERROR in main: " + e); // } } }