Skip to content

Commit

Permalink
Merge pull request #4371 from Be-ing/qhashiterator_minus
Browse files Browse the repository at this point in the history
replace `- 1` with `std::prev` for QMap iterators
  • Loading branch information
uklotzde authored Oct 10, 2021
2 parents fbaafb4 + 82b8846 commit 2e8f321
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/controllers/learningutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ MidiInputMappings LearningUtils::guessMidiInputMappings(
// QMap keys are sorted so we can check this easily by checking the last key
// is <= 0x7F.
bool only_7bit_values = !stats.value_histogram.isEmpty() &&
(stats.value_histogram.end() - 1).key() <= 0x7F;
(std::prev(stats.value_histogram.end(), 1)).key() <= 0x7F;

// A 7-bit two's complement ticker swinging from +1 to -1 can generate
// unsigned differences of up to 126 (0x7E). If we see differences in
// individual messages above 96 (0x60) that's a good hint that we're looking
// at a two's complement ticker.
bool abs_differences_above_60 = !stats.abs_diff_histogram.isEmpty() &&
(stats.abs_diff_histogram.end() - 1).key() >= 0x60;
(std::prev(stats.abs_diff_histogram.end(), 1)).key() >= 0x60;

if (one_control && one_channel &&
two_values_7bit_max_and_min &&
Expand Down Expand Up @@ -268,9 +268,9 @@ MidiInputMappings LearningUtils::guessMidiInputMappings(
int control2 = *(++stats.controls.begin());

int control1_max_abs_diff =
(stats_by_control[control1].abs_diff_histogram.end() - 1).key();
(std::prev(stats_by_control[control1].abs_diff_histogram.end(), 1)).key();
int control2_max_abs_diff =
(stats_by_control[control2].abs_diff_histogram.end() - 1).key();
(std::prev(stats_by_control[control2].abs_diff_histogram.end(), 1)).key();

// The control with the larger abs difference in messages is the LSB. If
// they are equal we choose one arbitrarily (depends on QSet iteration
Expand Down

0 comments on commit 2e8f321

Please sign in to comment.