midi-sound-controller / index.html
MarcRyan's picture
Add 3 files
30cc86b verified
Raw History Blame Contribute Delete
29 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MIDI Sound Controller</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/tone@14.7.77/build/Tone.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/webmidi@3.0.0/dist/iife/webmidi.iife.js"></script>
<style>
@keyframes pulse {
0% { opacity: 0.6; }
50% { opacity: 1; }
100% { opacity: 0.6; }
}
.sound-wave {
animation: pulse 2s infinite ease-in-out;
}
.knob {
width: 60px;
height: 60px;
border-radius: 50%;
background: conic-gradient(#3b82f6 0%, #1e40af 100%);
position: relative;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.knob::after {
content: '';
position: absolute;
top: 5px;
left: 50%;
width: 4px;
height: 15px;
background: white;
transform-origin: bottom center;
transform: translateX(-50%) rotate(0deg);
border-radius: 2px;
}
.midi-key {
width: 30px;
height: 100px;
background: white;
border: 1px solid #ccc;
border-radius: 0 0 4px 4px;
position: relative;
transition: transform 0.1s;
}
.midi-key.black {
width: 20px;
height: 60px;
background: #111;
position: absolute;
z-index: 2;
margin-left: -10px;
margin-right: -10px;
}
.midi-key.active {
background: #3b82f6;
transform: translateY(2px);
}
.midi-key.black.active {
background: #1e40af;
}
.pad {
width: 80px;
height: 80px;
border-radius: 8px;
background: linear-gradient(145deg, #1e293b, #0f172a);
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
display: flex;
align-items: center;
justify-content: center;
transition: all 0.1s;
}
.pad.active {
transform: translateY(2px);
box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
background: linear-gradient(145deg, #3b82f6, #1e40af);
}
.fader {
width: 30px;
height: 150px;
background: #1e293b;
border-radius: 4px;
position: relative;
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}
.fader-handle {
width: 100%;
height: 20px;
background: #3b82f6;
border-radius: 3px;
position: absolute;
top: 50%;
cursor: ns-resize;
}
.led {
width: 12px;
height: 12px;
border-radius: 50%;
background: #4b5563;
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}
.led.active {
background: #10b981;
box-shadow: 0 0 10px #10b981;
}
.gradient-bg {
background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
}
.midi-device-card {
transition: all 0.3s ease;
border-left: 4px solid transparent;
}
.midi-device-card.active {
border-left-color: #3b82f6;
background: rgba(59, 130, 246, 0.1);
}
.midi-device-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -5px rgba(0, 0, 0, 0.3);
}
.midi-cc-visualizer {
height: 4px;
background: linear-gradient(90deg, #3b82f6, #10b981);
width: 0%;
transition: width 0.1s;
}
</style>
</head>
<body class="gradient-bg min-h-screen text-white font-sans">
<div class="container mx-auto px-4 py-8">
<header class="text-center mb-8">
<h1 class="text-4xl md:text-5xl font-bold mb-2 bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-emerald-400">
MIDI Sound Controller
</h1>
<p class="text-xl text-blue-300 max-w-2xl mx-auto">Connect your MIDI device to control the sound parameters</p>
<div id="midi-status" class="mt-6 p-3 rounded-lg bg-blue-900/50 inline-flex items-center">
<div class="led mr-3" id="midi-connection-led"></div>
<span id="midi-status-text">Initializing MIDI...</span>
</div>
</header>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- MIDI Device Panel -->
<div class="bg-slate-800/50 rounded-xl p-6 backdrop-blur-sm border border-slate-700/50">
<h2 class="text-2xl font-semibold mb-4 flex items-center">
<i class="fas fa-midi mr-3 text-blue-400"></i>
MIDI Devices
</h2>
<div class="mb-6">
<div class="flex justify-between items-center mb-2">
<h3 class="text-lg font-medium">Connected Devices</h3>
<button id="refresh-devices" class="text-blue-400 hover:text-blue-300">
<i class="fas fa-sync-alt mr-1"></i> Refresh
</button>
</div>
<div id="midi-devices" class="space-y-3">
<div class="midi-device-card p-3 rounded bg-slate-700/50">
<div class="flex items-center">
<div class="led mr-3"></div>
<span>No devices connected</span>
</div>
</div>
</div>
</div>
<div class="mb-6">
<h3 class="text-lg font-medium mb-3">MIDI Channel</h3>
<div class="grid grid-cols-4 gap-2">
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="1">1</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="2">2</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="3">3</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="4">4</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="5">5</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="6">6</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="7">7</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="8">8</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="9">9</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="10">10</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="11">11</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="12">12</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="13">13</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="14">14</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="15">15</button>
<button class="midi-channel-btn py-2 px-3 rounded bg-slate-700 hover:bg-slate-600" data-channel="16">16</button>
</div>
</div>
<div>
<h3 class="text-lg font-medium mb-3">MIDI Activity</h3>
<div class="midi-cc-visualizer mb-2"></div>
<div class="text-sm text-slate-400" id="midi-activity-text">No MIDI activity detected</div>
</div>
</div>
<!-- MIDI Controller Interface -->
<div class="bg-slate-800/50 rounded-xl p-6 backdrop-blur-sm border border-slate-700/50 lg:col-span-2">
<h2 class="text-2xl font-semibold mb-6 flex items-center">
<i class="fas fa-sliders-h mr-3 text-blue-400"></i>
Controller Interface
</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<!-- Knobs Section -->
<div class="bg-slate-900/50 rounded-lg p-4">
<h3 class="text-lg font-medium mb-4 flex items-center">
<i class="fas fa-dial mr-2 text-blue-400"></i>
Continuous Controllers (CC)
</h3>
<div class="grid grid-cols-3 gap-4">
<div class="text-center">
<div class="knob mx-auto mb-2" style="transform: rotate(45deg);" data-cc="1"></div>
<div class="text-xs font-mono">CC1 (Mod)</div>
<div class="text-xs text-slate-400">Volume</div>
</div>
<div class="text-center">
<div class="knob mx-auto mb-2" style="transform: rotate(90deg);" data-cc="7"></div>
<div class="text-xs font-mono">CC7 (Vol)</div>
<div class="text-xs text-slate-400">Reverb</div>
</div>
<div class="text-center">
<div class="knob mx-auto mb-2" style="transform: rotate(135deg);" data-cc="10"></div>
<div class="text-xs font-mono">CC10 (Pan)</div>
<div class="text-xs text-slate-400">Filter</div>
</div>
<div class="text-center">
<div class="knob mx-auto mb-2" style="transform: rotate(180deg);" data-cc="11"></div>
<div class="text-xs font-mono">CC11 (Expr)</div>
<div class="text-xs text-slate-400">Delay</div>
</div>
<div class="text-center">
<div class="knob mx-auto mb-2" style="transform: rotate(225deg);" data-cc="74"></div>
<div class="text-xs font-mono">CC74</div>
<div class="text-xs text-slate-400">LFO Rate</div>
</div>
<div class="text-center">
<div class="knob mx-auto mb-2" style="transform: rotate(270deg);" data-cc="71"></div>
<div class="text-xs font-mono">CC71</div>
<div class="text-xs text-slate-400">Resonance</div>
</div>
</div>
</div>
<!-- Pads Section -->
<div class="bg-slate-900/50 rounded-lg p-4">
<h3 class="text-lg font-medium mb-4 flex items-center">
<i class="fas fa-th-large mr-2 text-blue-400"></i>
Drum Pads
</h3>
<div class="grid grid-cols-4 gap-3">
<div class="pad" data-note="36">
<span class="text-xs font-mono">C1</span>
</div>
<div class="pad" data-note="37">
<span class="text-xs font-mono">C#1</span>
</div>
<div class="pad" data-note="38">
<span class="text-xs font-mono">D1</span>
</div>
<div class="pad" data-note="39">
<span class="text-xs font-mono">D#1</span>
</div>
<div class="pad" data-note="40">
<span class="text-xs font-mono">E1</span>
</div>
<div class="pad" data-note="41">
<span class="text-xs font-mono">F1</span>
</div>
<div class="pad" data-note="42">
<span class="text-xs font-mono">F#1</span>
</div>
<div class="pad" data-note="43">
<span class="text-xs font-mono">G1</span>
</div>
</div>
</div>
<!-- Faders Section -->
<div class="bg-slate-900/50 rounded-lg p-4">
<h3 class="text-lg font-medium mb-4 flex items-center">
<i class="fas fa-sliders-v mr-2 text-blue-400"></i>
Faders
</h3>
<div class="grid grid-cols-4 gap-4">
<div class="text-center">
<div class="fader mx-auto mb-2">
<div class="fader-handle" style="top: 30%;" data-cc="16"></div>
</div>
<div class="text-xs font-mono">CC16</div>
<div class="text-xs text-slate-400">Volume</div>
</div>
<div class="text-center">
<div class="fader mx-auto mb-2">
<div class="fader-handle" style="top: 50%;" data-cc="17"></div>
</div>
<div class="text-xs font-mono">CC17</div>
<div class="text-xs text-slate-400">Reverb</div>
</div>
<div class="text-center">
<div class="fader mx-auto mb-2">
<div class="fader-handle" style="top: 70%;" data-cc="18"></div>
</div>
<div class="text-xs font-mono">CC18</div>
<div class="text-xs text-slate-400">Filter</div>
</div>
<div class="text-center">
<div class="fader mx-auto mb-2">
<div class="fader-handle" style="top: 20%;" data-cc="19"></div>
</div>
<div class="text-xs font-mono">CC19</div>
<div class="text-xs text-slate-400">Delay</div>
</div>
</div>
</div>
<!-- Keyboard Section -->
<div class="bg-slate-900/50 rounded-lg p-4">
<h3 class="text-lg font-medium mb-4 flex items-center">
<i class="fas fa-keyboard mr-2 text-blue-400"></i>
Keyboard
</h3>
<div class="flex relative" style="height: 100px;">
<!-- White keys -->
<div class="midi-key" data-note="60"></div>
<div class="midi-key" data-note="62"></div>
<div class="midi-key" data-note="64"></div>
<div class="midi-key" data-note="65"></div>
<div class="midi-key" data-note="67"></div>
<div class="midi-key" data-note="69"></div>
<div class="midi-key" data-note="71"></div>
<!-- Black keys -->
<div class="midi-key black" data-note="61" style="left: 21px;"></div>
<div class="midi-key black" data-note="63" style="left: 51px;"></div>
<div class="midi-key black" data-note="66" style="left: 111px;"></div>
<div class="midi-key black" data-note="68" style="left: 141px;"></div>
<div class="midi-key black" data-note="70" style="left: 171px;"></div>
</div>
<div class="text-center mt-2 text-xs text-slate-400">C4 to B4 (Middle Octave)</div>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Initialize WebMidi
let midiInput = null;
let midiOutput = null;
let currentChannel = 1;
// Audio context and synth
const synth = new Tone.PolySynth(Tone.Synth).toDestination();
synth.volume.value = -10;
// Effects
const reverb = new Tone.Reverb(2).toDestination();
const delay = new Tone.FeedbackDelay("8n", 0.5).toDestination();
const filter = new Tone.Filter(800, "lowpass").toDestination();
// Connect synth to effects
synth.chain(filter, delay, reverb, Tone.Destination);
// Initialize WebMidi
WebMidi.enable()
.then(onEnabled)
.catch(err => {
document.getElementById('midi-status-text').textContent = "WebMidi could not be enabled: " + err;
document.getElementById('midi-connection-led').classList.add('bg-red-500');
});
function onEnabled() {
updateMidiStatus("WebMidi enabled!", true);
refreshDevices();
// Listen for changes in MIDI devices
WebMidi.addListener("connected", refreshDevices);
WebMidi.addListener("disconnected", refreshDevices);
// Set up refresh button
document.getElementById('refresh-devices').addEventListener('click', refreshDevices);
// Set up channel buttons
document.querySelectorAll('.midi-channel-btn').forEach(btn => {
btn.addEventListener('click', function() {
currentChannel = parseInt(this.dataset.channel);
document.querySelectorAll('.midi-channel-btn').forEach(b => {
b.classList.remove('bg-blue-600');
b.classList.add('bg-slate-700');
});
this.classList.remove('bg-slate-700');
this.classList.add('bg-blue-600');
if (midiInput) {
updateMidiStatus(`Listening on channel ${currentChannel} from ${midiInput.name}`, true);
}
});
});
}
function refreshDevices() {
const devicesContainer = document.getElementById('midi-devices');
devicesContainer.innerHTML = '';
if (WebMidi.inputs.length === 0) {
devicesContainer.innerHTML = `
<div class="midi-device-card p-3 rounded bg-slate-700/50">
<div class="flex items-center">
<div class="led mr-3"></div>
<span>No MIDI devices found</span>
</div>
</div>
`;
updateMidiStatus("No MIDI devices connected", false);
return;
}
WebMidi.inputs.forEach(device => {
const isActive = midiInput && device.id === midiInput.id;
const deviceElement = document.createElement('div');
deviceElement.className = `midi-device-card p-3 rounded bg-slate-700/50 cursor-pointer ${isActive ? 'active' : ''}`;
deviceElement.innerHTML = `
<div class="flex items-center">
<div class="led mr-3 ${isActive ? 'active' : ''}"></div>
<span>${device.name}</span>
</div>
`;
deviceElement.addEventListener('click', () => {
selectMidiDevice(device);
});
devicesContainer.appendChild(deviceElement);
});
}
function selectMidiDevice(device) {
// Remove previous listener if exists
if (midiInput) {
midiInput.removeListener();
}
midiInput = device;
// Add new listener
midiInput.addListener('noteon', e => {
handleNoteOn(e.note.number, e.velocity);
});
midiInput.addListener('noteoff', e => {
handleNoteOff(e.note.number);
});
midiInput.addListener('controlchange', e => {
handleControlChange(e.controller.number, e.value);
});
updateMidiStatus(`Connected to ${device.name} on channel ${currentChannel}`, true);
refreshDevices();
}
function handleNoteOn(note, velocity) {
// Visual feedback
const pad = document.querySelector(`.pad[data-note="${note}"]`);
const key = document.querySelector(`.midi-key[data-note="${note}"]`);
if (pad) pad.classList.add('active');
if (key) key.classList.add('active');
// Play sound
const freq = Tone.Frequency(note, "midi").toFrequency();
synth.triggerAttack(freq, undefined, velocity);
// Update activity display
updateMidiActivity(`Note On: ${note} (Velocity: ${Math.round(velocity * 127)})`);
}
function handleNoteOff(note) {
// Visual feedback
const pad = document.querySelector(`.pad[data-note="${note}"]`);
const key = document.querySelector(`.midi-key[data-note="${note}"]`);
if (pad) pad.classList.remove('active');
if (key) key.classList.remove('active');
// Stop sound
const freq = Tone.Frequency(note, "midi").toFrequency();
synth.triggerRelease(freq);
// Update activity display
updateMidiActivity(`Note Off: ${note}`);
}
function handleControlChange(cc, value) {
// Normalize value to 0-1
const normalized = value / 127;
// Update visual elements
const knob = document.querySelector(`.knob[data-cc="${cc}"]`);
const fader = document.querySelector(`.fader-handle[data-cc="${cc}"]`);
if (knob) {
const rotation = normalized * 270; // 0-270 degrees
knob.style.transform = `rotate(${rotation}deg)`;
}
if (fader) {
const position = (1 - normalized) * 100; // Invert for faders (0 at top)
fader.style.top = `${position}%`;
}
// Map CC to parameters
switch(cc) {
case 1: // Modulation
synth.volume.value = Tone.gainToDb(normalized);
break;
case 7: // Volume
reverb.wet.value = normalized;
break;
case 10: // Pan
filter.frequency.value = 20 + (normalized * 2000);
break;
case 11: // Expression
delay.wet.value = normalized;
break;
case 74: // Brightness
filter.Q.value = normalized * 10;
break;
}
// Update activity display
updateMidiActivity(`CC${cc}: ${Math.round(value)}`);
}
function updateMidiStatus(message, isConnected) {
document.getElementById('midi-status-text').textContent = message;
const led = document.getElementById('midi-connection-led');
led.classList.remove('bg-red-500', 'active');
if (isConnected) {
led.classList.add('active');
} else {
led.classList.add('bg-red-500');
}
}
function updateMidiActivity(message) {
document.getElementById('midi-activity-text').textContent = message;
// Visualizer animation
const visualizer = document.querySelector('.midi-cc-visualizer');
visualizer.style.width = '100%';
setTimeout(() => {
visualizer.style.width = '0%';
}, 100);
}
// Keyboard controls for testing without MIDI
document.addEventListener('keydown', function(e) {
const keyMap = {
'a': 60, 'w': 61, 's': 62, 'e': 63, 'd': 64,
'f': 65, 't': 66, 'g': 67, 'y': 68, 'h': 69,
'u': 70, 'j': 71
};
if (keyMap[e.key]) {
handleNoteOn(keyMap[e.key], 0.7);
}
});
document.addEventListener('keyup', function(e) {
const keyMap = {
'a': 60, 'w': 61, 's': 62, 'e': 63, 'd': 64,
'f': 65, 't': 66, 'g': 67, 'y': 68, 'h': 69,
'u': 70, 'j': 71
};
if (keyMap[e.key]) {
handleNoteOff(keyMap[e.key]);
}
});
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=MarcRyan/midi-sound-controller" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>