# iOS Core MIDI support

**URL:** <https://forum.juce.com/t/ios-core-midi-support/7205>\
**Category:** MacOSX and iOS\
**Created:** [July 25, 2011, 5:00pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205 "2011-07-25T17:00:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [July 25, 2011, 5:00pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/1 "2011-07-25T17:00:12Z")

</div>

Hi Jules,

Is CoreMIDI supported by Juce on the iOS platform ?

I just checked the Juce Demo in the simulator and it does not receive any MIDI input.  
Maybe I am missing though: Not working in the simulator without tricks but works on the device.

Thanks,

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 25, 2011, 5:02pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/2 "2011-07-25T17:02:20Z")

</div>

It’s supported in iOS, but I don’t know whether the simulator can do it.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [July 25, 2011, 5:16pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/3 "2011-07-25T17:16:11Z")

</div>

Ok. Good to know.

Will check on the device then.

Thanks,

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 25, 2011, 5:19pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/4 "2011-07-25T17:19:49Z")

</div>

Oh no, sorry, I’m talking nonsense - the midi classes are stubs in iOS, I hadn’t finished doing them yet.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [July 26, 2011, 9:52am UTC](https://forum.juce.com/t/ios-core-midi-support/7205/5 "2011-07-26T09:52:58Z")

</div>

So far it looks like the mac code compile on ios at least for MidiInput beside EndianS32\_BtoN

I need to check on the device as so far the simulator reports 0 to MIDIGetNumberOfSources.

Waiting on the dock adapter for more testing 🙂

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [July 26, 2011, 1:36pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/6 "2011-07-26T13:36:21Z")

</div>

Working fine on the device. Juce Demo reports two devices: a network one and the one connected.  
The only issue sems that if I enable both, it won’t receive any midi events. It works fine if I only activate the one connected.

Can’t compile MidiOutput because of missing AudioGetCurrentHostTime (or don’t know where to find it). Only thing missing.

For MidiInput, I’ve replaced only EndianS32\_BtoN by a nop.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 26, 2011, 2:18pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/7 "2011-07-26T14:18:54Z")

</div>

Thanks, that’s interesting to hear that it works!

I think the EndianS32\_BtoN call could just be replaced by ByteOrder::swapIfLittleEndian ((uint32) \*pid)

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [July 26, 2011, 3:33pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/8 "2011-07-26T15:33:45Z")

</div>

More on the “enable both” issue

In fact when checking the two devices in the Juce Demo’s Audio Device setup, only the first one checked works.  
So the physical and the network one works both but only the one that I have checked in first will work.

Does it ring a bells ?

Unfortunately this is quite hard to debug as I can’t have a physical keyboard plugged and connected to the computer for remote debugging as the same time.

Thanks,

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 26, 2011, 3:45pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/9 "2011-07-26T15:45:27Z")

</div>

No idea about that - it shouldn’t make any difference which ones are enabled. It sounds like a driver issue to me.

---

<div class="post-metadata">

