Musical keyboard component written in React.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122
  1. import SoundGenerator from '../services/SoundGenerator'
  2. import MidiGenerator, { MIDIOutput } from '../services/generators/MidiGenerator'
  3. import WaveGenerator from '../services/generators/WaveGenerator'
  4. type Load = () => Promise<SoundGenerator>
  5. export const load: Load = async (): Promise<SoundGenerator> => {
  6. const { navigator: maybeNavigator } = window
  7. const navigator = maybeNavigator as Navigator & {
  8. requestMIDIAccess: () => Promise<{ outputs: Map<string, unknown> }>
  9. }
  10. if ('requestMIDIAccess' in navigator) {
  11. const m = await navigator.requestMIDIAccess()
  12. const outputs = Array.from(m.outputs.values()) as MIDIOutput[]
  13. if (outputs.length > 0) {
  14. return new MidiGenerator(outputs[0])
  15. }
  16. }
  17. return new WaveGenerator()
  18. }