Refactoring for shorter names

This commit is contained in:
Andrey M. Tokarev 2013-08-17 17:28:15 +04:00
parent b476e8851b
commit 2b1a262f51
6 changed files with 58 additions and 59 deletions

View file

@ -956,7 +956,7 @@ void MTrack::convertTrack(const ReducedFraction &lastTick)
QList<MidiChord> midiChords;
for (auto it = chords.begin(); it != chords.end();) {
const ReducedFraction &nextChordTick = it->first;
const auto &nextChordTick = it->first;
const MidiChord& midiChord = it->second;
if (midiChord.voice != voice) {
++it;
@ -1184,16 +1184,16 @@ std::multimap<int, MTrack> createMTrackList(ReducedFraction &lastTick,
for (auto i : t.events()) {
const MidiEvent& e = i.second;
// change division to MScore::division
ReducedFraction tick = ReducedFraction::fromTicks(
(i.first * MScore::division + mf->division()/2) / mf->division());
auto tick = ReducedFraction::fromTicks(
(i.first * MScore::division + mf->division() / 2) / mf->division());
// remove time signature events
if ((e.type() == ME_META) && (e.metaType() == META_TIME_SIGNATURE))
sigmap->add(tick.ticks(), metaTimeSignature(e));
else if (e.type() == ME_NOTE) {
++events;
int pitch = e.pitch();
ReducedFraction len = ReducedFraction::fromTicks(
(e.len() * MScore::division + mf->division()/2) / mf->division());
auto len = ReducedFraction::fromTicks(
(e.len() * MScore::division + mf->division() / 2) / mf->division());
if (tick + len > lastTick)
lastTick = tick + len;
@ -1516,7 +1516,7 @@ void convertMidi(Score *score, const MidiFile *mf)
auto sigmap = score->sigmap();
auto tracks = createMTrackList(lastTick, sigmap, mf);
ReducedFraction minNoteDuration = ReducedFraction::fromTicks(MScore::division) / 32;
auto minNoteDuration = ReducedFraction::fromTicks(MScore::division) / 32;
collectChords(tracks, minNoteDuration);
quantizeAllTracks(tracks, sigmap, lastTick);
removeOverlappingNotes(tracks);

View file

@ -95,7 +95,7 @@ DivisionInfo metricDivisionsOfTuplet(const MidiTuplet::TupletData &tuplet,
tupletDivInfo.len = tuplet.len;
tupletDivInfo.isTuplet = true;
tupletDivInfo.divLengths.push_back({tuplet.len, TUPLET_BOUNDARY_LEVEL});
ReducedFraction divLen = tuplet.len / tuplet.tupletNumber;
auto divLen = tuplet.len / tuplet.tupletNumber;
tupletDivInfo.divLengths.push_back({divLen, tupletStartLevel--});
while (tupletDivInfo.divLengths.back().len >= minAllowedDuration() * 2) {
tupletDivInfo.divLengths.push_back({
@ -106,7 +106,7 @@ DivisionInfo metricDivisionsOfTuplet(const MidiTuplet::TupletData &tuplet,
ReducedFraction beatLength(const ReducedFraction &barFraction)
{
ReducedFraction beatLen = barFraction / 4;
auto beatLen = barFraction / 4;
if (Meter::isDuple(barFraction))
beatLen = barFraction / 2;
else if (Meter::isTriple(barFraction))
@ -122,7 +122,7 @@ std::vector<ReducedFraction> divisionsOfBarForTuplets(const ReducedFraction &bar
{
DivisionInfo info = metricDivisionsOfBar(barFraction);
std::vector<ReducedFraction> divLengths;
ReducedFraction beatLen = beatLength(barFraction);
auto beatLen = beatLength(barFraction);
for (const auto &i: info.divLengths) {
// in compound meter tuplet starts from beat level, not the whole bar
if (Meter::isCompound(barFraction) && i.len > beatLen)
@ -177,22 +177,22 @@ Meter::MaxLevel maxLevelBetween(const ReducedFraction &startTickInBar,
const DivisionInfo &divInfo)
{
Meter::MaxLevel level;
ReducedFraction startTickInDiv = startTickInBar - divInfo.onTime;
ReducedFraction endTickInDiv = endTickInBar - divInfo.onTime;
auto startTickInDiv = startTickInBar - divInfo.onTime;
auto endTickInDiv = endTickInBar - divInfo.onTime;
if (startTickInDiv >= endTickInDiv
|| startTickInDiv < 0 || endTickInDiv > divInfo.len)
return level;
for (const auto &divLengthInfo: divInfo.divLengths) {
const auto &divLen = divLengthInfo.len;
ReducedFraction maxEndRaster = divLen * (endTickInDiv.ticks() / divLen.ticks());
auto maxEndRaster = divLen * (endTickInDiv.ticks() / divLen.ticks());
if (maxEndRaster == endTickInDiv)
maxEndRaster -= divLen;
if (startTickInDiv < maxEndRaster) {
// max level is found
level.lastPos = maxEndRaster + divInfo.onTime;
ReducedFraction maxStartRaster = divLen * (startTickInDiv.ticks() / divLen.ticks());
ReducedFraction count = (maxEndRaster - maxStartRaster) / divLen;
auto maxStartRaster = divLen * (startTickInDiv.ticks() / divLen.ticks());
auto count = (maxEndRaster - maxStartRaster) / divLen;
level.levelCount = qRound(count.numerator() * 1.0 / count.denominator());
level.level = divLengthInfo.level;
break;
@ -264,8 +264,8 @@ bool isPowerOfTwo(unsigned int x)
bool isSingleNoteDuration(const ReducedFraction &ticks)
{
ReducedFraction division = ReducedFraction::fromTicks(MScore::division);
ReducedFraction div = (ticks > division) ? ticks / division : division / ticks;
auto division = ReducedFraction::fromTicks(MScore::division);
auto div = (ticks > division) ? ticks / division : division / ticks;
if (div > ReducedFraction(0))
return isPowerOfTwo((unsigned int)div.ticks());
return false;
@ -288,9 +288,8 @@ bool is23EndOfBeatInCompoundMeter(const ReducedFraction &startTickInBar,
if (!isCompound(barFraction))
return false;
ReducedFraction beatLen = beatLength(barFraction);
ReducedFraction divLen = beatLen / 3;
auto beatLen = beatLength(barFraction);
auto divLen = beatLen / 3;
if ((startTickInBar - beatLen * (startTickInBar.ticks() / beatLen.ticks()) == divLen)
&& (endTickInBar.ticks() % beatLen.ticks() == 0))
return true;
@ -394,7 +393,7 @@ toDurationList(const ReducedFraction &startTickInBar,
else if (durationType == DurationType::REST)
tol = 0;
// each child node duration after division is not less than minDuration()
const ReducedFraction minDuration = minAllowedDuration() * 2;
const auto minDuration = minAllowedDuration() * 2;
// build duration tree such that durations don't go across strong beat divisions
while (!nodesToProcess.isEmpty()) {
Node *node = nodesToProcess.dequeue();

View file

@ -27,8 +27,8 @@ ReducedFraction shortestNoteInBar(const std::multimap<ReducedFraction, MidiChord
const std::multimap<ReducedFraction, MidiChord>::const_iterator &endChordIt,
const ReducedFraction &endBarTick)
{
ReducedFraction division = ReducedFraction::fromTicks(MScore::division);
ReducedFraction minDuration = division;
auto division = ReducedFraction::fromTicks(MScore::division);
auto minDuration = division;
// find shortest note in measure
for (auto it = startBarChordIt; it != endChordIt; ++it) {
if (it->first >= endBarTick)
@ -40,7 +40,7 @@ ReducedFraction shortestNoteInBar(const std::multimap<ReducedFraction, MidiChord
}
// determine suitable quantization value based
// on shortest note in measure
ReducedFraction div = division;
auto div = division;
for (ReducedFraction duration(1, 16); duration <= ReducedFraction(8, 1); duration *= 2) {
// minimum duration is 1/64
if (minDuration <= division * duration) {
@ -58,8 +58,8 @@ ReducedFraction shortestNoteInBar(const std::multimap<ReducedFraction, MidiChord
ReducedFraction userQuantNoteToTicks(MidiOperation::QuantValue quantNote)
{
ReducedFraction division = ReducedFraction::fromTicks(MScore::division);
ReducedFraction userQuantValue = ReducedFraction::fromTicks(preferences.shortestNote);
auto division = ReducedFraction::fromTicks(MScore::division);
auto userQuantValue = ReducedFraction::fromTicks(preferences.shortestNote);
// specified quantization value
switch (quantNote) {
case MidiOperation::QuantValue::N_4:
@ -99,11 +99,11 @@ ReducedFraction findRegularQuantRaster(const std::multimap<ReducedFraction, Midi
const ReducedFraction &endBarTick)
{
auto operations = preferences.midiImportOperations.currentTrackOperations();
ReducedFraction raster = userQuantNoteToTicks(operations.quantize.value);
auto raster = userQuantNoteToTicks(operations.quantize.value);
// if user value larger than the smallest note in bar
// then use the smallest note to keep faster events
if (operations.quantize.reduceToShorterNotesInBar) {
ReducedFraction shortest = shortestNoteInBar(startBarChordIt, endChordIt, endBarTick);
auto shortest = shortestNoteInBar(startBarChordIt, endChordIt, endBarTick);
if (shortest < raster)
raster = shortest;
}
@ -112,8 +112,8 @@ ReducedFraction findRegularQuantRaster(const std::multimap<ReducedFraction, Midi
ReducedFraction reduceRasterIfDottedNote(const ReducedFraction &len, const ReducedFraction &raster)
{
ReducedFraction newRaster = raster;
ReducedFraction div = len / raster;
auto newRaster = raster;
auto div = len / raster;
double ratio = div.numerator() * 1.0 / div.denominator();
if (ratio > 1.4 && ratio < 1.6) // 1.5: dotted note that is larger than quantization value
newRaster /= 2; // reduce quantization error for dotted notes
@ -144,12 +144,12 @@ void doGridQuantizationOfBar(std::multimap<ReducedFraction, MidiChord> &quantize
if (found != chordsNotQuant.end())
continue;
auto chord = it->second;
ReducedFraction onTimeRaster = reduceRasterIfDottedNote(maxNoteLen(chord.notes), regularRaster);
ReducedFraction onTime = quantizeValue(it->first, onTimeRaster);
auto onTimeRaster = reduceRasterIfDottedNote(maxNoteLen(chord.notes), regularRaster);
auto onTime = quantizeValue(it->first, onTimeRaster);
for (auto &note: chord.notes) {
ReducedFraction offTime = onTime + note.len;
ReducedFraction offTimeRaster = MidiTuplet::findOffTimeRaster(offTime, it->second.voice,
regularRaster, tuplets);
auto offTime = onTime + note.len;
auto offTimeRaster = MidiTuplet::findOffTimeRaster(offTime, it->second.voice,
regularRaster, tuplets);
if (offTimeRaster == regularRaster) // offTime is not inside tuplet
offTimeRaster = reduceRasterIfDottedNote(note.len, offTimeRaster);
offTime = quantizeValue(offTime, offTimeRaster);
@ -171,11 +171,11 @@ void applyGridQuant(std::multimap<ReducedFraction, MidiChord> &chords,
ReducedFraction startBarTick;
auto startBarChordIt = chords.begin();
for (int i = 1;; ++i) { // iterate over all measures by indexes
ReducedFraction endBarTick = ReducedFraction::fromTicks(sigmap->bar2tick(i, 0));
auto endBarTick = ReducedFraction::fromTicks(sigmap->bar2tick(i, 0));
startBarChordIt = findFirstChordInRange(startBarTick, endBarTick,
startBarChordIt, chords.end());
if (startBarChordIt != chords.end()) { // if chords are found in this bar
ReducedFraction onTimeRaster = findRegularQuantRaster(startBarChordIt, chords.end(), endBarTick);
auto onTimeRaster = findRegularQuantRaster(startBarChordIt, chords.end(), endBarTick);
doGridQuantizationOfBar(quantizedChords, startBarChordIt, chords.end(),
onTimeRaster, endBarTick, chordsNotQuant, tuplets);
}
@ -209,8 +209,8 @@ void quantizeChordsAndTuplets(std::multimap<ReducedFraction, MidiTuplet::TupletD
// quantize tuplet chords, if any
ReducedFraction startBarTick;
for (int i = 1;; ++i) { // iterate over all measures by indexes
ReducedFraction endBarTick = ReducedFraction::fromTicks(sigmap->bar2tick(i, 0));
ReducedFraction barFraction = sigmap->timesig(startBarTick.ticks()).timesig();
auto endBarTick = ReducedFraction::fromTicks(sigmap->bar2tick(i, 0));
auto barFraction = sigmap->timesig(startBarTick.ticks()).timesig();
auto tuplets = MidiTuplet::findTuplets(startBarTick, endBarTick, barFraction, inputChords);
tupletInformation.insert(tupletInformation.end(), tuplets.begin(), tuplets.end());
@ -218,16 +218,16 @@ void quantizeChordsAndTuplets(std::multimap<ReducedFraction, MidiTuplet::TupletD
auto &infoChords = tupletInfo.chords;
for (auto &tupletChord: infoChords) {
int tupletNoteNum = tupletChord.first;
ReducedFraction onTime = tupletInfo.onTime
+ tupletInfo.len / tupletInfo.tupletNumber * tupletNoteNum;
auto onTime = tupletInfo.onTime
+ tupletInfo.len / tupletInfo.tupletNumber * tupletNoteNum;
const auto &midiChordEventIt = tupletChord.second;
// quantize chord to onTime value
MidiChord midiChord = midiChordEventIt->second;
for (auto &note: midiChord.notes) {
ReducedFraction raster = MidiTuplet::findOffTimeRaster(
auto raster = MidiTuplet::findOffTimeRaster(
onTime + note.len, midiChord.voice,
tupletInfo.regularQuantValue, tuplets);
ReducedFraction offTime = Quantize::quantizeValue(onTime + note.len, raster);
tupletInfo.regularQuant, tuplets);
auto offTime = Quantize::quantizeValue(onTime + note.len, raster);
note.len = offTime - onTime;
}
quantizedChords.insert({onTime, midiChord});

View file

@ -189,10 +189,10 @@ TupletInfo findTupletApproximation(const ReducedFraction &tupletLen,
tupletInfo.tupletNumber = tupletNumber;
tupletInfo.onTime = startTupletTime;
tupletInfo.len = tupletLen;
tupletInfo.tupletQuantValue = tupletLen / tupletNumber;
while (tupletInfo.tupletQuantValue / 2 >= raster)
tupletInfo.tupletQuantValue /= 2;
tupletInfo.regularQuantValue = raster;
tupletInfo.tupletQuant = tupletLen / tupletNumber;
while (tupletInfo.tupletQuant / 2 >= raster)
tupletInfo.tupletQuant /= 2;
tupletInfo.regularQuant = raster;
auto startTupletChordIt = startChordIt;
for (int k = 0; k != tupletNumber; ++k) {
@ -335,7 +335,7 @@ validateTuplets(std::list<int> &indexes, const std::vector<TupletInfo> &tuplets)
for (const auto &chord: tuplets[i].chords)
excludedChords.erase(&*chord.second);
}
const ReducedFraction &regularRaster = tuplets.front().regularQuantValue;
const ReducedFraction &regularRaster = tuplets.front().regularQuant;
for (const auto &chordIt: excludedChords)
sumError += findQuantizationError(chordIt->first, regularRaster);
@ -742,7 +742,7 @@ ReducedFraction findOffTimeRaster(const ReducedFraction &noteOffTime,
&& voice == tupletInfo.chords.begin()->second->second.voice
&& noteOffTime > tupletInfo.onTime
&& noteOffTime < tupletInfo.onTime + tupletInfo.len)
return tupletInfo.tupletQuantValue;
return tupletInfo.tupletQuant;
}
return regularQuant;
}
@ -820,15 +820,15 @@ void addFirstTiedTupletNotes(std::multimap<ReducedFraction, MidiChord> &chords,
+ tupletInfo.len / tupletInfo.tupletNumber * firstNoteIndex;
ReducedFraction chordOffTime = chord.first + maxLen;
// if chord offTime is outside tuplet - discard chord
if (chord.first + tupletInfo.tupletQuantValue >= tupletInfo.onTime
if (chord.first + tupletInfo.tupletQuant >= tupletInfo.onTime
|| chordOffTime <= tupletInfo.onTime
|| chordOffTime >= tupletFreeEnd + tupletInfo.tupletQuantValue)
|| chordOffTime >= tupletFreeEnd + tupletInfo.tupletQuant)
continue;
ReducedFraction chordError = findQuantizationError(chordOffTime,
tupletInfo.regularQuantValue);
tupletInfo.regularQuant);
ReducedFraction tupletError = findQuantizationError(chordOffTime,
tupletInfo.tupletQuantValue);
tupletInfo.tupletQuant);
auto it = errors.find(&chord);
bool found = (it != errors.end());
if (tupletError < chordError && (!found || (found && tupletError < it->second))) {
@ -882,9 +882,9 @@ void minimizeOffTimeError(std::vector<TupletInfo> &tuplets,
&& notes.size() > (int)removedIndexes.size() + 1))
{
ReducedFraction tupletError = noteLenQuantError(
onTime, note.len, tupletInfo.tupletQuantValue);
onTime, note.len, tupletInfo.tupletQuant);
ReducedFraction regularError = noteLenQuantError(
onTime, note.len, tupletInfo.regularQuantValue);
onTime, note.len, tupletInfo.regularQuant);
if (tupletError > regularError) {
removedIndexes.push_back(i);
continue;

View file

@ -26,8 +26,8 @@ struct TupletInfo
ReducedFraction onTime = -1; // invalid
ReducedFraction len = -1;
int tupletNumber = -1;
ReducedFraction tupletQuantValue;
ReducedFraction regularQuantValue;
ReducedFraction tupletQuant;
ReducedFraction regularQuant;
// <note index in tuplet, chord iterator>
std::map<int, std::multimap<ReducedFraction, MidiChord>::iterator> chords;
ReducedFraction tupletSumError;

View file

@ -498,8 +498,8 @@ void TestImportMidi::findTupletApproximation()
QCOMPARE(tupletApprox.onTime, startTupletTime);
QCOMPARE(tupletApprox.len, tupletLen);
QCOMPARE(tupletApprox.tupletNumber, tupletNumber);
QCOMPARE(tupletApprox.tupletQuantValue, ReducedFraction::fromTicks(MScore::division) / 3);
QCOMPARE(tupletApprox.regularQuantValue, quantValue);
QCOMPARE(tupletApprox.tupletQuant, ReducedFraction::fromTicks(MScore::division) / 3);
QCOMPARE(tupletApprox.regularQuant, quantValue);
QVERIFY(tupletApprox.chords.size() == 3);
QCOMPARE(tupletApprox.tupletSumError, ReducedFraction::fromTicks(0));
QCOMPARE(tupletApprox.regularSumError, ReducedFraction::fromTicks(80));