Package Exports
- beautiful-piano
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (beautiful-piano) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Beautiful Piano
This library provides a JavaScript API to generate HTML markup for a beautiful musical keyboard. It comes with a CSS file which makes it so nice.
Demo
See the demo on rawgit
Setup
Either embed the file from the dist directory via script tag in your HTML:
<script src="beautiful-piano/dist/piano.js"></script>Then you can access to the global variable piano.
Otherwise install it via npm npm i beautiful-piano
Don't forget to include the CSS file, for instance:
<link rel="stylesheet" href="beautiful-piano/styles.css">Usage
piano(document.querySelector('body'), {octaves: 3});piano(parent, options)
Arguments:
parent- DOM element where to inject the pianooptionsOptions object,octavesandrangeproperty can't be used in combination You can also pass anamesModeproperty.octaves- A positive integer, the amount of octaves to generate, starts always with an A and ends with a C, min: 1, max: 9range- Options object with a custom rangestartKey- A string, key where the piano should start,A-HstartOctave- An integer on which octave the piano should start, min: 0, max: 10endKey- A string, key where the piano should end,A-HendOctave- An integer on which octave the piano should end, min: 0, max: 10
namesMode- A string, eithersharporflatwhen names for the black keys are shownlang- A string, eitherenordeto swap H and Bnotation- A string, eitherscientificorhelmholzwill be used for octave notation
Selectors
You can toggle the pressed effect of each key with CSS class.
For instance: document.querySelector('.C4').classList.add('active')
The selector for the keys use the scientific notatino for the octave. All 12 keys for the fourth octave can be accessed with these selectors:
.C4
.Cs4 or .Db4
.D4
.Ds4 or .Eb4
.E4
.F4
.Fs4 or .Gb4
.G4
.Gs4 or .Ab4
.A4
.As4 or .Bb
.B
WTF? I can't hear anything!
This library provides just a visual interface. Playing a sound while pressing a key is comming soon as an extra module.
Credits
All visual credits goes to Taufik Nurrohman
I started with the style sheets from his codepen and modified it for more dynamic use cases.
