An open API service indexing awesome lists of open source software.

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

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.

Piano screenshot

### πŸ“² 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`