Skip to content

Commit 0b7790d

Browse files
update fable projects
1 parent d885de2 commit 0b7790d

12 files changed

+2725
-1414
lines changed

Midinette.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Midinette.Platform.Tests",
2626
EndProject
2727
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Midinette.Elektron.Tests", "tests\Midinette.Elektron.Tests\Midinette.Elektron.Tests.fsproj", "{E45F6DEF-20D0-412B-B962-57D4C8705523}"
2828
EndProject
29+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Midinette.Fable.Tests", "src\Midinette.Fable\tests\Fable.Midinette.Fable.Tests.fsproj", "{05E236C3-A811-4114-854F-0F361680E459}"
30+
EndProject
2931
Global
3032
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3133
Debug|Any CPU = Debug|Any CPU
@@ -60,6 +62,10 @@ Global
6062
{E45F6DEF-20D0-412B-B962-57D4C8705523}.Debug|Any CPU.Build.0 = Debug|Any CPU
6163
{E45F6DEF-20D0-412B-B962-57D4C8705523}.Release|Any CPU.ActiveCfg = Release|Any CPU
6264
{E45F6DEF-20D0-412B-B962-57D4C8705523}.Release|Any CPU.Build.0 = Release|Any CPU
65+
{05E236C3-A811-4114-854F-0F361680E459}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
66+
{05E236C3-A811-4114-854F-0F361680E459}.Debug|Any CPU.Build.0 = Debug|Any CPU
67+
{05E236C3-A811-4114-854F-0F361680E459}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{05E236C3-A811-4114-854F-0F361680E459}.Release|Any CPU.Build.0 = Release|Any CPU
6369
EndGlobalSection
6470
GlobalSection(SolutionProperties) = preSolution
6571
HideSolutionNode = FALSE

paket.dependencies

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ source ../portmidisharp/build/Debug/AnyCPU
33
source ../fsnative/build/Debug/AnyCPU
44
source https://nuget.org/api/v2
55
storage: none
6-
clitool dotnet-fable
76
github fsprojects/FSharp.UMX src/FSharp.UMX.fs
8-
nuget Fable.Core
9-
nuget Fable.Promise
10-
nuget Fable.Import.Browser
11-
nuget Fable.Import.WebMIDI
127
nuget FSharp.Core = 4.6.2
138
nuget fsnative
149
nuget PortMidiSharp
@@ -28,3 +23,19 @@ group Test
2823
nuget FsCheck.NUnit
2924
nuget Logary.Adapters.Facade prerelease
3025

26+
group Fable
27+
source https://nuget.org/api/v2
28+
storage: none
29+
30+
clitool dotnet-fable
31+
nuget Thoth.Fetch prerelease
32+
nuget Fable.Core prerelease
33+
nuget Fable.Fetch prerelease
34+
nuget Fable.Promise prerelease
35+
nuget Fable.Browser.Dom prerelease
36+
nuget Fable.Browser.Event prerelease
37+
nuget Fable.Browser.Blob prerelease
38+
nuget Fable.React.Native prerelease
39+
nuget Fable.Elmish.HMR prerelease
40+
nuget Fable.Elmish.React prerelease
41+
nuget Fable.Elmish.Browser prerelease

paket.lock

Lines changed: 342 additions & 142 deletions
Large diffs are not rendered by default.

