Merge pull request #658 from jpcima/tuning-load-fail

Load equal temperament if scl loading fails
This commit is contained in:
JP Cimalando 2021-02-23 20:11:46 +01:00 committed by GitHub
commit 419d8fcfb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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