Simple monitor for displaying MIDI status for digital pianos.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

22 linhas
551 B

  1. const NATURAL_KEYS = [0, 2, 4, 5, 7, 9, 11]
  2. interface IsNaturalKey {
  3. (k: number): boolean
  4. }
  5. const isNaturalKey: IsNaturalKey = (k: number): boolean => {
  6. const type = typeof (k as unknown)
  7. if ((type as string) !== 'number') {
  8. throw TypeError(`Invalid value type passed to isNaturalKey, expected 'number', got ${type}.`)
  9. }
  10. if (isNaN(k)) {
  11. throw RangeError('Value passed is NaN.')
  12. }
  13. if (k < 0) {
  14. throw RangeError('Value must be positive.')
  15. }
  16. return NATURAL_KEYS.includes(Math.floor(k) % 12)
  17. }
  18. export default isNaturalKey