src/Midinette.Fable/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"private": true,
33
"devDependencies": {
4-
"babel-core": "6.26.0",
5-
"babel-loader": "7.1.1",
6-
"babel-preset-es2015": "6.24.1",
7-
"fable-loader": "1.0.7",
8-
"isomorphic-fetch": "2.2.1",
9-
"mocha": "3.5.0",
10-
"webpack": "3.5.5"
4+
"@babel/core": "^7.5.5",
5+
"babel-loader": "^8.0.6",
6+
"babel-preset-env": "^1.7.0",
7+
"fable-loader": "^2.1.8",
8+
"isomorphic-fetch": "^2.2.1",
9+
"mocha": "^6.2.2",
10+
"webpack": "^4.41.2"
1111
}
12-
}
12+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// updated version of https://github.com/magicmonty/fable-import-webmidi
2+
module Fable.WebMIDI
3+
4+
open Fable.Core
5+
open Fable.Core.JS
6+
open Browser
7+
type MIDIOptions =
8+
| Sysex of bool
9+
10+
[<StringEnum>]
11+
type MIDIPortType =
12+
| Input
13+
| Output
14+
15+
[<StringEnum>]
16+
type MIDIPortDeviceState =
17+
| Disconnected
18+
| Connected
19+
20+
[<StringEnum>]
21+
type MIDIPortConnectionState =
22+
| Open
23+
| Closed
24+
| Pending
25+
26+
type IMIDIPort =
27+
[<Emit("$0.id")>]
28+
abstract Id: string with get
29+
[<Emit("$0.manufacturer")>]
30+
abstract Manufacturer: string option with get
31+
[<Emit("$0.name")>]
32+
abstract Name: string option with get
33+
[<Emit("$0.type")>]
34+
abstract Type: MIDIPortType with get
35+
[<Emit("$0.version")>]
36+
abstract Version: string option with get
37+
[<Emit("$0.state")>]
38+
abstract State: MIDIPortDeviceState with get
39+
[<Emit("$0.connection")>]
40+
abstract Connection: MIDIPortConnectionState with get
41+
[<Emit("$0.onstatechange=$1")>]
42+
abstract OnStateChange: (IMIDIConnectionEvent -> unit) with set
43+
[<Emit("$0.open")>]
44+
abstract Open: (unit -> Promise<IMIDIPort>)
45+
[<Emit("$0.close")>]
46+
abstract Close: (unit -> Promise<IMIDIPort>)
47+
48+
and IMIDIConnectionEvent =
49+
inherit Browser.Types.EventType
50+
[<Emit("$0.port")>]
51+
abstract Port: IMIDIPort with get
52+
53+
type IMIDIMessageEvent =
54+
inherit Browser.Types.EventType
55+
[<Emit("$0.receivedTime")>]
56+
abstract member ReceivedTime: double with get
57+
[<Emit("$0.data")>]
58+
abstract member Data: byte array with get
59+
60+
type IMIDIInput =
61+
inherit IMIDIPort
62+
[<Emit("$0.onmidimessage=$1")>]
63+
abstract OnMidiMessage: (IMIDIMessageEvent -> unit) with set
64+
65+
type IMIDIInputMap = JS.Map<string, IMIDIInput>
66+
67+
type IMIDIOutput =
68+
inherit IMIDIPort
69+
[<Emit("$0.send")>]
70+
abstract Send: (byte array -> unit)
71+
[<Emit("$0.send($2, $1)")>]
72+
abstract SendAt: (float -> byte array -> unit)
73+
[<Emit("$0.clear")>]
74+
abstract Clear: (unit -> unit)
75+
76+
type IMIDIOutputMap = JS.Map<string, IMIDIOutput>
77+
78+
type IMIDIAccess =
79+
[<Emit("$0.inputs")>]
80+
abstract Inputs: IMIDIInputMap with get
81+
[<Emit("$0.outputs")>]
82+
abstract Outputs: IMIDIOutputMap with get
83+
[<Emit("$0.onstatechange=$1")>]
84+
abstract OnStateChange: (IMIDIConnectionEvent -> unit) with set
85+
[<Emit("$0.sysexEnabled")>]
86+
abstract SysexEnabled: bool with get, set
87+
88+
module internal Intern =
89+
90+
[<Emit("navigator.requestMIDIAccess($0)")>]
91+
let requestAccess (options: obj) : Promise<IMIDIAccess> = jsNative
92+
93+
module Map =
94+
let toList (m: JS.Map<'a,'b>): ('a*'b) list =
95+
let mutable result : ('a*'b) list = []
96+
m.forEach (fun b a _ -> result <- (a, b) :: result)
97+
result |> List.ofSeq
98+
99+
module ArrayBuffer =
100+
let toArray (m: ArrayBuffer) : byte array =
101+
let c = JS.Constructors.Uint8ClampedArray.Create(m)
102+
let mutable result : byte list = []
103+
c.forEach (fun a _ _ -> result <- (byte a) :: result; true)
104+
result |> List.rev |> List.toArray
105+
106+
[<RequireQualifiedAccess>]
107+
module MIDI =
108+
let requestAccess (options: MIDIOptions list) =
109+
Intern.requestAccess (JsInterop.keyValueList CaseRules.LowerFirst options)
110+
111+
let send (output: IMIDIOutput) (data : byte array) =
112+
promise {
113+
output.Send data
114+
}
115+
let sendAt (output: IMIDIOutput) (sendTime: float) (data : byte array) =
116+
promise {
117+
data |> output.SendAt sendTime
118+
}
119+

src/Midinette.Fable/src/Midinette.Fable.fs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
module Midinette.Fable
22
open Midi
33
open Midinette.Platform
4-
module WM = Fable.Import.WebMIDI
4+
module WM = Fable.WebMIDI
55

66
type DeviceInfo(port: WM.IMIDIPort) =
77
member x.Port = port
88
interface IDeviceInfo with
9-
member x.DeviceId = port.Id |> int
109
member x.Name = sprintf "id:%20A name:%20A manufacturer:%A" port.Id port.Name.Value port.Manufacturer
1110

