@@ -1341,14 +1341,68 @@ class Activity {
1341
1341
} ) ;
1342
1342
} ;
1343
1343
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
+
1344
1397
/*
1345
1398
* Clears "canvas"
1346
1399
*/
1347
1400
const renderClearConfirmation = ( clearCanvasAction ) => {
1348
- if ( document . getElementsByClassName ( "modalBox" ) . length > 0 ) return ;
1401
+ if ( docById ( "clear-confirm" ) ) return ;
1349
1402
// Create a custom modal for confirmation
1350
1403
const modal = document . createElement ( "div" ) ;
1351
1404
modal . classList . add ( "modalBox" ) ;
1405
+ modal . id = "clear-confirm" ;
1352
1406
const title = document . createElement ( "h2" ) ;
1353
1407
title . textContent = _ ( "Clear Workspace" ) ;
1354
1408
title . classList . add ( "modal-title" ) ;
@@ -1357,9 +1411,8 @@ class Activity {
1357
1411
const message = document . createElement ( "p" ) ;
1358
1412
message . textContent = _ ( "Are you sure you want to clear the workspace?" ) ;
1359
1413
message . classList . add ( "modal-message" ) ;
1360
-
1361
1414
modal . appendChild ( message ) ;
1362
- // Add buttons
1415
+
1363
1416
const buttonContainer = document . createElement ( "div" ) ;
1364
1417
buttonContainer . classList . add ( "clear-button-container" ) ;
1365
1418
@@ -6477,7 +6530,7 @@ class Activity {
6477
6530
const midi = new Midi ( e . target . result ) ;
6478
6531
// eslint-disable-next-line no-console
6479
6532
console . debug ( midi ) ;
6480
- transcribeMidi ( midi ) ;
6533
+ midiImportBlocks ( midi ) ;
6481
6534
} ;
6482
6535
6483
6536
const file = that . fileChooser . files [ 0 ] ;
@@ -6579,7 +6632,7 @@ class Activity {
6579
6632
const midi = new Midi ( e . target . result )
6580
6633
// eslint-disable-next-line no-console
6581
6634
console . debug ( midi ) ;
6582
- transcribeMidi ( midi ) ;
6635
+ midiImportBlocks ( midi ) ;
6583
6636
}
6584
6637
6585
6638
// Music Block Parser from abc to MB
0 commit comments