use of javax.sound.midi.ShortMessage in project jdk8u_jdk by JetBrains.
the class GetReceiver2 method main.
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
Receiver recv = synth.getReceiver();
assertTrue(recv != null);
ShortMessage sm = new ShortMessage();
sm.setMessage(ShortMessage.NOTE_OFF, 0, 64, 64);
synth.open(new DummySourceDataLine(), null);
recv.send(sm, -1);
synth.close();
try {
recv.send(sm, -1);
throw new RuntimeException("Exception not thrown!");
} catch (Exception e) {
// Just checking if exception is thrown
}
}
use of javax.sound.midi.ShortMessage in project jdk8u_jdk by JetBrains.
the class EventDispatcher method processEvent.
/**
* Invoked when there is at least one event in the queue.
* Implement this as a callback to process one event.
*/
void processEvent(EventInfo eventInfo) {
int count = eventInfo.getListenerCount();
// process an LineEvent
if (eventInfo.getEvent() instanceof LineEvent) {
LineEvent event = (LineEvent) eventInfo.getEvent();
if (Printer.debug)
Printer.debug("Sending " + event + " to " + count + " listeners");
for (int i = 0; i < count; i++) {
try {
((LineListener) eventInfo.getListener(i)).update(event);
} catch (Throwable t) {
if (Printer.err)
t.printStackTrace();
}
}
return;
}
// process a MetaMessage
if (eventInfo.getEvent() instanceof MetaMessage) {
MetaMessage event = (MetaMessage) eventInfo.getEvent();
for (int i = 0; i < count; i++) {
try {
((MetaEventListener) eventInfo.getListener(i)).meta(event);
} catch (Throwable t) {
if (Printer.err)
t.printStackTrace();
}
}
return;
}
// process a Controller or Mode Event
if (eventInfo.getEvent() instanceof ShortMessage) {
ShortMessage event = (ShortMessage) eventInfo.getEvent();
int status = event.getStatus();
// c is the channel they are sent on.
if ((status & 0xF0) == 0xB0) {
for (int i = 0; i < count; i++) {
try {
((ControllerEventListener) eventInfo.getListener(i)).controlChange(event);
} catch (Throwable t) {
if (Printer.err)
t.printStackTrace();
}
}
}
return;
}
Printer.err("Unknown event type: " + eventInfo.getEvent());
}
use of javax.sound.midi.ShortMessage in project blue by kunstmusik.
the class MidiImportUtilities method getMidiImportSettings.
private static MidiImportSettings getMidiImportSettings(Track[] tracks) {
MidiImportSettings settings = new MidiImportSettings();
for (int i = 0; i < tracks.length; i++) {
Track track = tracks[i];
boolean containsNotes = false;
for (int j = 0; j < track.size(); j++) {
MidiEvent me = track.get(j);
MidiMessage message = me.getMessage();
if (message instanceof ShortMessage) {
ShortMessage shortMsg = (ShortMessage) message;
int velocity;
MNote n;
switch(shortMsg.getCommand()) {
case ShortMessage.NOTE_ON:
velocity = shortMsg.getData2();
if (velocity == 0) {
containsNotes = true;
}
break;
case ShortMessage.NOTE_OFF:
containsNotes = true;
break;
}
if (containsNotes) {
break;
}
}
}
if (containsNotes) {
TrackImportSettings trSettings = new TrackImportSettings();
String instrId = Integer.toString(i);
trSettings.setInstrId(instrId);
trSettings.setTrackNumber(i);
trSettings.setNoteTemplate(NOTE_TEMPLATE);
settings.addTrackImportSetting(trSettings);
}
}
return settings;
}
use of javax.sound.midi.ShortMessage in project blue by kunstmusik.
the class VirtualKeyboardPanel method handleKey.
protected void handleKey(char key, boolean keyDown) {
int index = -1;
switch(key) {
case 'z':
index = 0;
break;
case 's':
index = 1;
break;
case 'x':
index = 2;
break;
case 'd':
index = 3;
break;
case 'c':
index = 4;
break;
case 'v':
index = 5;
break;
case 'g':
index = 6;
break;
case 'b':
index = 7;
break;
case 'h':
index = 8;
break;
case 'n':
index = 9;
break;
case 'j':
index = 10;
break;
case 'm':
index = 11;
break;
case 'q':
index = 12;
break;
case '2':
index = 13;
break;
case 'w':
index = 14;
break;
case '3':
index = 15;
break;
case 'e':
index = 16;
break;
case 'r':
index = 17;
break;
case '5':
index = 18;
break;
case 't':
index = 19;
break;
case '6':
index = 20;
break;
case 'y':
index = 21;
break;
case '7':
index = 22;
break;
case 'u':
index = 23;
break;
case 'i':
index = 24;
break;
case '9':
index = 25;
break;
case 'o':
index = 26;
break;
case '0':
index = 27;
break;
case 'p':
index = 28;
break;
default:
return;
}
if (index < 0) {
return;
}
index = ((octave * 12) + index) - 21;
if (index < 0 || index > 87) {
return;
}
if (keyStates[index].get() != keyDown) {
keyStates[index].set(keyDown);
try {
ShortMessage sme = new ShortMessage();
int state = keyDown ? ShortMessage.NOTE_ON : ShortMessage.NOTE_OFF;
sme.setMessage(state, channel, index + KEY_OFFSET, velocity);
midiEngine.send(sme, 0L);
} catch (InvalidMidiDataException ex) {
Exceptions.printStackTrace(ex);
}
repaint();
}
}
use of javax.sound.midi.ShortMessage in project blue by kunstmusik.
the class VirtualKeyboardPanel method allNotesOff.
public void allNotesOff() {
ShortMessage sme = new ShortMessage();
for (int i = 0; i < 88; i++) {
if (keyStates[i].getAndSet(false)) {
try {
sme.setMessage(ShortMessage.NOTE_OFF, channel, i + KEY_OFFSET, velocity);
midiEngine.send(sme, 0L);
} catch (InvalidMidiDataException ex) {
Exceptions.printStackTrace(ex);
}
}
}
repaint();
}
Aggregations