#music #piano #graphics


Provides graphical representation of a piano keyboard

4 releases

0.2.3 Apr 7, 2020
0.2.2 Mar 3, 2019
0.1.1 Feb 16, 2019
0.1.0 Feb 16, 2019

#73 in Graphics APIs

24 downloads per month
Used in rusthesia

MIT license



Build Status

This crate provides the graphical elements in order to draw a piano keyboard with close to realistic, pixel accurate appearance.

Reference for the dimension is this internet image: octave drawing

The dimensions described have been used to create the elements of a piano keyboard like for an octave like this: img

It is visible, that between white keys and even between white and black keys a gap is ensured.

The graphical representation only provides the white and black areas for the keys. Those areas are represented by pixel accurate, non-overlapping rectangles. No aliasing or similar is done on this level.

Pixel accurate has the consequence, that in order to fill the requested width, any gaps, white or black keys may need to be modified by up to one pixel. Those changes may or may not be visible. If no adjustments have been made for a given width and key range is reported by the function is_perfect()

If the enlargement of various elements does not succeed, then as last resort technique the outter gaps are enlarged.

The gap between white and black keys can be removed by an option of the KeyboardBuilder.

The interface is prepared to be compatible for an extension towards a 3d keyboard. That's why the returned keyboard is called Keyboard2D and the related build function is called build2d().

Thanks for contribution

No runtime deps