Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中访问MIDI设备_Java_Midi - Fatal编程技术网

在Java中访问MIDI设备

在Java中访问MIDI设备,java,midi,Java,Midi,我目前正在尝试将我的钢琴midiport连接到我的电脑。 我已经读了所有我能找到的关于这个的东西,但不知怎么的,我遗漏了一些东西,所以我希望这里的人能帮助我。我已经试着这样做了一个星期了,现在真的很沮丧 public class MidiDeviceGetter { public MidiDeviceGetter() {} public static void listTransmitterDevices() throws MidiUnavailableException {

我目前正在尝试将我的钢琴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"));
   }
}
公共类MidiDeviceGetter{
公共MidiDeviceGetter(){}
public static void listTransmitterDevices()引发MidiUnavailableException{
MidiDevice.Info[]infos=MidiSystem.getMidiDeviceInfo();
for(int i=0;i
嗯,到目前为止我已经知道了。我只是想把钢琴连接起来,这样我就可以走得更远,但正如我所说的,我无法让它工作

为了进行测试,我从

非常感谢您的帮助,谢谢

另外,对不起,我的英语不是以英语为母语的

编辑1:根据评论:

我希望当我按下一个键时,程序会在控制台中打印一些东西 System.in()正在运行,因为在接收方的send(Midimessage,long)方法中,最后一行是Prinstream.print(midimsg)。我是对的,我认为如果在接收器连接的发射器上播放音符,总是调用接收器接口类的send方法,不是吗? 如果那样不行的话,我可以找到答案,但是还有一些接收者的membervariables应该保存被点击的键的数量,但是这些membervariables总是空的。所以我这里的主要问题是,从未调用send方法。 我希望我能弄清楚我的主要问题是什么


Edit2:如果你对“java中的midi编程”感兴趣,并且没有发现任何重大错误,那么请告诉我。我刚刚发现我在斯坦伯格立方体中也不能得到任何MIDI信号。也许这一次,问题不在屏幕前。

好的,我已经解决了。我发布的代码完全正确且有效。问题是,我的usb MIDI接口的MIDI输入插头属于我钢琴的MIDI输出插头。我想我要把头撞在墙上几个小时了

感谢阅读。

“我无法让它工作”可能是罢工,或是困倦,或是纯粹的懒惰。首先,谈判。第二,好好休息一晚上,早上再试试。第三,尝试胡萝卜加大棒的方法。对于其他内容,请尝试描述1)您期望发生的事情2)实际发生的事情,以及实用工具3)您期望(1)发生的原因。此外,为了更快地获得更好的帮助,请发布一个。