本文整理汇总了Java中javax.sound.midi.Sequencer类的典型用法代码示例。如果您正苦于以下问题:Java Sequencer类的具体用法?Java Sequencer怎么用?Java Sequencer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sequencer类属于javax.sound.midi包,在下文中一共展示了Sequencer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultProvider
import javax.sound.midi.Sequencer; //导入依赖的package包/类
/** Obtain the value of a default provider property.
@param typeClass The type of the default provider property. This
should be one of Receiver.class, Transmitter.class, Sequencer.class,
Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
Clip.class or Port.class.
@return The complete value of the property, if available.
If the property is not set, null is returned.
*/
private static synchronized String getDefaultProvider(Class typeClass) {
if (!SourceDataLine.class.equals(typeClass)
&& !TargetDataLine.class.equals(typeClass)
&& !Clip.class.equals(typeClass)
&& !Port.class.equals(typeClass)
&& !Receiver.class.equals(typeClass)
&& !Transmitter.class.equals(typeClass)
&& !Synthesizer.class.equals(typeClass)
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String name = typeClass.getName();
String value = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> System.getProperty(name));
if (value == null) {
value = getProperties().getProperty(name);
}
if ("".equals(value)) {
value = null;
}
return value;
}
示例2: play
import javax.sound.midi.Sequencer; //导入依赖的package包/类
public void play() {
if (isPlaying) { // 如果已经在播放,返回
return;
}
try {
sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.setSequence(sequence);
sequencer.setLoopCount(Sequencer.LOOP_CONTINUOUSLY );
sequencer.addMetaEventListener(this);
} catch (InvalidMidiDataException ex) {
} catch (MidiUnavailableException e) {
}
thread = new Thread(this);
thread.start();
}
示例3: test
import javax.sound.midi.Sequencer; //导入依赖的package包/类
static boolean test(Sequencer sequencer) throws MidiUnavailableException {
log("");
log("opening sequencer...");
sequencer.open(); // opens connected synthesizer implicitly
MidiDevice synth = getConnectedDevice(sequencer);
log(" connected device: " + getDeviceStr(synth));
log("closing sequencer...");
sequencer.close(); // closes the synth implicitly
log(" synth is " + getDeviceStr(synth));
MidiDevice synth2 = getConnectedDevice(sequencer);
log(" currently connected device: " + getDeviceStr(synth2));
if (synth != null && synth.isOpen()) {
log("FAIL.");
return false;
}
log("OK.");
return true;
}
示例4: getConnectedDevice
import javax.sound.midi.Sequencer; //导入依赖的package包/类
static MidiDevice getConnectedDevice(Sequencer sequencer) {
List<Transmitter> trans = sequencer.getTransmitters();
log(" sequencer has " + trans.size() + " opened transmitters:");
for (Transmitter tr: trans) {
Receiver r = tr.getReceiver();
log(" " + getClassStr(tr) + " connected to " + getClassStr(r));
if (r instanceof MidiDeviceReceiver) {
MidiDeviceReceiver recv = (MidiDeviceReceiver)r;
MidiDevice dev = recv.getMidiDevice();
log(" - receiver of " + getClassStr(dev));
return dev;
} else {
log(" - does NOT implement MidiDeviceReceiver");
}
}
return null;
}
示例5: getDefaultProvider
import javax.sound.midi.Sequencer; //导入依赖的package包/类
/** Obtain the value of a default provider property.
@param typeClass The type of the default provider property. This
should be one of Receiver.class, Transmitter.class, Sequencer.class,
Synthesizer.class, SourceDataLine.class, TargetDataLine.class,
Clip.class or Port.class.
@return The complete value of the property, if available.
If the property is not set, null is returned.
*/
private static synchronized String getDefaultProvider(Class<?> typeClass) {
if (!SourceDataLine.class.equals(typeClass)
&& !TargetDataLine.class.equals(typeClass)
&& !Clip.class.equals(typeClass)
&& !Port.class.equals(typeClass)
&& !Receiver.class.equals(typeClass)
&& !Transmitter.class.equals(typeClass)
&& !Synthesizer.class.equals(typeClass)
&& !Sequencer.class.equals(typeClass)) {
return null;
}
String name = typeClass.getName();
String value = AccessController.doPrivileged(
(PrivilegedAction<String>) () -> System.getProperty(name));
if (value == null) {
value = getProperties().getProperty(name);
}
if ("".equals(value)) {
value = null;
}
return value;
}
示例6: doTest
import javax.sound.midi.Sequencer; //导入依赖的package包/类
public static void doTest(Sequencer seq) throws Exception {
seq.setTempoInMPQ(3.0f);
System.out.println("Setting tempo in MPQ to "+3.0f);
if (!equalsFloat(seq.getTempoInMPQ(), 3.0f)) {
System.err.println("getTempoInMPQ() returns wrong value : "
+ seq.getTempoInMPQ());
failed = true;
}
System.out.println("Setting tempo factor to "+2.0f);
seq.setTempoFactor(2.0f);
if (!equalsFloat(seq.getTempoFactor(), 2.0f)) {
System.err.println("getTempoFactor() returns: " + seq.getTempoFactor());
failed = true;
}
float bpmTempo = 120.0f;
System.out.println("Setting tempo to "+120.0f+"bpm");
seq.setTempoInBPM(bpmTempo);
if (!equalsFloat(seq.getTempoInMPQ(), (60000000.0f/seq.getTempoInBPM()))) {
System.err.println("getTempoInMPQ() returns: " + seq.getTempoInMPQ());
System.err.println("getTempoInBPM() returns: " + seq.getTempoInBPM());
failed = true;
}
}
示例7: main
import javax.sound.midi.Sequencer; //导入依赖的package包/类
public static void main(String argv[]) {
Sequencer seq = null;
try {
seq = MidiSystem.getSequencer();
seq.open();
} catch (final MidiUnavailableException ignored) {
// the test is not applicable
return;
}
try {
seq.startRecording();
System.out.println("Test passed.");
} catch (NullPointerException npe) {
System.out.println("Caught NPE: "+npe);
npe.printStackTrace();
throw new RuntimeException("Test FAILED!");
} catch (Exception e) {
System.out.println("Unexpected Exception: "+e);
e.printStackTrace();
System.out.println("Test NOT failed.");
} finally {
seq.close();
}
}
示例8: isMidiInstalled
import javax.sound.midi.Sequencer; //导入依赖的package包/类
/**
* Returns true if at least one MIDI (port) device is correctly installed on
* the system.
*/
public static boolean isMidiInstalled() {
boolean result = false;
MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < devices.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
} catch (Exception e1) {
System.err.println(e1);
}
if (result)
break;
}
return result;
}
示例9: isMidiInstalled
import javax.sound.midi.Sequencer; //导入依赖的package包/类
/**
* Returns true if at least one MIDI (port) device is correctly installed on
* the system.
*/
private static boolean isMidiInstalled() {
boolean result = false;
MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < devices.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
result = !(device instanceof Sequencer)
&& !(device instanceof Synthesizer);
} catch (Exception e1) {
System.err.println(e1);
}
if (result)
break;
}
return result;
}
示例10: doAll
import javax.sound.midi.Sequencer; //导入依赖的package包/类
private static void doAll() throws Exception {
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for (int i=0; i < infos.length; i++) {
MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
if ((! (device instanceof Sequencer)) &&
(! (device instanceof Synthesizer)) &&
(device.getMaxReceivers() > 0 || device.getMaxReceivers() == -1)) {
System.out.println("--------------");
System.out.println("Testing MIDI device: " + infos[i]);
testDevice(device);
}
if (infos.length==0) {
System.out.println("No MIDI devices available!");
}
}
}
示例11: isMidiInstalled
import javax.sound.midi.Sequencer; //导入依赖的package包/类
/**
* Returns true if at least one MIDI (port) device is correctly installed on
* the system.
*/
public static boolean isMidiInstalled() {
boolean result = false;
MidiDevice.Info[] devices = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < devices.length; i++) {
try {
MidiDevice device = MidiSystem.getMidiDevice(devices[i]);
result = ! (device instanceof Sequencer) && ! (device instanceof Synthesizer);
} catch (Exception e1) {
System.err.println(e1);
}
if (result)
break;
}
if (!result) {
System.err.println("Soundcard does not exist or sound drivers not installed!");
System.err.println("This test requires sound drivers for execution.");
}
return result;
}
示例12: getDevice
import javax.sound.midi.Sequencer; //导入依赖的package包/类
public static MidiDevice getDevice(String inDeviceName) throws MiException
{
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for(int i = 0; i < infos.length; i++)
{
if(infos[i].getName().equals(inDeviceName))
{
try {
MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
if( device.getMaxTransmitters() == 0 ||
device instanceof Sequencer)
continue;
return(device);
}
catch(MidiUnavailableException mue)
{
throw new MiException(TuxGuitar.getProperty("midiinput.error.midi.unavailable"), mue);
}
}
}
return(null);
}
示例13: DesktopMidiPlayer
import javax.sound.midi.Sequencer; //导入依赖的package包/类
public DesktopMidiPlayer() throws MidiUnavailableException, IOException, InvalidMidiDataException {
// Obtains the default Sequencer connected to a default device.
Sequencer sequencer = MidiSystem.getSequencer();
// Opens the device, indicating that it should now acquire any
// system resources it requires and become operational.
sequencer.open();
// create a stream from a file
// FileHandle fh = Gdx.files.internal(Constants.MUSIC);
// InputStream is = new BufferedInputStream(new FileInputStream(fh.file()));
InputStream is = new BufferedInputStream(new FileInputStream(new File(Constants.MUSIC2)));
// Sets the current sequence on which the sequencer operates.
// The stream must point to MIDI file data.
sequencer.setSequence(is);
// Starts playback of the MIDI data in the currently loaded sequence.
sequencer.start();
/*try {
this.sequencer = MidiSystem.getSequencer();
} catch (MidiUnavailableException e) {
// Log.error("Error opening midi device.", e);
}*/
}
示例14: go
import javax.sound.midi.Sequencer; //导入依赖的package包/类
public void go() {
setUpGui();
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
sequencer.addControllerEventListener(ml, new int[] {127});
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
int r = 0;
for (int i = 0; i < 60; i+=4) {
r = (int) ((Math.random() * 50) + 1);
track.add(makeEvent(144, 1, r, 100, i));
track.add(makeEvent(176, 1, 127, 0, i));
track.add(makeEvent(128, 1, r, 100, i + 2));
} // end loop
sequencer.setSequence(seq);
sequencer.start();
sequencer.setTempoInBPM(120);
} catch (Exception ex) {ex.printStackTrace();}
}
示例15: go
import javax.sound.midi.Sequencer; //导入依赖的package包/类
public void go() {
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.open();
int[] eventsIWant = {127};
sequencer.addControllerEventListener(this, eventsIWant);
Sequence seq = new Sequence(Sequence.PPQ, 4);
Track track = seq.createTrack();
for (int i = 5; i < 60; i+= 4) {
track.add(makeEvent(144, 1, i, 100, i));
track.add(makeEvent(176, 1, 127, 0, i));
track.add(makeEvent(128, 1, i, 100, i + 2));
} // end loop
sequencer.setSequence(seq);
sequencer.setTempoInBPM(220);
sequencer.start();
} catch (Exception ex) {ex.printStackTrace();}
}