title: iOS how to play midi notes?
body: <p>I have searched and already have done an OS X app that can play MIDI notes, but when i tried in iOS, nothing happened. Here is the core code:</p>
  
  <pre><code>AUGraph graph;
  AudioUnit synthUnit;
  AUNode synthNode, outNode;
  
  NewAUGraph(&amp;graph);
  
  AudioComponentDescription cd;
  cd.componentManufacturer = kAudioUnitManufacturer_Apple;
  
  cd.componentType = kAudioUnitType_MusicDevice;
  cd.componentSubType = kAudioUnitSubType_MIDISynth;
  AUGraphAddNode(graph, &amp;cd, &amp;synthNode);
  
  cd.componentType = kAudioUnitType_Output;
  cd.componentSubType = kAudioUnitSubType_GenericOutput;
  AUGraphAddNode(graph, &amp;cd, &amp;outNode), "AUGraphAddNode");
  
  CheckError(AUGraphOpen(graph), "AUGraphOpen");
  
  AUGraphConnectNodeInput(graph, synthNode, 0, outNode, 0);
  
  AUGraphNodeInfo(graph, synthNode, 0, &amp;synthUnit);
  
  AUGraphInitialize(graph);
  CAShow(graph);
  
  AUGraphStart(graph);
  
  CFURLRef bankURL = ... //gs_instruments.dls
  AudioUnitSetProperty(synthUnit,
                      kMusicDeviceProperty_SoundBankURL,
                      kAudioUnitScope_Global,
                      0,
                      &amp;bankURL,
                      sizeof(bankURL));
  
  static UInt32 kChannelMessage_NoteOn = 0x90;
  UInt8 channel = 0;
  UInt8 note = 60;
  UInt32 velocity = 127;
  
  MusicDeviceMIDIEvent(synthUnit,
                      kChannelMessage_NoteOn | channel,
                      note,
                      velocity,
                      0);
  
  AUGraphStop(graph);
  DisposeAUGraph(graph);
  </code></pre>
  
  <p>I know the <code>cd.componentType</code> and <code>cd.componentSubType</code> settings may be not correct, because the difference between iOS app and OS X app is just it. In OS X:</p>
  
  <pre><code>AudioComponentDescription cd;
  cd.componentManufacturer = kAudioUnitManufacturer_Apple;
  
  cd.componentType = kAudioUnitType_MusicDevice;
  cd.componentSubType = kAudioUnitSubType_DLSSynth;
  AUGraphAddNode(graph, &amp;cd, &amp;synthNode);
  
  cd.componentType = kAudioUnitType_Output;
  cd.componentSubType = kAudioUnitSubType_DefaultOutput;
  AUGraphAddNode(graph, &amp;cd, &amp;outNode);
  </code></pre>
  
  <p>How to set <code>cd</code> and play MIDI note correctly in iOS? I don't have clearly or deeply understanding on <code>Audio Unit</code> / <code>AUGraph</code>...</p>
  
  <p><strong>UPDATED:</strong> Using <code>cd.componentSubType = kAudioUnitSubType_RemoteIO;</code> when adding <code>outNode</code> will be right and play soft MIDI notes successfully.</p>