Skip to content

Commit

Permalink
Fix #141 - Track whether the tuning matches one of the presets.
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronwhite committed Dec 27, 2014
1 parent b8c8185 commit e3d22f3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
27 changes: 22 additions & 5 deletions source/dialogs/tuningdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ TuningDialog::TuningDialog(QWidget *parent, const Tuning &currentTuning,
connect(ui->sharpsCheckBox, SIGNAL(toggled(bool)), this,
SLOT(toggleSharps(bool)));
connect(ui->sharpsCheckBox, SIGNAL(clicked(bool)), this,
SLOT(invalidatePreset()));
SLOT(updateCurrentPreset()));

ui->capoSpinBox->setMinimum(Tuning::MIN_CAPO);
ui->capoSpinBox->setMaximum(Tuning::MAX_CAPO);
ui->capoSpinBox->setValue(currentTuning.getCapo());
connect(ui->capoSpinBox, SIGNAL(valueChanged(int)), this,
SLOT(invalidatePreset()));
SLOT(updateCurrentPreset()));

ui->notationOffsetSpinBox->setMinimum(Tuning::MIN_MUSIC_NOTATION_OFFSET);
ui->notationOffsetSpinBox->setMaximum(Tuning::MAX_MUSIC_NOTATION_OFFSET);
ui->notationOffsetSpinBox->setValue(currentTuning.getMusicNotationOffset());
connect(ui->notationOffsetSpinBox, SIGNAL(valueChanged(int)), this,
SLOT(invalidatePreset()));
SLOT(updateCurrentPreset()));

ui->numStringsSpinBox->setMinimum(Tuning::MIN_STRING_COUNT);
ui->numStringsSpinBox->setMaximum(Tuning::MAX_STRING_COUNT);
Expand All @@ -73,7 +73,7 @@ TuningDialog::TuningDialog(QWidget *parent, const Tuning &currentTuning,
for (QComboBox *selector : myStringSelectors)
{
connect(selector, SIGNAL(activated(int)), this,
SLOT(invalidatePreset()));
SLOT(updateCurrentPreset()));
}

updateTuningDictionary(currentTuning.getStringCount());
Expand All @@ -83,6 +83,8 @@ TuningDialog::TuningDialog(QWidget *parent, const Tuning &currentTuning,

connect(ui->presetComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(loadPreset()));

updateCurrentPreset();
}

TuningDialog::~TuningDialog()
Expand Down Expand Up @@ -200,7 +202,22 @@ Tuning TuningDialog::getTuning() const
return newTuning;
}

void TuningDialog::invalidatePreset()
void TuningDialog::updateCurrentPreset()
{
const Tuning currentTuning = getTuning();

// Check if the current tuning matches one of the available presets.
for (int i = 0; i < ui->presetComboBox->count(); ++i)
{
auto tuning = ui->presetComboBox->itemData(i).value<const Tuning *>();

if (tuning->isSameTuning(currentTuning))
{
ui->presetComboBox->setCurrentIndex(i);
return;
}
}

// Otherwise, the tuning currently doesn't match any presets.
ui->presetComboBox->setCurrentIndex(-1);
}
2 changes: 1 addition & 1 deletion source/dialogs/tuningdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private slots:
void loadPreset();

/// Once a change is made to the tuning, update the preset combobox.
void invalidatePreset();
void updateCurrentPreset();

private:
Ui::TuningDialog *ui;
Expand Down
11 changes: 7 additions & 4 deletions source/score/tuning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ Tuning::Tuning()

bool Tuning::operator==(const Tuning &other) const
{
return myName == other.myName &&
myNotes == other.myNotes &&
return myName == other.myName && isSameTuning(other);
}

bool Tuning::isSameTuning(const Tuning &other) const
{
return myNotes == other.myNotes &&
myMusicNotationOffset == other.myMusicNotationOffset &&
myUsesSharps == other.myUsesSharps &&
myCapo == other.myCapo;
myUsesSharps == other.myUsesSharps && myCapo == other.myCapo;
}

const std::string &Tuning::getName() const
Expand Down
2 changes: 2 additions & 0 deletions source/score/tuning.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Tuning
Tuning();

bool operator==(const Tuning &other) const;
/// This is like operator==, but ignores the name of the tuning.
bool isSameTuning(const Tuning &other) const;

template <class Archive>
void serialize(Archive &ar, const FileVersion version);
Expand Down

0 comments on commit e3d22f3

Please sign in to comment.