From 54c06d846f0a94ba150684789b8a815d0c84eaa8 Mon Sep 17 00:00:00 2001 From: David Lowndes Date: Tue, 19 Nov 2024 18:39:23 +0000 Subject: [PATCH 1/2] Find single characters rather than single character strings. Remove unused variable. --- include/TuningsImpl.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/TuningsImpl.h b/include/TuningsImpl.h index 5473e05..bf02137 100644 --- a/include/TuningsImpl.h +++ b/include/TuningsImpl.h @@ -29,7 +29,6 @@ inline std::istream &getlineEndingIndependent(std::istream &is, std::string &t) { t.clear(); - std::istream::sentry se(is, true); std::streambuf *sb = is.rdbuf(); for (;;) @@ -72,7 +71,7 @@ inline Tone toneFromString(const std::string &line, int lineno) Tone t; t.stringRep = line; t.lineno = lineno; - if (line.find(".") != std::string::npos) + if (line.find('.') != std::string::npos) { t.type = Tone::kToneCents; t.cents = locale_atof(line.c_str()); @@ -80,7 +79,7 @@ inline Tone toneFromString(const std::string &line, int lineno) else { t.type = Tone::kToneRatio; - auto slashPos = line.find("/"); + auto slashPos = line.find('/'); if (slashPos == std::string::npos) { t.ratio_n = atoll(line.c_str()); From 90c32e311da3d798cfb47ede1439557eb9a52410 Mon Sep 17 00:00:00 2001 From: David Lowndes Date: Wed, 20 Nov 2024 18:13:12 +0000 Subject: [PATCH 2/2] Revise the use of the sentry. Minor changes to Tuning::Tuning: Use actual type rather than auto because modern tools will warn that the auto probably ought to be a reference, but in this case a copy is clearly needed. Move pitches array closer to usage. --- include/TuningsImpl.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/TuningsImpl.h b/include/TuningsImpl.h index bf02137..44c9221 100644 --- a/include/TuningsImpl.h +++ b/include/TuningsImpl.h @@ -29,6 +29,10 @@ inline std::istream &getlineEndingIndependent(std::istream &is, std::string &t) { t.clear(); + std::istream::sentry se(is, true); + if (!se) + return is; + std::streambuf *sb = is.rdbuf(); for (;;) @@ -507,7 +511,7 @@ inline Tuning::Tuning(const Scale &s_, const KeyboardMapping &k_, bool allowTuni { for (const auto &t : s.tones) { - auto tCopy = t; + Tunings::Tone tCopy = t; tCopy.type = Tone::kToneCents; tCopy.cents += pushOff; tCopy.floatValue = tCopy.cents / 1200.0 + 1; @@ -530,8 +534,6 @@ inline Tuning::Tuning(const Scale &s_, const KeyboardMapping &k_, bool allowTuni " to smaller scale of size " + std::to_string(s.count)); } - double pitches[N]; - int posPitch0 = 256 + k.tuningConstantNote; int posScale0 = 256 + useMiddleNote; @@ -632,6 +634,8 @@ inline Tuning::Tuning(const Scale &s_, const KeyboardMapping &k_, bool allowTuni } } + double pitches[N]; + for (int i = 0; i < N; ++i) { // TODO: ScaleCenter and PitchCenter are now two different notes.