Add metronome

This commit is contained in:
Skyler Lehmkuhl
2025-11-06 10:59:25 -05:00
parent e97dc5695f
commit e51a6b803d
11 changed files with 311 additions and 16 deletions
+10
View File
@@ -0,0 +1,10 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<!-- Metronome body (trapezoid) -->
<path d="M12 4 L8 20 L16 20 Z" fill="currentColor" stroke="currentColor" stroke-width="1.5" stroke-linejoin="miter"/>
<!-- Base -->
<rect x="6" y="20" width="12" height="2" fill="currentColor"/>
<!-- Pendulum arm -->
<line x1="12" y1="8" x2="14" y2="16" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
<!-- Pendulum weight -->
<circle cx="14" cy="16" r="1.5" fill="currentColor"/>
</svg>

After

Width:  |  Height:  |  Size: 554 B

+67
View File
@@ -1608,6 +1608,10 @@ async function _newFile(width, height, fps, layoutKey) {
// Set default time format to measures for music mode
if (layoutKey === 'audioDaw' && context.timelineWidget?.timelineState) {
context.timelineWidget.timelineState.timeFormat = 'measures';
// Show metronome button for audio projects
if (context.metronomeGroup) {
context.metronomeGroup.style.display = '';
}
}
}
@@ -4536,6 +4540,54 @@ function timelineV2() {
controls.push(recordGroup);
// Metronome button (only visible in measures mode)
const metronomeGroup = document.createElement("div");
metronomeGroup.className = "playback-controls-group";
// Initially hide if not in measures mode
if (timelineWidget.timelineState.timeFormat !== 'measures') {
metronomeGroup.style.display = 'none';
}
const metronomeButton = document.createElement("button");
metronomeButton.className = context.metronomeEnabled
? "playback-btn playback-btn-metronome active"
: "playback-btn playback-btn-metronome";
metronomeButton.title = context.metronomeEnabled ? "Disable Metronome" : "Enable Metronome";
// Load SVG inline for currentColor support
(async () => {
try {
const response = await fetch('./assets/metronome.svg');
const svgText = await response.text();
metronomeButton.innerHTML = svgText;
} catch (error) {
console.error('Failed to load metronome icon:', error);
}
})();
metronomeButton.addEventListener("click", async () => {
context.metronomeEnabled = !context.metronomeEnabled;
const { invoke } = window.__TAURI__.core;
try {
await invoke('set_metronome_enabled', { enabled: context.metronomeEnabled });
// Update button appearance
metronomeButton.className = context.metronomeEnabled
? "playback-btn playback-btn-metronome active"
: "playback-btn playback-btn-metronome";
metronomeButton.title = context.metronomeEnabled ? "Disable Metronome" : "Enable Metronome";
} catch (error) {
console.error('Failed to set metronome:', error);
}
});
metronomeGroup.appendChild(metronomeButton);
// Store reference for state updates and visibility toggling
context.metronomeButton = metronomeButton;
context.metronomeGroup = metronomeGroup;
controls.push(metronomeGroup);
// Time display
const timeDisplay = document.createElement("div");
timeDisplay.className = "time-display";
@@ -4610,6 +4662,10 @@ function timelineV2() {
timelineWidget.toggleTimeFormat();
updateTimeDisplay();
updateCanvasSize();
// Update metronome button visibility
if (context.metronomeGroup) {
context.metronomeGroup.style.display = timelineWidget.timelineState.timeFormat === 'measures' ? '' : 'none';
}
return;
}
@@ -4620,6 +4676,10 @@ function timelineV2() {
timelineWidget.toggleTimeFormat();
updateTimeDisplay();
updateCanvasSize();
// Update metronome button visibility
if (context.metronomeGroup) {
context.metronomeGroup.style.display = timelineWidget.timelineState.timeFormat === 'measures' ? '' : 'none';
}
} else if (action === 'edit-fps') {
// Clicked on FPS - show input to edit framerate
console.log('[FPS Edit] Starting FPS edit');
@@ -10722,6 +10782,13 @@ function switchLayout(layoutKey) {
updateLayers();
updateMenu();
// Update metronome button visibility based on timeline format
// (especially important when switching to audioDaw layout)
if (context.metronomeGroup && context.timelineWidget?.timelineState) {
const shouldShow = context.timelineWidget.timelineState.timeFormat === 'measures';
context.metronomeGroup.style.display = shouldShow ? '' : 'none';
}
console.log(`Layout switched to: ${layoutDef.name}`);
} catch (error) {
console.error(`Error switching layout:`, error);
+4
View File
@@ -43,6 +43,10 @@ export let context = {
playPauseButton: null, // Reference to play/pause button for updating appearance
// MIDI activity indicator
lastMidiInputTime: 0, // Timestamp (Date.now()) of last MIDI input
// Metronome state
metronomeEnabled: false,
metronomeButton: null, // Reference to metronome button for updating appearance
metronomeGroup: null, // Reference to metronome button group for showing/hiding
};
// Application configuration
+18
View File
@@ -1022,6 +1022,24 @@ button {
animation: pulse 1s ease-in-out infinite;
}
/* Metronome Button - Inline SVG with currentColor */
.playback-btn-metronome {
color: var(--text-primary);
}
.playback-btn-metronome svg {
width: 18px;
height: 18px;
display: block;
margin: auto;
}
/* Active metronome state - use highlight color */
.playback-btn-metronome.active {
background-color: var(--highlight);
border-color: var(--highlight);
}
/* Dark mode playback button adjustments */
@media (prefers-color-scheme: dark) {
.playback-btn {
-16
View File
@@ -814,27 +814,11 @@ class TimelineWindowV2 extends Widget {
const fadeTime = 1000 // Fade out over 1 second (increased for visibility)
if (elapsed < fadeTime) {
// const mindicatorSize = 12 // Made larger
// const mindicatorX = this.trackHeaderWidth - 35 // Position to the left of buttons
// const mindicatorY = y + this.trackHierarchy.trackHeight / 2
// console.log(`[MIDI mIndicator] Drawing at (${mindicatorX}, ${mindicatorY}) with alpha ${1}`)
// // Draw pulsing circle with border
// ctx.strokeStyle = `rgba(0, 255, 0, ${1})`
// ctx.fillStyle = `rgba(0, 255, 0, ${1 * 0.5})`
// ctx.lineWidth = 2
// ctx.beginPath()
// ctx.arc(mindicatorX, mindicatorY, mindicatorSize / 2, 0, Math.PI * 2)
// ctx.fill()
// ctx.stroke()
const alpha = Math.max(0.2, 1 - (elapsed / fadeTime)) // Minimum alpha of 0.3 for visibility
const indicatorSize = 10
const indicatorX = this.trackHeaderWidth - 35 // Position to the left of buttons
const indicatorY = y + this.trackHierarchy.trackHeight / 2
console.log(`[MIDI Indicator] Drawing at (${indicatorX}, ${indicatorY}) with alpha ${alpha}`)
// Draw pulsing circle with border
ctx.strokeStyle = `rgba(0, 255, 0, ${alpha})`