Obj C and C with CoreMidi
Obj C and C with CoreMidi
- Subject: Obj C and C with CoreMidi
- From: Craig Bakalian <email@hidden>
- Date: Wed, 31 Dec 2003 05:47:28 -0500
This the only way you can mix Obj C and C with CoreMidi ReadProc. You
must set up a shared instance in objective C, and place a static
instance of that shared instance directly in the .m file like so...
and the shared instance must be outside of the @implementation @end
protocols
MIDIPortRef inPort;
MIDIEndpointRef origin;
int channel;
int numMidiDevices;
BOOL isPlaying;
AUMIDIControllerRef midiController;
MIDIClientRef client;
static MidiKeyboardSetting *setting; ////this is the shared
instance of my objective c object!!!!!
@implementation MidiKeyboardSetting
-(id)init
{
self = [super init];
return self;
}
-(void)dealloc
{
if(inPort)CFRelease(inPort);
if(origin)CFRelease(origin);
if(midiController)CFRelease(midiController);
}
+(id)sharedMidiKeyboardSetting
{
setting = nil;
if(!setting)
{
setting = [[MidiKeyboardSetting allocWithZone: [self
zone]]init];
}
return setting;
}
void MyReadProc(const MIDIPacketList *pktlist, void *refCon, void
*connRefConn)
{
int i, j;
MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
for(j = 0; j < pktlist->numPackets; ++j)
{
for(i = 0; i < packet->length; ++i)
{
if(packet->data[i]>=0x80 && packet->data[i] < 0xF0)
{
packet->data[i] = (packet->data[i] & 0xF0) | channel;
MusicTimeStamp mStamp;
if(packet->data[0] >= 128 && packet-> data[0] <= 191)
{
MusicPlayer mPlayer = [setting currentPlayer];
MusicPlayerGetTime(mPlayer, &mStamp);
[setting addChannelEventToTrack:
(UInt8)packet->data[0] note: (UInt8)packet->data[1] velocity:
packet->data[2] withStamp: mStamp];
}
if(packet->data[0] >= 192 && packet->data[0] <= 207)
{
}
if(packet->data[0] >= 0xE0 && packet->data[0] <= 0xEF)
{
MusicPlayer mPlayer = [setting currentPlayer];
MusicPlayerGetTime(mPlayer, &mStamp);
[setting addChannelEventToTrack:
(UInt8)packet->data[0] note: (UInt8)packet->data[1] velocity:
packet->data[2] withStamp: mStamp];
}
}
}
packet = MIDIPacketNext(packet);
}
}
-(void)addChannelEventToTrack: (UInt8)type note: (UInt8)val velocity:
(UInt8)vel withStamp: (Float64)time
{
if([[[NSApp mainWindow] windowController] isRecording])
{
MusicTrack selectedTrack = [[[[NSApp mainWindow]
windowController] document] getSelectedTrack];
MIDIChannelMessage message;
message.status = type;
message.data1 = val;
message.data2 = vel;
MusicTrackNewMIDIChannelEvent(selectedTrack, time, &message);
}
}
-(void)setCurrentPlayer
{
currentPlayer = [[[[NSApp mainWindow] windowController] document]
player];
}
-(MusicPlayer)currentPlayer
{
return currentPlayer;
}
Notice that the ReadProc can access the objective c objective called *
"setting".
Craig Bakalian
www.eThinkingCap.com
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.