0.3.3 • Published 12 months ago

@litecanvas/plugin-music v0.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Music plugin for litecanvas

Plugin to compose and play music in litecanvas games using ZzFX.

Install

NPM: npm i @litecanvas/plugin-music

CDN: https://unpkg.com/@litecanvas/plugin-music/dist/dist.js

Introduction

To compose a music you must use the function music(bpm, notes, instrument) that accepts 3 arguments:

  • bpm means "beats per minute" (the music tempo);
  • notes is array of arrays of the musical notes (A, B, C, etc). This plugins supports notes from C4 to B5.
  • instrument is a ZzFX sound used as a "timbre". This argument is optional.

Notes

Each note is a array with 2 numbers: the first number is the note and the second is the duration of that note. Example: [1, 4] is a C4 (Dó) with 4 beats of duration.

See all avaliable notes in the table below:

NoteNumber
0"silence"
1C4
2D4
3E4
4F4
5G4
6A4
7B4
8C5
9D5
10E5
11F5
12G5
13A5
14B5

Note: to indicate a flat (♭) or sharp (♯), add or reduce 0.5 to the note number. Example: C sharp 4 (C#4) is 1.5.

Usage

npm.io

import litecanvas from "litecanvas"
import pluginMusic from "@litecanvas/plugin-music"

litecanvas({
  loop: { init, tapped },
})

use(pluginMusic) // load the plugin

function init() {
  const musicNotes = [
    [5, 0.5], // Happy
    [5, 0.5],
    [6, 1], // Birthday
    [5, 1],
    [8, 1], // to
    [7, 2], // you
  ]
  happyBirthday = music(120, musicNotes)
}

function tapped() {
  // tap to play the music
  if (!happyBirthday.playing) {
    happyBirthday.play()
  }
}
0.3.2

12 months ago

0.3.3

12 months ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago