11module Elektron.MonoMachine
2-
2+ open FSharp. UMX
33open System
44open Midi
5+
56open Midinette.Platform
67open Elektron.Platform
78open Elektron.Platform .SilverMachines
@@ -19,21 +20,22 @@ type LFOShape =
1920 match value with
2021 | _ -> failwithf " %i not defined" value
2122
22-
2323type LFOMultiplier = Times1 | Times2 | Times4 | Times8 | Times16 | Times32 | Times64
2424
2525module internal Helpers =
26- let monoMachineHeader = [|
26+ let monoMachineHeader =
27+ [|
2728 0xf0 uy
2829 0x00 uy
2930 0x20 uy
3031 0x3c uy
3132 0x03 uy
3233 0x00 uy
3334 |]
35+ |> UMX.tag_ sysex_ data
3436
3537 let makeSysexMessage message =
36- let sysexEnd = [| 0xf7 uy|]
38+ let sysexEnd = [| UMX.tag _ sysex _ data 0xf7 uy|]
3739 Array.concat [| monoMachineHeader; message; sysexEnd|]
3840
3941open Helpers
5860 | SequencerMode -> 0x10 uy
5961 | AudioMode -> 0x20 uy
6062 | SequencerModeMode -> 0x21 uy
61- static member FromByte v =
62- match v with
63+ static member FromByte ( v : byte < _ >) =
64+ match UMX.untag v with
6365 | 0x01 uy -> GlobalSlot
6466 | 0x02 uy -> KitNumber
6567 | 0x04 uy -> PatternNumber
7375type Track = Track1 | Track2 | Track3 | Track4 | Track5 | Track6
7476with
7577 static member FromByte b =
76- match b with
78+ match UMX.untag _ byte _ 7bits b with
7779 | 0x0 uy -> Track1
7880 | 0x1 uy -> Track2
7981 | 0x2 uy -> Track3
@@ -173,7 +175,7 @@ type MachineParameters(bytes: byte array) =
173175 member x.MIDI = getBytes midiBase
174176 member x.ADSR = getBytes adsrBase
175177
176- type MonoMachineKit ( data : byte array ) =
178+ type MonoMachineKit ( data : sysex_data ) =
177179 member x.Version = data.[ 0x07 ]
178180 member x.Revision = data.[ 0x08 ]
179181 member x.OriginalPosition = data.[ 0x09 ]
@@ -186,17 +188,17 @@ type MonoMachineKit (data: byte array) =
186188 |> dataToByte
187189 //else [||]
188190 member x.Name =
189- x.unpacked |> getSlice 0 11 |> ASCIIEncoding.ASCII.GetString
191+ x.unpacked |> SysexBufferEdit. getSlice 0 11 |> unbox |> ASCIIEncoding.ASCII.GetString
190192 member x.Levels =
191- x.unpacked |> getSlice 0xb 6
193+ x.unpacked |> SysexBufferEdit. getSlice 0xb 6
192194 member x.Parameters =
193195 x.unpacked
194- |> getSlice 0x11 ( 72 * 6 )
196+ |> SysexBufferEdit. getSlice 0x11 ( 72 * 6 )
195197 |> Array.chunkBySize 72
196198 |> Array.map MachineParameters
197199 member x.Machines =
198200 x.unpacked
199- |> getSlice 0x1c1 6
201+ |> SysexBufferEdit. getSlice 0x1c1 6
200202 |> Array.map ((&&&) 0b01111111 uy)
201203 |> Array.map MonoMachineType.FromValue
202204
@@ -214,57 +216,58 @@ with
214216 | Fixed v -> v
215217
216218type GlobalSettings = {
217- midiChannelAutoTrack : byte
218- midiChannel : byte
219- midiChannelMultiTrig : byte
220- midiChannelMultiMap : byte
221- midiMachineChannels : byte array
222- ccDestinationsPerChannel: byte array array
219+ midiChannelAutoTrack : byte_7bits
220+ midiChannel : byte_7bits
221+ midiChannelMultiTrig : byte_7bits
222+ midiChannelMultiMap : byte_7bits
223+ midiMachineChannels : byte_7bits array
224+ ccDestinationsPerChannel: byte_7bits array array
223225 programChangeIn : bool
224226 velocityCurve : VelocityCurve
225- fixedVelocity : byte
226- knobSpeed : byte
227+ fixedVelocity : byte_7bits
228+ knobSpeed : byte_7bits
227229 baseFrequency : int
228230}
229231with
230232 static member Default =
231233 {
232- midiChannelAutoTrack= 8 uy
233- midiChannel = 0 uy
234- midiChannelMultiTrig = 7 uy
235- midiChannelMultiMap = 08 uy
236- midiMachineChannels = [| 0 uy .. 05 uy|]
234+ midiChannelAutoTrack = UMX.tag _ byte _ 7bits 8 uy
235+ midiChannel = UMX.tag _ byte _ 7bits 0 uy
236+ midiChannelMultiTrig = UMX.tag _ byte _ 7bits 7 uy
237+ midiChannelMultiMap = UMX.tag _ byte _ 7bits 08 uy
238+ midiMachineChannels = UMX.tag _ byte _ 7bits [| 0 uy .. 05 uy|]
237239 ccDestinationsPerChannel= [||]
238240 programChangeIn = true
239241 velocityCurve = VelocityCurve.Linear
240- fixedVelocity = 0 uy
241- knobSpeed = 0 uy
242+ fixedVelocity = UMX.tag _ byte _ 7bits 0 uy
243+ knobSpeed = UMX.tag _ byte _ 7bits 0 uy
242244 baseFrequency = 440
243245
244246 }
245- static member FromSysex ( sysexData : byte array ) =
247+ static member FromSysex ( sysexData : sysex_data ) =
246248 // note: this is just plain broken on hardware side
247249 if areMonoMachineCheckSumAndLengthValid sysexData then
248250 let globalData =
249251 ( getMonoMachineDataSliceFromSysexMessage sysexData)
250252 |> Seq.toArray
251- |> Elektron.Platform.dataToByte
253+ |> dataToByte
254+
252255 //if globalData.Length < 0x101 then None
253256 //else
254257 Some
255258 {
256- midiChannelAutoTrack = globalData.[ 0x00 ]
257- midiChannel = globalData.[ 0x01 ]
258- midiChannelMultiTrig = globalData.[ 0x02 ]
259- midiChannelMultiMap = globalData.[ 0x03 ]
259+ midiChannelAutoTrack = UMX.tag _ byte _ 7bits globalData.[ 0x00 ]
260+ midiChannel = UMX.tag _ byte _ 7bits globalData.[ 0x01 ]
261+ midiChannelMultiTrig = UMX.tag _ byte _ 7bits globalData.[ 0x02 ]
262+ midiChannelMultiMap = UMX.tag _ byte _ 7bits globalData.[ 0x03 ]
260263 midiMachineChannels = [||] //globalData.[0x12..0x1]
261264
262265 // external sync
263266 ccDestinationsPerChannel = [||] //[|globalData.[0x18..0x1]|]
264267 programChangeIn = true //globalData.[0xfd] = 1uy
265268 velocityCurve = VelocityCurve.Fixed 1 uy //globalData.[0xff] |> VelocityCurve.FromByte
266- fixedVelocity = 0 uy //globalData.[0x100]
267- knobSpeed = 0 uy//globalData.[0x101]
269+ fixedVelocity = UMX.tag _ byte _ 7bits 0 uy //globalData.[0x100]
270+ knobSpeed = UMX.tag _ byte _ 7bits 0 uy//globalData.[0x101]
268271 baseFrequency = 0 //globalData.[0x104..] |> Elektron.fourBytesToBigEndianInt
269272 }
270273 else
@@ -274,26 +277,26 @@ with
274277type MonoMachineSysexResponse =
275278| GlobalSettings of GlobalSettings
276279| Kit of MonoMachineKit
277- | Pattern of byte array
278- | Song of byte array
279- | StatusResponse of statusType : MonoMachineStatusType * value : byte
280+ | Pattern of sysex_data
281+ | Song of sysex_data
282+ | StatusResponse of statusType : MonoMachineStatusType * value : byte_7bits
280283with
281- static member BuildResponse ( bytes : byte array ) =
282- match bytes.[ 6 ] with
283- | 72 uy -> StatusResponse( MonoMachineStatusType.FromByte bytes.[ 7 ], bytes.[ 8 ])
284+ static member BuildResponse ( bytes : sysex_data ) =
285+ match UMX.untag _ sysex bytes.[ 6 ] with
286+ | 72 uy -> StatusResponse( MonoMachineStatusType.FromByte bytes.[ 7 ], UMX.to _ byte _ 7bits bytes.[ 8 ])
284287 | 0x50 uy -> GlobalSettings ( GlobalSettings.FromSysex( bytes) .Value)
285288 | 0x52 uy -> Kit ( MonoMachineKit( bytes))
286289 | 0x67 uy -> Pattern bytes
287290 | _ -> failwithf " h:%x response not understood" bytes.[ 6 ]
288291
289292
290293type MonoMachineSysexRequests =
291- | DumpGlobalSettings of globalSettingsIndex : byte
292- | DumpKit of kit : byte
293- | DumpPattern of pattern : byte
294- | DumpSong of song : byte
294+ | DumpGlobalSettings of globalSettingsIndex : byte_7bits
295+ | DumpKit of kit : byte_7bits
296+ | DumpPattern of pattern : byte_7bits
297+ | DumpSong of song : byte_7bits
295298| QueryStatus of statusType : MonoMachineStatusType
296- | AssignMachine of track : byte * machine : MonoMachineType * parametersMode : AssignMachineParameterMode
299+ | AssignMachine of track : byte_7bits * machine : MonoMachineType * parametersMode : AssignMachineParameterMode
297300with
298301 member x.MessageId =
299302 match x with
@@ -306,13 +309,14 @@ with
306309 member x.Sysex =
307310 let data =
308311 match x with
309- | DumpGlobalSettings id -> id |> Array.singleton
310- | DumpKit kit -> kit |> Array.singleton
311- | DumpPattern pattern -> pattern |> Array.singleton
312- | DumpSong song -> song |> Array.singleton
312+ | DumpGlobalSettings id -> id |> UMX.untag |> Array.singleton
313+ | DumpKit kit -> kit |> UMX.untag |> Array.singleton
314+ | DumpPattern pattern -> pattern |> UMX.untag |> Array.singleton
315+ | DumpSong song -> song |> UMX.untag |> Array.singleton
313316 | QueryStatus status -> status.Id |> Array.singleton
314- | AssignMachine ( t, m, p) -> [| t; m.Value; p.Value|]
315- makeSysexMessage ( Array.concat ([| x.MessageId |> Array.singleton; data|]))
317+ | AssignMachine ( t, m, p) -> [| UMX.untag t; UMX.untag m.Value; UMX.untag p.Value|]
318+ let data = UMX.tag_ sysex_ data data
319+ makeSysexMessage ( Array.concat ([| x.MessageId |> UMX.tag_ sysex_ data |> Array.singleton; data|]))
316320 member x.ResponseMessageId =
317321 match x with
318322 | DumpGlobalSettings _
327331 | DumpKit _ -> Some <| Kit( MonoMachineKit data)
328332 | DumpPattern _ -> Some <| Pattern data
329333 | DumpSong _ -> Some <| Song data
330- | QueryStatus _ -> Some <| StatusResponse(( MonoMachineStatusType.FromByte data.[ monoMachineHeader.Length + 1 ]), data.[ monoMachineHeader.Length + 2 ])
334+ | QueryStatus _ -> Some <| StatusResponse(( MonoMachineStatusType.FromByte data.[ monoMachineHeader.Length + 1 ]), UMX.to _ byte _ 7bits data.[ monoMachineHeader.Length + 2 ])
331335 | AssignMachine(_) -> failwithf " not implemented"
332336 //| _ -> None
333337
@@ -347,8 +351,8 @@ type MonoMachine<'timestamp>(inPort: IMidiInput<'timestamp>, outPort: IMidiOutpu
347351 maxMessage
348352 timeout
349353 ( fun sysex ->
350- sysex.[ 0 .. 5 ] = Helpers. monoMachineHeader
351- && Some sysex.[ 6 ] = request.ResponseMessageId
354+ sysex.[ 0 .. 5 ] = monoMachineHeader
355+ && Some ( UMX.untag _ sysex sysex.[ 6 ]) = request.ResponseMessageId
352356 )
353357 request.BuildResponse
354358 inPort
@@ -647,7 +651,7 @@ type MonoMachineEvent =
647651| Unknown of MidiMessage
648652| UnknownNRPN of Midi.Nrpn.NRPNEvent
649653| MonoMachineSysex of MonoMachineSysexResponse
650- | Sysex of byte array
654+ | Sysex of sysex_data
651655| KitChanged of byte
652656| SequencerStarted
653657| SequencerStopped
@@ -706,12 +710,12 @@ type MonoMachineEventListener<'timestamp>
706710 let settings = GlobalSettings.Default //settings |> Option.defaultValue
707711 let message = midiEvent.Message
708712 let messageChannel = message.Channel.Value
709- let midiChannelIsTrack = messageChannel >= settings.midiChannel && messageChannel < ( settings.midiChannel + 6 uy)
713+ let midiChannelIsTrack = messageChannel >= settings.midiChannel && messageChannel < ( settings.midiChannel + ( UMX.tag _ byte _ 7bits 6 uy) )
710714 if midiChannelIsTrack then
711- let track = Track.FromByte ( byte ( messageChannel - settings.midiChannel) )
715+ let track = Track.FromByte ( messageChannel - settings.midiChannel)
712716 match message with
713- | NoteOn (_, note, velocity) -> TrackTrigger( track, note, velocity)
714- | NoteOff (_, note, velocity) -> TrackRelease( track, note, velocity)
717+ | NoteOn (_, note, velocity) -> TrackTrigger( track, UMX.tag note, velocity)
718+ | NoteOff (_, note, velocity) -> TrackRelease( track, UMX.tag note, velocity)
715719 | ProgramChange { program = program} ->
716720 let locator = PatternLocator.FromByte program
717721 PatternSelected( locator)
0 commit comments