gpt4 book ai didi

objective-c - MIDI 文件解析

转载 作者:行者123 更新时间:2023-12-04 03:07:59 25 4
gpt4 key购买 nike

我们如何使用 objective-C 解析 midi 文件?

在 Java 中用于解析 MIDI 文件的包名为 javax.sound.midi;Objective-c 有什么东西吗?

如果你们中的任何人发送回复,将会有很大的帮助..

提前致谢。

最佳答案

您可以使用 CoreMidi 解析 MIDI 文件。一般的想法是您从文件中获取 MusicSequence:

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, &timestamp, &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);
}
}

关于objective-c - MIDI 文件解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4666935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com