| 122 | ]); |
| 123 | |
| 124 | public static parseTuning(name: string): TuningParseResult | null { |
| 125 | let note: string = ''; |
| 126 | let octave: string = ''; |
| 127 | for (let i: number = 0; i < name.length; i++) { |
| 128 | const c: number = name.charCodeAt(i); |
| 129 | if (c >= 0x30 && c <= 0x39 /* 0-9 */) { |
| 130 | // number without note? |
| 131 | if (!note) { |
| 132 | return null; |
| 133 | } |
| 134 | octave += String.fromCharCode(c); |
| 135 | } else if (note.length === 0) { |
| 136 | if (ModelUtils.tuningLetters.has(c)) { |
| 137 | note += String.fromCharCode(c); |
| 138 | } else { |
| 139 | return null; |
| 140 | } |
| 141 | } else { |
| 142 | note += String.fromCharCode(c); |
| 143 | } |
| 144 | } |
| 145 | if (!octave || !note) { |
| 146 | return null; |
| 147 | } |
| 148 | |
| 149 | const result: TuningParseResult = new TuningParseResult(); |
| 150 | |
| 151 | result.octave = Number.parseInt(octave, 10) + 1; |
| 152 | result.note = note.toLowerCase(); |
| 153 | const tone = ModelUtils.getToneForText(result.note); |
| 154 | if (tone === null) { |
| 155 | return null; |
| 156 | } |
| 157 | result.tone = tone; |
| 158 | |
| 159 | // if tone.noteValue is negative (eg. on Cb note) |
| 160 | // we adjust roll-over to a lower octave |
| 161 | if (result.tone.noteValue < 0) { |
| 162 | result.octave--; |
| 163 | result.tone.noteValue += 12; |
| 164 | } |
| 165 | |
| 166 | return result; |
| 167 | } |
| 168 | |
| 169 | public static getTuningForText(str: string): number { |
| 170 | const result: TuningParseResult | null = ModelUtils.parseTuning(str); |