原因
用Qwen做了一个节拍器,主要是拍合唱分镜时,每一次唱的节拍不固定,导致后期剪辑非常难受,常规节拍器有声音,也不能录进去,而且不能让大家都听到,但是用看的方式就好许多,于是就有了这个想法。

具体代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
| <!DOCTYPE html> <html> <head> <title>可定制节拍器</title> <style> :root { --primary-bg: #1a1a1a; --secondary-bg: #333; --accent: #ff6b6b; --text-color: white; --border-radius: 8px; }
body { margin: 0; height: 100vh; display: flex; flex-direction: column; align-items: center; background-color: var(--primary-bg); color: var(--text-color); transition: all 0.3s; }
.container { flex: 1; width: 80%; max-width: 400px; display: flex; flex-direction: column; padding: 20px 0; }
.beat-pad { flex: 1; width: 100%; background-color: var(--secondary-bg); border: 2px solid #444; margin: 4px 0; border-radius: var(--border-radius); transition: background-color 0.2s; }
.controls { margin: 20px; text-align: center; }
.settings-panel { position: fixed; top: 0; right: -320px; width: 300px; height: 100%; background: var(--primary-bg); padding: 20px; transition: right 0.3s; box-shadow: -2px 0 5px rgba(0,0,0,0.2); }
.settings-panel.active { right: 0; }
.setting-group { margin-bottom: 20px; }
input[type="color"], input[type="range"] { width: 100%; margin: 8px 0; }
button { background: var(--secondary-bg); color: var(--text-color); border: none; padding: 8px 16px; margin: 5px 0; cursor: pointer; border-radius: 4px; }
.preset-colors { display: flex; gap: 8px; margin: 10px 0; }
.preset-color { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 2px solid #555; }
.close-btn { position: absolute; right: 10px; top: 10px; background: none; color: var(--text-color); border: none; font-size: 1.2em; cursor: pointer; } </style> </head> <body> <div class="container" id="beatContainer"></div> <div class="controls"> <div>BPM: <span id="bpmDisplay">60</span></div> <button onclick="toggleSettings()">⚙️ 设置</button> <button onclick="toggleMetronome()" id="startStopBtn">开始</button> </div>
<div class="settings-panel" id="settingsPanel"> <button class="close-btn" onclick="toggleSettings()">×</button> <h3>设置</h3> <div class="setting-group"> <label>速度 (BPM):</label> <input type="range" id="bpmSlider" min="30" max="240" value="60"> <div class="bpm-value">60</div> </div> <div class="setting-group"> <label>主题模式:</label> <select id="themeSelect" onchange="updateTheme()"> <option value="dark">深色模式</option> <option value="light">亮色模式</option> </select> </div> <div class="setting-group"> <label>节拍颜色:</label> <div class="preset-colors"> <div class="preset-color" style="background: #ff6b6b" onclick="selectColor('#ff6b6b')"></div> <div class="preset-color" style="background: #4ecdc4" onclick="selectColor('#4ecdc4')"></div> <div class="preset-color" style="background: #45b7d1" onclick="selectColor('#45b7d1')"></div> <div class="preset-color" style="background: #96ce7d" onclick="selectColor('#96ce7d')"></div> </div> <input type="color" id="customColor" value="#ff6b6b"> </div>
<div class="setting-group"> <label>圆角大小:</label> <input type="range" id="radiusSlider" min="0" max="25" value="8"> <span id="radiusValue">8px</span> </div>
<div class="setting-group"> <label>声音开关:</label> <input type="checkbox" id="soundToggle" checked> </div> </div>
<script> const beatContainer = document.getElementById('beatContainer'); const bpmDisplay = document.getElementById('bpmDisplay'); const bpmSlider = document.getElementById('bpmSlider'); const settingsPanel = document.getElementById('settingsPanel'); const customColor = document.getElementById('customColor'); const radiusSlider = document.getElementById('radiusSlider'); const radiusValue = document.getElementById('radiusValue'); const soundToggle = document.getElementById('soundToggle'); let currentStep = 0; let intervalId = null; let audioContext = new (window.AudioContext || window.webkitAudioContext)(); let soundEnabled = true;
for(let i = 0; i < 4; i++) { const pad = document.createElement('div'); pad.className = 'beat-pad'; beatContainer.appendChild(pad); }
function playSound(isPrimary) { if(!soundEnabled) return; const oscillator = audioContext.createOscillator(); const gainNode = audioContext.createGain(); oscillator.type = isPrimary ? 'sine' : 'square'; oscillator.frequency.setValueAtTime( isPrimary ? 440 : 880, audioContext.currentTime ); oscillator.connect(gainNode); gainNode.connect(audioContext.destination); gainNode.gain.setValueAtTime(0.3, audioContext.currentTime); oscillator.start(); gainNode.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.1); oscillator.stop(audioContext.currentTime + 0.1); }
function updateMetronome() { const pads = document.querySelectorAll('.beat-pad'); const bpm = parseInt(bpmDisplay.textContent); pads.forEach(pad => pad.style.backgroundColor = 'var(--secondary-bg)'); if(currentStep < 3) { pads[currentStep].style.backgroundColor = 'white'; playSound(true); } else { pads[currentStep].style.backgroundColor = 'var(--accent)'; playSound(false); } currentStep = (currentStep + 1) % 4; }
function toggleMetronome() { if(intervalId) { clearInterval(intervalId); intervalId = null; document.getElementById('startStopBtn').textContent = '开始'; } else { const bpm = parseInt(bpmDisplay.textContent); const interval = (60 / bpm) * 1000; intervalId = setInterval(updateMetronome, interval); document.getElementById('startStopBtn').textContent = '停止'; updateMetronome(); } }
function toggleSettings() { settingsPanel.classList.toggle('active'); }
function updateTheme() { const theme = document.getElementById('themeSelect').value; const root = document.documentElement; if(theme === 'dark') { root.style.setProperty('--primary-bg', '#1a1a1a'); root.style.setProperty('--secondary-bg', '#333'); root.style.setProperty('--text-color', 'white'); } else { root.style.setProperty('--primary-bg', 'white'); root.style.setProperty('--secondary-bg', '#f0f0f0'); root.style.setProperty('--text-color', '#1a1a1a'); } }
function selectColor(color) { customColor.value = color; document.documentElement.style.setProperty('--accent', color); }
function syncBPM() { const value = bpmSlider.value; bpmDisplay.textContent = value; document.querySelector('.bpm-value').textContent = value; if(intervalId) { clearInterval(intervalId); const interval = (60 / value) * 1000; intervalId = setInterval(updateMetronome, interval); } }
function updateRadius() { const radius = radiusSlider.value; document.documentElement.style.setProperty('--border-radius', `${radius}px`); radiusValue.textContent = `${radius}px`; }
function toggleSound() { soundEnabled = soundToggle.checked; }
bpmSlider.addEventListener('input', syncBPM); radiusSlider.addEventListener('input', updateRadius); customColor.addEventListener('change', () => selectColor(customColor.value)); soundToggle.addEventListener('change', toggleSound); syncBPM(); </script> </body> </html>
|