Convert a single line of a Scala scale file to a frequency relative to 1/1.
| 104 | |
| 105 | // Convert a single line of a Scala scale file to a frequency relative to 1/1. |
| 106 | static double |
| 107 | parseScalaLine(const std::string & line) |
| 108 | { |
| 109 | std::istringstream iss(line); |
| 110 | if (line.find('.') == std::string::npos) |
| 111 | { // treat as ratio |
| 112 | long n, d; |
| 113 | char slash; |
| 114 | iss >> n >> slash >> d; |
| 115 | if (iss.fail() || slash != '/' || n <= 0 || d <= 0) |
| 116 | { |
| 117 | return -1; |
| 118 | } |
| 119 | return (double) n / d; |
| 120 | } |
| 121 | else |
| 122 | { // treat as cents |
| 123 | double cents; |
| 124 | iss >> cents; |
| 125 | if (iss.fail()) |
| 126 | { |
| 127 | return -1; |
| 128 | } |
| 129 | return pow(2., cents/1200.); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | int |
| 134 | TuningMap::loadScale (const std::string & filename) |