Я сейчас пытаюсь подключить мидипорт пианино к компьютеру. Я прочитал все, что смог найти об этом, но почему-то мне что-то не хватает, поэтому я надеюсь, что кто-то здесь может мне помочь. Я пытаюсь делать это в течение недели, и это действительно меня расстраивает.
public class MidiDeviceGetter {
public MidiDeviceGetter() {}
public static void listTransmitterDevices() throws MidiUnavailableException {
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < infos.length; i++) {
MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
if (device.getMaxTransmitters() != 0)
System.out.println(device.getDeviceInfo().getName().toString()
+ " has transmitters");
}
}
// should get me my USB MIDI Interface. There are two of them but only one
// has Transmitters so the if statement should get me the one i want
public static MidiDevice getInputDevice() throws MidiUnavailableException {
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for (int i = 0; i < infos.length; i++) {
MidiDevice device = MidiSystem.getMidiDevice(infos[i]);
if (device.getMaxTransmitters() != 0
&& device.getDeviceInfo().getName().contains("USB")) {
System.out.println(device.getDeviceInfo().getName().toString()
+ " was chosen");
return device;
}
}
return null;
}
public static void main(String[] args) throws MidiUnavailableException,
IOException {
MidiDevice inputDevice;
// MidiDeviceGetter.listTransmitterDevices();
inputDevice = MidiDeviceGetter.getInputDevice();
// just to make sure that i got the right one
System.out.println(inputDevice.getDeviceInfo().getName().toString());
System.out.println(inputDevice.getMaxTransmitters());
// opening the device
System.out.println("open inputDevice: "
+ inputDevice.getDeviceInfo().toString());
inputDevice.open();
System.out.println("connect Transmitter to Receiver");
// Creating a Dumpreceiver and setting up the Midi wiring
Receiver r = new DumpReceiver(System.out);
Transmitter t = inputDevice.getTransmitter();
t.setReceiver(r);
System.out.println("connected.");
System.out.println("running...");
System.in.read();
// at this point the console should print out at least something, as the
// send method of the receiver should be called when i hit a key on my
// keyboard
System.out.println("close inputDevice: "
+ inputDevice.getDeviceInfo().toString());
inputDevice.close();
System.out.println(("Received " + ((DumpReceiver) r).seCount
+ " sysex messages with a total of "
+ ((DumpReceiver) r).seByteCount + " bytes"));
System.out.println(("Received " + ((DumpReceiver) r).smCount
+ " short messages with a total of "
+ ((DumpReceiver) r).smByteCount + " bytes"));
System.out.println(("Received a total of "
+ (((DumpReceiver) r).smByteCount +
((DumpReceiver) r).seByteCount) + " bytes"));
}
}
Что ж, это то, что у меня есть на данный момент. Я просто хотел подключить пианино, чтобы я мог пойти дальше, но, как я уже сказал, я не могу заставить его работать.
Для тестирования я взял класс DumpReceiver из http://www.jsresources.org/examples/DumpReceiver.java.html .
Буду очень признателен за любую помощь, спасибо.
P.S .: Прошу прощения за мой английский, я не носитель языка.
Edit1: Согласно комментарию:
Я ожидаю, что программа что-то напечатает в консоли, когда я нажимаю клавишу, пока System.in () работает, потому что в методе send (Midimessage, long) получателя последней строкой является Prinstream.print (midimsg). Я прав, думая, что метод send класса интерфейса Receiver всегда вызывается, если на передатчике, к которому подключен приемник, воспроизводится нота, не так ли? Если бы только это не сработало, я мог бы это понять, но есть также некоторые переменные-члены получателя, которые должны сохранять количество нажатых клавиш, но эти переменные-члены всегда равны нулю. Итак, моя основная проблема здесь в том, что метод send никогда не вызывается.Надеюсь, я ясно дал понять, в чем моя основная проблема.
Edit2: Если вы занимаетесь всем этим «midi-программированием на java» и не видите никаких серьезных ошибок, то, пожалуйста, скажите мне. Я только что узнал, что в Steinbergs Cubase я тоже не могу получить Midisignals. Возможно, на этот раз проблема была не в экране.