0.1.24 • Published 1 year ago

musical-components v0.1.24

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

musical-components   GitHub Workflow Status   Node version

React/MIDI library that renders and plays musical notation in all major browsers.

Install

$ npm install musical-components --save

Usage

Instantiate notes (as well as rests), specifying the duration and pitch.

import { Note, NotationType, Pitch } from 'musical-components'

...

const notes = [
    new Note(NotationType.Eighth, Pitch.A3),
    new Note(NotationType.Eighth, Pitch.B3),
    new Note(NotationType.Eighth, Pitch.C4)
]

Pass your note array into the Staff element's initialNotations prop within your React app, providing the clef, key signature, and time signature as additional props.

import { NotationType, Clef, Staff } from 'musical-components'

<Staff initialNotations={notes} beatsPerMeasure={4} beatDuration={NotationType.Quarter} clef={Clef.TrebleClef} />

Result:

Specifying Key Signature

The Staff component allows you to specify your own sharps or flats for the key signature. To create a staff in E Major, for example, pass an array of the the four sharped notes into the sharps prop:

import { NaturalNote, Staff } from 'musical-components'

const EMajor = [NaturalNote.F, NaturalNote.C, NaturalNote.G, NaturalNote.D]

<Staff ... sharps={EMajor} />

See example including key signature usage here.

Core Library

The library contains React components for rendering musical notation and the core logic required, such as determining whether to write an sharp, flat, or natural next to a note based on its pitch and the staff's key signature. It also converts musical pitches into audio frequencies and sends / listens to MIDI messages. The React UI optionally highlights the notes as they are played by intercepting these MIDI messages.

The primary React component is <Staff />, with the following props:

NameDescription
clefEither TrebleClef or BassClef
beatsPerMeasureNumber of beats per measure (top of time signature)
beatDurationInherent beat value (bottom of time signature)
beatsPerMinute*Determines speed of audio playback
sharps*Notes that are sharped in the key signature
flats*Notes that are flatted in the key signature

*optional

Examples

See examples here.

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.22

1 year ago

0.1.23

1 year ago

0.1.24

1 year ago

0.1.16

1 year ago

0.1.8

1 year ago

0.1.17

1 year ago

0.1.7

1 year ago

0.1.18

1 year ago

0.1.19

1 year ago

0.1.9

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago