Skip to content

twlite/jspiano

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Piano

Simple Node.js Piano

Installing

$ npm i jspiano

Example

const { Piano } = require("jspiano");
const piano = new Piano("C4"); // load piano with octave C4

piano.press("C#", "C4", 1000); // press C# of octave C4 for 1 second

Sheets

Sheet format

mysheet.json

[
    {
        "note": "C",
        "octave": "C4",
        "duration": 1000
    },
    {
        "note": "D",
        "octave": "C4",
        "duration": 1000
    },
    {
        "note": "E",
        "octave": "C4",
        "duration": 1000
    },
    {
        "note": "F",
        "octave": "C4",
        "duration": 1000
    },
    {
        "note": "G",
        "octave": "C4",
        "duration": 1000
    },
    {
        "note": "A",
        "octave": "C4",
        "duration": 1000
    },
    {
        "note": "B",
        "octave": "C4",
        "duration": 1000
    },
    {
        "note": "C",
        "octave": "C5",
        "duration": 1000
    }
]

Load Sheets

const { Piano } = require("jspiano");
const piano = new Piano(["C4", "C5"]);

piano.playSheet("./mysheet.json");

Octaves

Available from C0 to C7.

Events

press

Emitted when a note is pressed! Returns object with note, octave, frequency, duration and time.

piano.on("press", ({ note, duration }) => console.log(note, duration));

Preview

video

Join my discord