tone-rhythm
Version:
Generate an array of Tone.Transport times for use in Tone.Part
156 lines (65 loc) • 2.97 kB
Markdown
# tone-rhythm *1.2.0*
> Generate an array of Tone.Transport times for use in Tone.Part
### src/tone-rhythm.js
#### toneRhythm(ToneTime)
Factory to get tone-rhythm methods
BREAKING CHANGE IN v1.0.0 - Tone is now a true "peer dependency" and needs to be included here:
##### Parameters
| Name | Type | Description | |
| ---- | ---- | ----------- | -------- |
| ToneTime | `Object` | - import of Tone.Time. example: const ToneTime = require('tone/Tone/type/Time'); | |
##### Returns
- `Object` - tone-rhythm methods { getBarsBeats,
addTimes,
getTransportTimes,
mergeMusicDataPart
}
#### getBarsBeats(value)
##### Parameters
| Name | Type | Description | |
| ---- | ---- | ----------- | -------- |
| value | `string` `number` | - a rhythm value Tone recognizes | |
##### Examples
```javascript
getBarsBeats('4n') -> '0:1:0'
```
##### Returns
- `string` - rhythm value converted to Tone's bars/beats format.
#### addTimes(item)
##### Parameters
| Name | Type | Description | |
| ---- | ---- | ----------- | -------- |
| item | `Array.<string>` `string` | if item is array, return summation of items in Tone's bars/beats format.<br> Note: The first item of the array may be 'r' (rest) | |
##### Examples
```javascript
addTimes('4n.') -> '4n.'
```
```javascript
addTimes(['8n', '4t', '4t', '4t', '4t', '4t', '4t', '8n']) -> '1:1:0'
```
##### Returns
- `string` - if item is an array, returns rhythm value converted to Tone's bars/beats format.
If item was a string, it gets returned as is.
#### getTransportTimes(arrOfDurations[, startTime=0])
Given an array of durations (see API), return transport times.
see [README.md](README.md) for examples
##### Parameters
| Name | Type | Description | |
| ---- | ---- | ----------- | -------- |
| arrOfDurations | `Array.<string>` | - see README.md API | |
| startTime=0 | `number` `string` | - a start time in Tone's Time format. | *Optional* |
##### Returns
- `Array` of start times in Tone's bars/beats format.
#### mergeMusicDataPart(config)
see [README.md](README.md) for examples and return values.
##### Parameters
| Name | Type | Description | |
| ---- | ---- | ----------- | -------- |
| config | `Object` | (see properties below) | |
| config.rhythms | `Array` | - see API | |
| config.notes | `Array.<string>` | - ex: ['C4', 'D4', 'E4'] | *Optional* |
| config.times | `Array` | - see return of `getTransportTimes` | *Optional* |
| config.startTime | `string` `number` | - see startTime of `getTransportTimes` | *Optional* |
##### Returns
- `Array` of objects for consumption by Tone.Part. Object properties always include `time` (number|string), array index `idx` (number - integer) and `duration` (string). May also include `notes` and `velocities`. (see readme)
*Documentation generated with [doxdox](https://github.com/neogeek/doxdox).*