Browse Source

Bug in Scales.h

master
Joshua Moerman 12 years ago
parent
commit
092045a2c2
  1. 9
      Scales.h

9
Scales.h

@ -14,6 +14,7 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <stdexcept> #include <stdexcept>
#include <cassert>
// http://www.phys.unsw.edu.au/jw/notes.html // http://www.phys.unsw.edu.au/jw/notes.html
@ -27,14 +28,20 @@ struct Scale {
std::vector<int> notes; std::vector<int> notes;
int note_for_length(float length){ int note_for_length(float length){
assert(notes.size() > 1);
// determine note // determine note
length /= 200.0; length /= 200.0;
float note = -std::log(length) / std::log(2.0f) * 12.0f + 69.0f; float note = -std::log(length) / std::log(2.0f) * 12.0f + 69.0f;
// determine note in scale // determine note in scale
auto it = notes.begin(); auto it = notes.begin();
while(*it < note && it != notes.end()){ while(*it < note){
++it; ++it;
if(it == notes.end()) {
--it;
break;
}
} }
// determine closest note in scale // determine closest note in scale