Musical keyboard component written in React.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Generator.ts 745 B

12345678910111213141516171819202122
  1. import SoundGenerator from '../services/SoundGenerator'
  2. import MidiGenerator 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. }