Musical keyboard component written in React.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

23 rivejä
745 B

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