Skip to content

Instantly share code, notes, and snippets.

@rraallvv
Created February 1, 2016 02:58
Show Gist options
  • Select an option

  • Save rraallvv/d613d3086a4ab9d149d2 to your computer and use it in GitHub Desktop.

Select an option

Save rraallvv/d613d3086a4ab9d149d2 to your computer and use it in GitHub Desktop.
Simple Midi In Setup
#include <iostream>
#include <AudioToolbox/AudioToolbox.h>
int main (int argc, char * const argv[]) {
AUGraph graph;
AUNode outputNode, mixerNode, synthNode;
AudioUnit synthUnit;
//Setup Graph
NewAUGraph(&graph);
AudioComponentDescription cd;
cd.componentManufacturer = kAudioUnitManufacturer_Apple;
cd.componentFlags = 0;
cd.componentFlagsMask = 0;
cd.componentType = kAudioUnitType_Output;
//cd.componentSubType = kAudioUnitSubType_HALOutput;
cd.componentSubType = kAudioUnitSubType_DefaultOutput;
AUGraphAddNode(graph, &cd, &outputNode);
AUGraphOpen(graph);
AUGraphInitialize(graph);
AUGraphStart(graph);
//New NODES
cd.componentManufacturer = kAudioUnitManufacturer_Apple;
cd.componentFlags = 0;
cd.componentFlagsMask = 0;
cd.componentType = kAudioUnitType_MusicDevice;
cd.componentSubType = kAudioUnitSubType_DLSSynth;
AUGraphAddNode(graph, &cd, &synthNode);
AUGraphNodeInfo(graph, synthNode, NULL, &synthUnit);
cd.componentManufacturer = kAudioUnitManufacturer_Apple;
cd.componentFlags = 0;
cd.componentFlagsMask = 0;
cd.componentType = kAudioUnitType_Mixer;
cd.componentSubType = kAudioUnitSubType_StereoMixer;
AUGraphAddNode(graph, &cd, &mixerNode);
//Connect NODES
AUGraphConnectNodeInput(graph, mixerNode, 0, outputNode, 0);
AUGraphConnectNodeInput(graph, synthNode, 0, mixerNode, 0);
//Update Graph
AUGraphUpdate(graph,NULL);
//send program changes and notes
//using 3 different channels
MusicDeviceMIDIEvent(synthUnit, 0xC0, 40, 0, 0);
MusicDeviceMIDIEvent(synthUnit, 0xC1, 9, 0, 0);
MusicDeviceMIDIEvent(synthUnit, 0xC2, 104, 0, 0);
sleep(1);
MusicDeviceMIDIEvent(synthUnit, 0x90, 60, 80, 0);
sleep(1);
MusicDeviceMIDIEvent(synthUnit, 0x80, 60, 0, 0);
MusicDeviceMIDIEvent(synthUnit, 0x91, 60, 80, 0);
sleep(1);
MusicDeviceMIDIEvent(synthUnit, 0x81, 60, 0, 0);
MusicDeviceMIDIEvent(synthUnit, 0x92, 60, 80, 0);
sleep(1);
MusicDeviceMIDIEvent(synthUnit, 0x82, 60, 0, 0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment