https://github.com/banghuazhao/piano
A simple iOS piano keyboard built with SwiftUI and AVAudioEngine
https://github.com/banghuazhao/piano
audio ios iosgames midi music mvvm piano piano-keyboard sf2 swift swiftui
Last synced: 2 months ago
JSON representation
A simple iOS piano keyboard built with SwiftUI and AVAudioEngine
- Host: GitHub
- URL: https://github.com/banghuazhao/piano
- Owner: banghuazhao
- License: mit
- Created: 2025-09-07T11:05:25.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-17T10:48:09.000Z (9 months ago)
- Last Synced: 2025-10-07T09:27:54.320Z (9 months ago)
- Topics: audio, ios, iosgames, midi, music, mvvm, piano, piano-keyboard, sf2, swift, swiftui
- Language: Swift
- Homepage: https://apps.apple.com/us/app/pianoflow-keyboard/id6752531110
- Size: 9.96 MB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## πΉ PianoFlow
A modern, responsive iOS piano keyboard built with SwiftUI and AVAudioEngine. Features a scrollable 7-octave keyboard with customizable settings, haptic feedback, and realistic piano sound using SoundFont technology.

### π² Download on the App Store
- iOS: [PianoFlow on the App Store](https://apps.apple.com/us/app/pianoflow-keyboard/id6752531110)
### β¨ Features
- **πΉ 7-Octave Keyboard**: Full piano range from C1 to B7 with smooth horizontal scrolling
- **π§ Interactive Navigation**: Octave buttons and scroll slider for quick navigation
- **βοΈ Customizable Settings**: Adjustable key width, key name display options, and haptic feedback
- **π΅ Realistic Audio**: SoundFont-backed piano sound with low-latency playback
- **π± Modern UI**: SwiftUI interface with responsive keys and smooth animations
- **ποΈ MVVM Architecture**: Clean separation with `@Observable` view models and Swift concurrency
### ποΈ Architecture
- **π Pattern**: MVVM with Swift concurrency
- **ποΈ ViewModel**: `@Observable` and `@MainActor`-scoped for UI-safe state management
- **π Audio**: `AVAudioEngine` + `AVAudioUnitSampler` for SoundFont playback
- **πΎ State Management**: User preferences stored with `@AppStorage`
**π Data Flow**:
- π± `PianoView` renders the scrollable keyboard and handles user interactions
- ποΈ `PianoViewModel` manages key state, scroll position, and audio playback
- π `AudioEngine` service handles audio session and SoundFont loading
- βοΈ `SettingsView` provides customization options with persistent storage
### π οΈ Requirements
- π» Xcode 15 or later
- π± iOS 17 or later (SwiftUI `@Observable` macro)
- π₯οΈ macOS Sonoma or later for development
### π Getting Started
1. π₯ Clone the repository
```bash
git clone https://github.com/banghuazhao/PianoFlow.git
cd PianoFlow
```
2. π§ Open the project in Xcode
```bash
open Piano.xcodeproj
```
3. βΆοΈ Select the `Piano` scheme and a simulator or device, then Run.
**π Note**: If you replace the SoundFont, put your `.sf2` file in `Piano/Sound/` and update the load call if needed.
### π Project Structure
```text
Piano/
App/ # π App entry point (`PianoApp.swift`)
Sound/ # π΅ SoundFont file (`Piano.sf2`)
Assets.xcassets/ # π¨ App icons and colors
Config/ # βοΈ Build configurations
Model/ # π `PianoKey`, `PianoNote`, `OctaveColor`
Service/ # π `AudioEngine` for audio playback
View/ # π± `PianoView`, `PianoKeyView`, `SettingsView`
ViewModel/ # ποΈ `PianoViewModel` with @Observable
```
### πΌ Usage
- **πΉ Playing Notes**: Tap any key to play piano notes with realistic sound
- **π§ Navigation**:
- Use octave buttons (C1-C7) to jump to specific octaves
- Drag the scroll slider to navigate smoothly across the keyboard
- Swipe horizontally on the keyboard for fine control
- **βοΈ Settings**: Tap the gear icon to access:
- Key width adjustment (30-80 points)
- Show/hide key names on keys
- Toggle haptic feedback
- Octave-specific key name display options
- **π¨ Customization**: Replace `Piano.sf2` with your own SoundFont file to change the piano sound
### πΊοΈ Roadmap
- **π Multi-touch Support**: Enhanced chord playing with multiple simultaneous notes
- **ποΈ Sustain Pedal**: Virtual sustain pedal functionality
- **πΉ MIDI Support**: MIDI input/output for external controllers
- **ποΈ Recording**: Basic recording and playback capabilities
- **β¨ Visual Feedback**: Enhanced visual indicators for active notes
- **ποΈ Custom Key Ranges**: Configurable octave ranges and key layouts
### π€ Contributing
- π Open an issue or pull request on GitHub
- ποΈ Follow MVVM architecture with `@Observable` view models and Swift concurrency
- π§ Prefer small, well-scoped changes
- π Maintain consistent code style and documentation
### π License
No license file is included yet. If you intend to use this project beyond personal use, please add a license.
### π Acknowledgements
- π οΈ Built with SwiftUI and AVFoundation
- π΅ Uses a bundled SoundFont file (`Piano.sf2`). Replace with your own if licensing requires.
- Β©οΈ Copyright Apps Bay Limited. All rights reserved.
### π Links
- π¦ Repository: `https://github.com/banghuazhao/PianoFlow`
- ποΈ App Store: `https://apps.apple.com/us/app/pianoflow-keyboard/id6752531110`