**Author:** ![mucoder](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mucoder/32/595_2.png) [@mucoder](https://forum.juce.com/u/mucoder)\
**Post date:** [October 28, 2011, 7:47pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/10 "2011-10-28T19:47:04Z")

</div>

took my first baby steps and got the Juce demo running on an ipad - wonderful!

but now I got stuck as well on the midi stuff I’m afraid - that is, midi devices don’t seem to show up yet in Juce  
sooo, any chance of coremidi support coming to our beloved library in the near future?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [October 29, 2011, 12:00pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/11 "2011-10-29T12:00:03Z")

</div>

It’s been on the to-do-list, but sorry, haven’t had time to think about it yet!

---

<div class="post-metadata">

**Author:** ![skelman](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@skelman](https://forum.juce.com/u/skelman)\
**Post date:** [November 10, 2011, 7:08pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/12 "2011-11-10T19:08:19Z")

</div>

I also add the IOS CoreMIDI support on my Christmas wish list 🙂

---

<div class="post-metadata">

**Author:** ![skelman](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@skelman](https://forum.juce.com/u/skelman)\
**Post date:** [November 13, 2011, 9:52am UTC](https://forum.juce.com/t/ios-core-midi-support/7205/13 "2011-11-13T09:52:06Z")

</div>

Christmas before Christmas ! I followed the tips described in this thread. As I just needed one MIDI input, I could make it work with a few copy/paste.  
This is really great ! For those who might be interested. I tested succesfully my App with an iRig MIDI on an iPhone 4 with a latency of 512 samples. I’ll make further test with iPad.

---

<div class="post-metadata">

**Author:** ![e1e8](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/e1e8/32/356_2.png) [@e1e8](https://forum.juce.com/u/e1e8)\
**Post date:** [December 18, 2011, 9:47am UTC](https://forum.juce.com/t/ios-core-midi-support/7205/14 "2011-12-18T09:47:51Z")

</div>

Here’s one more vote for expanding those stubs.

In the meantime I think I’ll start working from Pete Goodliffe’s bit

> **[petegoodliffe/PGMidi](https://github.com/petegoodliffe/PGMidi)**
>
> PGMidi iOS MIDI library and example code. Contribute to petegoodliffe/PGMidi development by creating an account on GitHub.

But as he says somewhere in his comments, to get low latency it will be necessary to go straight into CoreMIDI, so via Juce would be a great way,  
once I get a little further up the learning curve.

---

<div class="post-metadata">

**Author:** ![skelman](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@skelman](https://forum.juce.com/u/skelman)\
**Post date:** [December 18, 2011, 10:22am UTC](https://forum.juce.com/t/ios-core-midi-support/7205/15 "2011-12-18T10:22:48Z")

</div>

I could go down to 64 samples on iPad modifying this part of the juce\_ios\_audio.cpp :

int getNumBufferSizesAvailable()  
{  
return 6;  
}

```
int getBufferSizeSamples (int index)
{
    switch (index)
    {
        case 0: return 64; break;
        case 1: return 128; break;
        case 2: return 256; break;
        case 3: return 512; break;
        case 4: return 1024; break;
        case 5: return 2048; break;
        default: return getDefaultBufferSize(); 
    }
    
}

```

I tried intermediate values such as 192 but my app crashed when changing to another sample size.  
It works with this list. I can change the latency while juce is running without problem.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 18, 2011, 11:34am UTC](https://forum.juce.com/t/ios-core-midi-support/7205/16 "2011-12-18T11:34:00Z")

</div>

[quote=“skelman”]I could go down to 64 samples on iPad modifying this part of the juce\_ios\_audio.cpp :

int getNumBufferSizesAvailable()  
{  
return 6;  
}

```
int getBufferSizeSamples (int index)
{
    switch (index)
    {
        case 0: return 64; break;
        case 1: return 128; break;
        case 2: return 256; break;
        case 3: return 512; break;
        case 4: return 1024; break;
        case 5: return 2048; break;
        default: return getDefaultBufferSize(); 
    }
    
}

```

I tried intermediate values such as 192 but my app crashed when changing to another sample size.  
It works with this list. I can change the latency while juce is running without problem.[/quote]

Not sure if this belongs in this thread, but thanks for the info!

---

<div class="post-metadata">

**Author:** ![skelman](https://avatars.discourse-cdn.com/v4/letter/s/48db29/32.png) [@skelman](https://forum.juce.com/u/skelman)\
**Post date:** [December 18, 2011, 12:10pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/17 "2011-12-18T12:10:59Z")

</div>

arg ! You’re right. I mixed it up with another thread regarding latency that’s why I got confused.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [January 5, 2012, 4:42pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/18 "2012-01-05T16:42:31Z")

</div>

Bump.

Hi Jules,

You only to use the mac version and replace EndianS32\_BtoN by ByteOrder::swapIfLittleEndian ((uint32) \*pid) and it works fine.

Works fine here but just want it to be in the trunk for ease of maintenance.

Thanks,

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 5, 2012, 4:53pm UTC](https://forum.juce.com/t/ios-core-midi-support/7205/19 "2012-01-05T16:53:22Z")

</div>

Ah sorry, it was supposed to already by in there, but I’d left it #ifdef’ed out by mistake… Will sort that.

---

<div class="post-metadata">

**Author:** ![KrisG](https://avatars.discourse-cdn.com/v4/letter/k/96bed5/32.png) [@KrisG](https://forum.juce.com/u/KrisG)\
**Post date:** [January 10, 2012, 12:16am UTC](https://forum.juce.com/t/ios-core-midi-support/7205/20 "2012-01-10T00:16:34Z")

</div>

I’ve read your post about modules and downloaded some new files (modules-juce\_audio\_devices-juce\_audio\_devices.cpp, modules-juce\_audio\_devices-juce\_module\_info, modules-juce\_audio\_devices-midi\_io-juce\_MidiInput.h, modules-juce\_audio\_devices-midi\_io-juce\_MidiOutput.h, modules-juce\_audio\_devices-native-juce\_mac\_CoreMidi.cpp, extras-JuceDemo-Builds-iOS-Juce Demo.xcodeproj), but have no idea so far how to implement the changes, and first of all how to create the modules folders. Also - each module folder should contain a “module\_info” file, and I only have one: modules-juce\_audio\_devices-juce\_module\_info.  
What should I do to make MIDI work on iOS?  
Please help!!!  
☹

[Next page](https://forum.juce.com/t/ios-core-midi-support/7205.md?page=2)
