Skip to content

Commit 077c566

Browse files
author
Vanshika
committed
Merge upstream/master and resolve modify/delete conflict in tuner.test.js
2 parents aa4dd9a + 8214452 commit 077c566

File tree

15 files changed

+147
-2672
lines changed

15 files changed

+147
-2672
lines changed

.github/workflows/node.js.yml

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,38 @@
44
name: Smoke Test
55

66
on:
7-
push:
8-
branches: [master]
9-
pull_request:
10-
branches: [master]
7+
push:
8+
branches: [master]
9+
pull_request:
10+
branches: [master]
1111

1212
jobs:
13-
build:
14-
runs-on: ubuntu-latest
15-
16-
strategy:
17-
matrix:
18-
node-version: [18.x, 20.x]
19-
20-
steps:
21-
- name: Checkout code
22-
uses: actions/checkout@v4
23-
with:
24-
fetch-depth: 0
25-
26-
- name: Use Node.js ${{ matrix.node-version }}
27-
uses: actions/setup-node@v4
28-
with:
29-
node-version: ${{ matrix.node-version }}
30-
31-
- run: npm ci
32-
- run: npm run build --if-present
33-
34-
# Post-run cleanup to remove the build directory after the job finishes
35-
- name: Post-run cleanup
36-
if: always()
37-
run: rm -rf ./build
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [18.x, 20.x]
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Use Node.js ${{ matrix.node-version }}
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
cache: "npm"
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Build project
36+
run: npm run build --if-present
37+
38+
# Post-run cleanup to remove the build directory after the job finishes
39+
- name: Post-run cleanup
40+
if: always()
41+
run: rm -rf ./build

css/activities.css

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,12 +1051,12 @@ table {
10511051
}
10521052

10531053
#right-arrow {
1054-
left: 385px;
1054+
right: 25px;
10551055
background: url("../header-icons/right-arrow.png");
10561056
}
10571057

10581058
#left-arrow {
1059-
left: 5px;
1059+
left: 10px;
10601060
background: url("../header-icons/left-arrow.png");
10611061
}
10621062