1211
type MyMidiIn(input: WM.IMIDIInput, onMidiIn, onStateChange) =
@@ -33,7 +32,7 @@ type WebMIDIInputPortWrapper(webMidiInput: WM.IMIDIInput, onStateChange, onMidiI
3332
let realtimeMessageReceived = new Event<_>()
3433

3534
do
36-
let midiIn = this :> IMidiInput<MidiEvent<double>>
35+
let midiIn = this :> IMidiInput<double>
3736

3837
webMidiInput.set_OnMidiMessage (fun mm ->
3938
let midiMessage = Midi.MidiMessage.Encode mm.Data.[0] mm.Data.[1] mm.Data.[2]
@@ -51,7 +50,7 @@ type WebMIDIInputPortWrapper(webMidiInput: WM.IMIDIInput, onStateChange, onMidiI
5150
| _ -> ()
5251
)
5352

54-
interface IMidiInput<MidiEvent<double>> with
53+
interface IMidiInput<double> with
5554
member x.DeviceInfo = DeviceInfo(webMidiInput) :> _
5655
member x.Close () = webMidiInput.Close () |> ignore
5756
member x.Open bufferSize = webMidiInput.Open() |> ignore
@@ -64,21 +63,21 @@ type WebMIDIInputPortWrapper(webMidiInput: WM.IMIDIInput, onStateChange, onMidiI
6463

6564
type WebMIDIOutputPortWrapper(webMidiOutput: WM.IMIDIOutput, device, onStateChange) as this =
6665
do
67-
let midiOut = this :> IMidiOutput<double, MidiMessage>
66+
let midiOut = this :> IMidiOutput<double>
6867

6968
webMidiOutput.set_OnStateChange (fun sc ->
7069
match onStateChange with
7170
| Some onStateChange -> onStateChange sc
7271
| _ -> ()
7372
)
7473

75-
interface IMidiOutput<double, MidiMessage> with
74+
interface IMidiOutput<double> with
7675
member x.Open bufferSize latency = ()
7776
member x.Close () = ()
7877
member x.WriteMessage timestamp message =
7978
webMidiOutput.SendAt (float timestamp) [|message.Status; message.Data1; message.Data2|]
8079
member x.WriteMessages timestamp messages =
81-
messages |> Array.iter (((x :> IMidiOutput<_,_>).WriteMessage )timestamp)
80+
messages |> Array.iter (((x :> IMidiOutput<_>).WriteMessage )timestamp)
8281
member x.WriteSysex timestamp data =
83-
webMidiOutput.SendAt (float timestamp) data
82+
webMidiOutput.SendAt (float timestamp) (Midi.UMX.untag_sysex data)
8483
member x.DeviceInfo = (DeviceInfo device) :> _

src/Midinette.Fable/src/Midinette.Fable.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
<OutputPath>..\..\..\build\$(Configuration)\$(Platform)</OutputPath>
77
</PropertyGroup>
88
<ItemGroup>
9+
<Compile Include="Fable.WebMIDI.fs" />
910
<Compile Include="Midinette.Fable.fs" />
1011
</ItemGroup>
1112
<ItemGroup>
1213
<Content Include="*.fsproj; *.fs" PackagePath="fable\" />
14+
<Content Remove="Fable.WebMIDI.fs" />
1315
<Content Include="paket.references" />
1416
</ItemGroup>
1517
<ItemGroup>
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
FSharp.Core
2-
Fable.Core
3-
dotnet-fable
4-
Fable.Promise
5-
Fable.Import.WebMIDI
1+
group Fable
2+
Fable.Core
3+
dotnet-fable
4+
Fable.Promise
5+
Fable.Browser.Dom
6+
Fable.Browser.Event

src/Midinette.Fable/tests/Fable.Midinette.Fable.Tests.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ module Fable.Midinette.Fable.Tests
22

33
open Fable.Core
44
open Fable.Core.JsInterop
5-
open Fable.Midinette.Fable
5+
//open Fable.Midinette.Fable
6+
open Midinette.Fable
67
open Fable.Core.Testing
78

89
[<Global>]
910
let it (msg: string) (f: unit->unit): unit = jsNative
10-
11+
let add a b = a + b
1112
it "Adding works" <| fun () ->
1213
let expected = 3
1314
let actual = add 1 2
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFramework>netstandard1.6</TargetFramework>
4+
<TargetFramework>netstandard2.0</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
77
<Compile Include="Fable.Midinette.Fable.Tests.fs" />
88
<Compile Include="Main.fs" />
99
</ItemGroup>
1010
<ItemGroup>
11-
<ProjectReference Include="../src/Fable.Midinette.Fable.fsproj" />
11+
<ProjectReference Include="../src/Midinette.Fable.fsproj" />
1212
</ItemGroup>
1313
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
1414
</Project>

0 commit comments

Comments
 (0)