是否有新的ANDROID M MIDI

时间:2015-11-01 17:47:05

标签: java android midi

我正在尝试使用新的Android Mushroom Midi读取MIDI数据。 我正在尝试使用新的MIDI方法。

https://developer.android.com/reference/android/media/midi/package-summary.html

Android Midi有一个例子。它包含微调器,上下文,包装器,并且是复杂的方式以获得第一个理解。它有许多java程序和大约800行代码。我只想打开设备0和MIDI输出端口2。

是否有一个简单的例子只使用类m.openDevice和public void onDeviceOpened(MidiDevice device)?我正在寻找仅在main中运行的第一个示例,并生成textview输出。

这看起来很简单,因为MIDI只发送三位数据,按键向下,按键编号和影响。经过数周的尝试,似乎无法让它发挥作用。以下是我的代码的oneIDI示例。它只包含大约30行代码。这就是我想要的一切。

// get the MIDI parameters out of the MIDI transmitter


    public void midi_info() {

        MidiManager m = (MidiManager) getSystemService(MIDI_SERVICE);
        //get the system device information
        final MidiDeviceInfo[] deviceInfo = m.getDevices();

        //Your devices only have info in array poiston 0
        MidiDeviceInfo info = deviceInfo[0];


        // get the midi device port information
        int numInputs = info.getInputPortCount();
        int numOutputs = info.getOutputPortCount();

        // test for a connection
        if (numOutputs < 1) {
            //out put no prot found
            TextView textout = null;
            textout = (TextView) findViewById(R.id.log);
            textout.setTextColor(Color.RED);
            textout.setText("     Midi Port Disconnected");
            //send the device info to a test box
        } else {
            TextView textout = null;
            textout = (TextView) findViewById(R.id.log);
            textout.setTextColor(Color.BLUE);
            textout.setText(String.format(" Midi Input Port Number   =  %d  of %d \n" +
                    " Midi Output Port Number = %d  of %d\n" +
                    " \n" +
                    " %s", MidiDeviceInfo.PortInfo.TYPE_INPUT, numInputs, MidiDeviceInfo.PortInfo.TYPE_OUTPUT, numOutputs, deviceInfo[0].toString()));


        }

    }

    //method open_device opens midi device
    public void open_device() {


        //Call Midimanager within the onCreate method
        MidiManager m = (MidiManager) getSystemService(MIDI_SERVICE);


        MidiDeviceInfo[] info = m.getDevices();
        final MidiDeviceInfo info0 = info[0];

        //Open an instance of the class openDevice

        Bundle properties = info0.getProperties();
        final String name = properties.getString(MidiDeviceInfo.PROPERTY_NAME);
        final String deviceusb = properties.getString(MidiDeviceInfo.PROPERTY_USB_DEVICE);

        m.openDevice(info0, new OnDeviceOpenedListener() {


            @Override


            public void onDeviceOpened(MidiDevice device) {



                if (name.equals("AndroidMidiScope0")) {
                    TextView textout = null;
                    textout = (TextView) findViewById(R.id.log);
                    textout.setTextColor(Color.RED);
                    textout.setText("Device failed to open");
                } else {


                    TextView textout = null;
                    textout = (TextView) findViewById(R.id.log);
                    textout.setTextColor(Color.BLUE);
                    textout.setText(String.format("Device opened  = %s", device));
                    int portNumber = 2;
                    MidiOutputPort OutputPort = device.openOutputPort(portNumber);




                }


            }


        }, new Handler(Looper.getMainLooper()));
    }

    }


public class MyReceiver extends MidiReceiver {


    MidiDevice device =null;
    public void onSend(byte[] data, int offset, int count, long timestamp) throws IOException {
        TextView textout = null;
        textout = (TextView) textout.findViewById(R.id.log);
        textout.setTextColor(Color.RED);
        textout.setText(String.format("Midi Keydown detected  data =%s", data[0]));

    }




}

0 个答案:

没有答案