How can I generate programmatically a MIDI event on iPad - ipad

I would like to test a MIDI app and want to generate some MIDI events without attaching a physical keyboard. Any hints?

If you are using CoreMidi, setup your app to use MIDINetworkSessions. Once you advertise your iPad over the network, use any MIDI sequencer etc to connect to it and send messages over WiFi.
That way you can test without constantly unplugging/replugging things, and while still tethered to Xcode which is a huge bonus.
The other option would be to create an artificial MIDIPacketList and send it directly to your handler, but this is a lot less flexible.

If you mean sending a MIDI event to an iPad, then you could use a simple program like Rondo to play a MIDI file to it.

I suppose you need some source codes to generate MIDI events on iPad.
I found this one. It is a wrapper class of CoreMIDI, and it has source codes of sending/receiving some MIDI events.
RCTMidiLib
https://github.com/recotana/RCTMidiLib
I connect iPad and Mac wirelessly, and successfully send/receive MIDI events using the test application on iPad.

Related

MIDI messages are multiplying

I keep running into a strange issue when running AKMIDI on IOS. I also think it may be an IOS problem and not necessarily from Audiokit. I can connect a MIDI controller to IPad and receive messages as expected using the MIDI listener protocol after I open the input. If I disconnect the MIDI controller by cycling the power or unplugging it from the IPad and then reconnect it, I then start receiving two identical messages at each event. If I cycle the power again I start getting three messages, etc. I should also mention that when I detect the device is removed I close the input and clear the listeners. When I detect the new connection I open the input and start over. Does anyone know what can cause this to happen?
I think I have found a workaround for this:
If I only open the midi in and midi out one time, when my device is first detected, it seems to work correctly. I now only close the in and out when the app is terminated. You can cycle the power on the midi controller and it will still communicate with the app when it reconnects. I am also now using the more generic calls openInput(), addListener(self), openOutput().

AudioKit MIDI Events - basic questions, sending to external synth, not sure about handling

I had some more time to play around with AudioKit, yet I have a few questions about MIDI. I tried googling and I also checked the AKMIDI class reference, but this just further confused me.
Let's keep it simple: I have a UIButton that should give out a "C" to an external synth.
import AudioKit
midiOut.openOutput()
midiOut.sendEvent(AKMIDIEvent(noteOn: 72, velocity: 80, channel: 1))
sleep(1)
midiOut.sendEvent(AKMIDIEvent(noteOff: 72, velocity: 0, channel: 1))
Obviously this code is spread over the entire ViewController.swift and the sendEvents are inside an #IBAction, but for the sake of keeping it simple, I merged the LOCs.
So my questions are:
Will this send out MIDI signals to external machines? (I ordered the Lightning Camera Connection Kit, but it will take a few more days to arrive, so I cannot test it yet.) I cannot get anything from the iPhone Simulator, so I take it, this is not working.
Will this send out MIDI signals over wireless MIDI as well? According to what I read on some Google group, you can have Wireless MIDI on macOS. Unfortunately I didn't find anything on if and how you can use this in AudioKit.
What about MIDI over Bluetooth? Will this all be handled by AudioKit automatically or will I have to change anything? I read something about midi.createVirtualPorts(), but I am not sure what this actually does. But the word "virtual" makes me believe this is for testing?
Sorry if these questions are ridiculously noobish, but I really am confused by the exact inner workings of this.
Thanks a lot in advance!
You can test your app with simulator as well. Just run your app on simulator and open the Audio MIDI Setup app on your Mac, go to network settings and connect your simulator. Here is a screenshot:
You have full control over AKMIDI.
* If you want to open all available outputs, just call midi.openOutput().
* If you want to open a specific one, like a network session, mostly named "Session 1", call midi.openOutput(name: "Session 1").
* You can get all available destinations by midi.destinationNames string array, if you want to prompt a midi dest picker to user, then just open them with their names.
* For closing them midi.endpoints.removeValue(forKey: "Session 1").
* And for virtual outputs, call sequencer.midi.createVirtualOutputPort(name: "App MIDI Out") which is useful to send MIDI to other apps living in your iOS/Mac.
* Also, you can subscribe to AKMIDIListener protocol's receivedMIDISetupChange function to get notified when a MIDI hardware/software available or not to connect.
Yes it should. You've opened all outputs, so everything should get the output.
I'm not sure about wireless MIDI as there's nothing specifically done with that in mind in AudioKit. If it doesn't "just work" I can try to replicate.
You might have to explicitly open the bluetooth connection with openOutput("Bluetooth")

ios midi voice like(0x90,30,127)

**I had a piano ios applications, I can use CoreMidi normally receive external MIDI controller information, but no voice. So I want to use MIDI like (0x90,30,127) bytes to make a sound, can someone answer my question? Thank you very much!!!
If you mean uses iOS device as MIDI Synthesizer (sound output from iOS device),
You needs AUGraph & AudioUnit (Look up in Xcode Help search for "Sampler Unit Presets (LoadPresetDemo)")
After you understand that some tips from me:
define your custom structure that contains AUGraph & AudioUnit.
pass your custom structure pointer as refCon in MIDIInputPortCreate or srcConnRefCon in MIDIPortConnectSource for call functions such as MusicDeviceMIDIEvent in your MIDIReadProc at that callback thread.

How to monitor outgoing MIDI messages in CoreMIDI?

Is there a way to take a device's destination endpoint and monitor what messages are being sent to it via CoreMIDI?
This here is a very good free MIDI Monitor
I have also built a MIDI Monitor with Xcode for iMac and iPhone using coreMIDI. The only problem I have is the "MIDIThruConnectionCreate" for MIDI Thru. Of corse I could send the received MIDI data packet to MIDI out, but this is not the right way.
MIDIThruConnection is for this. See MIDIThruConnection.h in CoreMIDI.framework for more details.

How to tell when your iPhone audio is being rerouted to an external device?

I would like to be notified when my iPhone's audio is being re-routed to another device , say if I connect it to an external Hi-fi system (an MFi device). Put another way, how do I detect if the audio is playing from my iPhone vs. another device when it happens?
How should I go about doing this?
Read Apple's Audio Session documentation on how to request and handle Audio Session route change notifications, and what kind of audio notifications are possible.

Resources