How to use tonal-pitches - 10 common examples

To help you get started, we’ve selected a few tonal-pitches examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tonaljs / tonal / packages / tonal-distances / dist / index.js View on Github external
function interval(a, b) {
  if (arguments.length === 1) return function (b) {
    return distance(a, b);
  };
  var pa = tonalPitches.asPitch(a);
  var pb = tonalPitches.asPitch(b);
  var i = substr(pa, pb);
  // if a and b are in array notation, no conversion back
  return a === pa && b === pb ? i : tonalPitches.toIvlStr(i);
}
github tonaljs / tonal / packages / tonal-distances / lib / index.js View on Github external
export function interval (a, b) {
  if (arguments.length === 1) return (b) => distance(a, b)
  const pa = asPitch(a)
  const pb = asPitch(b)
  const i = substr(pa, pb)
  // if a and b are in array notation, no conversion back
  return a === pa && b === pb ? i : toIvlStr(i)
}
github tonaljs / tonal / packages / tonal-distances / lib / index.js View on Github external
export function interval (a, b) {
  if (arguments.length === 1) return (b) => distance(a, b)
  const pa = asPitch(a)
  const pb = asPitch(b)
  const i = substr(pa, pb)
  // if a and b are in array notation, no conversion back
  return a === pa && b === pb ? i : toIvlStr(i)
}
github tonaljs / tonal / packages / tonal-notes / dist / index.js View on Github external
* if not valid note
 *
 * @function
 * @param {Pitch|String}
 * @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')
 */
var noteName = tonalPitches.noteFn(tonalPitches.id);

/**
 * Get pitch class of a note. The note can be a string or a pitch array.
 *
 * @function
 * @param {String|Pitch}
 * @return {String} the pitch class
 * @example
 * tonal.pc('Db3') // => 'Db'
 */
var pc = tonalPitches.noteFn(function (p) {
  return ['tnl', p[1]];
});

var ASC = ['tnl', -12, 7, 1]; // dimished second
var DESC = ['tnl', 12, -7, -1]; // descending dimished second
github tonaljs / tonal / packages / tonal-notes / dist / index.js View on Github external
* var tonal = require('tonal')
 * tonal.noteName('cb2') // => 'Cb2'
 * tonal.map(tonal.noteName, 'c db3 2 g+ gx4')
 */
var noteName = tonalPitches.noteFn(tonalPitches.id);

/**
 * Get pitch class of a note. The note can be a string or a pitch array.
 *
 * @function
 * @param {String|Pitch}
 * @return {String} the pitch class
 * @example
 * tonal.pc('Db3') // => 'Db'
 */
var pc = tonalPitches.noteFn(function (p) {
  return ['tnl', p[1]];
});

var ASC = ['tnl', -12, 7, 1]; // dimished second
var DESC = ['tnl', 12, -7, -1]; // descending dimished second

/**
 * Get the enharmonics of a note. It returns an array of three elements: the
 * below enharmonic, the note, and the upper enharmonic
 *
 * @param {String} note - the note to get the enharmonics from
 * @return {Array} an array of pitches ordered by distance to the given one
 *
 * @example
 * enharmonics = require('enharmonics')
 * enharmonics('C') // => ['B#', 'C', 'Dbb']
github tonaljs / tonal / packages / tonal-notes / lib / index.js View on Github external
* var tonal = require('tonal')
 * tonal.noteName('cb2') // => 'Cb2'
 * tonal.map(tonal.noteName, 'c db3 2 g+ gx4')
 */
export const noteName = noteFn(id)

/**
 * Get pitch class of a note. The note can be a string or a pitch array.
 *
 * @function
 * @param {String|Pitch}
 * @return {String} the pitch class
 * @example
 * tonal.pc('Db3') // => 'Db'
 */
export const pc = noteFn((p) => [ 'tnl', p[1] ])

var ASC = ['tnl', -12, 7, 1] // dimished second
var DESC = ['tnl', 12, -7, -1] // descending dimished second

/**
 * Get the enharmonics of a note. It returns an array of three elements: the
 * below enharmonic, the note, and the upper enharmonic
 *
 * @param {String} note - the note to get the enharmonics from
 * @return {Array} an array of pitches ordered by distance to the given one
 *
 * @example
 * enharmonics = require('enharmonics')
 * enharmonics('C') // => ['B#', 'C', 'Dbb']
 * enharmonics('A') // => ['G##', 'A', 'Bbb']
 * enharmonics('C#4') // => ['B##3', 'C#4' 'Db4']
github tonaljs / tonal / packages / tonal-notes / lib / index.js View on Github external
* if not valid note
 *
 * @function
 * @param {Pitch|String}
 * @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')
 */
export const noteName = noteFn(id)

/**
 * Get pitch class of a note. The note can be a string or a pitch array.
 *
 * @function
 * @param {String|Pitch}
 * @return {String} the pitch class
 * @example
 * tonal.pc('Db3') // => 'Db'
 */
export const pc = noteFn((p) => [ 'tnl', p[1] ])

var ASC = ['tnl', -12, 7, 1] // dimished second
var DESC = ['tnl', 12, -7, -1] // descending dimished second

/**
github tonaljs / tonal / packages / tonal-distances / dist / index.js View on Github external
function interval(a, b) {
  if (arguments.length === 1) return function (b) {
    return distance(a, b);
  };
  var pa = tonalPitches.asPitch(a);
  var pb = tonalPitches.asPitch(b);
  var i = substr(pa, pb);
  // if a and b are in array notation, no conversion back
  return a === pa && b === pb ? i : tonalPitches.toIvlStr(i);
}
github tonaljs / tonal / packages / tonal-distances / lib / index.js View on Github external
export function interval (a, b) {
  if (arguments.length === 1) return (b) => distance(a, b)
  const pa = asPitch(a)
  const pb = asPitch(b)
  const i = substr(pa, pb)
  // if a and b are in array notation, no conversion back
  return a === pa && b === pb ? i : toIvlStr(i)
}
github tonaljs / tonal / packages / tonal-arrays / dist / index.js View on Github external
function asArr(src) {
  return tonalPitches.isArr(src) ? src : typeof src === 'string' ? src.trim().split(SEP) : src === null || typeof src === 'undefined' ? [] : [src];
}