@@ -212,26 +212,32 @@ type GlobalSettings = {
212
212
baseFrequency : int
213
213
}
214
214
with
215
- static member FromSysex ( bytes : byte array ) =
216
- let globalData = ( getMonoMachineDataSliceFromSysexMessage bytes) |> Seq.toArray |> Elektron.Platform.byteToData
217
-
218
- {
219
- midiChannelAutoTrack = globalData.[ 0x00 ]
220
- midiChannel = globalData.[ 0x01 ]
221
- midiChannelMultiTrig = globalData.[ 0x02 ]
222
- midiChannelMultiMap = globalData.[ 0x03 ]
223
- midiMachineChannels = [||] //globalData.[0x12..0x1]
224
-
225
- // external sync
226
- ccDestinationsPerChannel = [||] //[|globalData.[0x18..0x1]|]
227
- programChangeIn = globalData.[ 0xfd ] = 1 uy
228
- velocityCurve = globalData.[ 0xff ] |> VelocityCurve.FromByte
229
- fixedVelocity = globalData.[ 0x100 ]
230
- knobSpeed = globalData.[ 0x101 ]
231
- baseFrequency = 0 //globalData.[0x104..] |> Elektron.fourBytesToBigEndianInt
232
- }
215
+ static member FromSysex ( sysexData : byte array ) =
216
+ if areMonoMachineCheckSumAndLengthValid sysexData then
217
+ let globalData = ( getMonoMachineDataSliceFromSysexMessage sysexData) |> Seq.toArray |> Elektron.Platform.byteToData
218
+ if globalData.Length < 0x101 then None
219
+ else
220
+ Some
221
+ {
222
+ midiChannelAutoTrack = globalData.[ 0x00 ]
223
+ midiChannel = globalData.[ 0x01 ]
224
+ midiChannelMultiTrig = globalData.[ 0x02 ]
225
+ midiChannelMultiMap = globalData.[ 0x03 ]
226
+ midiMachineChannels = [||] //globalData.[0x12..0x1]
227
+
228
+ // external sync
229
+ ccDestinationsPerChannel = [||] //[|globalData.[0x18..0x1]|]
230
+ programChangeIn = globalData.[ 0xfd ] = 1 uy
231
+ velocityCurve = globalData.[ 0xff ] |> VelocityCurve.FromByte
232
+ fixedVelocity = globalData.[ 0x100 ]
233
+ knobSpeed = globalData.[ 0x101 ]
234
+ baseFrequency = 0 //globalData.[0x104..] |> Elektron.fourBytesToBigEndianInt
235
+ }
236
+ else
237
+ failwithf " can't parse globalsettings from sysex %A " sysexData
238
+
233
239
type MonoMachineSysexResponse =
234
- | GlobalSettings of byte array
240
+ | GlobalSettings of GlobalSettings
235
241
| Kit of MonoMachineKit
236
242
| Pattern of byte array
237
243
| Song of byte array
@@ -279,11 +285,11 @@ with
279
285
| QueryStatus _ -> Some 0x72 uy
280
286
member x.BuildResponse data =
281
287
match x with
282
- | DumpGlobalSettings _ -> GlobalSettings data
283
- | DumpKit _ -> Kit( MonoMachineKit data)
284
- | DumpPattern _ -> Pattern data
285
- | DumpSong _ -> Song data
286
- | QueryStatus _ -> StatusResponse(( MonoMachineStatusType.FromByte data.[ monoMachineHeader.Length + 1 ]), data.[ monoMachineHeader.Length + 2 ])
288
+ | DumpGlobalSettings _ -> GlobalSettings.FromSysex data |> Option.map GlobalSettings
289
+ | DumpKit _ -> Some <| Kit( MonoMachineKit data)
290
+ | DumpPattern _ -> Some <| Pattern data
291
+ | DumpSong _ -> Some <| Song data
292
+ | QueryStatus _ -> Some <| StatusResponse(( MonoMachineStatusType.FromByte data.[ monoMachineHeader.Length + 1 ]), data.[ monoMachineHeader.Length + 2 ])
287
293
| AssignMachine(_) -> failwithf " not implemented"
288
294
//| _ -> None
289
295
@@ -295,9 +301,31 @@ type MonoMachineTrig =
295
301
296
302
type MonoMachine ( inPort : IMidiInput < _ >, outPort : IMidiOutput < _ >) =
297
303
let helpGetMonomachineSysex maxMessage ( timeout : TimeSpan ) ( request : MonoMachineSysexRequests ) ( inPort : IMidiInput < _ >) =
298
- Midi.Sysex.helpGetSysex maxMessage timeout ( fun sysex ->
299
- sysex.[ 0 .. 5 ] = Helpers.monoMachineHeader && Some sysex.[ 6 ] = request.ResponseMessageId) request.BuildResponse inPort
300
-
304
+ #if FABLE_ COMPILER
305
+ failwithf " TODO FABLE"
306
+ #else
307
+ let getSysexAsync =
308
+ Midi.Sysex.helpGetSysex
309
+ maxMessage
310
+ timeout
311
+ ( fun sysex ->
312
+ sysex.[ 0 .. 5 ] = Helpers.monoMachineHeader
313
+ && Some sysex.[ 6 ] = request.ResponseMessageId
314
+ )
315
+ request.BuildResponse
316
+ inPort
317
+ async {
318
+ let! sysx = getSysexAsync
319
+ match sysx with
320
+ | Choice1Of2( Some( sysx)) -> return sysx
321
+ | Choice1Of2 (_) ->
322
+ printfn " oops1"
323
+ return None
324
+ | Choice2Of2 exn ->
325
+ printfn " oops2"
326
+ return None
327
+ }
328
+ #endif
301
329
let performSysExRequest ( requestMessage : MonoMachineSysexRequests ) =
302
330
match requestMessage.ResponseMessageId with
303
331
| Some id ->
@@ -581,7 +609,7 @@ type TimestampedMessage<'t> = {
581
609
582
610
583
611
type MonoMachineEventListener ( getNow : unit -> int , mm : MonoMachine ) =
584
- let settings = mm.CurrentGlobalSettings |> Option.map GlobalSettings.FromSysex
612
+ let settings = mm.CurrentGlobalSettings
585
613
//let settings = { GlobalSettings.midiBaseChannel = 0uy }
586
614
let midiIn = mm.MidiOutPort
587
615
let midiRealtimeState = Midi.Registers.MidiRealtimeState()
0 commit comments