Skip to content

Commit 1024d31

Browse files
rtmidi, doing some more things now, but requires to build own fork
1 parent 02d9bde commit 1024d31

File tree

5 files changed

+84
-35
lines changed

5 files changed

+84
-35
lines changed

paket.dependencies

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
source https://nuget.org/api/v2
1+
source ../../../github.com/micdah/RtMidi.Core/RtMidi.Core/bin/Debug
22
source ../portmidisharp/build/Debug/AnyCPU
3-
3+
source ../fsnative/build/Debug/AnyCPU
4+
source https://nuget.org/api/v2
45
storage: none
56
redirects: force
6-
generate_load_scripts: on
7-
87
clitool dotnet-fable
9-
108
nuget Fable.Core
119
nuget Fable.Promise
1210
nuget Fable.Import.Browser
1311
nuget Fable.Import.WebMIDI
1412
nuget FSharp.Core
13+
nuget fsnative
1514
nuget PortMidiSharp
16-
nuget RtMidi.Core
15+
nuget RtMidi.Core = 1.0.59-alpha-3
1716

1817
group Build
1918
source https://nuget.org/api/v2

paket.lock

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
GENERATE-LOAD-SCRIPTS: ON
21
REDIRECTS: FORCE
32
STORAGE: NONE
43
NUGET
@@ -62,8 +61,6 @@ NUGET
6261
NETStandard.Library (2.0.3) - restriction: >= netcoreapp2.2
6362
Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (>= net45) (< netstandard1.3)) (&& (< net45) (>= netstandard1.1) (< netstandard1.2) (< win8)) (&& (< net45) (>= netstandard1.2) (< netstandard1.3) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.3) (< netstandard1.4) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.4) (< netstandard1.5) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.5) (< netstandard1.6) (< win8) (< wpa81)) (&& (< net45) (>= netstandard1.6) (< netstandard2.0) (< win8) (< wpa81)) (&& (< net45) (>= netstandard2.0)) (&& (>= net46) (< netstandard1.4)) (>= net461) (>= netcoreapp2.0) (&& (>= netstandard1.0) (< portable-net45+win8+wpa81)) (&& (< netstandard1.0) (>= portable-net45+win8) (< win8)) (&& (< netstandard1.0) (< portable-net45+win8) (>= portable-net45+win8+wpa81)) (&& (< netstandard1.0) (>= portable-net45+win8+wp8+wpa81) (< portable-net45+win8+wpa81)) (&& (< netstandard1.0) (>= win8)) (&& (< netstandard1.3) (< win8) (>= wpa81)) (&& (< netstandard1.5) (>= uap10.0)) (>= uap10.1) (>= wp8)
6463
Newtonsoft.Json (12.0.2) - restriction: >= netcoreapp2.0
65-
RtMidi.Core (1.0.50)
66-
Serilog (>= 2.8) - restriction: >= netstandard2.0
6764
runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: >= netcoreapp2.0
6865
runtime.debian.9-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: >= netcoreapp2.0
6966
runtime.fedora.23-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: >= netcoreapp2.0
@@ -101,7 +98,7 @@ NUGET
10198
runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: >= netcoreapp2.0
10299
runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: >= netcoreapp2.0
103100
runtime.ubuntu.18.04-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3) - restriction: >= netcoreapp2.0
104-
Serilog (2.8) - restriction: >= netstandard2.0
101+
Serilog (2.8) - restriction: || (>= net45) (>= netstandard2.0)
105102
System.Collections.NonGeneric (>= 4.3) - restriction: || (&& (< net45) (>= netstandard1.3) (< netstandard2.0)) (&& (< net45) (>= netstandard2.0))
106103
System.Collections (4.3) - restriction: >= netcoreapp2.0
107104
Microsoft.NETCore.Platforms (>= 1.1) - restriction: || (&& (< monoandroid) (< monotouch) (< net45) (>= netstandard1.3) (< win8) (< wpa81) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)) (&& (< monoandroid) (< net45) (>= netstandard1.0) (< netstandard1.3) (< win8) (< wp8) (< wpa81))
@@ -314,12 +311,18 @@ NUGET
314311
System.Threading.ThreadPool (4.3) - restriction: >= netcoreapp2.0
315312
System.Runtime (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net46) (>= netstandard1.3) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
316313
System.Runtime.Handles (>= 4.3) - restriction: && (< monoandroid) (< monotouch) (< net46) (>= netstandard1.3) (< xamarinios) (< xamarinmac) (< xamarintvos) (< xamarinwatchos)
317-
System.ValueTuple (4.5) - restriction: >= netcoreapp2.0
314+
System.ValueTuple (4.5) - restriction: || (>= net45) (>= netstandard2.0)
318315
Thoth.Json (3.3) - restriction: >= netstandard2.0
319316
Fable.Core (>= 3.0) - restriction: >= netstandard2.0
320317
FSharp.Core (>= 4.6.2) - restriction: >= netstandard2.0
318+
remote: ../fsnative/build/Debug/AnyCPU
319+
fsnative (1.0.0)
321320
remote: ../portmidisharp/build/Debug/AnyCPU
322321
PortMidiSharp (1.0.0)
322+
remote: ../../../github.com/micdah/RtMidi.Core/RtMidi.Core/bin/Debug
323+
RtMidi.Core (1.0.59-alpha-3)
324+
Serilog (>= 2.8) - restriction: || (>= net45) (>= netstandard2.0)
325+
System.ValueTuple (>= 4.5) - restriction: || (>= net45) (>= netstandard2.0)
323326

