花了将近半天的时间,我仍然无法理解如何使用iOS (目标c,CoreMIDI)从midi文件中获得4和4 (4/4)的值。
我有一个midi文件4/4 19巴120 bmp
我尝试了以下代码:
MusicTimeStamp inBeats;
UInt32 inSubbeatDivisor;
CABarBeatTime outBarBeatTime;
MusicSequenceBeatsToBarBeatTime(aSequence, inBeats, inSubbeatDivisor, &outBarBeatTime);
NSLog(@"%i, %i, %i, %i, %i, %f", outBarBeatTime.bar, outBarBeatTime.beat, outBarBeatTime.reserved, outBarBeatTime.subbeat, outBarBeatTime.subbeatDivisor, inBeats);结果: 5,3,755,0,50617,0.000000
不知道如何处理这些来自NSLog的信息。
如果midi文件是6/2、4/2或5/8,那么我只想得到这个值(第二个/第一个)
有人能帮我算一下吗?谢谢!
发布于 2014-09-17 06:53:39
MusicSequenceBeatsToBarBeatTime只是在两种不同格式之间转换时间戳,但它没有告诉您它用于转换的时间签名。
时间签名是使用节奏轨道中的时间签名元事件指定的。因此,您必须使用MusicSequenceGetTempoTrack获得节奏跟踪,使用MusicEventIterator搜索具有kMusicEventType_Meta类型的事件,并检查这些事件是否为时间签名元事件(如果时间签名更改,可能会出现多个时间签名事件)。
发布于 2014-09-17 11:20:45
谢谢你的CL。用户经过小规模的实验后,我做了并得到了以下结果:
在这里,我们加载midi文件:
+(void) openMidiFile: (NSString *) path{
MusicSequence s;
NewMusicSequence(&s);
NSURL * midiFileURL = [NSURL fileURLWithPath:path];
MusicSequenceFileLoad(s, (CFURLRef)midiFileURL, 0, 0);
//Get tempo and time signature
[self getSequenceTempo:s];
}在这里,我们从节奏轨道上获得所需的信息。
+(MusicTrack) getSequenceTempo: (MusicSequence) aSequence{
OSStatus result = noErr;
MusicTrack tempoTrack;
result = MusicSequenceGetTempoTrack(aSequence, &tempoTrack);
if (noErr != result) {
NSLog(@"MusicSequenceGetTempoTrack, %d", (int)result);
}
// Create an interator
MusicEventIterator iterator = NULL;
NewMusicEventIterator(tempoTrack, &iterator);
MusicTimeStamp timestamp = 0;
MusicEventType eventType = 0;
const void *eventData = NULL;
UInt32 eventDataSize = 0;
Boolean hasNext = YES;
// A variable to store note messages
ExtendedTempoEvent * message;
MIDIMetaEvent *metaEvent;
// 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_ExtendedTempo) {
// Cast the midi event data as a midi note message
message = (ExtendedTempoEvent*) eventData;
// NSLog(@"%f", message->bpm); //TEMPO VALUE
}
if (eventType == kMusicEventType_Meta){
metaEvent = (MIDIMetaEvent *) eventData;
for (int i = 0; i < metaEvent->dataLength;i++){
NSLog(@"%i, %i, %i, %i, %i", metaEvent->metaEventType, metaEvent->data[i], metaEvent->unused1, metaEvent->unused2, metaEvent->unused3);
}
NSLog(@"...");
}
MusicEventIteratorNextEvent(iterator);
}
return tempoTrack;
}结果是:
**For 7/8:**
2014-09-17 14:03:14.073 MidiSequencer[1959:907] 88, **7**, 224, 215, 47
2014-09-17 14:03:14.075 MidiSequencer[1959:907] 88, **3**, 224, 215, 47
2014-09-17 14:03:14.077 MidiSequencer[1959:907] 88, 36, 224, 215, 47
2014-09-17 14:03:14.079 MidiSequencer[1959:907] 88, 8, 224, 215, 47
2014-09-17 14:03:14.080 MidiSequencer[1959:907] ...
2014-09-17 14:03:14.081 MidiSequencer[1959:907] 88, **7**, 224, 215, 47
2014-09-17 14:03:14.083 MidiSequencer[1959:907] 88, **3**, 224, 215, 47
2014-09-17 14:03:14.084 MidiSequencer[1959:907] 88, 36, 224, 215, 47
2014-09-17 14:03:14.086 MidiSequencer[1959:907] 88, 8, 224, 215, 47
**For 7/4**
2014-09-17 13:59:45.455 MidiSequencer[1922:907] 88, **7**, 32, 220, 47
2014-09-17 13:59:45.457 MidiSequencer[1922:907] 88, **2**, 32, 220, 47
2014-09-17 13:59:45.459 MidiSequencer[1922:907] 88, 36, 32, 220, 47
2014-09-17 13:59:45.461 MidiSequencer[1922:907] 88, 8, 32, 220, 47
2014-09-17 13:59:45.462 MidiSequencer[1922:907] 88, **7**, 32, 220, 47
2014-09-17 13:59:45.464 MidiSequencer[1922:907] 88, **2**, 32, 220, 47
2014-09-17 13:59:45.465 MidiSequencer[1922:907] 88, 36, 32, 220, 47
2014-09-17 13:59:45.466 MidiSequencer[1922:907] 88, 8, 32, 220, 47因此,如果我们看7/4的例子,这里有值:7和值:2。第二个值是:0是1;1是2;2是4;3是8,4是16;
https://stackoverflow.com/questions/25880178
复制相似问题