当前位置: 首页>>代码示例>>C++>>正文


C++ MidiMessageSequence::updateMatchedPairs方法代码示例

本文整理汇总了C++中MidiMessageSequence::updateMatchedPairs方法的典型用法代码示例。如果您正苦于以下问题:C++ MidiMessageSequence::updateMatchedPairs方法的具体用法?C++ MidiMessageSequence::updateMatchedPairs怎么用?C++ MidiMessageSequence::updateMatchedPairs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MidiMessageSequence的用法示例。


在下文中一共展示了MidiMessageSequence::updateMatchedPairs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createMelody

MidiMessageSequence* MidiStochaster::createMelody(int minOctaveOffset, int maxOctaveOffset, double speedFactor) {
    
    int currentOctaveOffset;
    if (minOctaveOffset <= 0) {
        currentOctaveOffset = 0;
    } else { 
        currentOctaveOffset = minOctaveOffset;
    }
    
    int randInt1 = randomInt(100, 200);
    double stopProbability = (double) randInt1 / (randInt1 + 1);
    int randInt2 = randomInt(4, 10);
    double octaveSwitchProbability = (double) randInt2 / (randInt2 + 1);
    
    
    double currentTime = 0.0;
    MidiMessageSequence* melody = new MidiMessageSequence(starter);
    if (!goodSource) {
        return melody;
    }
    
    while (randomDouble(0,1) < stopProbability) {
        int notePitch = pitches->at(randomInt(0, pitches->size() - 1)) + 12 * currentOctaveOffset;
        while (notePitch < 0) {
            notePitch+=12;
            currentOctaveOffset++;
            minOctaveOffset++;
        }
        while (notePitch > 127) {
            notePitch-=12;
            currentOctaveOffset--;
            maxOctaveOffset--;
        }
        int noteVelocity = randomInt(lowVelocity, highVelocity);
        int noteLength = randomDouble(lowNoteLength, highNoteLength) * (1.0 / speedFactor);
        int nextRestLength;
        if (randomDouble(0,1) < negRestProbability) {
            nextRestLength = randomDouble(lowNegRestLength, highNegRestLength) * 1.0 / speedFactor;
        } else {
            nextRestLength = randomDouble(lowRestLength, highRestLength) * 1.0 / speedFactor;
        }
        
        MidiMessage noteDown = MidiMessage::noteOn(1, notePitch, (uint8_t) noteVelocity);
        noteDown.setTimeStamp(currentTime);
        MidiMessage noteUp = MidiMessage::noteOff(1, notePitch);
        noteUp.setTimeStamp(currentTime + noteLength);

        melody->addEvent(noteDown);
        melody->addEvent(noteUp);
        melody->updateMatchedPairs();
        
        currentTime += noteLength + nextRestLength;
        
        if (randomDouble(0,1) > octaveSwitchProbability) {
            currentOctaveOffset = randomInt(minOctaveOffset, maxOctaveOffset);
        }
    }
        
    return melody;
    
    
}
开发者ID:lathertonj,项目名称:MelodyStochaster,代码行数:62,代码来源:MidiStochaster.cpp


注:本文中的MidiMessageSequence::updateMatchedPairs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。