|
42 | 42 |
|
43 | 43 | /* exported Singer */ |
44 | 44 |
|
| 45 | +/** |
| 46 | + * Gets the number of pitch intervals per octave for the current temperament. |
| 47 | + * Defaults to 12 (standard Western tuning) if temperament is not set or not found. |
| 48 | + * @param {Object} activity - The activity object containing synth information. |
| 49 | + * @returns {number} The number of intervals per octave. |
| 50 | + */ |
| 51 | +const getOctaveInterval = activity => { |
| 52 | + try { |
| 53 | + if (!activity?.logo?.synth) { |
| 54 | + return 12; |
| 55 | + } |
| 56 | + const temperamentName = activity.logo.synth.inTemperament; |
| 57 | + if (!temperamentName) { |
| 58 | + return 12; |
| 59 | + } |
| 60 | + const temperament = getTemperament(temperamentName); |
| 61 | + if (temperament && typeof temperament.pitchNumber === "number") { |
| 62 | + return temperament.pitchNumber; |
| 63 | + } |
| 64 | + return 12; |
| 65 | + } catch (e) { |
| 66 | + console.warn("getOctaveInterval: Error getting temperament, using default 12", e); |
| 67 | + return 12; |
| 68 | + } |
| 69 | +}; |
| 70 | + |
45 | 71 | /** |
46 | 72 | * Class pertaining to music related actions for each turtle. |
47 | 73 | * |
@@ -1012,8 +1038,7 @@ class Singer { |
1012 | 1038 | noteObj = getNote( |
1013 | 1039 | anote, |
1014 | 1040 | octave, |
1015 | | - // FIXME: should not be hardwired to 12 |
1016 | | - atrans + tur.singer.register * 12, |
| 1041 | + atrans + tur.singer.register * getOctaveInterval(activity), |
1017 | 1042 | tur.singer.keySignature, |
1018 | 1043 | tur.singer.movable, |
1019 | 1044 | direction, |
@@ -1226,8 +1251,7 @@ class Singer { |
1226 | 1251 | const noteObj = getNote( |
1227 | 1252 | note, |
1228 | 1253 | octave, |
1229 | | - // FIXME: should not be hardwired to 12 |
1230 | | - transposition + tur.singer.register * 12, |
| 1254 | + transposition + tur.singer.register * getOctaveInterval(activity), |
1231 | 1255 | tur.singer.keySignature, |
1232 | 1256 | tur.singer.movable, |
1233 | 1257 | direction, |
|
0 commit comments