Musical keyboard component written in React.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

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