@@ -1,5 +1,5 @@ | |||||
{ | { | ||||
"version": "1.0.3", | |||||
"version": "1.0.4", | |||||
"license": "MIT", | "license": "MIT", | ||||
"main": "dist/index.js", | "main": "dist/index.js", | ||||
"typings": "dist/index.d.ts", | "typings": "dist/index.d.ts", | ||||
@@ -0,0 +1,7 @@ | |||||
export const getKeyOctave = new Map() | |||||
export const getOctaveCompleteness = new Map() | |||||
export const getKeyXOffset = new Map() | |||||
export const isNaturalKey = new Map() |
@@ -2,8 +2,9 @@ import mem from 'mem' | |||||
import generateKeys from './generateKeys' | import generateKeys from './generateKeys' | ||||
import groupKeysIntoOctaves from './groupKeysIntoOctaves' | import groupKeysIntoOctaves from './groupKeysIntoOctaves' | ||||
import getOctaveCompletenessUnmemoized from './getOctaveCompleteness' | import getOctaveCompletenessUnmemoized from './getOctaveCompleteness' | ||||
import * as caches from './caches' | |||||
const getOctaveCompleteness = mem(getOctaveCompletenessUnmemoized) | |||||
const getOctaveCompleteness = mem(getOctaveCompletenessUnmemoized, { cache: caches.getOctaveCompleteness }) | |||||
interface GetFractionalOctaveCount { | interface GetFractionalOctaveCount { | ||||
(startKey: number, endKey: number): number | (startKey: number, endKey: number): number | ||||
@@ -3,11 +3,12 @@ import getKeyXOffsetUnmemoized from './getKeyXOffset' | |||||
import getOctaveCountUnmemoized from './getOctaveCount' | import getOctaveCountUnmemoized from './getOctaveCount' | ||||
import getFractionalOctaveCountUnmemoized from './getFractionalOctaveCount' | import getFractionalOctaveCountUnmemoized from './getFractionalOctaveCount' | ||||
import getKeyOctaveUnmemoized from './getKeyOctave' | import getKeyOctaveUnmemoized from './getKeyOctave' | ||||
import * as caches from './caches' | |||||
const getKeyXOffset = mem(getKeyXOffsetUnmemoized) | |||||
const getKeyXOffset = mem(getKeyXOffsetUnmemoized, { cache: caches.getKeyXOffset }) | |||||
const getOctaveCount = mem(getOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | const getOctaveCount = mem(getOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | ||||
const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | ||||
const getKeyOctave = mem(getKeyOctaveUnmemoized) | |||||
const getKeyOctave = mem(getKeyOctaveUnmemoized, { cache: caches.getKeyOctave }) | |||||
export interface GetKeyLeft { | export interface GetKeyLeft { | ||||
(k: number): number | (k: number): number | ||||
@@ -3,6 +3,7 @@ import isNaturalKeyUnmemoized from './isNaturalKey' | |||||
import getOctaveCountUnmemoized from './getOctaveCount' | import getOctaveCountUnmemoized from './getOctaveCount' | ||||
import getFractionalOctaveCountUnmemoized from './getFractionalOctaveCount' | import getFractionalOctaveCountUnmemoized from './getFractionalOctaveCount' | ||||
import { ACCIDENTAL_KEY_TO_NATURAL_KEY_WIDTH_RATIO } from './constants' | import { ACCIDENTAL_KEY_TO_NATURAL_KEY_WIDTH_RATIO } from './constants' | ||||
import * as caches from './caches' | |||||
export interface GetKeyWidth { | export interface GetKeyWidth { | ||||
(k: number): number | (k: number): number | ||||
@@ -12,19 +13,17 @@ interface GetKeyWidthDecorator { | |||||
(startKey: number, endKey: number): GetKeyWidth | (startKey: number, endKey: number): GetKeyWidth | ||||
} | } | ||||
const isNaturalKey = mem(isNaturalKeyUnmemoized) | |||||
const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | |||||
const isNaturalKey = mem(isNaturalKeyUnmemoized, { cache: caches.isNaturalKey }) | |||||
const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { | |||||
cacheKey: (args) => args.join(':'), | |||||
}) | |||||
const getOctaveCount = mem(getOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | const getOctaveCount = mem(getOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | ||||
const getKeyWidthDecorator: GetKeyWidthDecorator = (startKey, endKey) => { | |||||
const getKeyWidth: GetKeyWidth = (k) => { | |||||
const fractionalOctaveCount = getFractionalOctaveCount(startKey, endKey) | |||||
const octaveCount = getOctaveCount(startKey, endKey) | |||||
const naturalKeyWidth = (100 * (octaveCount / fractionalOctaveCount)) / (octaveCount * 7) | |||||
return isNaturalKey(k) ? naturalKeyWidth : naturalKeyWidth * ACCIDENTAL_KEY_TO_NATURAL_KEY_WIDTH_RATIO | |||||
} | |||||
return mem(getKeyWidth) | |||||
const getKeyWidthDecorator: GetKeyWidthDecorator = (startKey, endKey) => (k) => { | |||||
const fractionalOctaveCount = getFractionalOctaveCount(startKey, endKey) | |||||
const octaveCount = getOctaveCount(startKey, endKey) | |||||
const naturalKeyWidth = (100 * (octaveCount / fractionalOctaveCount)) / (octaveCount * 7) | |||||
return isNaturalKey(k) ? naturalKeyWidth : naturalKeyWidth * ACCIDENTAL_KEY_TO_NATURAL_KEY_WIDTH_RATIO | |||||
} | } | ||||
export default getKeyWidthDecorator | export default getKeyWidthDecorator |
@@ -1,9 +1,10 @@ | |||||
import mem from 'mem' | import mem from 'mem' | ||||
import * as caches from './caches' | |||||
import getKeyXOffsetUnmemoized from './getKeyXOffset' | import getKeyXOffsetUnmemoized from './getKeyXOffset' | ||||
import isNaturalKeyUnmemoized from './isNaturalKey' | import isNaturalKeyUnmemoized from './isNaturalKey' | ||||
const getKeyXOffset = mem(getKeyXOffsetUnmemoized) | |||||
const isNaturalKey = mem(isNaturalKeyUnmemoized) | |||||
const getKeyXOffset = mem(getKeyXOffsetUnmemoized, { cache: caches.getKeyXOffset }) | |||||
const isNaturalKey = mem(isNaturalKeyUnmemoized, { cache: caches.isNaturalKey }) | |||||
interface GetOctaveCompleteness { | interface GetOctaveCompleteness { | ||||
(firstKey: number, lastKey: number): number | (firstKey: number, lastKey: number): number | ||||
@@ -1,7 +1,8 @@ | |||||
import mem from 'mem' | import mem from 'mem' | ||||
import getKeyOctaveUnmemoized from './getKeyOctave' | import getKeyOctaveUnmemoized from './getKeyOctave' | ||||
import * as caches from './caches' | |||||
const getKeyOctave = mem(getKeyOctaveUnmemoized) | |||||
const getKeyOctave = mem(getKeyOctaveUnmemoized, { cache: caches.getKeyOctave }) | |||||
interface GetOctaveCount { | interface GetOctaveCount { | ||||
(startKey: number, endKey: number): number | (startKey: number, endKey: number): number | ||||