convert enum TransposeDirection and TransposeMode into enum class

This commit is contained in:
Joachim Schmitz 2014-05-27 08:58:31 +02:00
parent 38f8ca1bf2
commit e41f26e3c7
5 changed files with 35 additions and 35 deletions

View file

@ -177,16 +177,16 @@ enum class BeamMode : signed char {
// TransposeDirection // TransposeDirection
//--------------------------------------------------------- //---------------------------------------------------------
enum TransposeDirection { enum class TransposeDirection : char {
TRANSPOSE_UP, TRANSPOSE_DOWN, TRANSPOSE_CLOSEST UP, DOWN, CLOSEST
}; };
//--------------------------------------------------------- //---------------------------------------------------------
// TransposeMode // TransposeMode
//--------------------------------------------------------- //---------------------------------------------------------
enum TransposeMode { enum class TransposeMode : char {
TRANSPOSE_BY_KEY, TRANSPOSE_BY_INTERVAL, TRANSPOSE_DIATONICALLY BY_KEY, BY_INTERVAL, DIATONICALLY
}; };
//--------------------------------------------------------- //---------------------------------------------------------

View file

@ -889,7 +889,7 @@ class Score : public QObject {
const QList<Layer>& layer() const { return _layer; } const QList<Layer>& layer() const { return _layer; }
bool tagIsValid(uint tag) const { return tag & _layer[_currentLayer].tags; } bool tagIsValid(uint tag) const { return tag & _layer[_currentLayer].tags; }
void transpose(int mode, TransposeDirection, int transposeKey, int transposeInterval, void transpose(TransposeMode mode, TransposeDirection, int transposeKey, int transposeInterval,
bool trKeys, bool transposeChordNames, bool useDoubleSharpsFlats); bool trKeys, bool transposeChordNames, bool useDoubleSharpsFlats);
void addViewer(MuseScoreView* v) { viewer.append(v); } void addViewer(MuseScoreView* v) { viewer.append(v); }
void removeViewer(MuseScoreView* v) { viewer.removeAll(v); } void removeViewer(MuseScoreView* v) { viewer.removeAll(v); }

View file

@ -52,10 +52,10 @@ static Interval keydiff2Interval(int oKey, int nKey, TransposeDirection dir)
int chromatic = (cofSteps * 7) % 12; int chromatic = (cofSteps * 7) % 12;
if ((dir == TRANSPOSE_CLOSEST) && (chromatic > 6)) if ((dir == TransposeDirection::CLOSEST) && (chromatic > 6))
dir = TRANSPOSE_DOWN; dir = TransposeDirection::DOWN;
if (dir == TRANSPOSE_DOWN) { if (dir == TransposeDirection::DOWN) {
chromatic = chromatic - 12; chromatic = chromatic - 12;
diatonic = diatonic - 7; diatonic = diatonic - 7;
if (diatonic == -7) if (diatonic == -7)
@ -262,7 +262,7 @@ void Score::transpose(Note* n, Interval interval, bool useDoubleSharpsFlats)
// transpose // transpose
//--------------------------------------------------------- //---------------------------------------------------------
void Score::transpose(int mode, TransposeDirection direction, int transposeKey, void Score::transpose(TransposeMode mode, TransposeDirection direction, int transposeKey,
int transposeInterval, bool trKeys, bool transposeChordNames, bool useDoubleSharpsFlats) int transposeInterval, bool trKeys, bool transposeChordNames, bool useDoubleSharpsFlats)
{ {
bool rangeSelection = selection().state() == SelState::RANGE; bool rangeSelection = selection().state() == SelState::RANGE;
@ -275,15 +275,15 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
KeyList* km = staff(startStaffIdx)->keymap(); KeyList* km = staff(startStaffIdx)->keymap();
Interval interval; Interval interval;
if (mode != TRANSPOSE_DIATONICALLY) { if (mode != TransposeMode::DIATONICALLY) {
if (mode == TRANSPOSE_BY_KEY) { if (mode == TransposeMode::BY_KEY) {
// calculate interval from "transpose by key" // calculate interval from "transpose by key"
int oKey = km->key(startTick).accidentalType(); int oKey = km->key(startTick).accidentalType();
interval = keydiff2Interval(oKey, transposeKey, direction); interval = keydiff2Interval(oKey, transposeKey, direction);
} }
else { else {
interval = intervalList[transposeInterval]; interval = intervalList[transposeInterval];
if (direction == TRANSPOSE_DOWN) if (direction == TransposeDirection::DOWN)
interval.flip(); interval.flip();
} }
@ -291,13 +291,13 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
trKeys = false; trKeys = false;
} }
bool fullOctave = (interval.chromatic % 12) == 0; bool fullOctave = (interval.chromatic % 12) == 0;
if (fullOctave && (mode != TRANSPOSE_BY_KEY)) { if (fullOctave && (mode != TransposeMode::BY_KEY)) {
trKeys = false; trKeys = false;
transposeChordNames = false; transposeChordNames = false;
} }
} }
else // diatonic transposition else // diatonic transposition
if (direction == TRANSPOSE_DOWN) if (direction == TransposeDirection::DOWN)
transposeInterval *= -1; transposeInterval *= -1;
if (_selection.state() == SelState::LIST) { if (_selection.state() == SelState::LIST) {
@ -306,7 +306,7 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
continue; continue;
if (e->type() == Element::ElementType::NOTE) { if (e->type() == Element::ElementType::NOTE) {
Note* note = static_cast<Note*>(e); Note* note = static_cast<Note*>(e);
if (mode == TRANSPOSE_DIATONICALLY) if (mode == TransposeMode::DIATONICALLY)
note->transposeDiatonic(transposeInterval, trKeys, useDoubleSharpsFlats); note->transposeDiatonic(transposeInterval, trKeys, useDoubleSharpsFlats);
else else
transpose(note, interval, useDoubleSharpsFlats); transpose(note, interval, useDoubleSharpsFlats);
@ -314,7 +314,7 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
else if ((e->type() == Element::ElementType::HARMONY) && transposeChordNames) { else if ((e->type() == Element::ElementType::HARMONY) && transposeChordNames) {
Harmony* h = static_cast<Harmony*>(e); Harmony* h = static_cast<Harmony*>(e);
int rootTpc, baseTpc; int rootTpc, baseTpc;
if (mode == TRANSPOSE_DIATONICALLY) { if (mode == TransposeMode::DIATONICALLY) {
int tick = 0; int tick = 0;
if (h->parent()->type() == Element::ElementType::SEGMENT) if (h->parent()->type() == Element::ElementType::SEGMENT)
tick = static_cast<Segment*>(h->parent())->tick(); tick = static_cast<Segment*>(h->parent())->tick();
@ -334,7 +334,7 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
} }
undoTransposeHarmony(h, rootTpc, baseTpc); undoTransposeHarmony(h, rootTpc, baseTpc);
} }
else if ((e->type() == Element::ElementType::KEYSIG) && mode != TRANSPOSE_DIATONICALLY && trKeys) { else if ((e->type() == Element::ElementType::KEYSIG) && mode != TransposeMode::DIATONICALLY && trKeys) {
KeySig* ks = static_cast<KeySig*>(e); KeySig* ks = static_cast<KeySig*>(e);
KeySigEvent key = km->key(ks->tick()); KeySigEvent key = km->key(ks->tick());
KeySigEvent okey = km->key(ks->tick() - 1); KeySigEvent okey = km->key(ks->tick() - 1);
@ -384,14 +384,14 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
Chord* chord = static_cast<Chord*>(e); Chord* chord = static_cast<Chord*>(e);
QList<Note*> nl = chord->notes(); QList<Note*> nl = chord->notes();
for (Note* n : nl) { for (Note* n : nl) {
if (mode == TRANSPOSE_DIATONICALLY) if (mode == TransposeMode::DIATONICALLY)
n->transposeDiatonic(transposeInterval, trKeys, useDoubleSharpsFlats); n->transposeDiatonic(transposeInterval, trKeys, useDoubleSharpsFlats);
else else
transpose(n, interval, useDoubleSharpsFlats); transpose(n, interval, useDoubleSharpsFlats);
} }
for (Chord* g : chord->graceNotes()) { for (Chord* g : chord->graceNotes()) {
for (Note* n : g->notes()) { for (Note* n : g->notes()) {
if (mode == TRANSPOSE_DIATONICALLY) if (mode == TransposeMode::DIATONICALLY)
n->transposeDiatonic(transposeInterval, trKeys, useDoubleSharpsFlats); n->transposeDiatonic(transposeInterval, trKeys, useDoubleSharpsFlats);
else else
transpose(n, interval, useDoubleSharpsFlats); transpose(n, interval, useDoubleSharpsFlats);
@ -404,7 +404,7 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
continue; continue;
Harmony* h = static_cast<Harmony*>(e); Harmony* h = static_cast<Harmony*>(e);
int rootTpc, baseTpc; int rootTpc, baseTpc;
if (mode == TRANSPOSE_DIATONICALLY) { if (mode == TransposeMode::DIATONICALLY) {
int tick = segment->tick(); int tick = segment->tick();
int key = !h->staff() ? Key::KEY_C : h->staff()->keymap()->key(tick).accidentalType(); int key = !h->staff() ? Key::KEY_C : h->staff()->keymap()->key(tick).accidentalType();
rootTpc = transposeTpcDiatonicByKey(h->rootTpc(), rootTpc = transposeTpcDiatonicByKey(h->rootTpc(),
@ -420,7 +420,7 @@ void Score::transpose(int mode, TransposeDirection direction, int transposeKey,
} }
} }
} }
if (trKeys && mode != TRANSPOSE_DIATONICALLY) { if (trKeys && mode != TransposeMode::DIATONICALLY) {
transposeKeys(_selection.staffStart(), _selection.staffEnd(), transposeKeys(_selection.staffStart(), _selection.staffEnd(),
_selection.tickStart(), _selection.tickEnd(), interval); _selection.tickStart(), _selection.tickEnd(), interval);
} }
@ -480,7 +480,7 @@ void Score::transposeSemitone(int step)
if (step < -1) if (step < -1)
step = -1; step = -1;
TransposeDirection dir = step > 0 ? TRANSPOSE_UP : TRANSPOSE_DOWN; TransposeDirection dir = step > 0 ? TransposeDirection::UP : TransposeDirection::DOWN;
KeyList* km = staff(0)->keymap(); KeyList* km = staff(0)->keymap();
@ -510,7 +510,7 @@ void Score::transposeSemitone(int step)
cmdSelectAll(); cmdSelectAll();
startCmd(); startCmd();
transpose(TRANSPOSE_BY_INTERVAL, dir, 0, interval, true, true, false); transpose(TransposeMode::BY_INTERVAL, dir, 0, interval, true, true, false);
deselectAll(); deselectAll();
setLayoutAll(true); setLayoutAll(true);
endCmd(); endCmd();

View file

@ -76,8 +76,8 @@ void TransposeDialog::transposeByIntervalToggled(bool val)
TransposeMode TransposeDialog::mode() const TransposeMode TransposeDialog::mode() const
{ {
return chromaticBox->isChecked() return chromaticBox->isChecked()
? (transposeByKey->isChecked() ? TRANSPOSE_BY_KEY : TRANSPOSE_BY_INTERVAL) ? (transposeByKey->isChecked() ? TransposeMode::BY_KEY : TransposeMode::BY_INTERVAL)
: TRANSPOSE_DIATONICALLY; : TransposeMode::DIATONICALLY;
} }
//--------------------------------------------------------- //---------------------------------------------------------
@ -99,16 +99,16 @@ TransposeDirection TransposeDialog::direction() const
{ {
switch(mode()) switch(mode())
{ {
case TRANSPOSE_BY_KEY: case TransposeMode::BY_KEY:
if (closestKey->isChecked()) if (closestKey->isChecked())
return TRANSPOSE_CLOSEST; return TransposeDirection::CLOSEST;
return upKey->isChecked() ? TRANSPOSE_UP : TRANSPOSE_DOWN; return upKey->isChecked() ? TransposeDirection::UP : TransposeDirection::DOWN;
case TRANSPOSE_BY_INTERVAL: case TransposeMode::BY_INTERVAL:
return upInterval->isChecked() ? TRANSPOSE_UP : TRANSPOSE_DOWN; return upInterval->isChecked() ? TransposeDirection::UP : TransposeDirection::DOWN;
case TRANSPOSE_DIATONICALLY: case TransposeMode::DIATONICALLY:
return upDiatonic->isChecked() ? TRANSPOSE_UP : TRANSPOSE_DOWN; return upDiatonic->isChecked() ? TransposeDirection::UP : TransposeDirection::DOWN;
} }
return TRANSPOSE_UP; return TransposeDirection::UP;
} }

View file

@ -62,7 +62,7 @@ void TestTranspose::undoTranspose()
// transpose major second up // transpose major second up
score->startCmd(); score->startCmd();
score->transpose(TRANSPOSE_BY_INTERVAL, TRANSPOSE_UP, 0, 4, score->transpose(TransposeMode::INTERVAL, TransposeDirection::UP, 0, 4,
true, true, true); true, true, true);
score->endCmd(); score->endCmd();
QVERIFY(saveCompareScore(score, writeFile1, reference1)); QVERIFY(saveCompareScore(score, writeFile1, reference1));
@ -89,7 +89,7 @@ void TestTranspose::undoDiatonicTranspose()
// transpose diatonic fourth down // transpose diatonic fourth down
score->startCmd(); score->startCmd();
score->transpose(TRANSPOSE_DIATONICALLY, TRANSPOSE_DOWN, 0, 3, score->transpose(TransposeMode::DIATONICALLY, TransposeDirection::DOWN, 0, 3,
true, false, false); true, false, false);
score->endCmd(); score->endCmd();
QVERIFY(saveCompareScore(score, writeFile1, reference1)); QVERIFY(saveCompareScore(score, writeFile1, reference1));