From f00a3669b4c7bb0ebc612d26c538e54e97568901 Mon Sep 17 00:00:00 2001 From: Jens Mohrmann Date: Sun, 21 Dec 2025 12:58:40 +0100 Subject: [PATCH] fix pitch analysis --- .github/workflows/deploy.yml | 50 ++++++++++++++++++++++++++++++++++++ src/App.tsx | 10 +++++++- src/audio/PitchAnalyzer.ts | 10 +++++++- src/styles/skip-button.css | 27 +++++++++++++++++++ vite.config.ts | 2 ++ 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 src/styles/skip-button.css diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7642f29 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,50 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: [main] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./dist + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + needs: build + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/src/App.tsx b/src/App.tsx index e26aa9e..9dca115 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,8 +12,9 @@ import { getFirstPositionNotes, getFretboardPositions } from './music/Tunings'; -import { Mic, MicOff } from 'lucide-react'; +import { Mic, MicOff, SkipForward } from 'lucide-react'; import './App.css'; +import './styles/skip-button.css'; const NOTE_MATCH_THRESHOLD_MS = 300; // How long to convert hold note to confirm @@ -149,6 +150,13 @@ function App() { )} {error &&
{error}
} + +
+ +
diff --git a/src/audio/PitchAnalyzer.ts b/src/audio/PitchAnalyzer.ts index 6711f50..2dd717f 100644 --- a/src/audio/PitchAnalyzer.ts +++ b/src/audio/PitchAnalyzer.ts @@ -58,9 +58,17 @@ export class PitchAnalyzer { } rms = Math.sqrt(rms / this.buffer.length); - if (rms < 0.01) return null; // Silence threshold + if (rms < 0.05) return null; // Silence threshold increased to 0.05 for robustness because 0.01 picked up noise const pitch = this.detector(this.buffer); + + // Guitar range filtering: + // Low E (E2) is ~82Hz. Drop D is ~73Hz. + // High E (E4) is ~330Hz. 12th fret E5 is ~660Hz. + // Harmonics can go higher, but unlikely above 1500Hz for fundamental training. + // 19kHz (user reported D#10) is definitely noise. + if (pitch && (pitch < 70 || pitch > 1500)) return null; + return pitch; } } diff --git a/src/styles/skip-button.css b/src/styles/skip-button.css new file mode 100644 index 0000000..c454455 --- /dev/null +++ b/src/styles/skip-button.css @@ -0,0 +1,27 @@ +/* App.css additions */ + +/* Skip Button */ +.skip-button { + background: none; + border: 2px solid var(--color-text-muted); + color: var(--color-text-muted); + border-radius: var(--radius-lg); + padding: var(--spacing-sm) var(--spacing-md); + font-weight: 600; + cursor: pointer; + transition: all 0.2s ease; + display: flex; + align-items: center; + gap: var(--spacing-xs); + font-size: 0.9rem; +} + +.skip-button:hover { + border-color: var(--color-text-main); + color: var(--color-text-main); + background-color: rgba(0, 0, 0, 0.05); +} + +.skip-button:active { + transform: scale(0.98); +} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 8b0f57b..820002f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,4 +4,6 @@ import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], + // IMPORTANT: Replace 'sheet-music-trainer' with your GitHub repository name + base: '/sheetmusictrainer/', })