Package com.softsynth.jmsl.midi
Class MidiInstrument
java.lang.Object
com.softsynth.jmsl.InstrumentAdapter
com.softsynth.jmsl.midi.MidiInstrument
- All Implemented Interfaces:
Instrument
,Namable
,NoteOnOff
,OutputProvider
,Transposable
- Direct Known Subclasses:
MidiScoreInstrument
,PitchBendInstrument
public class MidiInstrument extends InstrumentAdapter implements NoteOnOff
An Instrument that outputs MIDI. The default Interpreter for a MidiInstrument
is a NoteInterpreter. The default Mixer classname is
"com.softsynth.jmsl.midi.MidiMixer"
- Author:
- Phil Burk and Nick Didkovsky
-
Constructor Summary
Constructors Constructor Description MidiInstrument()
Default constructor with channel set to 1MidiInstrument(int ch)
construct a Midi Instrument that uses specified channelMidiInstrument(int ch, int program)
construct a Midi Instrument that uses specified channel and send specified programChange when it is open()'ed -
Method Summary
Modifier and Type Method Description static void
clearMIDIProgramChangeTracker()
resets program changes stored in tracker.double
close(double playTime)
int
getChannel()
MusicDevice
getMusicDevice()
Get the MusicDevice associated with this Instrumentint
getNumOutputs()
java.lang.Object
getOutput()
get this output (SynthOutput in the case of a JSyn Instrument, for examplejava.lang.Object
getOutput(int partNum)
int
getProgram()
static void
main(java.lang.String[] args)
play marimba and accordion with MusicShapes with Midi Instrumentsdouble
noteOff(double playTime, double pitch, double vel)
Turn off a MIDI note.double
noteOn(double playTime, double pitch, double vel)
Turn on a MIDI note.java.lang.Object
off(double playTime, double timeStretch, double[] dar)
Calls noteOff(playTime, dar[1], dar[2]);java.lang.Object
on(double playTime, double timeStretch, double[] dar)
calls noteOn(playTime, dar[1], dar[2]);double
open(double playTime)
void
print()
void
setChannel(int ch)
set the midi channel to be used by this instrumentvoid
setProgram(int p)
When this instrument is open()'ed, a program change will be called on the program value set here.static void
useSparseMIDIProgramChange(boolean flag)
if true, will track which program change was sent on which MIDI channel, and will only send program changes when the value is different from the last one.Methods inherited from class com.softsynth.jmsl.InstrumentAdapter
getDimensionNameSpace, getInterpreter, getMixerClassName, getName, getTransposition, noteOnFor, play, setDimensionNameSpace, setInterpreter, setMixerClassName, setMusicDevice, setName, setTransposition, toString, update
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
MidiInstrument
public MidiInstrument()Default constructor with channel set to 1 -
MidiInstrument
public MidiInstrument(int ch)construct a Midi Instrument that uses specified channel -
MidiInstrument
public MidiInstrument(int ch, int program)construct a Midi Instrument that uses specified channel and send specified programChange when it is open()'ed
-
-
Method Details
-
open
public double open(double playTime) throws java.lang.InterruptedException- Specified by:
open
in interfaceInstrument
- Overrides:
open
in classInstrumentAdapter
- Throws:
java.lang.InterruptedException
-
useSparseMIDIProgramChange
public static void useSparseMIDIProgramChange(boolean flag)if true, will track which program change was sent on which MIDI channel, and will only send program changes when the value is different from the last one. Else sends program change every MIDIInsrument.open()- Parameters:
flag
-
-
clearMIDIProgramChangeTracker
public static void clearMIDIProgramChangeTracker()resets program changes stored in tracker. this is used when useSparseMIDIProgramChange is true. Each MIDI channel stores the program change it sent last, and will not resend it in ins.open(). Call this before every time you launch() your piece. -
setProgram
public void setProgram(int p)When this instrument is open()'ed, a program change will be called on the program value set here. To ignore, setProgram(-1) which is the default Recall the instruments are open()'ed automatically when a MusicShape launches Other situations may call for an explicit call to open() -
getProgram
public int getProgram() -
close
public double close(double playTime) throws java.lang.InterruptedException- Specified by:
close
in interfaceInstrument
- Overrides:
close
in classInstrumentAdapter
- Throws:
java.lang.InterruptedException
-
getOutput
public java.lang.Object getOutput()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:
- this Instrument in case you need some reference to it. Otherwise getOutput() is not meaningful for MidiInstrument.
-
getOutput
public java.lang.Object getOutput(int partNum)- Specified by:
getOutput
in interfaceOutputProvider
- Overrides:
getOutput
in classInstrumentAdapter
- Returns:
- null
-
getNumOutputs
public int getNumOutputs()- Specified by:
getNumOutputs
in interfaceOutputProvider
- Overrides:
getNumOutputs
in classInstrumentAdapter
- Returns:
- 1 so Mixer will create a fader for it.
-
getMusicDevice
Description copied from interface:Instrument
Get the MusicDevice associated with this Instrument- Specified by:
getMusicDevice
in interfaceInstrument
- Overrides:
getMusicDevice
in classInstrumentAdapter
-
getChannel
public int getChannel()- Returns:
- midi channel
-
setChannel
public void setChannel(int ch)set the midi channel to be used by this instrument -
on
public java.lang.Object on(double playTime, double timeStretch, double[] dar)calls noteOn(playTime, dar[1], dar[2]);- Specified by:
on
in interfaceInstrument
- Overrides:
on
in classInstrumentAdapter
- Returns:
- null
- See Also:
Instrument.on(double, double, double[])
-
off
public java.lang.Object off(double playTime, double timeStretch, double[] dar)Calls noteOff(playTime, dar[1], dar[2]);- Specified by:
off
in interfaceInstrument
- Overrides:
off
in classInstrumentAdapter
- Returns:
- null
- See Also:
com.softsynth.jmsl.Instrument#off(double, Object)
-
noteOn
public double noteOn(double playTime, double pitch, double vel)Turn on a MIDI note.- Specified by:
noteOn
in interfaceNoteOnOff
- Overrides:
noteOn
in classInstrumentAdapter
-
noteOff
public double noteOff(double playTime, double pitch, double vel)Turn off a MIDI note.- Specified by:
noteOff
in interfaceNoteOnOff
- Overrides:
noteOff
in classInstrumentAdapter
-
print
public void print() -
main
public static void main(java.lang.String[] args)play marimba and accordion with MusicShapes with Midi Instrumentspublic static void main(String args[]) { System.out.println("Java version: " + System.getProperty("java.version")); JMSL.setViewFactory(new ViewFactorySwing()); PVFrame f = new PVFrameAdapter("close to exit"); f.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { JMSL.closeMusicDevices(); System.exit(0); } }); JMSL.midi = MidiIO_JavaSound.instance(); JMSL.midi.edit((Frame) f.getComponent()); JMSL.midi.open(); MidiInstrument m1 = new MidiInstrument(1, 13); // set up instrument on // channel 1, program 13 m1.setName("Marimba"); m1.print(); MusicShape s = new MusicShape(4); s.add(1.0, 84, 64, 1.0); s.add(1.0, 52, 64, 1.5); s.add(1.0, 74, 64, 0.8); s.add(1.0, 46, 80, 0.8); s.setInstrument(m1); s.setRepeats(100); s.setTimeStretch(0.5); MidiInstrument m2 = new MidiInstrument(2, 22); // set up instrument on // channel 2, program 22 m2.setName("Accordion"); MusicShape s2 = new MusicShape(4); s2.add(0.0, 86, 64, 2.0); s2.add(0.0, 40, 64, 1.5); s2.add(1.0, 72, 64, 0.8); s2.add(1.0, 44, 80, 0.8); s2.setInstrument(m2); s2.setRepeats(50); s2.setTimeStretch(2.2); JMSLMixerContainer mixer = new JMSLMixerContainer(); mixer.start(); mixer.addInstrument(m1, 0, 0.5); mixer.addInstrument(m2, 1, 0.5); f.add(mixer.getPanAmpControlPanel()); f.pack(); f.setVisible(true); ParallelCollection p = new ParallelCollection(s, s2); double when = JMSL.now() + 1; p.launch(when); }
-