Good afternoon. I'm working on a new app for iOS, this is sequencer with built-in sampler.
I've already implement a polyphonic sampler as audiounit plugin (kAudioUnitType_MusicDevice).
Unfortunately I haven't found any information on how to write units with this type nor how to use it in my host code.
Naive solution not working.
//_______________________________________________________________________________________________________________
class LSQSwing : public AUBase, public AUMIDIBase
{
public:
LSQSwing(AudioComponentInstance inInstance) : AUBase(inInstance, 1, 1),
AUMIDIBase(this)
{
}
~LSQSwing()
{
}
virtual bool StreamFormatWritable(AudioUnitScope scope, AudioUnitElement element)
{
return false;
}
virtual bool CanScheduleParameters() const
{
return false;
}
virtual OSStatus MIDIEvent(UInt32 inStatus,
UInt32 inData1,
UInt32 inData2,
UInt32 inOffsetSampleFrame)
{
return AUMIDIBase::MIDIEvent (inStatus, inData1, inData2, inOffsetSampleFrame);
}
};
//_______________________________________________________________________________________________________________
AUDIOCOMPONENT_ENTRY (AUMIDIProcessFactory, LSQSwing);
AUDIOCOMPONENT_REGISTER(LSQSwing,
kLSQSwingName,
kLSQSwingVersion,
kAudioUnitType_MIDIProcessor,
kAudioUnitSubType_LSQMIDISwing,
kAudioUnitManufacturer_CasualUnderground,
0,
0);
//_______________________________________________________________________________________________________________
// Somewhere in my host program...
_instrument = [[instrumentClass alloc] initWithComponentDescription:description
audioController:controller
error:nil];
LSQQueuePushHead(_mainChain, (__bridge void *)(_instrument));
// Connect instrument to midi processor
LSQNodeRef midiHead = LSQQueueHead(_midiFxChain);
if (midiHead)
{
id<MIDIProcessorProtocol> headProc = (__bridge id<MIDIProcessorProtocol>)(LSQNodeGetContent(midiHead));
if (AUGraphConnectNodeInput(controller.audioGraph,
_instrument.audioGraphNode,
0,
headProc.audioGraphNode,
0) != noErr)
{
NSLog(@"Failed to connect node: %i to node: %i", (int)headProc.audioGraphNode, (int)_instrument.audioGraphNode);
}
}
// ...Somewhere
id<ComponentProtocol> midiProc = [channel midiProcessor];
MusicTrack mTrk = MSSequencerTrackGetOutputTrack(track);
AUNode node = -1;
// Check if music track already connected to aunode
if (MusicTrackGetDestNode(mTrk, &node) == noErr && (node != midiProc.audioGraphNode || node == -1))
{
if (MusicTrackSetDestNode(mTrk, midiProc.audioGraphNode) != noErr)
{
[NSException raise:NSStringFromSelector(_cmd)
format:@"Failed to set destination node of music track."];
}
}