Я сейчас пытаюсь подключить midiport моего пианино к компьютеру.Я прочитал все, что мог найти об этом, но почему-то мне чего-то не хватает, поэтому я надеюсь, что кто-то здесь сможет мне помочь.Я пытаюсь сделать это в течение недели, и это действительно расстраивает.
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.
Я бы очень признателен за любую помощь, спасибо.
PS: И извините за мой английский, я не являюсь носителем языка.
Edit1: Согласно комментарию:
Я ожидаю, что программа напечатает что-то в консоли, когда я нажму клавишу во время работы System.in (), потому что в методе Receiver send (Midimessage, long) последняя строка - Prinstream.print (midimsg).Я прав, полагая, что метод send класса интерфейса Receiver всегда вызывается, если на передатчике, к которому подключен приемник, воспроизводится нота, не так ли?Если бы только это не сработало, я мог бы это выяснить, но есть также некоторые переменные-члены получателя, которые должны сохранять количество нажатых клавиш, но эти переменные-члены всегда равны нулю.Поэтому моя главная проблема в том, что метод send никогда не вызывается.Надеюсь, я ясно дал понять, в чем заключается моя основная проблема.
Edit2: Если вы увлечены всем этим «миди-программированием на Java» и не видите каких-либо серьезных ошибок, то, пожалуйста, сообщите мне.Я только что узнал, что я не могу получить Midisignals в Steinbergs Cubase.Возможно, на этот раз проблема была не перед экраном.