Musical keyboard component written in React.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

20 lines
770 B

  1. import mem from 'mem'
  2. import * as caches from './caches'
  3. import getKeyXOffsetUnmemoized from './getKeyXOffset'
  4. import isNaturalKeyUnmemoized from './isNaturalKey'
  5. const getKeyXOffset = mem(getKeyXOffsetUnmemoized, { cache: caches.getKeyXOffset })
  6. const isNaturalKey = mem(isNaturalKeyUnmemoized, { cache: caches.isNaturalKey })
  7. type GetOctaveCompleteness = (firstKey: number, lastKey: number) => number
  8. // expect firstKey and lastKey within the same octave
  9. const getOctaveCompleteness: GetOctaveCompleteness = (firstKey, lastKey) =>
  10. // see if there are missing higher notes
  11. getKeyXOffset(lastKey) +
  12. (isNaturalKey(lastKey) ? 1 / 7 : ((1 / 7) * 18) / 36) -
  13. // see if there are missing lower notes
  14. getKeyXOffset(firstKey)
  15. export default getOctaveCompleteness