Skip to content

Commit

Permalink
fix regression with pitch class
Browse files Browse the repository at this point in the history
  • Loading branch information
walterbender committed May 29, 2021
1 parent 48f92b2 commit 7b12621
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 33 deletions.
13 changes: 11 additions & 2 deletions js/blocks/PitchBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
INVALIDPITCH, pitchToNumber, LeftBlock, SHARP, FLAT, DOUBLEFLAT,
DOUBLESHARP, NATURAL, FIXEDSOLFEGE, SOLFEGENAMES, SOLFEGENAMES1,
NOTENAMES, NOTENAMES1, getPitchInfo, YSTAFFOCTAVEHEIGHT,
YSTAFFNOTEHEIGHT, MUSICALMODES, keySignatureToMode,
YSTAFFNOTEHEIGHT, MUSICALMODES, keySignatureToMode, ALLNOTENAMES,
nthDegreeToPitch, A0, C8, calcOctave, SOLFEGECONVERSIONTABLE,
NOTESFLAT, NOTESSHARP, NOTESTEP, scaleDegreeToPitchMapping
*/
Expand Down Expand Up @@ -546,7 +546,16 @@ function setupPitchBlocks(activity) {
} else {
notePlayed += foundOctave;
}
} else if (NOTENAMES.indexOf(arg1) !== -1) {
} else if (NOTENAMES1.indexOf(arg1) !== -1) {
if (foundOctave.length === 0) {
notePlayed =
arg1 +
(tur.singer.currentOctave ? tur.singer.currentOctave : 4);
} else {
notePlayed = arg1 + foundOctave;
}
} else if (ALLNOTENAMES.indexOf(arg1) !== -1) {
// Why would the accidental be "b or #"?
if (foundOctave.length === 0) {
notePlayed =
arg1 +
Expand Down
95 changes: 64 additions & 31 deletions js/utils/musicutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
/*
exported
SYNTHSVG, RSYMBOLS, NOTENAMES, NOTENAMES1, WESTERN2EISOLFEGENAMES,
PITCHES1, PITCHES3, SCALENOTES, EASTINDIANSOLFNOTES, DRUMS,
GRAPHICS, SOLFATTRS, DEGREES, RHYTHMRULERHEIGHT, SLIDERHEIGHT,
SLIDERWIDTH, MATRIXLABELCOLOR, MATRIXNOTECELLCOLOR,
MATRIXTUPLETCELLCOLOR, MATRIXRHYTHMCELLCOLOR,
SYNTHSVG, RSYMBOLS, NOTENAMES, ALLNOTENAMES, NOTENAMES1,
WESTERN2EISOLFEGENAMES, PITCHES1, PITCHES3, SCALENOTES,
EASTINDIANSOLFNOTES, DRUMS, GRAPHICS, SOLFATTRS, DEGREES,
RHYTHMRULERHEIGHT, SLIDERHEIGHT, SLIDERWIDTH, MATRIXLABELCOLOR,
MATRIXNOTECELLCOLOR, MATRIXTUPLETCELLCOLOR, MATRIXRHYTHMCELLCOLOR,
MATRIXBUTTONCOLORHOVER, MATRIXNOTECELLCOLORHOVER, MATRIXSOLFEWIDTH,
EIGHTHNOTEWIDTH, MATRIXBUTTONHEIGHT, MATRIXBUTTONHEIGHT2,
MATRIXSOLFEHEIGHT, NOTESYMBOLS, SELECTORSTRINGS, ACCIDENTALLABELS,
Expand Down Expand Up @@ -228,6 +228,43 @@ const SOLFEGENAMES1 = [
"ti"
];
const NOTENAMES = ["C", "D", "E", "F", "G", "A", "B"];
const ALLNOTENAMES = [
"C",
"C#",
"Cx",
"Dbb",
"Db",
"D",
"D#",
"Dx",
"Ebb",
"Eb",
"E",
"E#",
"Ex",
"Fbb",
"Fb",
"F",
"F#",
"Fx",
"Gbb",
"Gb",
"G",
"G#",
"Gx",
"Abb",
"Ab",
"A",
"A#",
"Ax",
"Bbb",
"Bb",
"B",
"B#",
"Bx",
"Cbb",
"Cb"
];
const NOTENAMES1 = [
"C",
"C" + SHARP,
Expand Down Expand Up @@ -1200,20 +1237,20 @@ const TEMPERAMENT = {
]
},
"custom": {
"0": Math.pow(2, 0 / 12),
"1": Math.pow(2, 1 / 12),
"2": Math.pow(2, 2 / 12),
"3": Math.pow(2, 3 / 12),
"4": Math.pow(2, 4 / 12),
"5": Math.pow(2, 5 / 12),
"6": Math.pow(2, 6 / 12),
"7": Math.pow(2, 7 / 12),
"8": Math.pow(2, 8 / 12),
"9": Math.pow(2, 9 / 12),
"10": Math.pow(2, 10 / 12),
"11": Math.pow(2, 11 / 12),
"pitchNumber": 12,
"interval": [
0: Math.pow(2, 0 / 12),
1: Math.pow(2, 1 / 12),
2: Math.pow(2, 2 / 12),
3: Math.pow(2, 3 / 12),
4: Math.pow(2, 4 / 12),
5: Math.pow(2, 5 / 12),
6: Math.pow(2, 6 / 12),
7: Math.pow(2, 7 / 12),
8: Math.pow(2, 8 / 12),
9: Math.pow(2, 9 / 12),
10: Math.pow(2, 10 / 12),
11: Math.pow(2, 11 / 12),
pitchNumber: 12,
interval: [
"perfect 1",
"minor 2",
"major 2",
Expand All @@ -1235,22 +1272,18 @@ const setOctaveRatio = (newOctaveRatio) => {
octaveRatio = newOctaveRatio;
};


const getOctaveRatio = () => {
return octaveRatio;
};


const getTemperamentsList = () => {
return TEMPERAMENTS;
};


const getTemperament = (entry) => {
return TEMPERAMENT[entry];
};


const getTemperamentKeys = () => {
const keys = [];
for (const k in TEMPERAMENT) {
Expand All @@ -1260,7 +1293,6 @@ const getTemperamentKeys = () => {
return keys;
};


const addTemperamentToList = (newEntry) => {
for (let i = 0; i < TEMPERAMENTS.length; i++) {
if (PreDefinedTemperaments[i] === newEntry) {
Expand All @@ -1270,17 +1302,14 @@ const addTemperamentToList = (newEntry) => {
TEMPERAMENTS.push(newEntry);
};


const deleteTemperamentFromList = (oldEntry) => {
delete TEMPERAMENT[oldEntry];
};


const addTemperamentToDictionary = (entryName, entryValue) => {
TEMPERAMENT[entryName] = entryValue;
};


const updateTemperaments = () => {
TEMPERAMENTS = [...INITIALTEMPERAMENTS];
for (const i in TEMPERAMENT) {
Expand Down Expand Up @@ -2974,14 +3003,14 @@ function getNote(
for (const number in TEMPERAMENT[temperament]) {
if (number !== "pitchNumber") {
if (note === TEMPERAMENT[temperament][number][3]) {
if (typeof(number) === "string") {
if (typeof number === "string") {
pitchNumber = Number(number);
} else {
pitchNumber = number;
}
break;
} else if (note === TEMPERAMENT[temperament][number][1]) {
if (typeof(number) === "string") {
if (typeof number === "string") {
pitchNumber = Number(number);
} else {
pitchNumber = number;
Expand Down Expand Up @@ -4237,7 +4266,8 @@ function getPitchInfo(activity, type, notePlayed, tur) {
if (tur.singer.moveable === false) return SOLFEGECONVERSIONTABLE[np];
return SOLFEGENAMES[buildScale(tur.singer.keySignature)[0].indexOf(np)];
case "pitch class":
if (Number(np)) {
// If it is a frequency, convert it to a pitch/octave.
if (!isNaN(Number(np))) {
np = frequencyToPitch(np)[0] + frequencyToPitch(np)[1];
}
return (
Expand Down Expand Up @@ -4303,7 +4333,10 @@ function getPitchInfo(activity, type, notePlayed, tur) {
case "pitch number":
return _calculate_pitch_number(activity, np, tur);
case "pitch in hertz":
return activity.logo.synth._getFrequency(np, activity.logo.synth.changeInTemperament);
return activity.logo.synth._getFrequency(
np,
activity.logo.synth.changeInTemperament
);
case "pitch to color":
if (Number(np)) {
[np, octave] = frequencyToPitch(np);
Expand Down

0 comments on commit 7b12621

Please sign in to comment.