Skip to content

refactor: optimize JSON generation and improve MIDI handling logic - #10

Open
tomaustin700 wants to merge 19 commits into
mainfrom
0.1.1
Open

refactor: optimize JSON generation and improve MIDI handling logic#10
tomaustin700 wants to merge 19 commits into
mainfrom
0.1.1

Conversation

@tomaustin700

Copy link
Copy Markdown
Collaborator

No description provided.

Tom Austin added 19 commits May 27, 2026 13:26
- Fix naming conventions (f_name/max_characters/tempText)
- Make EEPROM addresses static constexpr
- Remove commented-out code and obvious comments
- Remove excessive blank lines
- Inline single-use variables in toggleMidiFilePlayback
- Add comprehensive README with preset format docs
- Add setup-local.ps1 for local build prerequisites
…d and prev-preset

- Replace 3 toggle booleans with switchToggled[3] array
- Extract sendPcArray/sendCcArray to deduplicate PC/CC iteration
- Fix long-hold: measure actual hold duration (press→release) not time-between-presses
- Fix prev-preset reloading same preset when already at 0
- Clamp CC numbers in sendControlChange (was only clamping values)
- Pad trailing spaces in displayCenteredLine to clear stale characters
- Remove redundant presetListCount (use presetCount directly)
- Remove unused pinMode(13, OUTPUT)
- Extract pure logic functions and constants into logic.h for testability
- Add test/CMakeLists.txt with Google Test v1.14.0 via FetchContent
- Add test/test_logic.cpp covering all extracted functions:
  clampMidi, hasElapsed, extractNumber, comparePresetNames,
  calculateCenterPadding, calculateSwitchPadding, canNavigateNext,
  canNavigatePrev, adjustPcProgram, plus constants and toggle state
- Update midicontroller.ino to include logic.h (removes duplicates)
- Add unit-tests job to CI workflow (runs before firmware compile)
- Add .gitignore for test/build/
Extract and test additional pure logic from branch changes:
- validateStoredPreset / validateStoredPcProgram: EEPROM validation
- toggleCcValue: refactored toggle CC value determination
- computePrefetchCandidate: directional preset prefetch logic
- hasJsonExtension: file filtering for preset list loading
- pcJsonToMidi: 1-indexed JSON to 0-indexed MIDI conversion
- formatSwitchActionMessage: null-safe UI message formatting
- clampPresetIndex: preset bounds clamping in changePreset

Integration tests:
- Full switch toggle cycle with CC values across all switches
- Reset-all after preset change
- Forward/backward navigation with prefetch scenarios
- Direction reversal prefetch adaptation
Verify correct MIDI output for all button-press scenarios:
- Preset OnLoad: PC/CC messages sent on preset navigation
- Switch press (non-toggle): CC values sent as-is from JSON
- Switch press (toggle): CC overridden to 127/0 based on state
- PC mode: increment/decrement with clamping, always via USB
- Long-hold PC mode toggle: sends current program
- Value clamping: out-of-range PC/CC values safely bounded
- PC offset: 1-indexed JSON → 0-indexed MIDI verified
- USB routing: defaults to false, respects explicit true/false
- Channel routing: each event routed to its specified channel
- Full scenarios: preset load + switch cycles, navigation, toggle reset

Uses ArduinoJson v6.21.5 in test build via FetchContent and a
MIDI mock layer that records messages for assertion.
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