Skip to content

Restructure: tuning engine out of Vue, scoped styles, ESLint, CI on pull requests - #3

Merged
AndrianLeah merged 6 commits into
masterfrom
refactor/project-structure
Nov 23, 2026
Merged

AndrianLeah merged 6 commits into
masterfrom
refactor/project-structure

Conversation

@AndrianLeah

Copy link
Copy Markdown
Owner

Built on the tests in #2 and contains its commit: merge #2 first and this diff shrinks to the commits below. App behaviour is unchanged, except one layout bug fixed (phone landscape, see "Styles").

Engine out of Vue (src/tuner/)

useTuner.ts held constants, pure pitch helpers, the state machine, the session log and the Vue refs in 629 lines. Now:

File What
src/tuner/pitch.ts centsBetween, isHarmonicOf, median, foldTowardTarget (now tested on their own)
src/tuner/instruments.ts per-instrument settings
src/tuner/engine.ts createTunerEngine: the state machine, no Vue, no audio APIs
src/tuner/sessionLog.ts the "paste to Copilot" log, development builds only — production no longer prints it on every Stop
src/composables/useTuner.ts feeds the engine, mirrors it into the same read-only refs; its API is unchanged, GuitarTuner.vue untouched

The overtone-fold path no longer repeats ~60 lines of the direct path: both go through acceptPitch. It differed in three small ways, kept as explicit options (FOLDED_OVERTONE) so behaviour is identical. They may be unintended and are worth a look:

  1. it shows the folded frame's frequency instead of the median one;
  2. a rejected continuity jump is not counted or logged;
  3. staying more than 20 cents off does not restart the stability timer (the direct path does after 150 ms).

Proof of equivalence — commit 95c3f62 contains a verbatim copy of the old useTuner and a test that feeds it and the new one the same random frames, string choices, tuning changes and restarts at the same fake time: 8 sessions × 6000 steps, everything the UI sees equal after every step. Flipping option 1 or 3 makes it fail. The next commit removes the copy and the test; check out 95c3f62 to run them.

Styles

src/styles/*.css were global and imported one by one in main.ts; each is now a <style scoped> block in its component, src/style.css stays global and is imported first.

This fixes the phone-landscape layout: GuitarTuner.css's landscape rules (ring 140 px, note 2.75rem, chips aligned left) lost to TunerRing.css and StringChips.css, imported later with selectors just as specific, so the ring stayed at 190 px. Checked in the browser by recording position, size and 26 style properties of every element in 10 states (phone portrait/landscape, desktop; dark/light; tuning selector and settings open): identical before and after except phone landscape, where only the chips, the ring and the note changed. The listening state was checked with an oscillator as the microphone.

Other

  • Removed files nothing uses: public/icons.svg (Vite template's social icons), src/assets/hero.svg, src/assets/icon.svg.
  • ESLint (the create-vue configuration: Vue + TypeScript recommended, Prettier for formatting), npm run lint; the code already passed it.
  • .github/workflows/ci.yml: lint, tests and the type-checked build on every pull request (until now only pushes to master ran anything); deploy.yml lints too.

Found, not changed here

  • In StringChips.vue the chip number is reversed: the high E shows "6" and the low E "1", while the line under the ring (and guitar convention) calls the low E string 6. tuning.strings - di should be di + 1.
  • Switching between two presets of the same instrument while listening, without the locked string changing index, leaves the low-pass filter at the previous preset's cutoff (it only follows lockedStringIndex), e.g. ukulele standard → baritone.

🤖 Generated with Claude Code

AndrianLeah and others added 6 commits November 23, 2026 22:41
useTuner.ts held constants, pure pitch helpers, the state machine, the
session log and the Vue refs in 629 lines. Now:

- src/tuner/pitch.ts: centsBetween, isHarmonicOf, median, foldTowardTarget.
- src/tuner/instruments.ts: the per-instrument settings.
- src/tuner/engine.ts: createTunerEngine, the state machine with no Vue and
  no audio APIs: process(frame, now), selectString, setTuning, reset, and
  the values the UI shows in `display`.
- src/tuner/sessionLog.ts: the "paste to Copilot" session log, now only in
  development builds; production no longer prints it on every stop.
- useTuner.ts: feeds the engine, mirrors it into the same read-only refs,
  steers the low-pass filter and stops 2 s after "all in tune". Its API is
  unchanged, so GuitarTuner.vue is untouched.

The overtone-fold path no longer repeats the direct path: both go through
acceptPitch. The three ways it differed (it shows the folded frame's pitch,
drops a continuity jump silently, and does not restart the stability timer
when far off) are kept as options of FOLDED_OVERTONE, so behaviour is the
same.

useTuner.equivalence.test.ts proves it: the old useTuner (verbatim copy in
src/test/legacyUseTuner.ts) and the new one get the same random frames,
string choices, tuning changes and restarts at the same fake time, 8
sessions of 6000 steps, and everything the UI sees is equal after every
step. Changing showFramePitch or resetStabilityWhenOff makes it fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The old useTuner copy and the test comparing it with the new engine served
the previous commit; check that commit out to run them again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
public/icons.svg is the Vite template's sprite of social icons (Bluesky,
Discord, GitHub, X...); src/assets/hero.svg and src/assets/icon.svg are
older copies of the splash and the icon. None is referenced by the app,
index.html or the manifest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Now that they live in src/tuner/pitch.ts they can be imported on their own:
cents arithmetic and rounding, which multiples count as harmonics, the
median against an octave-error spike, and when folding a harmonic down
applies and when it leaves the pitch alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/styles/*.css were global stylesheets imported one by one in main.ts.
Each is now a <style scoped> block in its component; src/style.css stays
global (theme tokens, page background, resets) and is imported first.

Scoping also fixes the phone-landscape layout. GuitarTuner's landscape
rules shrink the ring to 140 px, the note to 2.75rem and align the chips
left, but TunerRing.css and StringChips.css were imported after
GuitarTuner.css with selectors just as specific, so they won and the ring
stayed at 190 px. Now the parent's rules win as intended; the two rules on
TunerRing's inner note use :deep().

Checked in the browser by recording position, size and 26 style
properties of every element in 10 states (phone portrait and landscape,
desktop; dark and light; tuning selector and settings open): identical
before and after except phone landscape, where only the chips, the ring
and the note changed, as above. The listening state (in-tune colours,
Stop button, locked chip) was checked with an oscillator as microphone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ESLint with the configuration create-vue generates: eslint-plugin-vue's
recommended rules, typescript-eslint's recommended rules through
@vue/eslint-config-typescript, and @vue/eslint-config-prettier so that
formatting stays Prettier's job. The code already passes it.

- npm run lint
- .github/workflows/ci.yml: lint, tests and the type-checked build on every
  pull request (until now only pushes to master ran anything).
- deploy.yml: lints too, before the tests and the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AndrianLeah
AndrianLeah merged commit ff19ff7 into master Nov 23, 2026
1 check passed
@AndrianLeah
AndrianLeah deleted the refactor/project-structure branch November 23, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant