diff --git a/index.html b/index.html index 95f91db..965c42b 100644 --- a/index.html +++ b/index.html @@ -256,14 +256,47 @@ canvas{display:block;}
@@ -6057,22 +6090,357 @@ function edDoImport(){ document.getElementById("ed-import-status").textContent="JSON parse error: "+e.message; } } -function edImportMIDI(){document.getElementById("ed-midi-file").click();} function edHandleFile(e){ var file=e.target.files[0];if(!file)return; var reader=new FileReader(); - if(file.name.endsWith(".json")){ - reader.onload=function(ev){ - document.getElementById("ed-import-text").value=ev.target.result; - edDoImport(); - }; - reader.readAsText(file); - }else{ - document.getElementById("ed-import-status").textContent="MIDI parsing not yet supported — convert to JSON first (use AI or online converter)"; - } + reader.onload=function(ev){ + document.getElementById("ed-import-text").value=ev.target.result; + edDoImport(); + }; + reader.readAsText(file); e.target.value=""; } +// Tab switching for import panel +function edShowImportTab(tab){ + ["json","text","musicxml","midi"].forEach(function(t){ + document.getElementById("ed-imp-"+t).style.display=t===tab?"block":"none"; + var btn=document.getElementById("ed-imp-tab-"+t); + btn.style.background=t===tab?"#3182ce":""; + }); + document.getElementById("ed-import-status").textContent=""; +} + +// --- TEXT/SHORTHAND IMPORT --- +// Parses: "C4 quarter, D4 eighth, E4 half" or "C4 q D4 e E4 h" or one-per-line +function edDoShorthandImport(){ + var text=document.getElementById("ed-shorthand-text").value.trim(); + if(!text){document.getElementById("ed-import-status").textContent="Type some notes first";return;} + var status=document.getElementById("ed-import-status"); + var durMap={ + "w":"whole","whole":"whole", + "dh":"dotted-half","dotted-half":"dotted-half","d.h":"dotted-half", + "h":"half","half":"half", + "dq":"dotted-quarter","dotted-quarter":"dotted-quarter","d.q":"dotted-quarter", + "q":"quarter","quarter":"quarter", + "de":"dotted-eighth","dotted-eighth":"dotted-eighth","d.e":"dotted-eighth", + "e":"eighth","eighth":"eighth", + "s":"sixteenth","sixteenth":"sixteenth", + "ts":"32nd","32nd":"32nd" + }; + // Normalize: replace commas and newlines with spaces, collapse whitespace + var tokens=text.replace(/,/g," ").replace(/\n/g," ").replace(/\s+/g," ").trim().split(" "); + var notes=[]; + var t=0; + var q=60/edBpm; // quarter note duration in seconds + var i=0; + var errors=[]; + while(i