tonal-pitchset
Advanced tools
Comparing version 0.66.0 to 0.67.0
@@ -6,2 +6,3 @@ 'use strict'; | ||
var tonalPitch = require('tonal-pitch'); | ||
var tonalNote = require('tonal-note'); | ||
var tonalArray = require('tonal-array'); | ||
@@ -14,2 +15,15 @@ var tonalTranspose = require('tonal-transpose'); | ||
/** | ||
* Given a list of notes, return the notes of the pitchset | ||
* starting with the first note of the list | ||
*/ | ||
function notes (notes) { | ||
var pcs = tonalArray.map(tonalNote.pc, notes) | ||
if (!pcs.length) return pcs | ||
var tonic = pcs[0] | ||
// since the first note of the chroma is always C, we have to rotate it | ||
var rotated = tonalArray.rotate(pitchChr(tonic), chroma(pcs).split('')).join('') | ||
return fromChroma(rotated, tonic) | ||
} | ||
/** | ||
* Given a pitch set (a list of notes or a pitch set chroma), produce the 12 rotations | ||
@@ -78,3 +92,3 @@ * of the chroma (and discard the ones that starts with '0') | ||
if (arguments.length === 1) return function (s) { return withTonic(tonic, s) } | ||
return fromBinary(chroma(set), tonic) | ||
return fromChroma(chroma(set), tonic) | ||
} | ||
@@ -90,6 +104,6 @@ | ||
* @example | ||
* pitchset.fromBinary('101010101010', 'C') // => ['C', 'D', 'E', 'Gb', 'Ab', 'Bb'] | ||
* pitchset.fromChroma('101010101010', 'C') // => ['C', 'D', 'E', 'Gb', 'Ab', 'Bb'] | ||
*/ | ||
function fromBinary (binary, tonic) { | ||
if (arguments.length === 1) return function (t) { return fromBinary(binary, t) } | ||
function fromChroma (binary, tonic) { | ||
if (arguments.length === 1) return function (t) { return fromChroma(binary, t) } | ||
if (!isChroma(binary)) return null | ||
@@ -176,2 +190,3 @@ | ||
exports.notes = notes; | ||
exports.rotations = rotations; | ||
@@ -181,3 +196,3 @@ exports.isChroma = isChroma; | ||
exports.withTonic = withTonic; | ||
exports.fromBinary = fromBinary; | ||
exports.fromChroma = fromChroma; | ||
exports.equal = equal; | ||
@@ -184,0 +199,0 @@ exports.subset = subset; |
22
index.js
@@ -11,2 +11,3 @@ /** | ||
import { chr, asPitch } from 'tonal-pitch' | ||
import { pc } from 'tonal-note' | ||
import { map, asArr, rotate, compact } from 'tonal-array' | ||
@@ -19,2 +20,15 @@ import { transpose } from 'tonal-transpose' | ||
/** | ||
* Given a list of notes, return the notes of the pitchset | ||
* starting with the first note of the list | ||
*/ | ||
export function notes (notes) { | ||
var pcs = map(pc, notes) | ||
if (!pcs.length) return pcs | ||
var tonic = pcs[0] | ||
// since the first note of the chroma is always C, we have to rotate it | ||
var rotated = rotate(pitchChr(tonic), chroma(pcs).split('')).join('') | ||
return fromChroma(rotated, tonic) | ||
} | ||
/** | ||
* Given a pitch set (a list of notes or a pitch set chroma), produce the 12 rotations | ||
@@ -83,3 +97,3 @@ * of the chroma (and discard the ones that starts with '0') | ||
if (arguments.length === 1) return function (s) { return withTonic(tonic, s) } | ||
return fromBinary(chroma(set), tonic) | ||
return fromChroma(chroma(set), tonic) | ||
} | ||
@@ -95,6 +109,6 @@ | ||
* @example | ||
* pitchset.fromBinary('101010101010', 'C') // => ['C', 'D', 'E', 'Gb', 'Ab', 'Bb'] | ||
* pitchset.fromChroma('101010101010', 'C') // => ['C', 'D', 'E', 'Gb', 'Ab', 'Bb'] | ||
*/ | ||
export function fromBinary (binary, tonic) { | ||
if (arguments.length === 1) return function (t) { return fromBinary(binary, t) } | ||
export function fromChroma (binary, tonic) { | ||
if (arguments.length === 1) return function (t) { return fromChroma(binary, t) } | ||
if (!isChroma(binary)) return null | ||
@@ -101,0 +115,0 @@ |
{ | ||
"name": "tonal-pitchset", | ||
"version": "0.66.0", | ||
"version": "0.67.0", | ||
"description": "Pitch set utilities", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
var test = require('tape') | ||
var pitchset = require('..') | ||
test('pitchset: notes', function (t) { | ||
t.deepEqual(pitchset.notes('g4 f5 g3 d3 a3 a4 c6 a1'), | ||
[ 'G', 'A', 'C', 'D', 'F' ]) | ||
t.end() | ||
}) | ||
test('pitchset: chroma', function (t) { | ||
@@ -13,6 +19,6 @@ t.equal(pitchset.chroma('c d e'), '101010000000') | ||
test('pitchset: fromBinary', function (t) { | ||
t.deepEqual(pitchset.fromBinary('101010101010', 'C'), | ||
test('pitchset: fromChroma', function (t) { | ||
t.deepEqual(pitchset.fromChroma('101010101010', 'C'), | ||
[ 'C', 'D', 'E', 'Gb', 'Ab', 'Bb' ]) | ||
t.deepEqual(pitchset.fromBinary('101010101010', null), | ||
t.deepEqual(pitchset.fromChroma('101010101010', null), | ||
[ '1P', '2M', '3M', '5d', '6m', '7m' ]) | ||
@@ -19,0 +25,0 @@ t.end() |
16453
432