Ios 从midi文件中读取时间签名(如4/4)

Ios 从midi文件中读取时间签名(如4/4),ios,objective-c,time,midi,Ios,Objective C,Time,Midi,花了将近半天的时间,仍然不明白我是如何得到这些价值观的​​使用iOS从midi文件中选择4和4(4/4)(目标c,CoreMIDI) 我有一个midi文件4/4 19条120 bmp 我尝试了以下代码: MusicTimeStamp inBeats; UInt32 inSubbeatDivisor; CABarBeatTime outBarBeatTime; MusicSequenceBeatsToBarBeatTime(aSequence, inBeats, inSubbeatDivisor,

花了将近半天的时间,仍然不明白我是如何得到这些价值观的​​使用iOS从midi文件中选择4和4(4/4)(目标c,CoreMIDI)

我有一个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);
NSLOG结果:5,3755,050617,0.000000

不确定如何处理NSLog中的此信息

如果midi文件是6/2或4/2或5/8。然后我只想得到这个值(第二个/第一个)


有人能帮我计算一下吗?谢谢大家!

MusicSequenceBeatToBarBeatTime
仅在两种不同格式之间转换时间戳,但它不会告诉您转换使用的时间签名

时间签名是在节奏音轨中用时间签名元事件指定的。
因此,您必须使用获取节奏轨迹,使用a搜索类型为
kMusicEventType\u Meta
的事件,并检查这些事件是否为时间特征元事件(如果时间特征发生变化,可能会有多个时间特征事件)。

感谢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, &timestamp, &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;
}
所以,如果我们看7/4示例,这里有值7和值2。第二个平均值:0为1;1是2;2是4;3是8,4是16

**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