npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

svg-interactive-piano

v0.0.1-a

Published

A dependency free piano display and interaction plugin for browsers using svg.

Downloads

1

Readme

SVGIntPiano

An interactive SVG piano keyboard plugin written in pure JavaScript with no dependencies

This library/plugin provides a stylable piano keyboard using SVG and CSS. The library can function both as an input and output. The goal is to be very lightweight so that it contains a small footprint and remains modifiable.

Examples

Currently, there are three examples that demonstrates the library's functionality:

  • an example showing how to connect key presses to callbacks
  • an example showing how to use svgintpiano as a display
  • an example showing how to style the piano with SVG

Installation

Currently, you can download the files in the dist directory and include the js file and, optionally, the CSS file.

Initializing

To initialize an SVGIntPiano object:

const params = {
  \\ setup parameters go here
};
const piano = new SVGIntPiano("cont", params);

Where "cont" is the id of an element defined similarly to:

<body>
  <div id="cont"></div>
</body>

The library creates an SVG within the element whose id is passed as the first argument.

Parameters

This library contains a number of parameters that enable some custimization of functionality.

lowNote

(int) The lowest note that the keyboard displays

highNote

(int) The highest note that the keyboard displays

width height

(int) The dimensions of the SVG in pixels

margin

(int) The margin around the sides of the SVG in pixels

interactive

(bool) Enables or disables touch interactivity

whiteKeySpacing

(int) The spacing of the white keys in pixels

blackKeyVScale

(float) How large the black keys are in relationship to the white keys in the vertical dimension

blackKeyHScale

(float) How large the black keys are in relationship to the white keys in the horizontal dimension

cssClassPrefix

(string) Default is svgkey. This defines the prefix of the classes used to style the keyboard plugin.

API

The plugin/library responds to the following functions:

set(state, key)

  • (boolean) state: the desired state
  • (int) key: the midi number responding to the key

Sets the key to the value of state. This sets the css value of the key for display purposes.

clear()

Sets all keys to off.

subscribe(message, callback)

  • (string) message: one of "keyon" and "keyoff"
  • (function) callback: a function that takes as its first argument the midi number of the key pressed or released

Returns: (string) id : the id that is used to unsubscribe from a callback

Use this to assign functions that take place when keys are pressed and released.

unsubscribe(message, key)

  • (string) message: one of "keyon" and "keyoff"
  • (string) key: string returned from subscribe()

Use this to unsubscribe from an event.

Styling

The appearance of the keyboard is specified through CSS. Declaration that can be used for SVG work for the keys of this piano plugin.

Note on the naming convention

The following class names are of the form svgkey_(specifier). This assumes that prop.cssClassPrefix mentioned above is not set. If it is, use what ever you set this to in the place of svgkey. For example, if you set cssClassPrefix to pianokey, your class names will be of the form pianokey_specifier.

The class names

.svgkey_off

The styling for white keys when they are not being depressed or when the set(false, midinumber) method is called.

.svgkey_on

The styling for white keys when they are being depressed or when the set(true, midinumber) method is called.

.svgkey_black_off

The styling for black keys when they are not being depressed or when the set(false, midinumber) method is called.

.svgkey_black_on

The styling for black keys when they are being depressed or when the set(true, midinumber) method is called.

Note as well, psuedo selectors such as hover are available to SVG rectangles.

Contributing

I do not have a maintenance model right now for accepting issues and pull requests. If you send one, I will try my best to answer questions or accept the pull request if its appropriate.

Thanks!