Skip to content

Commit 7b0cb74

Browse files
committed
fix: replace hardcoded octave interval with dynamic temperament value
1 parent 275db03 commit 7b0cb74

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

js/turtle-singer.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@
4242

4343
/* exported Singer */
4444

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+
4571
/**
4672
* Class pertaining to music related actions for each turtle.
4773
*
@@ -1012,8 +1038,7 @@ class Singer {
10121038
noteObj = getNote(
10131039
anote,
10141040
octave,
1015-
// FIXME: should not be hardwired to 12
1016-
atrans + tur.singer.register * 12,
1041+
atrans + tur.singer.register * getOctaveInterval(activity),
10171042
tur.singer.keySignature,
10181043
tur.singer.movable,
10191044
direction,
@@ -1226,8 +1251,7 @@ class Singer {
12261251
const noteObj = getNote(
12271252
note,
12281253
octave,
1229-
// FIXME: should not be hardwired to 12
1230-
transposition + tur.singer.register * 12,
1254+
transposition + tur.singer.register * getOctaveInterval(activity),
12311255
tur.singer.keySignature,
12321256
tur.singer.movable,
12331257
direction,

0 commit comments

Comments
 (0)