// Render piano roll on canvas function renderPianoRoll(notes, ticksPerQuarter, canvasElem) if (!notes.length) const ctx = canvasElem.getContext('2d'); ctx.clearRect(0, 0, canvasElem.width, canvasElem.height); ctx.fillStyle = "#aaa"; ctx.font = "14px Inter"; ctx.fillText("No notes to display", 20, 50); return; const width = canvasElem.width; const height = canvasElem.height; const ctx = canvasElem.getContext('2d'); ctx.clearRect(0, 0, width, height); const maxTick = Math.max(...notes.map(n => n.startTick + n.duration), 480 * 4); const ticksPerMeasure = ticksPerQuarter * 4; const maxMeasures = Math.min(8, Math.ceil(maxTick / ticksPerMeasure)); const timeRange = ticksPerMeasure * maxMeasures; const minPitch = Math.min(...notes.map(n => n.pitch), 48); const maxPitch = Math.max(...notes.map(n => n.pitch), 84); const pitchRange = maxPitch - minPitch + 1; const noteHeight = Math.min(14, (height - 60) / pitchRange); // Draw grid & labels ctx.fillStyle = "#ddd"; ctx.font = "10px monospace"; for (let i = 0; i <= maxMeasures; i++) let x = (i * ticksPerMeasure / timeRange) * width; ctx.beginPath(); ctx.strokeStyle = "#3a546d"; ctx.lineWidth = 0.7; ctx.moveTo(x, 0); ctx.lineTo(x, height); ctx.stroke(); ctx.fillStyle = "#b9d0e4"; ctx.fillText(`$i`, x+4, 18); // draw note rectangles for (let note of notes) const x = (note.startTick / timeRange) * width; const w = (note.duration / timeRange) * width; const y = ((maxPitch - note.pitch) / pitchRange) * (height - 40) + 20; ctx.fillStyle = `hsl($200 + (note.velocity * 0.5), 70%, 60%)`; ctx.fillRect(x, y, Math.max(w, 3), noteHeight-1); ctx.strokeStyle = "#ffffff80"; ctx.strokeRect(x, y, Math.max(w, 3), noteHeight-1); // pitch labels ctx.fillStyle = "#ffecb3"; ctx.font = "9px monospace"; for (let p = minPitch; p <= maxPitch; p+=2) let y = ((maxPitch - p) / pitchRange) * (height - 40) + 20 + noteHeight/2; ctx.fillText(MidiFile.pitchName ? MidiFile.pitchName(p) : `note$p`, 5, y);

.piano-roll h3 color: #eef4ff; margin-top: 0; margin-bottom: 12px; font-size: 1.2rem;

Below is a that lets users upload a MIDI file, converts it to a visual piano roll / notation preview, and allows downloading as a printable PDF (using free client-side tools).

<div id="controlsSection" style="display: none;"> <div class="action-bar"> <button class="btn btn-secondary" id="downloadPdfBtn">📄 Export as PDF (score)</button> <button class="btn btn-secondary" id="resetBtn">⟳ Load another MIDI</button> </div> <div class="sheet-preview"> <div style="display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap;"> <h2 style="font-weight: 500; margin: 0 0 12px 0;">🎼 Standard Notation (VexFlow)</h2> <span id="trackInfo" style="font-size:0.75rem; background:#eef2f8; padding:4px 12px; border-radius:20px;"></span> </div> <div id="vexflowContainer" style="overflow-x: auto; padding: 8px 0;"> <canvas id="notationCanvas" width="800" height="200" style="width:100%; height:auto; max-width:100%;"></canvas> </div> <div class="piano-roll"> <h3>🎹 Piano Roll Preview (first 2 tracks / 4 bars)</h3> <canvas id="pianoCanvas" width="900" height="280" style="width:100%; height:auto; background:#11181f; border-radius:12px;"></canvas> <div class="status" id="midiStatus">Ready — upload a MIDI file</div> </div> </div> </div> <footer> ⚡ 100% client-side • No server costs • Works offline • Ideal for $30 budget websites </footer> </div>

.sub color: #5b6f82; border-left: 3px solid #2c7da0; padding-left: 14px; margin: 12px 0 28px 0; font-weight: 400;

.upload-icon font-size: 48px; margin-bottom: 12px;

let events = []; for (let note of filtered) let durationTicks = note.duration; let durFraction = durationTicks / ticksPerQuarter; let vexDuration = '4'; // default quarter if (durFraction >= 1.8) vexDuration = '2'; else if (durFraction >= 0.9) vexDuration = '4'; else if (durFraction >= 0.45) vexDuration = '8'; else vexDuration = '16'; events.push( keys: [pitchToNoteName(note.pitch)], duration: vexDuration, startTick: note.startTick ); // sort by startTick for proper rendering events.sort((a,b)=> a.startTick - b.startTick); return events, ticksPerMeasure, maxTickLimit ;

#fileInput display: none;

.container max-width: 1300px; margin: 0 auto; background: white; border-radius: 32px; box-shadow: 0 20px 35px -12px rgba(0,0,0,0.1); overflow: hidden; padding: 28px 32px 40px; transition: all 0.2s;

.status font-size: 0.85rem; margin-top: 12px; padding: 8px 14px; background: #eef2f6; border-radius: 60px; display: inline-block;

@media (max-width: 700px) .container padding: 20px; .action-bar justify-content: center; </style> </head> <body> <div class="container"> <h1>🎹 MIDI to Sheet Music</h1> <div class="sub">Upload any .mid file → instant piano roll & standard notation → save as PDF (under $30 stack)</div>

canvas#pianoCanvas background: #0f1720; border-radius: 14px; width: 100%; height: auto; display: block;

Just Love Movies