Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fable MIDI test
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import
type MIDIPortType =
| Input
| Output
type MIDIPortDeviceState =
| Disconnected
| Connected
type MIDIPortConnectionState =
| Open
| Closed
| Pending
type MIDIPort =
abstract Id: string with get
abstract Manufacturer: string option with get
abstract Name: string option with get
abstract Type: MIDIPortType with get
abstract Version: string option with get
abstract State: MIDIPortDeviceState with get
abstract Connection: MIDIPortConnectionState with get
abstract OnStateChange : obj with get, set
abstract Open : unit -> JS.Promise<MIDIPort>
abstract Close : unit -> JS.Promise<MIDIPort>
type MIDIInput =
inherit MIDIPort
abstract OnMIDIMessage : obj with get, set
type MIDIOutput =
inherit MIDIPort
[<Emit("$0.send($1, $2)")>]
abstract Send: (byte list*double) -> unit
abstract Clear: unit -> unit
type MIDIInputMap = (string*MIDIInput) list
type MIDIOutputMap = (string*MIDIOutput) list
type MIDIAccess =
abstract Inputs : MIDIInputMap with get
abstract Outputs : MIDIOutputMap with get
abstract OnStateChange : obj with get, set
abstract SysexEnabled : bool with get, set
type MIDIOption =
| Sysex of bool
| Software of bool
module Intern =
let requestMIDIAccess obj : JS.Promise<MIDIAccess> = jsNative
module MIDI =
let requestAccess (options: MIDIOption list) =
Intern.requestMIDIAccess (keyValueList CaseRules.LowerFirst options)
let onMIDISuccess (midiAccess: MIDIAccess) =
let key, port = midiAccess.Outputs.[0]
printfn "%A" port.Name
let onMIDIError (ex: obj) =
printfn "Error: %s" (unbox ex?message)
let promise f = System.Func<_, _> f
let run f = (f >> U2.Case1) |> promise
(MIDI.requestAccess []).``then``(onfulfilled=run onMIDISuccess, onrejected=run onMIDIError)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.