Musical keyboard component written in React.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

23 righe
761 B

  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. }