Skip to content

Commit 41474c8

Browse files
authored
midi dialogue box (#4536)
* midi-dialogue-box * eslint * commets * remove comment
1 parent 627d358 commit 41474c8

File tree

3 files changed

+83
-9
lines changed

3 files changed

+83
-9
lines changed

css/activities.css

+22
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,28 @@ body:not(.dark) #helpfulSearchDiv {
150150
text-align: left;
151151
}
152152

153+
.block-count-dropdown {
154+
padding: 4px !important;
155+
font-size: 16px;
156+
border: 2px solid #ccc;
157+
border-radius: 8px;
158+
background: #dedededd;
159+
cursor: pointer;
160+
width: fit-content;
161+
text-align: center;
162+
}
163+
164+
.block-count-dropdown.expanded {
165+
max-height: 200px;
166+
overflow-y: auto;
167+
}
168+
169+
.message-container {
170+
display: flex;
171+
align-items: center;
172+
gap: 10px;
173+
}
174+
153175
.close {
154176
color: #aaa;
155177
float: right;

js/activity.js

+58-5
Original file line numberDiff line numberDiff line change
@@ -1341,14 +1341,68 @@ class Activity {
13411341
});
13421342
};
13431343

1344+
const midiImportBlocks = (midi) => {
1345+
if (docById("import-midi")) return;
1346+
1347+
const modal = document.createElement("div");
1348+
modal.classList.add("modalBox");
1349+
modal.id = "import-midi";
1350+
const title = document.createElement("h2");
1351+
title.textContent = _("Import MIDI");
1352+
title.classList.add("modal-title");
1353+
modal.appendChild(title);
1354+
1355+
const container = document.createElement("div");
1356+
container.classList.add("message-container");
1357+
const message = document.createElement("p");
1358+
message.textContent = _("Set the max blocks to generate :");
1359+
message.classList.add("modal-message");
1360+
container.appendChild(message)
1361+
1362+
const select = document.createElement("select");
1363+
select.classList.add("block-count-dropdown");
1364+
1365+
// 12 choices for block generation (100 to 1200)
1366+
for (let i = 1; i <= 12; i++) {
1367+
const option = document.createElement("option");
1368+
option.value = i*100;
1369+
option.textContent = i*100;
1370+
select.appendChild(option);
1371+
}
1372+
1373+
container.appendChild(select);
1374+
modal.appendChild(container);
1375+
1376+
const importConfirm = document.createElement("button");
1377+
importConfirm.classList.add("confirm-button");
1378+
importConfirm.textContent = "Confirm";
1379+
importConfirm.addEventListener("click", () => {
1380+
const maxNoteBlocks = select.value;
1381+
transcribeMidi(midi, maxNoteBlocks);
1382+
document.body.removeChild(modal);
1383+
});
1384+
modal.appendChild(importConfirm);
1385+
1386+
const cancelBtn = document.createElement("button");
1387+
cancelBtn.classList.add("cancel-button");
1388+
cancelBtn.textContent = "Cancel";
1389+
cancelBtn.addEventListener("click", () => {
1390+
document.body.removeChild(modal);
1391+
});
1392+
modal.appendChild(cancelBtn);
1393+
1394+
document.body.appendChild(modal);
1395+
}
1396+
13441397
/*
13451398
* Clears "canvas"
13461399
*/
13471400
const renderClearConfirmation = (clearCanvasAction) => {
1348-
if (document.getElementsByClassName("modalBox").length > 0) return;
1401+
if (docById("clear-confirm")) return;
13491402
// Create a custom modal for confirmation
13501403
const modal = document.createElement("div");
13511404
modal.classList.add("modalBox");
1405+
modal.id = "clear-confirm";
13521406
const title = document.createElement("h2");
13531407
title.textContent = _("Clear Workspace");
13541408
title.classList.add("modal-title");
@@ -1357,9 +1411,8 @@ class Activity {
13571411
const message = document.createElement("p");
13581412
message.textContent = _("Are you sure you want to clear the workspace?");
13591413
message.classList.add("modal-message");
1360-
13611414
modal.appendChild(message);
1362-
// Add buttons
1415+
13631416
const buttonContainer = document.createElement("div");
13641417
buttonContainer.classList.add("clear-button-container");
13651418

@@ -6477,7 +6530,7 @@ class Activity {
64776530
const midi = new Midi(e.target.result);
64786531
// eslint-disable-next-line no-console
64796532
console.debug(midi);
6480-
transcribeMidi(midi);
6533+
midiImportBlocks(midi);
64816534
};
64826535

64836536
const file = that.fileChooser.files[0];
@@ -6579,7 +6632,7 @@ class Activity {
65796632
const midi = new Midi(e.target.result)
65806633
// eslint-disable-next-line no-console
65816634
console.debug(midi);
6582-
transcribeMidi(midi);
6635+
midiImportBlocks(midi);
65836636
}
65846637

65856638
// Music Block Parser from abc to MB

js/midi.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
/* exported transcribeMidi*/
1515

1616

17-
const MAX_NOTEBLOCKS = 100;
1817
const defaultTempo = 90;
1918

2019
const standardDurations = [
@@ -43,7 +42,7 @@ const getClosestStandardNoteValue = (duration) => {
4342
return closest.value.split('/').map(Number);
4443
}
4544

46-
const transcribeMidi = async (midi) => {
45+
const transcribeMidi = async (midi, maxNoteBlocks) => {
4746
const currentMidi = midi;
4847
const drumMidi = getReverseDrumMidi();
4948
const isPercussion = [];
@@ -264,8 +263,8 @@ const transcribeMidi = async (midi) => {
264263
addNewActionBlock(isLastNoteInSched);
265264
}
266265

267-
if (totalnoteblockCount >= MAX_NOTEBLOCKS) {
268-
activity.textMsg("MIDI file is too large.. Generating only 100 noteblocks");
266+
if (totalnoteblockCount >= maxNoteBlocks) {
267+
activity.textMsg(`MIDI file is too large. Generating only ${maxNoteBlocks} noteblocks`);
269268
stopProcessing = true;
270269
break;
271270
}

0 commit comments

Comments
 (0)