Skip to content

justelson/Virtual-piano

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽน Virtual Piano

A professional-grade virtual piano application built with HTML5, CSS3, and JavaScript. Experience realistic piano sounds with multiple harmonics, octave-dependent characteristics, and a beautiful modern interface. image

Virtual Piano Screenshot HTML5 CSS3 JavaScript Web Audio API

โœจ Features

๐ŸŽต Realistic Piano Sound

  • Multiple Harmonics: Each note uses 5 oscillators (fundamental, 2nd, 3rd, 5th harmonics, plus slight detuning)
  • Octave-Dependent Characteristics: Lower notes emphasize fundamental frequency, higher notes have more prominent harmonics
  • Dynamic Audio Processing: Low-pass filtering and compression for authentic piano sound
  • Natural Envelopes: Attack, decay, and sustain times vary by octave to match real piano behavior

๐ŸŽฎ Interactive Controls

  • Keyboard Input: Full keyboard mapping for white and black keys
  • Mouse/Touch Support: Click or tap piano keys directly
  • Octave Shifting: Change octave range with buttons or arrow keys
  • Volume Control: Real-time volume adjustment with visual feedback
  • Responsive Design: Works seamlessly on desktop and mobile devices

๐ŸŽจ Modern Interface

  • Professional Design: Gradient backgrounds and modern typography
  • Realistic Piano Keys: 3D-styled keys with hover and press animations
  • Smart Notifications: Non-intrusive feedback for user actions
  • Comprehensive Instructions: Clear key mapping guide and controls

๐Ÿš€ Getting Started

Quick Start

  1. Simple Method: Open index.html directly in your web browser
  2. With Java Server (optional):
    javac PianoServer.java
    java PianoServer
    Then open http://localhost:8080 in your browser

Browser Requirements

  • Modern web browser with Web Audio API support
  • Chrome, Firefox, Safari, or Edge (latest versions recommended)
  • JavaScript enabled

๐ŸŽน How to Play

Keyboard Mapping

White Keys

Keys Notes
Z X C V B N M C3 - B3
, . / Q W E R C4 - B4
T Y U I O P C5 - G5

Black Keys (Sharps)

Keys Notes
S D G H J C#3 - A#3
L 1 3 4 5 C#4 - A#4
7 8 0 C#5 - F#5

Controls

  • Arrow Keys: โ†‘ / โ†“ to change octave
  • Volume Slider: Adjust sound level (0-100%)
  • Octave Buttons: Click Octave + / Octave - for octave control

๐Ÿ› ๏ธ Technical Details

Audio Architecture

Oscillators (5 per note) โ†’ Individual Gains โ†’ Master Gain โ†’ 
Low-pass Filter โ†’ Dynamic Compressor โ†’ Audio Output

Sound Generation

  • Fundamental Frequency: Triangle wave for rich base tone
  • Harmonics: Sine waves at 2x, 3x, 5x fundamental frequency
  • Detuning: Slight frequency offset for natural richness
  • Envelope Shaping: ADSR envelope with octave-specific timing

File Structure

piano-java-html-v2/
โ”œโ”€โ”€ index.html          # Main HTML file with UI
โ”œโ”€โ”€ piano.js           # Core piano logic and audio processing
โ”œโ”€โ”€ PianoServer.java   # Optional Java HTTP server
โ”œโ”€โ”€ run.bat           # Windows batch file to run server
โ””โ”€โ”€ README.md         # This documentation

๐ŸŽผ Note Range

The piano covers 3 octaves from C3 to G5:

  • Octave 3: C3 - B3 (12 notes)
  • Octave 4: C4 - B4 (12 notes)
  • Octave 5: C5 - G5 (7 notes)

Total: 31 keys (19 white keys, 12 black keys)

๐Ÿ”ง Customization

Adjusting Sound Characteristics

Modify the getHarmonicLevels() and getPianoEnvelope() methods in piano.js to customize:

  • Harmonic content ratios
  • Attack/decay/sustain timings
  • Octave-specific sound characteristics

Visual Styling

Edit the CSS in index.html to customize:

  • Color schemes and gradients
  • Key dimensions and spacing
  • Animation effects and transitions

๐ŸŒ Browser Compatibility

Browser Support Notes
Chrome โœ… Full Recommended
Firefox โœ… Full Excellent performance
Safari โœ… Full May require user interaction to start audio
Edge โœ… Full Good performance
Mobile Browsers โœ… Partial Touch support, may have audio latency

๐Ÿšจ Troubleshooting

No Sound

  1. Check browser support: Ensure Web Audio API is supported
  2. User interaction required: Click anywhere on the page first
  3. Volume settings: Check both app volume and system volume
  4. Browser permissions: Allow audio playback if prompted

Performance Issues

  1. Close other audio applications
  2. Use latest browser version
  3. Reduce number of simultaneous notes
  4. Lower volume if experiencing distortion

๐Ÿค Contributing

This project welcomes contributions! Areas for improvement:

  • Additional sound synthesis methods
  • More octave ranges
  • Recording/playback functionality
  • MIDI input support
  • Additional instrument sounds

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿ™ Acknowledgments

  • Inspired by real piano acoustics and Web Audio API capabilities
  • Built with modern web technologies for optimal performance
  • Designed for both casual users and music enthusiasts

Enjoy playing! ๐ŸŽต

For questions or suggestions, please open an issue or submit a pull request.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors