Java by API/javax.microedition.media.control/MIDIControl — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:15, 31 мая 2010
Содержание
MIDIControl.CONTROL_CHANGE
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.MIDIControl;
import javax.microedition.midlet.MIDlet;
public class MIDIEventsMIDlet extends MIDlet {
Display display = null;
Alert alert = new Alert("Message");
public MIDIEventsMIDlet() {
display = Display.getDisplay(this);
alert.setString("Working...");
alert.setTimeout(Alert.FOREVER);
}
public void startApp() {
display.setCurrent(alert);
try {
Player p = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
p.prefetch();
MIDIControl mControl = (MIDIControl) p
.getControl("javax.microedition.media.control.MIDIControl");
if (mControl == null)
throw new Exception("MIDIControl not available");
mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 100);
Thread.sleep(100);
mControl.shortMidiEvent(192 | 11, 14, 0);
Thread.sleep(100);
mControl.shortMidiEvent(MIDIControl.CONTROL_CHANGE | 11, 7, 50);
Thread.sleep(100);
mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 0);
} catch (Exception e) {
alert.setString(e.getMessage());
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
MIDIControl: isBankQuerySupported()
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Display;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.MIDIControl;
import javax.microedition.midlet.MIDlet;
public class MIDICapabilitiesMIDlet extends MIDlet {
public void startApp() {
try {
Player p = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
p.prefetch();
MIDIControl mControl = (MIDIControl) p
.getControl("javax.microedition.media.control.MIDIControl");
String msg = mControl.isBankQuerySupported() ? "MIDIControl is fully supported"
: "Minimum MIDIControl is provided";
Display.getDisplay(this).setCurrent(new Alert("Message", msg, null, AlertType.INFO));
} catch (Exception e) {
System.err.println(e);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
MIDIControl.NOTE_ON
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.MIDIControl;
import javax.microedition.midlet.MIDlet;
public class MIDIEventsMIDlet extends MIDlet {
Display display = null;
Alert alert = new Alert("Message");
public MIDIEventsMIDlet() {
display = Display.getDisplay(this);
alert.setString("Working...");
alert.setTimeout(Alert.FOREVER);
}
public void startApp() {
display.setCurrent(alert);
try {
Player p = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
p.prefetch();
MIDIControl mControl = (MIDIControl) p
.getControl("javax.microedition.media.control.MIDIControl");
if (mControl == null)
throw new Exception("MIDIControl not available");
mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 100);
Thread.sleep(100);
mControl.shortMidiEvent(192 | 11, 14, 0);
Thread.sleep(100);
mControl.shortMidiEvent(MIDIControl.CONTROL_CHANGE | 11, 7, 50);
Thread.sleep(100);
mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 0);
} catch (Exception e) {
alert.setString(e.getMessage());
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
MIDIControl: shortMidiEvent(int arg0, int arg1, int arg2)
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.MIDIControl;
import javax.microedition.midlet.MIDlet;
public class MIDIEventsMIDlet extends MIDlet {
Display display = null;
Alert alert = new Alert("Message");
public MIDIEventsMIDlet() {
display = Display.getDisplay(this);
alert.setString("Working...");
alert.setTimeout(Alert.FOREVER);
}
public void startApp() {
display.setCurrent(alert);
try {
Player p = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
p.prefetch();
MIDIControl mControl = (MIDIControl) p
.getControl("javax.microedition.media.control.MIDIControl");
if (mControl == null)
throw new Exception("MIDIControl not available");
mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 100);
Thread.sleep(100);
mControl.shortMidiEvent(192 | 11, 14, 0);
Thread.sleep(100);
mControl.shortMidiEvent(MIDIControl.CONTROL_CHANGE | 11, 7, 50);
Thread.sleep(100);
mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 0);
} catch (Exception e) {
alert.setString(e.getMessage());
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}