324327
GROUP Build
325328
RESTRICTION: >= net461

scripts/test.fsx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
1-
#load ".paket/load/net472/RtMidi.Core.fsx"
1+
#load "../.paket/load/net472/fsnative.fsx"
2+
#load "../.paket/load/net472/RtMidi.Core.fsx"
23
#r @"C:\dev\src\gitlab.com\gauthier\Midinette\build\Debug\AnyCPU\netstandard2.0\Midinette.dll"
34
#r @"C:\dev\src\gitlab.com\gauthier\Midinette\build\Debug\AnyCPU\netstandard2.0\Midinette.Platform.RtMidi.dll"
5+
open RtMidi.Core.Devices
6+
7+
open fsnative
8+
open fsnative.Internals
9+
let libNames =
10+
match () with
11+
| Windows -> [| (if System.Environment.Is64BitProcess then "rtmidi" else "rtmidi32") |]
12+
| OSX -> [|"rtmidi"|]
13+
| Linux -> [|"rtmidi"|]
14+
15+
let libPaths =
16+
match () with
17+
| Windows -> [|@"C:\dev\src\github.com\micdah\RtMidi.Core\RtMidi.Core\bin\Debug\net45\"|]
18+
19+
let loader = LibraryLoader.withRuntimeLoader id
20+
let library = LibraryLoader.tryLoadLibrary libNames libPaths loader
21+
match library with
22+
| None -> failwithf "couldn't load rtmidi!"
23+
| Some library -> printfn "loaded rtmidi!"
24+
425
open Midinette.Platform
526
let platform = Midinette.Platform.RtMidi.RtMidiMidinettePlatformImpl()
6-
727
let iplatform = platform :> IMidiPlatform<IDeviceInfo, Midi.MidiEvent<int64>, int64, Midi.MidiMessage>
8-
iplatform.InputDevices |> printfn "%A"
928

29+
let monoOut =
30+
(iplatform.InputDevices |> Array.filter (fun d -> d.Name = "monomachine-out ")).[0]
31+
|> iplatform.GetMidiInput
32+
33+
monoOut.Value.ChannelMessageReceived.Add(fun m -> printfn "[%20i] channel message: %A" m.Timestamp m.Message)
34+
monoOut.Value.SystemMessageReceived.Add(fun m -> printfn "[%20i] system message: %A" m.Timestamp m.Message)
35+
monoOut.Value.RealtimeMessageReceived.Add(fun m -> printfn "[%20i] realtime message: %A" m.Timestamp m.Message)
36+
monoOut.Value.SysexReceived.Add(fun bytes -> printfn "sysex message: %A" bytes)
37+
monoOut.Value.Open (1024*1024)
1038
let mdm = global.RtMidi.Core.MidiDeviceManager.Default
1139
mdm.GetAvailableMidiApis()
12-
mdm.InputDevices
13-
mdm.OutputDevices
40+
41+
let rtmin = (mdm.InputDevices |> Seq.find (fun d -> d.Name = "monomachine-out ")).CreateDevice()
42+
43+
rtmin.InputDevice.Message.Add(fun bytes -> printfn "inputmessage %A" bytes)
44+
rtmin.add_Nrpn (NrpnMessageHandler(fun a n -> printfn "[%20i] nrpn %A %i %i" platform.Now n.Channel n.Parameter n.Value))
45+
rtmin.Open()
46+
mdm.OutputDevices
47+
48+
49+
50+
let e : RtMidi.Core.Unmanaged.Devices.RtMidiInputDevice = null

src/Midinette.Platform.RtMidi/Midinette.Platform.RtMidi.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
55
<OutputPath>..\..\build\$(Configuration)\$(Platform)</OutputPath>
66
</PropertyGroup>
77
<ItemGroup>

src/Midinette.Platform.RtMidi/RtMidinettePlatformImpl.fs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ open System.Reflection
44
open Midinette.Platform
55

66
module Impl =
7-
let getRawDataReceivedEventFromInput port =
8-
let f = port.GetType().GetEvent "Message";
9-
let dataReceived = new Event<byte array>()
10-
let handler = System.EventHandler<byte array>(fun _ -> dataReceived.Trigger)
11-
f.AddEventHandler(port, handler)
12-
dataReceived
13-
147
let toBytes (message: Midi.MidiMessage) = [|message.Status;message.Data1;message.Data2|]
158
let rtMidiOut (bytes: byte array) port =
169
let f = port.GetType().GetField("_outputDevice", BindingFlags.NonPublic ||| BindingFlags.Instance)
@@ -22,6 +15,7 @@ module Impl =
2215

2316
open Impl
2417
open Midi
18+
open RtMidi.Core.Unmanaged.Devices
2519
open System.Diagnostics
2620

2721
type InPortEvents<'timestamp> = {
@@ -76,7 +70,20 @@ type RtMidiMidinettePlatformImpl() =
7670
let rtmidi = RtMidi.Core.MidiDeviceManager.Default
7771
let watch = Stopwatch.StartNew()
7872
let platformEvents = MidiPlatformTrigger()
79-
73+
let platformEventsPublish = platformEvents :> IMidiPlatformEvents<_,_,_,_>
74+
75+
member x.Trigger = platformEvents
76+
member x.Platform = x :> IMidiPlatformEvents<_,_,_,_>
77+
78+
member x.Now = watch.ElapsedTicks
79+
interface IMidiPlatformEvents<IDeviceInfo, Midi.MidiEvent<int64>, int64, Midi.MidiMessage> with
80+
[<CLIEvent>] member x.Error = platformEventsPublish.Error |> Event.map (fun (d,e) -> {info = d } :> IDeviceInfo, e)
81+
[<CLIEvent>] member x.ChannelMessageReceived = platformEventsPublish.ChannelMessageReceived |> Event.map (fun (d,e) -> {info = d } :> IDeviceInfo, e)
82+
[<CLIEvent>] member x.SystemMessageReceived = platformEventsPublish.SystemMessageReceived |> Event.map (fun (d,e) -> {info = d } :> IDeviceInfo, e)
83+
[<CLIEvent>] member x.SysexReceived = platformEventsPublish.SysexReceived |> Event.map (fun (d,e) -> {info = d } :> IDeviceInfo, e)
84+
[<CLIEvent>] member x.RealtimeMessageReceived = platformEventsPublish.RealtimeMessageReceived |> Event.map (fun (d,e) -> {info = d } :> IDeviceInfo, e)
85+
86+
8087
interface IMidiPlatform<IDeviceInfo, Midi.MidiEvent<int64>, int64, Midi.MidiMessage> with
8188
member x.InputDevices =
8289
RtMidi.Core.MidiDeviceManager.Default.InputDevices
@@ -94,29 +101,32 @@ type RtMidiMidinettePlatformImpl() =
94101
| :? RtMidi.Core.Devices.Infos.IMidiInputDeviceInfo as device ->
95102
// todo: keep that in store instead of creating / subscribing again
96103
let port = device.CreateDevice()
97-
let dataReceived = getRawDataReceivedEventFromInput port
98104
let error = new Event<_>()
99105
let channelMessage = new Event<_>()
100106
let sysex = new Event<_>()
101107
let systemMessage = new Event<_>()
102108
let realtimeMessage = new Event<_>()
103-
dataReceived.Publish.Add(fun bytes ->
109+
port.InputDevice.Message.Add(fun bytes ->
104110
let status : MidiMessageType = LanguagePrimitives.EnumOfValue (bytes.[0])
105-
let timestamp = watch.ElapsedTicks
106-
let inline triggerMessageEvent (event1: Event<_>) platformNoticer =
111+
let inline toMidiEvent (bytes: byte array) (watch: Stopwatch) =
112+
let timestamp = watch.ElapsedTicks
107113
let message = MidiMessage.Encode bytes.[0] bytes.[1] bytes.[2]
108-
let event = Midi.MidiEvent(message, timestamp)
114+
Midi.MidiEvent(message, timestamp)
115+
116+
let inline triggerMessageEvent (event1: Event<_>) platformNoticer =
117+
let event = toMidiEvent bytes watch
109118
event1.Trigger event
110-
platformNoticer (rtDevice,event)
119+
platformNoticer (device,event)
111120
if MidiMessageTypeIdentifaction.isChannelMessage status then
112121
triggerMessageEvent channelMessage platformEvents.NoticeChannelMessage
113122
elif MidiMessageTypeIdentifaction.isRealtimeMessage status then
114123
triggerMessageEvent realtimeMessage platformEvents.NoticeRealtimeMessage
115124
elif MidiMessageTypeIdentifaction.isSystemMessage status then
116-
triggerMessageEvent systemMessage platformEvents.NoticeSystemMessage
117-
elif MidiMessageTypeIdentifaction.isSysexBeginOrEnd status then
118-
sysex.Trigger bytes
119-
platformEvents.NoticeSysex(rtDevice, bytes)
125+
if MidiMessageTypeIdentifaction.isSysexBeginOrEnd status then
126+
sysex.Trigger bytes
127+
platformEvents.NoticeSysex(device, bytes)
128+
else
129+
triggerMessageEvent systemMessage platformEvents.NoticeSystemMessage
120130
else
121131
#if DEBUG
122132
failwithf "unable to parse what I received received %A" bytes

0 commit comments

Comments
 (0)