New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tonal-note

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tonal-note - npm Package Compare versions

Comparing version 0.60.0 to 0.61.0

build/index.js

14

build/tonal-note.js

@@ -39,3 +39,3 @@ 'use strict';

*/
function noteName (n) {
function name (n) {
var p = tonalPitch.asNotePitch(n)

@@ -46,11 +46,2 @@ return p ? tonalPitch.strNote(p) : null

/**
* An alias for `noteName`
* @see noteName
* @example
* tonal.note('fx4') // => 'F##4'
* tonal.note('blah') // => null
*/
var note = noteName
/**
* Get pitch class of a note. The note can be a string or a pitch array.

@@ -119,4 +110,3 @@ *

exports.chroma = chroma;
exports.noteName = noteName;
exports.note = note;
exports.name = name;
exports.pc = pc;

@@ -123,0 +113,0 @@ exports.enharmonics = enharmonics;

/**
* A collection of functions to get properties from musical notes.
* `tonal-note` is a collection of functions to get properties from musical notes.
*
* @module note
* @example
* var _ = require('tonal')
* tonal.note('bb2') // => 'Bb2'
* tonal.chroma('bb2') // => 10
* tonal.enharmonics('C#6') // => [ 'B##5', 'C#6', 'Db6' ]
* tonal.simpleEnh('B#3') // => 'C4'
* var note = require('tonal-note')
* note.name('bb2') // => 'Bb2'
* note.chroma('bb2') // => 10
* note.enharmonics('C#6') // => [ 'B##5', 'C#6', 'Db6' ]
* note.simplify('B#3') // => 'C4'
*
* @example
* // using ES6 import syntax
* import { name } from 'tonal-note'
* ['c', 'db3', '2', 'g+', 'gx4'].map(name) // => ['C', 'Db3', null, null, 'G##4']
*/
import { fifths, asNotePitch, strNote, parseIvl, chr } from 'tonal-pitch'
import { tr } from 'tonal-transpose'
import { transpose as tr } from 'tonal-transpose'

@@ -22,4 +27,5 @@ /**

* @example
* ['C', 'D', 'E', 'F'].map(_.chroma) // => [0, 2, 4, 5]
* _.map(_.chroma, 'cb db eb fb') // => [11, 1, 3, 4]
* var note = require('tonal-note')
* note.chroma('Cb') // => 11
* ['C', 'D', 'E', 'F'].map(note.chroma) // => [0, 2, 4, 5]
*/

@@ -39,13 +45,9 @@ export function chroma (n) {

* @return {String}
* @example
* import { noteName } from 'tonal-notes'
* ['c', 'db3', '2', 'g+', 'gx4'].map(noteName)
* // => ['C', 'Db3', null, null, 'G##4']
*
* @example
* var tonal = require('tonal')
* tonal.noteName('cb2') // => 'Cb2'
* tonal.map(tonal.noteName, 'c db3 2 g+ gx4') // => [ 'C', 'Db3', null, null, 'G##4' ]
* var note = require('tonal-note')
* note.toNote('cb2') // => 'Cb2'
* ['c', 'db3', '2', 'g+', 'gx4'].map(note.name) // => ['C', 'Db3', null, null, 'G##4']
*/
export function noteName (n) {
export function toNote (n) {
var p = asNotePitch(n)

@@ -56,11 +58,2 @@ return p ? strNote(p) : null

/**
* An alias for `noteName`
* @see noteName
* @example
* tonal.note('fx4') // => 'F##4'
* tonal.note('blah') // => null
*/
export var note = noteName
/**
* Get pitch class of a note. The note can be a string or a pitch array.

@@ -91,7 +84,7 @@ *

* @example
* enharmonics = require('enharmonics')
* enharmonics('C') // => ['B#', 'C', 'Dbb']
* enharmonics('A') // => ['G##', 'A', 'Bbb']
* enharmonics('C#4') // => ['B##3', 'C#4' 'Db4']
* enharmonics('Db') // => ['C#', 'Db', 'Ebbb'])
* var note = require('tonal-note')
* note.enharmonics('C') // => ['B#', 'C', 'Dbb']
* note.enharmonics('A') // => ['G##', 'A', 'Bbb']
* note.enharmonics('C#4') // => ['B##3', 'C#4' 'Db4']
* note.enharmonics('Db') // => ['C#', 'Db', 'Ebbb'])
*/

@@ -108,8 +101,2 @@ export function enharmonics (pitch) {

/**
* An alias for `enharmonics`
* @function
*/
export var enh = enharmonics
/**
* Get a simpler enharmonic note name from a note if exists

@@ -121,5 +108,6 @@ *

* @example
* tonal.simpleEnh('B#3') // => 'C4'
* var note = require('tonal-note')
* note.simplify('B#3') // => 'C4'
*/
export function simpleEnh (pitch) {
export function simplify (pitch) {
return enharmonics(pitch).reduce(function (simple, next) {

@@ -126,0 +114,0 @@ if (!simple) return next

{
"name": "tonal-note",
"version": "0.60.0",
"version": "0.61.0",
"description": "Encode pitches using fifths/octaves",
"keywords": [],
"scripts": {
"pretest": "rm -rf build && mkdir build && rollup -f cjs -n note -o build/tonal-note.js -- index.js",
"prepublish": "npm test"
"pretest": "rollup -f cjs -o build/index.js -- index.js",
"test": "tape test/*.js"
},

@@ -16,5 +16,5 @@ "main": "build/index.js",

"dependencies": {
"tonal-pitch": "^0.50.1",
"tonal-transpose": "^0.60.0"
"tonal-pitch": "^0.61.0",
"tonal-transpose": "^0.61.0"
}
}

@@ -5,3 +5,3 @@ # tonal-note [![npm version](https://img.shields.io/npm/v/tonal-note.svg)](https://www.npmjs.com/package/tonal-note)

`tonal-note` is a collection of functions to manipulate music note properties.
`tonal-note` is a collection of functions to extract properties from musical notes.

@@ -12,36 +12,32 @@ This is part of [tonal](https://www.npmjs.com/package/tonal) music theory library.

## API Reference
[Read the generated API documentation](https://danigb.github.io/tonal/api/module-note.html).
<dl>
<dt><a href="#chroma">chroma(note)</a> ⇒ <code>Integer</code></dt>
<dd><p>Return the chroma of a note. The chroma is the numeric equivalent to the
pitch class, where 0 is C, 1 is C# or Db, 2 is D... 11 is B</p>
</dd>
<dt><a href="#noteName">noteName(n)</a> ⇒ <code>String</code></dt>
<dd><p>Given a note (as string or as array notation) returns a string
with the note name in scientific notation or null
if not valid note</p>
</dd>
<dt><a href="#pc">pc(n)</a> ⇒ <code>String</code></dt>
<dd><p>Get pitch class of a note. The note can be a string or a pitch array.</p>
</dd>
<dt><a href="#enharmonics">enharmonics(note)</a> ⇒ <code>Array</code></dt>
<dd><p>Get the enharmonics of a note. It returns an array of three elements: the
below enharmonic, the note, and the upper enharmonic</p>
</dd>
<dt><a href="#enh">enh()</a></dt>
<dd><p>An alias for <code>enharmonics</code></p>
</dd>
<dt><a href="#simpleEnh">simpleEnh(note)</a> ⇒ <code>String</code></dt>
<dd><p>Get a simpler enharmonic note name from a note if exists</p>
</dd>
</dl>
## API
<a name="module_note"></a>
<a name="chroma"></a>
`tonal-note` is a collection of functions to get properties from musical notes.
## chroma(note) ⇒ <code>Integer</code>
**Example**
```js
var note = require('tonal-note')
note.name('bb2') // => 'Bb2'
note.chroma('bb2') // => 10
note.enharmonics('C#6') // => [ 'B##5', 'C#6', 'Db6' ]
note.simplify('B#3') // => 'C4'
```
* [note](#module_note)
* [.chroma(note)](#module_note.chroma) ⇒ <code>Integer</code>
* [.name(n)](#module_note.name) ⇒ <code>String</code>
* [.pc(n)](#module_note.pc) ⇒ <code>String</code>
* [.enharmonics(note)](#module_note.enharmonics) ⇒ <code>Array</code>
* [.simplify(note)](#module_note.simplify) ⇒ <code>String</code>
<a name="module_note.chroma"></a>
### note.chroma(note) ⇒ <code>Integer</code>
Return the chroma of a note. The chroma is the numeric equivalent to the
pitch class, where 0 is C, 1 is C# or Db, 2 is D... 11 is B
**Kind**: global function
**Kind**: static method of <code>[note](#module_note)</code>
**Returns**: <code>Integer</code> - the chroma

@@ -53,5 +49,10 @@

<a name="noteName"></a>
**Example**
```js
['C', 'D', 'E', 'F'].map(_.chroma) // => [0, 2, 4, 5]
_.map(_.chroma, 'cb db eb fb') // => [11, 1, 3, 4]
```
<a name="module_note.name"></a>
## noteName(n) ⇒ <code>String</code>
### note.name(n) ⇒ <code>String</code>
Given a note (as string or as array notation) returns a string

@@ -61,3 +62,3 @@ with the note name in scientific notation or null

**Kind**: global function
**Kind**: static method of <code>[note](#module_note)</code>

@@ -78,10 +79,10 @@ | Param | Type |

tonal.noteName('cb2') // => 'Cb2'
tonal.map(tonal.noteName, 'c db3 2 g+ gx4')
tonal.map(tonal.noteName, 'c db3 2 g+ gx4') // => [ 'C', 'Db3', null, null, 'G##4' ]
```
<a name="pc"></a>
<a name="module_note.pc"></a>
## pc(n) ⇒ <code>String</code>
### note.pc(n) ⇒ <code>String</code>
Get pitch class of a note. The note can be a string or a pitch array.
**Kind**: global function
**Kind**: static method of <code>[note](#module_note)</code>
**Returns**: <code>String</code> - the pitch class

@@ -96,10 +97,11 @@

tonal.pc('Db3') // => 'Db'
tonal.map(tonal.pc, 'db3 bb6 fx2') // => [ 'Db', 'Bb', 'F##']
```
<a name="enharmonics"></a>
<a name="module_note.enharmonics"></a>
## enharmonics(note) ⇒ <code>Array</code>
### note.enharmonics(note) ⇒ <code>Array</code>
Get the enharmonics of a note. It returns an array of three elements: the
below enharmonic, the note, and the upper enharmonic
**Kind**: global function
**Kind**: static method of <code>[note](#module_note)</code>
**Returns**: <code>Array</code> - an array of pitches ordered by distance to the given one

@@ -113,20 +115,14 @@

```js
enharmonics = require('enharmonics')
enharmonics('C') // => ['B#', 'C', 'Dbb']
enharmonics('A') // => ['G##', 'A', 'Bbb']
enharmonics('C#4') // => ['B##3', 'C#4' 'Db4']
enharmonics('Db') // => ['C#', 'Db', 'Ebbb'])
var note = require('tonal-note')
note.enharmonics('C') // => ['B#', 'C', 'Dbb']
note.enharmonics('A') // => ['G##', 'A', 'Bbb']
note.enharmonics('C#4') // => ['B##3', 'C#4' 'Db4']
note.enharmonics('Db') // => ['C#', 'Db', 'Ebbb'])
```
<a name="enh"></a>
<a name="module_note.simplify"></a>
## enh()
An alias for `enharmonics`
**Kind**: global function
<a name="simpleEnh"></a>
## simpleEnh(note) ⇒ <code>String</code>
### note.simplify(note) ⇒ <code>String</code>
Get a simpler enharmonic note name from a note if exists
**Kind**: global function
**Kind**: static method of <code>[note](#module_note)</code>
**Returns**: <code>String</code> - the simplfiied note (if not found, return same note)

@@ -140,4 +136,4 @@

```js
var enharmonics = require('enharmonics')
enharmonics.simpleEnh('B#3') // => 'C4'
var note = require('tonal-note')
note.simplify('B#3') // => 'C4'
```
var tape = require('tape')
var note = require('..')
tape('get enharmonics', function (test) {
test.deepEqual(note.enh('C'), [ 'B#', 'C', 'Dbb' ])
test.deepEqual(note.enh('B'), [ 'A##', 'B', 'Cb' ])
test.deepEqual(note.enh('B#'), [ 'A###', 'B#', 'C' ])
test.deepEqual(note.enh('F5'), [ 'E#5', 'F5', 'Gbb5' ])
test.deepEqual(note.enh('E#2'), [ 'D###2', 'E#2', 'F2' ])
test.deepEqual(note.enh('A###6'), [ 'G#####6', 'A###6', 'B#6' ])
test.deepEqual(note.enh('A'), [ 'G##', 'A', 'Bbb' ])
test.deepEqual(note.enh('Ab3'), [ 'G#3', 'Ab3', 'Bbbb3' ])
test.deepEqual(note.enh('Db'), [ 'C#', 'Db', 'Ebbb' ])
tape('note: enharmonics', function (test) {
test.deepEqual(note.enharmonics('C'), [ 'B#', 'C', 'Dbb' ])
test.deepEqual(note.enharmonics('B'), [ 'A##', 'B', 'Cb' ])
test.deepEqual(note.enharmonics('B#'), [ 'A###', 'B#', 'C' ])
test.deepEqual(note.enharmonics('F5'), [ 'E#5', 'F5', 'Gbb5' ])
test.deepEqual(note.enharmonics('E#2'), [ 'D###2', 'E#2', 'F2' ])
test.deepEqual(note.enharmonics('A###6'), [ 'G#####6', 'A###6', 'B#6' ])
test.deepEqual(note.enharmonics('A'), [ 'G##', 'A', 'Bbb' ])
test.deepEqual(note.enharmonics('Ab3'), [ 'G#3', 'Ab3', 'Bbbb3' ])
test.deepEqual(note.enharmonics('Db'), [ 'C#', 'Db', 'Ebbb' ])
test.end()
})
tape('returns empty array if not valid pitch', function (test) {
test.deepEqual(note.enh('blah'), null)
tape('note: enharmonics - returns empty array if not valid pitch', function (test) {
test.deepEqual(note.enharmonics('blah'), null)
test.end()
})
tape('with arrays', function (test) {
tape('note: enharmonics - pitch in array notation', function (test) {
var C = ['tnlp', [0]]
test.deepEqual(note.enh(C),
test.deepEqual(note.enharmonics(C),
[ [ 'tnlp', [ 12 ] ], [ 'tnlp', [ 0 ] ], [ 'tnlp', [ -12 ] ] ])
test.end()
})
tape('simpleEnh note', function (test) {
test.equal(note.simpleEnh('E#2'), 'F2')
test.equal(note.simpleEnh('B#2'), 'C3')
test.equal(note.simpleEnh('Cb2'), 'B1')
tape('note: simplify', function (test) {
test.equal(note.simplify('E#2'), 'F2')
test.equal(note.simplify('B#2'), 'C3')
test.equal(note.simplify('Cb2'), 'B1')
// strage case: not a COMPLETE simplification, but I think is enough
test.equal(note.simpleEnh('A###6'), 'B#6')
test.equal(note.simplify('A###6'), 'B#6')
test.end()
})
var tape = require('tape')
var note = require('..')
tape('note chromas', function (test) {
tape('note: chroma', function (test) {
test.deepEqual('Cb C Db D Eb E Fb F Gb G Ab A Bb B'.split(' ').map(note.chroma),

@@ -12,4 +12,4 @@ [ 11, 0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11 ])

tape('note names', function (test) {
test.deepEqual('c fx dbb bbb c##-1 fbb6'.split(' ').map(note.noteName),
tape('note: toNote', function (test) {
test.deepEqual('c fx dbb bbb c##-1 fbb6'.split(' ').map(note.toNote),
[ 'C', 'F##', 'Dbb', 'Bbb', 'C##-1', 'Fbb6' ])

@@ -19,3 +19,3 @@ test.end()

tape('pitch classes', function (test) {
tape('note: pc', function (test) {
test.deepEqual('a b0 d2 e# fb3 g###4 bbbb5 h j'.split(' ').map(note.pc),

@@ -22,0 +22,0 @@ [ 'A', 'B', 'D', 'E#', 'Fb', 'G###', 'Bbbb', null, null ])

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc