本文整理汇总了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;
}