Package com.softsynth.jmsl.jsyn
Class SimpleSamplePlayingInstrument
java.lang.Object
com.softsynth.jmsl.InstrumentAdapter
com.softsynth.jmsl.jsyn.SimpleSamplePlayingInstrument
- All Implemented Interfaces:
Editable
,Instrument
,Namable
,OutputProvider
,Transposable
,AttributeBuildable
,DirectorySettable
,HandleSpecialXMLTag
- Direct Known Subclasses:
SimpleSamplePlayingInstrumentWithLoops
public class SimpleSamplePlayingInstrument extends InstrumentAdapter implements AttributeBuildable, DirectorySettable, HandleSpecialXMLTag, Editable
Deprecated.
use the pure Java JSyn2 package instead
A JMSL Instrument that plays SynthSamples, mapped to integer pitch values. "One shot" style. No
transposition, no loop points, plays all the way through
If loadSample() fails to find it it will open a SampleFinderDialog.
IMPORTANT: For Applets, the root sample directory passed to the constructor is ignored and CODEBASE is used instead!!!! So your samples should be in your applet's CODEBASE. The use of subfolders is ok, just make everything relative to CODEBASE. So for example, if locally you have a root sample directory called F:/JMSLScoreWork/JMSLScoreSamples/ relative to which all your samples are located, and inside it is hr16_stereo/AlesisKick.aif, then your applet's CODEBASE, which might be a folder called "classes", should contain hr16_stereo/AlesisKick.aif
IMPORTANT: stereo samples must be AIFF for versions of JSyn prior to 1.43 ( see http://www.softsynth.com/jsyn/support/bugs.html#BUG0007 )
Since JMSLv103, SimpleSamplePlayingInstrument performs stereo AIF samples as well. For example:
New to build 20060408, this class supports new methods loadSample(SynthSample sample, int noteIndex) and loadSample(short[] shorts, int noteIndex) for dynamically created sample data MOD 20070306 constructor calls setDimensionNameSpace(DefaultDimensionNameSpace.instance());
If loadSample() fails to find it it will open a SampleFinderDialog.
IMPORTANT: For Applets, the root sample directory passed to the constructor is ignored and CODEBASE is used instead!!!! So your samples should be in your applet's CODEBASE. The use of subfolders is ok, just make everything relative to CODEBASE. So for example, if locally you have a root sample directory called F:/JMSLScoreWork/JMSLScoreSamples/ relative to which all your samples are located, and inside it is hr16_stereo/AlesisKick.aif, then your applet's CODEBASE, which might be a folder called "classes", should contain hr16_stereo/AlesisKick.aif
IMPORTANT: stereo samples must be AIFF for versions of JSyn prior to 1.43 ( see http://www.softsynth.com/jsyn/support/bugs.html#BUG0007 )
Since JMSLv103, SimpleSamplePlayingInstrument performs stereo AIF samples as well. For example:
SimpleSamplePlayingInstrument ins = new SimpleSamplePlayingInstrument("F:\\JMSLScoreWork\\JMSLScoreSamples\\"); ins.setNumChannels(2); ins.getMusicDevice().edit(f); ins.getMusicDevice().open(); ins.addSamplePitch("hr16_stereo\\AlesisKick.aif", 60); ins.addSamplePitch("hr16_stereo\\AlesisSnare.aif", 61); ins.addSamplePitch("hr16_stereo\\AlesisFloorTom.aif", 62); ins.addSamplePitch("hr16_stereo\\AlesisRackTom1.aif", 63); ins.addSamplePitch("hr16_stereo\\AlesisRackTom2.aif", 64); ins.buildFromAttributes(); JMSLMixerContainer mixer = new JMSLMixerContainer(); mixer.addInstrument(ins); mixer.start();This version adds new feature of being able to map pitches to different samples based on performance data, by overriding getAlternativeSampleIndex().
New to build 20060408, this class supports new methods loadSample(SynthSample sample, int noteIndex) and loadSample(short[] shorts, int noteIndex) for dynamically created sample data MOD 20070306 constructor calls setDimensionNameSpace(DefaultDimensionNameSpace.instance());
- Author:
- Nick Didkovsky, nick@didkovsky.com (C) 2000 Nick Didkovsky, all rights reserved.
- See Also:
SimpleSamplePlayingInstrumentWithAmplitudeMap
-
Field Summary
Fields Modifier and Type Field Description int
POLYPHONY
Deprecated.max number of voices to allocate, default 32. -
Constructor Summary
Constructors Constructor Description SimpleSamplePlayingInstrument()
Deprecated.SimpleSamplePlayingInstrument(java.lang.String sampleDirectory)
Deprecated.Sample directory string must end in file separator, ex "F:\samples\" All samples will be sought in this directory. -
Method Summary
Modifier and Type Method Description void
addEditListener(EditListener listener)
Deprecated.void
addSamplePitch(short[] shorts, int pitch)
Deprecated.Assign a dynamically created sample to a note index.void
addSamplePitch(com.softsynth.jsyn.SynthSample sample, int pitch)
Deprecated.Assign a dynamically created sample to a note index.void
addSamplePitch(java.lang.String filename, int pitch)
Deprecated.Assign a sample to be triggered when noteIndex is passed to play().void
buildFromAttributes()
Deprecated.void
clear()
Deprecated.remove all samples and pitch mappingsdouble
close(double time)
Deprecated.void
edit(java.awt.Frame fr)
Deprecated.Open a Frame containing a SampleInstrumentMapperPanel for this instrument.int
getAlternativeSampleIndex(int pitchIndex, double timeStretch, double[] data)
Deprecated.Precondition: pitchIndex points to a valid sample, previously loaded with addSamplePitch().java.io.File
getDirectory()
Deprecated.boolean
getEditEnabled()
Deprecated.int
getNumChannels()
Deprecated.int
getNumOutputs()
Deprecated.java.lang.Object
getOutput()
Deprecated.get this output (SynthOutput in the case of a JSyn Instrument, for examplejava.lang.Object
getOutput(int part)
Deprecated.same as getOutput(), only one outputdouble[]
getPitches()
Deprecated.java.lang.String
getSampleFilename(int pitch)
Deprecated.java.util.Hashtable
getSynthSamples()
Deprecated.Tuning
getTuning()
Deprecated.java.util.Hashtable
getVoices()
Deprecated.voices is a hashtable whose keys are synthnotes returned by allocator.steal() ( called in on() method), and whose values are the pitch which they were used to bang.boolean
handleSpecialTag(java.lang.String tag, java.util.Hashtable attributes)
Deprecated.HandleSpecialXMLTag interface.static void
main(java.lang.String[] args)
Deprecated.void
notifyEditListeners()
Deprecated.java.lang.Object
off(double playTime, double timeStretch, double[] dar)
Deprecated.Turn off all voices that are playing the sample associated with pitchIndex dar[1].java.lang.Object
on(double playTime, double timeStretch, double[] dar)
Deprecated.Look up sample assiciated with dar[1].double
open(double time)
Deprecated.double
play(double playTime, double timeStretch, double[] dar)
Deprecated.If there is a sample loaded at dar[1], bang it.void
reload()
Deprecated.void
removeEditListener(EditListener listener)
Deprecated.void
setDirectory(java.io.File dir)
Deprecated.void
setEditEnabled(boolean flag)
Deprecated.noopvoid
setNumChannels(int i)
Deprecated.void
setTuning(Tuning tuning)
Deprecated.void
testSampleDirectory()
Deprecated.void
writeSpecialXMLTags(java.io.PrintWriter out)
Deprecated.write pitch / soundfilename pairs to XML file These are not covered by simple bean model since there are many such pairs.Methods inherited from class com.softsynth.jmsl.InstrumentAdapter
getDimensionNameSpace, getInterpreter, getMixerClassName, getMusicDevice, getName, getTransposition, noteOff, noteOn, noteOnFor, setDimensionNameSpace, setInterpreter, setMixerClassName, setMusicDevice, setName, setTransposition, toString, update
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
POLYPHONY
public int POLYPHONYDeprecated.max number of voices to allocate, default 32. You may this change before creating new instances of this class and its subclasses
-
-
Constructor Details
-
SimpleSamplePlayingInstrument
public SimpleSamplePlayingInstrument()Deprecated. -
SimpleSamplePlayingInstrument
public SimpleSamplePlayingInstrument(java.lang.String sampleDirectory)Deprecated.Sample directory string must end in file separator, ex "F:\samples\" All samples will be sought in this directory. They can be in subfolders, but all must be relative to this dir.
-
-
Method Details
-
clear
public void clear()Deprecated.remove all samples and pitch mappings -
open
public double open(double time) throws java.lang.InterruptedExceptionDeprecated.- Specified by:
open
in interfaceInstrument
- Overrides:
open
in classInstrumentAdapter
- Throws:
java.lang.InterruptedException
-
close
public double close(double time) throws java.lang.InterruptedExceptionDeprecated.- Specified by:
close
in interfaceInstrument
- Overrides:
close
in classInstrumentAdapter
- Throws:
java.lang.InterruptedException
-
setDirectory
public void setDirectory(java.io.File dir)Deprecated.- Specified by:
setDirectory
in interfaceDirectorySettable
-
getDirectory
public java.io.File getDirectory()Deprecated.- Specified by:
getDirectory
in interfaceDirectorySettable
-
testSampleDirectory
public void testSampleDirectory()Deprecated. -
reload
public void reload()Deprecated. -
getOutput
public java.lang.Object getOutput()Deprecated.Description copied from interface:OutputProvider
get this output (SynthOutput in the case of a JSyn Instrument, for example- Specified by:
getOutput
in interfaceOutputProvider
- Overrides:
getOutput
in classInstrumentAdapter
- Returns:
- null
-
getOutput
public java.lang.Object getOutput(int part)Deprecated.same as getOutput(), only one output- Specified by:
getOutput
in interfaceOutputProvider
- Overrides:
getOutput
in classInstrumentAdapter
- Returns:
- null
-
getNumOutputs
public int getNumOutputs()Deprecated.- Specified by:
getNumOutputs
in interfaceOutputProvider
- Overrides:
getNumOutputs
in classInstrumentAdapter
- Returns:
- 1 or 2
-
addSamplePitch
public void addSamplePitch(java.lang.String filename, int pitch)Deprecated.Assign a sample to be triggered when noteIndex is passed to play().
For example, let's say all your samples are in C:\mysamples\
You pass "C:\mysamples\" to the constructor.
Let's say C:\mysamples\ contains a directory called DrumMachine which contains snare.wav
Then you would call addSamplePitch() with "DrumMachine/snare.wav" since that is its location relative to C:\mysamples\ The recommended way to subclass this instrument is to override buildFromAttributes, making multiple calls to addSamplePitch() first, finally calling super.buildFromAttributes() -
addSamplePitch
public void addSamplePitch(com.softsynth.jsyn.SynthSample sample, int pitch)Deprecated.Assign a dynamically created sample to a note index. If you do this you will not be able to save/reload. You are committed to runtime building -
addSamplePitch
public void addSamplePitch(short[] shorts, int pitch)Deprecated.Assign a dynamically created sample to a note index. If you do this you will not be able to save/reload from file. You are committed to runtime building -
getSampleFilename
public java.lang.String getSampleFilename(int pitch)Deprecated. -
getSynthSamples
public java.util.Hashtable getSynthSamples()Deprecated.- Returns:
- hashtable of (Integer) pitchindex keys and SynthSample values
-
getPitches
public double[] getPitches()Deprecated.- Returns:
- array of pitches which have been assigned to a sample
-
getAlternativeSampleIndex
public int getAlternativeSampleIndex(int pitchIndex, double timeStretch, double[] data)Deprecated.Precondition: pitchIndex points to a valid sample, previously loaded with addSamplePitch(). Override this method to point to a different valid sample index. For example, you might store a loud sample at pitchIndex 60 and quiet sample at index 200 (ie some pitch index you'd never bang directly), and if the amplitude of data[] lessthan 0.3 return 200 for this pitchIndex, else return 60)- Returns:
- valid index to use instead of pitchIndex. This default version returns incoming pitchIndex
-
on
public java.lang.Object on(double playTime, double timeStretch, double[] dar)Deprecated.Look up sample assiciated with dar[1]. Allocate a FixedRateSampleReader to play it. dar[3] is not used to cut sample short if the value is less than duration of sample. This instrument imsply queues up a sample and lets it run. Use off() to terminate early.- Specified by:
on
in interfaceInstrument
- Overrides:
on
in classInstrumentAdapter
- Returns:
- the allocated FixedRateSampleReader or null of there is no sample associated with dar[1]
- See Also:
Instrument.on(double, double, double[])
-
play
public double play(double playTime, double timeStretch, double[] dar)Deprecated.If there is a sample loaded at dar[1], bang it. No sustain, no transposition. Hold time is not used to terminate sample early.- Specified by:
play
in interfaceInstrument
- Overrides:
play
in classInstrumentAdapter
-
off
public java.lang.Object off(double playTime, double timeStretch, double[] dar)Deprecated.Turn off all voices that are playing the sample associated with pitchIndex dar[1]. These voices are stored in a hsahtable whenever play() is called. There may be more than one voice playing the sample mapped to index 60 for example. Turning off is accomplished by queuing up the last frame of the sample, with Synth.FLAG_AUTO_STOP- Specified by:
off
in interfaceInstrument
- Overrides:
off
in classInstrumentAdapter
- Returns:
- null
- See Also:
com.softsynth.jmsl.Instrument#off(double, Object)
-
buildFromAttributes
public void buildFromAttributes()Deprecated.- Specified by:
buildFromAttributes
in interfaceAttributeBuildable
-
getTuning
Deprecated.- Returns:
- tuning stored in this instrument. Not used to perform.
-
setTuning
Deprecated.- Parameters:
tuning
- to be stored in this instrument. Not used to perform.
-
handleSpecialTag
public boolean handleSpecialTag(java.lang.String tag, java.util.Hashtable attributes)Deprecated.HandleSpecialXMLTag interface. Store pitch / soundfilename pairs for loading later- Specified by:
handleSpecialTag
in interfaceHandleSpecialXMLTag
- Returns:
- true if this tag is recognized as special, false if the object permits normal bean model to handle attribute/value pairs
- See Also:
HandleSpecialXMLTag.handleSpecialTag(java.lang.String, java.util.Hashtable)
-
writeSpecialXMLTags
public void writeSpecialXMLTags(java.io.PrintWriter out) throws java.io.IOExceptionDeprecated.write pitch / soundfilename pairs to XML file These are not covered by simple bean model since there are many such pairs.- Specified by:
writeSpecialXMLTags
in interfaceHandleSpecialXMLTag
- Throws:
java.io.IOException
- See Also:
HandleSpecialXMLTag.writeSpecialXMLTags(java.io.PrintWriter)
-
notifyEditListeners
public void notifyEditListeners()Deprecated. -
addEditListener
Deprecated.- Specified by:
addEditListener
in interfaceEditable
-
removeEditListener
Deprecated.- Specified by:
removeEditListener
in interfaceEditable
-
edit
public void edit(java.awt.Frame fr)Deprecated.Open a Frame containing a SampleInstrumentMapperPanel for this instrument.- Specified by:
edit
in interfaceEditable
- See Also:
Editable.edit(java.awt.Frame)
-
setEditEnabled
public void setEditEnabled(boolean flag)Deprecated.noop- Specified by:
setEditEnabled
in interfaceEditable
- See Also:
Editable.setEditEnabled(boolean)
-
getEditEnabled
public boolean getEditEnabled()Deprecated.- Specified by:
getEditEnabled
in interfaceEditable
- Returns:
- true
-
main
public static void main(java.lang.String[] args)Deprecated. -
getNumChannels
public int getNumChannels()Deprecated.- Returns:
-
setNumChannels
public void setNumChannels(int i)Deprecated.- Parameters:
i
-
-
getVoices
public java.util.Hashtable getVoices()Deprecated.voices is a hashtable whose keys are synthnotes returned by allocator.steal() ( called in on() method), and whose values are the pitch which they were used to bang. This is used to retrieve the synthnote in off() and turn it off- Returns:
- Returns the voices.
-