Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
Merge 142e366 into 578b391
Browse files Browse the repository at this point in the history
  • Loading branch information
waterplea committed May 10, 2020
2 parents 578b391 + 142e366 commit c8734e7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions projects/midi/src/tokens/midi-messages.ts
@@ -1,10 +1,11 @@
import {inject, InjectionToken} from '@angular/core';
import {from, fromEvent, merge, Observable, throwError} from 'rxjs';
import {FromEventTarget} from 'rxjs/internal/observable/fromEvent';
import {share, switchMap} from 'rxjs/operators';
import {share, startWith, switchMap} from 'rxjs/operators';
import {MIDI_ACCESS} from './midi-access';

import MIDIMessageEvent = WebMidi.MIDIMessageEvent;
import MIDIConnectionEvent = WebMidi.MIDIConnectionEvent;

export const MIDI_MESSAGES = new InjectionToken<Observable<MIDIMessageEvent>>(
'All incoming MIDI messages stream',
Expand All @@ -15,11 +16,19 @@ export const MIDI_MESSAGES = new InjectionToken<Observable<MIDIMessageEvent>>(
switchMap(access =>
access instanceof Error
? throwError(access)
: merge(
...Array.from(access.inputs).map(([_, input]) =>
fromEvent(
input as FromEventTarget<MIDIMessageEvent>,
'midimessage',
: fromEvent(
access as FromEventTarget<MIDIConnectionEvent>,
'statechange',
).pipe(
startWith(null),
switchMap(() =>
merge(
...Array.from(access.inputs).map(([_, input]) =>
fromEvent(
input as FromEventTarget<MIDIMessageEvent>,
'midimessage',
),
),
),
),
),
Expand Down

0 comments on commit c8734e7

Please sign in to comment.