android / ndk-samples

Android NDK samples with Android Studio
http://developer.android.com/ndk
Apache License 2.0
10.06k stars 4.18k forks source link

MidiManager class can't find any MIDI device with an input port #979

Closed spencerparkin closed 8 months ago

spencerparkin commented 8 months ago

Hi. I can successfully find and open a MIDI device using the MidiManager API, but the only such device I can find is one with a single output port. Now, I can download and install apps on my phone that play synthesized MIDI data. If that's the case, then a MIDI device must exist that has an input port. Am I using the API wrong?

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val midiManager = this.getSystemService(Context.MIDI_SERVICE) as MidiManager
        val deviceInfoArray = midiManager.getDevices()
        for(deviceInfo in deviceInfoArray) {
            // TODO: This won't work.  We need an input port.
            if(deviceInfo.getOutputPortCount() > 0) {
                midiManager.openDevice(deviceInfo, this.listener, Handler(Looper.getMainLooper()))
                break
            }
        }

Note that my Android phone is a bit old and I must use "minSdk=29" in my gradle file. Is the problem that my phone is too old while the API is too new?

Is your API broken in this case?

Thanks, --Spencer

spencerparkin commented 8 months ago

New development (at 1:16 a.m.!)

I opened the MIDI device anyway and was able to open an input port on the device, but your API indicates that it has no input ports and only one output port.

So this really is a problem with your API. I'm not sure if you really care, but I'm convinced you guys have a bug.

Of course, it remains to be seen if I'll actually be able to write on the port, but I believe I will, because a logging app I downloaded shows activity on this MIDI device when I use a different MIDI app. The MIDI logging app also shows that this device has no input port, yet it is being used by the other app to synthesize music.

Am I going crazy? Is this a semantic mixup of the words "input" and "output"?

In any case, I'm going to bed. I hope I don't wake up tomorrow and live another day.

spencerparkin commented 8 months ago

Sorry for all the fuss. I'm finally understanding all this better. I don't think there is anything wrong with the Android API in this case. I was under the false impression that because some app could play MIDI files that there must be a built-in MIDI synth on my phone, but there probably isn't. To get music to actually play in my app, I just needed to be running another app first that could synthesize the music. My app connected to the exposed MIDI device and sent the MIDI commands, while the other app synthesized the music. Okay, now I get it. I'm an idiot.