2012-02-29 14 views
6

Şu anda piano'm midiport'umu bilgisayarıma bağlamaya çalışıyorum. Bu konuda bulabildiğim her şeyi okudum ama bir şekilde bir şeyi özlüyorum, bu yüzden birilerinin bana yardım edebileceğini umuyorum. Bunu bir hafta boyunca yapmaya çalışıyorum ve gerçekten sinir bozucu oluyor.Java'da bir MidiDevice'e erişme

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")); 
    } 
} 

Şimdiye kadar yaptığım şey. Ben sadece piyanoyu bağlamak istedim, böylece oradan daha fazla gidebilirim, ama dediğim gibi, işe yaramayacağım.

Test için DumpReceiver sınıfını http://www.jsresources.org/examples/DumpReceiver.java.html'dan aldım.

Herhangi bir yardım için minnettar olurum, teşekkürler.

P.S .: Ve ingilizcem için üzgünüm, ben ana dili konuşmacı değilim.

Edit1: comment göre:

Ben System.in() çalışırken bir tuşa vurduğunda olduğu program, konsolda bir şey yazdırmak için bekliyoruz Alıcının send (Midimessage, uzun) çünkü yöntem son satırdır Prinstream.print (midimsg). Alıcının bağlı olduğu Vericideki bir nota çalınırsa Receiver arabirim sınıfının gönderim yönteminin her zaman çağrıldığını düşünmüyorum, değil mi? Sadece bu işe yaramazsa, bunu anlayabiliyordum, fakat aynı zamanda, alıcıdan vurulmuş anahtar sayısını kaydetmesi gereken bazı üye değişkeni de var, ancak bu üye değişkenleri her zaman boş. Bu yüzden benim asıl problemim, gönderme yönteminin hiçbir zaman çağrılmadığıdır. Umarım ana problemimin ne olduğunu açıkladım.

Edit2: Eğer bu "java midi programlaması" içine giriyorsanız ve büyük bir hata göremiyorsanız, lütfen bana söyleyin. Ben de Steinbergs Cubase'de herhangi bir Midisignals alamayacağımı öğrendim. Belki bu sefer sorun ekranın önünde değildi.

+0

* "Çalışmayı başaramıyorum" * Belki de grevde, uykulu ya da sadece düz tembel. İlk önce müzakere et. İkincisi, iyi bir gece dinlen ve sabahları dene. 3. için havuç & çubuk yaklaşımını deneyin. Başka bir şey için, şunu açıklamayı deneyin: 1) Ne olmasını beklediğinizi 2) Gerçekte ne oldu ve faydası için 3) Neden (1) olmasını beklediniz. Ayrıca, daha iyi yardım için, bir [SSCCE] (http://sscce.org/) gönderin. –

cevap

7

Tamam, anladım. Gönderdiğim kod tamamen doğru ve çalışıyor. Sorun, benim usb midi arabirimin MIDI IN Fişinin piyanonun MIDI OUT fişine ait olmasıydı. Sanırım kafamı birkaç saatliğine duvara çarptıracağım.

Okumak için teşekkürler.

İlgili konular