MIDI 文件解析 [英] MIDI File Parsing
本文介绍了MIDI 文件解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何使用 Objective-C 进行 midi 文件解析?
How can we do midi file parsing using objective-C ?
在用于 MIDI 文件解析的 Java 中,有一个名为 javax.sound.midi 的包;Objective-c 中有什么东西吗?
In Java for MIDI file parsing there is package called javax.sound.midi; Is there something in Objective-c ?
如果你们中的任何人发送回复会很有帮助..
Would be of great help if anybody of you send a reply..
提前致谢.
推荐答案
您可以使用 CoreMidi 解析 MIDI 文件.总体思路是从文件中获取 MusicSequence:
You can parse a MIDI file using CoreMidi. The general idea is that you get the MusicSequence from the file:
MusicSequence s;
NewMusicSequence(&s);
NSString *midiFilePath = [[NSBundle mainBundle]
pathForResource:path
ofType:@"mid"];
NSURL * midiFileURL = [NSURL fileURLWithPath:midiFilePath];
MusicSequenceFileLoad(s, (CFURLRef)midiFileURL, 0, 0);
然后获取曲目:
MusicTrack track = NULL;
UInt32 tracks;
MusicSequenceGetTrackCount(s, &tracks);
for (NSInteger i=0; i<tracks; i++) {
MusicSequenceGetIndTrack(s, i, &track);
// Create an interator
MusicEventIterator iterator = NULL;
NewMusicEventIterator(track, &iterator);
MusicTimeStamp timestamp = 0;
MusicEventType eventType = 0;
const void *eventData = NULL;
UInt32 eventDataSize = 0;
Boolean hasNext = YES;
// A variable to store note messages
MIDINoteMessage * midiNoteMessage;
// Iterate over events
while (hasNext) {
// See if there are any more events
MusicEventIteratorHasNextEvent(iterator, &hasNext);
// Copy the event data into the variables we prepaired earlier
MusicEventIteratorGetEventInfo(iterator, ×tamp, &eventType, &eventData, &eventDataSize);
// Process Midi Note messages
if(eventType==kMusicEventType_MIDINoteMessage) {
// Cast the midi event data as a midi note message
midiNoteMessage = (MIDINoteMessage*) eventData;
}
// Load the next event
MusicEventIteratorNextEvent(iterator);
}
}
这篇关于MIDI 文件解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文