1.1.0 • Published 3 years ago

cotone v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

cotone.js

MIDI tick converter library for rhythm action game development.

About

Since timescale of music depends on it's tempo (BPM), music note data are usually managed by MIDI-tick unit instead of real-time in common music editing apps.

This library provides features for converting MIDI-tick <-> real-time, and also utils for drawing notes in rhythm action game app (which has note-speed changing feature by tempo).

Sample app

See following codesandbox project https://codesandbox.io/s/cotone-sample-938j8

Usage

Install

npm install cotone

Basic example

First, let's create an instance of key class, Converter.

import { Converter } from 'cotone'

const converter = new Converter()

Optional
The converting result depends on how you define the tick-unit value for quarter notes (This value is usually called "timebase", "ticks-per-quarter-note", "TPQN", etc.). Default is set to 480, but you can customize it with setTimebase

converter.setTimebase(480)

Then, set the tempo using setTempo.

// BPM: 128
converter.setTempo(128)

Now we're ready for conversion.
Assume we have a note data like below.

const noteTicks = [
  480, 960, 1920,
  // ... and so on
]

If you want real-time scale of these notes to schedule-play sounds, you can do like this.

const sound = new Audio('path/to/mysound.wav')
const noteRealSeconds = noteTicks.map(tick => converter.convertTickToSec(tick))

noteRealSeconds.forEach(noteSec => {
  setTimeout(() => {
    sound.play()
  }, noteSec * 1000)
})

Misc

Traditional browser style
<script src="path/to/cotone.js"></script>
<script type="text/javascript">
  const converter = new cotone.Converter()
  // Same as above...
</script>

Advanced

TODO

Documentation

TODO

Development

Build

You should run npm install once to prepare building condition.

Dev

npm run dev

Production

npm run build

Test

npm run test
1.1.0

3 years ago

1.0.0

4 years ago