Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const midiNumberAttributesCache = buildMidiNumberAttributesCache();
// Returns an object containing various attributes for a given MIDI number.
// Throws error for invalid midiNumbers.
function getAttributes(midiNumber) {
const attrs = midiNumberAttributesCache[midiNumber];
if (!attrs) {
throw Error('Invalid MIDI number');
}
return attrs;
}
// Returns all MIDI numbers corresponding to natural notes, e.g. C and not C# or Bb.
const NATURAL_MIDI_NUMBERS = range(MIN_MIDI_NUMBER, MAX_MIDI_NUMBER + 1).filter(
(midiNumber) => !getAttributes(midiNumber).isAccidental,
);
export default {
fromNote,
getAttributes,
MIN_MIDI_NUMBER,
MAX_MIDI_NUMBER,
NATURAL_MIDI_NUMBERS,
};
getMidiNumbers() {
return range(this.props.noteRange.first, this.props.noteRange.last + 1);
}
function buildMidiNumberAttributesCache() {
return range(MIN_MIDI_NUMBER, MAX_MIDI_NUMBER + 1).reduce((cache, midiNumber) => {
cache[midiNumber] = buildMidiNumberAttributes(midiNumber);
return cache;
}, {});
}