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.TransposingSampleSustainingInstrument; /** A subclass of TransposingSampleSustainingInstrument which maps pitches to sound files, and transposes to fill in unmapped gaps, * * This class does a better job of sustaining than TransposingSamplePlayingInstrument, as it uses two sample players to manage the loop, and crossfades between them * 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 CelloSampleSustainingIns extends TransposingSampleSustainingInstrument { static int insNum = 0; public CelloSampleSustainingIns() { super(); name = "CelloSampleSusIns_" + insNum++; } public CelloSampleSustainingIns(String sampleDirectory) { super(sampleDirectory); name = "CelloSampleSusIns_" + 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); // you can set the directory on SampleFinderDialog before loading or instantiating an instrument // to give a fall back directory in case the dir in the instrument fails. // This could be encountered if you are loading an instrument from an XML file that was saved on another machine // If the SampleFinderDialog directory is correct, it will use that and prevent a sample finding dialog from popping up. com.softsynth.jmsl.view.SampleFinderDialog.setDirectory( "E:/jwork/eclipse_projects/JMSL_Release/JMSL_v103/SAMPLES/"); CelloSampleSustainingIns ins = new CelloSampleSustainingIns("BAD PATH"); 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 { // java.io.PrintWriter out = new java.io.PrintWriter(new java.io.FileOutputStream("CelloSampleSusIns.xml")); // (new com.softsynth.jmsl.util.SimpleXMLSaver(ins, "jmslscoreinstrument")).writeXML(out); // out.close(); // } catch (Exception e) { // System.out.println("ERROR in main: " + e); // } // com.softsynth.jmsl.util.InstrumentXMLLoader loader = new com.softsynth.jmsl.util.InstrumentXMLLoader(); // try { // System.out.println(loader.loadXML("CelloSampleSusIns.xml")); // } catch (java.io.IOException e1) { // e1.printStackTrace(); // } } }