@@ -1177,12 +1177,14 @@ table {
11771177

11781178
#helpBodyDiv {
11791179
position: relative;
1180-
left: 45px;
1180+
margin: 0 auto !important;
1181+
left: 0 !important;
11811182
border: 0 !important;
11821183
overflow-x: hidden;
11831184
overflow-y: auto;
1184-
width: 350px;
1185-
padding: 1rem 1rem 0 0;
1185+
width: calc(100% - 130px) !important;
1186+
max-width: 350px;
1187+
padding: 1rem 1rem 0 1rem;
11861188
display: flex;
11871189
flex-direction: column;
11881190
justify-content: center;
@@ -2107,7 +2109,7 @@ table {
21072109

21082110
#right-arrow {
21092111
left: auto !important; /* Unset the old fixed pixel value */
2110-
right: 10px !important; /* Stick to the right edge */
2112+
right: 25px !important; /* Stick to the right edge */
21112113
}
21122114

21132115
/* --- Desktop View (Screens wider than 900px) --- */
@@ -2138,7 +2140,8 @@ table {
21382140

21392141
/* Fix the inner text box width so it doesn't overflow */
21402142
#helpBodyDiv {
2141-
width: 100% !important;
2143+
width: calc(100% - 110px) !important;
2144+
margin: 0 auto !important;
21422145
left: 0 !important;
21432146
padding: 0 10px;
21442147
box-sizing: border-box;

js/activity.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
SPECIALINPUTS, STANDARDBLOCKHEIGHT, StatsWindow, STROKECOLORS,
3838
TENOR, TITLESTRING, Toolbar, Trashcan, TREBLE, Turtles, TURTLESVG,
3939
updatePluginObj, ZERODIVIDEERRORMSG, GRAND_G, GRAND_F,
40-
SHARP, FLAT, buildScale, TREBLE_F, TREBLE_G, GIFAnimator
40+
SHARP, FLAT, buildScale, TREBLE_F, TREBLE_G, GIFAnimator,
41+
MUSICALMODES
4142
*/
4243

4344
/*
@@ -6994,8 +6995,13 @@ class Activity {
69946995
// Load custom mode saved in local storage.
69956996
const custommodeData = this.storage.custommode;
69966997
if (custommodeData !== undefined) {
6997-
// FIX ME: customMode is loaded but not yet used
6998-
JSON.parse(custommodeData);
6998+
// Parse and update the custom musical mode with saved data.
6999+
try {
7000+
const customModeDataObj = JSON.parse(custommodeData);
7001+
Object.assign(MUSICALMODES["custom"], customModeDataObj);
7002+
} catch (e) {
7003+
console.error("Error parsing custommode data:", e);
7004+
}
69997005
}
70007006

70017007
this.fileChooser.addEventListener("click", () => {
@@ -7216,21 +7222,6 @@ class Activity {
72167222
});
72177223
};
72187224

7219-
// Music Block Parser from abc to MB
7220-
abcReader.onload = event => {
7221-
//get the abc data and replace the / so that the block does not break
7222-
let abcData = event.target.result;
7223-
abcData = abcData.replace(/\\/g, "");
7224-
7225-
const tunebook = new ABCJS.parseOnly(abcData);
7226-
// eslint-disable-next-line no-console
7227-
console.log(tunebook);
7228-
tunebook.forEach(tune => {
7229-
//call parseABC to parse abcdata to MB json
7230-
this.parseABC(tune);
7231-
});
7232-
};
7233-
72347225
// Work-around in case the handler is called by the
72357226
// widget drag & drop code.
72367227
if (files[0] !== undefined) {
@@ -7248,7 +7239,6 @@ class Activity {
72487239
return;
72497240
}
72507241
reader.readAsText(files[0]);
7251-
reader.readAsText(files[0]);
72527242
window.scroll(0, 0);
72537243
}
72547244
};

js/blocks/ProgramBlocks.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,31 +1292,37 @@ function setupProgramBlocks(activity) {
12921292
i < activity.blocks.protoBlockDict[protoblk].dockTypes.length;
12931293
i++
12941294
) {
1295-
// FIXME: type check args
1295+
// Type check and handle args
12961296
if (i < blockArgs.length) {
1297-
if (typeof blockArgs[i] === "number") {
1298-
if (
1299-
!["anyin", "numberin"].includes(
1300-
activity.blocks.protoBlockDict[protoblk].dockTypes[i]
1301-
)
1302-
) {
1297+
const arg = blockArgs[i];
1298+
const dockType = activity.blocks.protoBlockDict[protoblk].dockTypes[i];
1299+
1300+
if (typeof arg === "number") {
1301+
if (!["anyin", "numberin"].includes(dockType)) {
1302+
activity.errorMsg(_("Warning: block argument type mismatch"));
1303+
}
1304+
newBlock.push([i, ["number", { value: arg }], 0, 0, [0]]);
1305+
newBlock[0][4].push(i);
1306+
} else if (typeof arg === "string") {
1307+
if (!["anyin", "textin"].includes(dockType)) {
13031308
activity.errorMsg(_("Warning: block argument type mismatch"));
13041309
}
1305-
newBlock.push([i, ["number", { value: blockArgs[i] }], 0, 0, [0]]);
1306-
} else if (typeof blockArgs[i] === "string") {
1307-
if (
1308-
!["anyin", "textin"].includes(
1309-
activity.blocks.protoBlockDict[protoblk].dockTypes[i]
1310-
)
1311-
) {
1310+
newBlock.push([i, ["string", { value: arg }], 0, 0, [0]]);
1311+
newBlock[0][4].push(i);
1312+
} else if (typeof arg === "boolean") {
1313+
if (!["anyin", "booleanin"].includes(dockType)) {
13121314
activity.errorMsg(_("Warning: block argument type mismatch"));
13131315
}
1314-
newBlock.push([i, ["string", { value: blockArgs[i] }], 0, 0, [0]]);
1316+
newBlock.push([i, ["boolean", { value: arg }], 0, 0, [0]]);
1317+
newBlock[0][4].push(i);
13151318
} else {
1319+
activity.errorMsg(
1320+
_("Warning: block argument type unhandled: ") + typeof arg
1321+
);
1322+
// eslint-disable-next-line no-console
1323+
console.warn("Unhandled argument type", arg);
13161324
newBlock[0][4].push(null);
13171325
}
1318-
1319-
newBlock[0][4].push(i);
13201326
} else {
13211327
newBlock[0][4].push(null);
13221328
}

js/utils/musicutils.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,19 @@ const DEGREES = _("1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th");
842842
*/
843843
const SEMITONES = 12;
844844

845+
/**
846+
* Number of cents per semitone in 12-TET tuning.
847+
* @constant {number}
848+
*/
849+
const CENTS_PER_SEMITONE = 100;
850+
851+
/**
852+
* Number of cents in an octave.
853+
* Derived from SEMITONES for future temperament support.
854+
* @constant {number}
855+
*/
856+
const CENTS_PER_OCTAVE = SEMITONES * CENTS_PER_SEMITONE;
857+
845858
/**
846859
* Array representing powers of 2.
847860
* @constant {number[]}
@@ -2883,18 +2896,20 @@ const frequencyToPitch = hz => {
28832896

28842897
// Calculate cents to keep track of drift
28852898
let cents = 0;
2886-
for (let i = 0; i < 10 * 1200; i++) {
2899+
// Standard tuning uses CENTS_PER_OCTAVE cents per octave.
2900+
2901+
for (let i = 0; i < 10 * CENTS_PER_OCTAVE; i++) {
28872902
const f = A0 * Math.pow(TWELVEHUNDRETHROOT2, i);
28882903
if (hz < f * 1.0003 && hz > f * 0.9997) {
2889-
cents = i % 100;
2890-
let j = Math.floor(i / 100);
2904+
cents = i % CENTS_PER_SEMITONE;
2905+
let j = Math.floor(i / CENTS_PER_SEMITONE);
28912906
if (cents > 50) {
2892-
cents -= 100;
2907+
cents -= CENTS_PER_SEMITONE;
28932908
j += 1;
28942909
}
28952910
return [
2896-
PITCHES[(j + PITCHES.indexOf("A")) % 12],
2897-
Math.floor((j + PITCHES.indexOf("A")) / 12),
2911+
PITCHES[(j + PITCHES.indexOf("A")) % SEMITONES],
2912+
Math.floor((j + PITCHES.indexOf("A")) / SEMITONES),
28982913
cents
28992914
];
29002915
}

js/utils/utils.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,20 @@ let fileBasename = file => {
562562
* @param {string} str - The input string.
563563
* @returns {string} The string with the first character in uppercase.
564564
*/
565-
let toTitleCase = str => {
565+
function toTitleCase (str) {
566566
if (typeof str !== "string") return;
567567
let tempStr = "";
568568
if (str.length > 1) tempStr = str.substring(1);
569569
return str.toUpperCase()[0] + tempStr;
570570
};
571571

572+
if (typeof module !== "undefined" && module.exports) {
573+
module.exports.toTitleCase = toTitleCase;
574+
}
575+
if (typeof window !== "undefined") {
576+
window.toTitleCase = toTitleCase;
577+
}
578+
572579
/**
573580
* Processes plugin data and updates the activity based on the provided JSON-encoded dictionary.
574581
* @param {object} activity - The activity object to update.

0 commit comments

Comments
 (0)