Convert interfaces to types for service functionsmaster
@@ -1,6 +1,4 @@ | |||||
interface GenerateKeys { | |||||
(startKey: number, endKey: number): number[] | |||||
} | |||||
type GenerateKeys = (startKey: number, endKey: number) => number[] | |||||
const generateKeys: GenerateKeys = (startKey, endKey) => | const generateKeys: GenerateKeys = (startKey, endKey) => | ||||
Array(endKey - startKey + 1) | Array(endKey - startKey + 1) | ||||
@@ -6,9 +6,7 @@ import * as caches from './caches' | |||||
const getOctaveCompleteness = mem(getOctaveCompletenessUnmemoized, { cache: caches.getOctaveCompleteness }) | const getOctaveCompleteness = mem(getOctaveCompletenessUnmemoized, { cache: caches.getOctaveCompleteness }) | ||||
interface GetFractionalOctaveCount { | |||||
(startKey: number, endKey: number): number | |||||
} | |||||
type GetFractionalOctaveCount = (startKey: number, endKey: number) => number | |||||
const getFractionalOctaveCount: GetFractionalOctaveCount = (startKey, endKey) => { | const getFractionalOctaveCount: GetFractionalOctaveCount = (startKey, endKey) => { | ||||
const dummyKeys = generateKeys(startKey, endKey) | const dummyKeys = generateKeys(startKey, endKey) | ||||
@@ -10,15 +10,9 @@ const getOctaveCount = mem(getOctaveCountUnmemoized, { cacheKey: (args) => args. | |||||
const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | ||||
const getKeyOctave = mem(getKeyOctaveUnmemoized, { cache: caches.getKeyOctave }) | const getKeyOctave = mem(getKeyOctaveUnmemoized, { cache: caches.getKeyOctave }) | ||||
export interface GetKeyLeft { | |||||
(k: number): number | |||||
} | |||||
interface GetKeyLeftDecorator { | |||||
(startKey: number, endKey: number): GetKeyLeft | |||||
} | |||||
type GetKeyLeft = (startKey: number, endKey: number) => (k: number) => number | |||||
const getKeyLeftDecorator: GetKeyLeftDecorator = (startKey, endKey): GetKeyLeft => (k) => { | |||||
const getKeyLeft: GetKeyLeft = (startKey, endKey) => (k) => { | |||||
const fractionalOctaveCount = getFractionalOctaveCount(startKey, endKey) | const fractionalOctaveCount = getFractionalOctaveCount(startKey, endKey) | ||||
const octaveCount = getOctaveCount(startKey, endKey) | const octaveCount = getOctaveCount(startKey, endKey) | ||||
const startOctave = getKeyOctave(startKey) | const startOctave = getKeyOctave(startKey) | ||||
@@ -29,4 +23,4 @@ const getKeyLeftDecorator: GetKeyLeftDecorator = (startKey, endKey): GetKeyLeft | |||||
return theKeyOffset - firstKeyOffset | return theKeyOffset - firstKeyOffset | ||||
} | } | ||||
export default getKeyLeftDecorator | |||||
export default getKeyLeft |
@@ -1,6 +1,4 @@ | |||||
interface GetKeyOctave { | |||||
(k: number): number | |||||
} | |||||
type GetKeyOctave = (k: number) => number | |||||
const getKeyOctave: GetKeyOctave = (k) => Math.floor(k / 12) | const getKeyOctave: GetKeyOctave = (k) => Math.floor(k / 12) | ||||
@@ -5,13 +5,7 @@ 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' | import * as caches from './caches' | ||||
export interface GetKeyWidth { | |||||
(k: number): number | |||||
} | |||||
interface GetKeyWidthDecorator { | |||||
(startKey: number, endKey: number): GetKeyWidth | |||||
} | |||||
type GetKeyWidthDecorator = (startKey: number, endKey: number) => (k: number) => number | |||||
const isNaturalKey = mem(isNaturalKeyUnmemoized, { cache: caches.isNaturalKey }) | const isNaturalKey = mem(isNaturalKeyUnmemoized, { cache: caches.isNaturalKey }) | ||||
const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { | const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { | ||||
@@ -19,11 +13,11 @@ const getFractionalOctaveCount = mem(getFractionalOctaveCountUnmemoized, { | |||||
}) | }) | ||||
const getOctaveCount = mem(getOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | const getOctaveCount = mem(getOctaveCountUnmemoized, { cacheKey: (args) => args.join(':') }) | ||||
const getKeyWidthDecorator: GetKeyWidthDecorator = (startKey, endKey) => (k) => { | |||||
const getKeyWidth: GetKeyWidthDecorator = (startKey, endKey) => (k) => { | |||||
const fractionalOctaveCount = getFractionalOctaveCount(startKey, endKey) | const fractionalOctaveCount = getFractionalOctaveCount(startKey, endKey) | ||||
const octaveCount = getOctaveCount(startKey, endKey) | const octaveCount = getOctaveCount(startKey, endKey) | ||||
const naturalKeyWidth = (100 * (octaveCount / fractionalOctaveCount)) / (octaveCount * 7) | const naturalKeyWidth = (100 * (octaveCount / fractionalOctaveCount)) / (octaveCount * 7) | ||||
return isNaturalKey(k) ? naturalKeyWidth : naturalKeyWidth * ACCIDENTAL_KEY_TO_NATURAL_KEY_WIDTH_RATIO | return isNaturalKey(k) ? naturalKeyWidth : naturalKeyWidth * ACCIDENTAL_KEY_TO_NATURAL_KEY_WIDTH_RATIO | ||||
} | } | ||||
export default getKeyWidthDecorator | |||||
export default getKeyWidth |
@@ -1,8 +1,6 @@ | |||||
import { KEY_OFFSETS } from './constants' | import { KEY_OFFSETS } from './constants' | ||||
interface GetKeyXOffset { | |||||
(k: number): number | |||||
} | |||||
type GetKeyXOffset = (k: number) => number | |||||
const getKeyXOffset: GetKeyXOffset = (k) => { | const getKeyXOffset: GetKeyXOffset = (k) => { | ||||
return KEY_OFFSETS[k % 12] | return KEY_OFFSETS[k % 12] | ||||
@@ -6,9 +6,7 @@ import isNaturalKeyUnmemoized from './isNaturalKey' | |||||
const getKeyXOffset = mem(getKeyXOffsetUnmemoized, { cache: caches.getKeyXOffset }) | const getKeyXOffset = mem(getKeyXOffsetUnmemoized, { cache: caches.getKeyXOffset }) | ||||
const isNaturalKey = mem(isNaturalKeyUnmemoized, { cache: caches.isNaturalKey }) | const isNaturalKey = mem(isNaturalKeyUnmemoized, { cache: caches.isNaturalKey }) | ||||
interface GetOctaveCompleteness { | |||||
(firstKey: number, lastKey: number): number | |||||
} | |||||
type GetOctaveCompleteness = (firstKey: number, lastKey: number) => number | |||||
// expect firstKey and lastKey within the same octave | // expect firstKey and lastKey within the same octave | ||||
const getOctaveCompleteness: GetOctaveCompleteness = (firstKey, lastKey) => | const getOctaveCompleteness: GetOctaveCompleteness = (firstKey, lastKey) => | ||||
@@ -4,9 +4,7 @@ import * as caches from './caches' | |||||
const getKeyOctave = mem(getKeyOctaveUnmemoized, { cache: caches.getKeyOctave }) | const getKeyOctave = mem(getKeyOctaveUnmemoized, { cache: caches.getKeyOctave }) | ||||
interface GetOctaveCount { | |||||
(startKey: number, endKey: number): number | |||||
} | |||||
type GetOctaveCount = (startKey: number, endKey: number) => number | |||||
const getOctaveCount: GetOctaveCount = (startKey, endKey) => getKeyOctave(endKey) - getKeyOctave(startKey) + 1 | const getOctaveCount: GetOctaveCount = (startKey, endKey) => getKeyOctave(endKey) - getKeyOctave(startKey) + 1 | ||||
@@ -1,6 +1,4 @@ | |||||
interface GroupKeysIntoOctaves { | |||||
(dummyKeys: number[]): Record<number, number[]> | |||||
} | |||||
type GroupKeysIntoOctaves = (dummyKeys: number[]) => Record<number, number[]> | |||||
const groupKeysIntoOctaves: GroupKeysIntoOctaves = (dummyKeys) => | const groupKeysIntoOctaves: GroupKeysIntoOctaves = (dummyKeys) => | ||||
dummyKeys | dummyKeys | ||||
@@ -1,8 +1,6 @@ | |||||
const NATURAL_KEYS = [0, 2, 4, 5, 7, 9, 11] | const NATURAL_KEYS = [0, 2, 4, 5, 7, 9, 11] | ||||
interface IsNaturalKey { | |||||
(k: number): boolean | |||||
} | |||||
type IsNaturalKey = (k: number) => boolean | |||||
const isNaturalKey: IsNaturalKey = (k: number): boolean => { | const isNaturalKey: IsNaturalKey = (k: number): boolean => { | ||||
const type = typeof (k as unknown) | const type = typeof (k as unknown) | ||||