'use strict'
// Map from number of fifths to interval number (0-index) and octave
// -1 = fourth, 0 = unison, 1 = fifth, 2 = second, 3 = sixth...
var BASES = [[3, 1], [0, 0], [4, 0], [1, -1], [5, -1], [2, -2], [6, -2], [3, -3]]
/**
* Get properties from a pitch in array format
*
* The properties is an array with the form [number, alteration, octave, duration]
*
* @name arrayProps
* @function
* @param {Array} array - the pitch in coord format
* @return {Array} the pitch in property format
* @private
*
* @example
* var props = require('music-notation/props')
* props([2, 1, 4]) // => [1, 2, 4]
*/
module.exports = function (arr) {
if (!Array.isArray(arr)) return null
var index = (arr[0] + 1) % 7
if (index < 0) index = 7 + index
var base = BASES[index]
var alter = Math.floor((arr[0] + 1) / 7)
var oct = arr.length === 1 ? null : arr[1] - base[1] + alter * 4
var dur = arr[2] || null
return [base[0], alter, oct, dur]
}
|