Load equal temperament if scl loading fails

This commit is contained in:
Jean Pierre Cimalando 2021-02-23 20:02:11 +01:00
parent 6dbdd1bb14
commit 45bab7289f

View file

@ -162,50 +162,59 @@ Tuning::~Tuning()
bool Tuning::loadScalaFile(const fs::path& path) bool Tuning::loadScalaFile(const fs::path& path)
{ {
Tunings::Scale scl;
fs::ifstream stream(path); fs::ifstream stream(path);
if (stream.bad()) { if (stream.bad()) {
DBG("Cannot open scale file: " << path); DBG("Cannot open scale file: " << path);
return false; goto failure;
} }
Tunings::Scale scl;
try { try {
scl = Tunings::readSCLStream(stream); scl = Tunings::readSCLStream(stream);
} }
catch (Tunings::TuningError& error) { catch (Tunings::TuningError& error) {
DBG("Tuning: " << error.what()); DBG("Tuning: " << error.what());
return false; goto failure;
} }
if (scl.count <= 0) { if (scl.count <= 0) {
DBG("The scale file is empty: " << path); DBG("The scale file is empty: " << path);
return false; goto failure;
} }
impl_->updateScale(scl, path); impl_->updateScale(scl, path);
return true; return true;
failure:
loadEqualTemperamentScale();
return false;
} }
bool Tuning::loadScalaString(const std::string& text) bool Tuning::loadScalaString(const std::string& text)
{ {
Tunings::Scale scl;
std::istringstream stream(text); std::istringstream stream(text);
Tunings::Scale scl;
try { try {
scl = Tunings::readSCLStream(stream); scl = Tunings::readSCLStream(stream);
} }
catch (Tunings::TuningError& error) { catch (Tunings::TuningError& error) {
DBG("Tuning: " << error.what()); DBG("Tuning: " << error.what());
return false; goto failure;
} }
if (scl.count <= 0) { if (scl.count <= 0) {
DBG("Error loading scala string: " << text); DBG("Error loading scala string: " << text);
return false; goto failure;
} }
impl_->updateScale(scl); impl_->updateScale(scl);
return true; return true;
failure:
loadEqualTemperamentScale();
return false;
} }
void Tuning::setScalaRootKey(int rootKey) void Tuning::setScalaRootKey(int rootKey)