Git Product home page Git Product logo

beautiful-piano's Introduction

Beautiful Piano

screenshot

npm version npm dependencies npm dev dependencies

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 piano
  • options Options object, octaves and range property can't be used in combination You can also pass a namesMode property.
    • octaves - A positive integer, the amount of octaves to generate, starts always with an A and ends with a C, min: 1, max: 9
    • range - Options object with a custom range
      • startKey - A string, key where the piano should start, A-H
      • startOctave - An integer on which octave the piano should start, min: 0, max: 10
      • endKey - A string, key where the piano should end, A-H
      • endOctave - An integer on which octave the piano should end, min: 0, max: 10
    • namesMode - A string, either sharp or flat when names for the black keys are shown
    • lang - A string, either en or de to swap H and B
    • notation - A string, either scientific or helmholz will 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.

beautiful-piano's People

Contributors

timaschew avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.