Skip to content

Conversation

@ftrain
Copy link
Owner

@ftrain ftrain commented Nov 6, 2025

No description provided.

Add comprehensive documentation and tooling:
- CLAUDE.md: Technical architecture, data model, Lua integration, and development guide
- DEVELOPMENT_ROADMAP.md: 6-phase implementation plan with actionable tasks
- PROJECT_STRUCTURE.md: Directory layout and file organization
- .claude/commands/: 5 slash commands for common development tasks
- modes/TEMPLATE.lua: Documented template for creating new Lua modes
- .gitignore: Build artifacts and platform-specific files

Project is now ready for Phase 1 (Core Foundation) development.
Core Implementation (Phase 1 Complete):

Data Model:
- Event: Bit-packed structure (switch + 4 pots in uint32_t)
- Pattern/Track: Hierarchical containers for musical data
- Song: Top-level structure (15 modes × 32 patterns × 8 tracks × 16 events)
- Memory footprint: ~245KB for full song data

Hardware Abstraction:
- HardwareInterface: Abstract interface for buttons, pots, MIDI
- MidiScheduler: Delta-timed MIDI event scheduling with priority queue
- DesktopHardware: macOS implementation using RtMidi

Lua Integration:
- LuaContext: Wraps lua_State, manages mode lifecycle
- LuaAPI: C++ functions exposed to Lua (note, off, cc, stopall)
- ModeLoader: Loads and manages .lua mode files

Playback Engine:
- Engine: Main loop, processes Events at tempo, calls Lua modes
- Automatic tempo-based step advancement
- Input handling for global pots (mode, tempo, pattern, track)
- Real-time pattern editing

Desktop Application:
- Terminal-based app with MIDI output
- Creates test drum pattern (kick, snare, hi-hat)
- Runs playback loop at 120 BPM
- Prints MIDI messages to console

Lua Modes:
- 00_boot.lua: Boot mode (stub for load/save/erase)
- 01_drums.lua: 808-style drum machine with 8 tracks

Build System:
- CMake configuration for macOS
- Finds Lua, RtMidi dependencies
- Links CoreMIDI/CoreAudio frameworks
- Builds static libraries + executable
- build.sh helper script

Documentation:
- BUILD.md: Complete build instructions with troubleshooting
- QUICKSTART.md: Get-running-fast guide with examples

Status: Desktop version compiles and runs! Ready for:
- Interactive keyboard input
- Real-time pattern editing
- Additional musical modes
- Save/load functionality
- Eventually: Teensy hardware port
- Updated .gitignore: /core (root only) instead of core (any directory)
- Added src/core/ directory with data model and engine
- CMakeLists.txt files added for all src/ subdirectories
@ftrain ftrain merged commit 77a6a51 into main Nov 6, 2025
ftrain pushed a commit that referenced this pull request Nov 9, 2025
This commit implements three major improvements from the code review:

## 1. Complete HardwareBase Migration (4 platforms)
- Migrated TeensyHardware to inherit from HardwareBase
- Removed ~60 lines of duplicate code from Teensy implementation
- All platforms (Desktop, macOS, iOS, Teensy) now use common base
- Total duplication eliminated: ~260 lines across 4 platforms

### Platform-specific changes:
- **TeensyHardware**: Now uses inherited buttons_/pots_ arrays from base
  - update() writes hardware readings to base class state
  - Overrides setLED() for PWM brightness control
  - Overrides getMillis() with Arduino millis()

## 2. Enhanced Lua Integration Tests (+7 tests)
- Added comprehensive ModeLoader test coverage
- Tests: mode_loader_creation, load_single_mode, reject_invalid_mode_number,
  reject_invalid_script, multiple_modes, channel_assignment, replace_mode
- Total test count: 24 tests (17 original + 7 new)
- Complete coverage of LuaContext, ModeLoader, and Lua API

## 3. Centralized Configuration (config.h)
- Created src/core/config.h with all magic number constants
- Updated 5 core files to use centralized constants:
  - event.h/pattern.h/song.h: Data structure sizes
  - engine.h/engine.cpp: Timing, tempo, LED patterns, pot mappings

### Constants centralized:
- Timing: AUTOSAVE_INTERVAL_MS, LED_TEMPO_DURATION_MS, TEMPO_DEBOUNCE_MS
- Musical: TEMPO_MIN/MAX/DEFAULT_BPM, MIDI_PPQN, STEPS_PER_BAR
- Hardware: NUM_BUTTONS, NUM_ROTARY_POTS, NUM_SLIDER_POTS, MIDI_MAX_VALUE
- Data: EVENTS_PER_TRACK, TRACKS_PER_PATTERN, PATTERNS_PER_MODE, NUM_MODES
- LED patterns: Fast blink timing constants
- Bit-packing: Event structure shifts and masks

### Benefits:
- Easier tuning and experimentation
- Self-documenting code with clear constant names
- Single source of truth for all configuration
- Improved maintainability

## Impact Summary:
- **Code reduction**: ~260 lines of duplication eliminated
- **Test coverage**: +7 comprehensive ModeLoader tests
- **Maintainability**: All magic numbers centralized in config.h
- **No functional changes**: All changes preserve existing behavior

Addresses items #1, #2, and #3 from docs/IMMEDIATE_ACTIONS.md
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.

2 participants