Grok Piano
by ethanpil
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Piano Sampler</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
background-color: #f0f0f0;
}
.piano {
display: flex;
margin-top: 20px;
}
.key {
width: 40px;
height: 150px;
border: 1px solid #333;
cursor: pointer;
position: relative;
background: white;
display: flex;
align-items: flex-end;
justify-content: center;
padding-bottom: 10px;
user-select: none;
}
.key.black {
width: 25px;
height: 100px;
background: black;
color: white;
margin: 0 -12.5px;
z-index: 1;
}
.key:active {
background: #ddd;
}
.key.black:active {
background: #333;
}
.upload-section {
margin-bottom: 20px;
}
#message {
color: #666;
font-style: italic;
}
</style>
</head>
<body>
<div class="upload-section">
<h2>Piano Sampler</h2>
<input type="file" id="audioUpload" accept="audio/mp3">
<p>Upload an MP3 file to use as your piano sound</p>
<div id="message"></div>
</div>
<div class="piano" id="piano">
<!-- Piano keys will be generated by JavaScript -->
</div>
<script>
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
let audioBuffer = null;
const messageDiv = document.getElementById('message');
// Default MP3 file (base64 encoded)
const defaultAudioBase64...