Skip to content

Commit f21a803

Browse files
fixing getVarlen implementation
1 parent dabb99e commit f21a803

File tree

1 file changed

+3
-52
lines changed

1 file changed

+3
-52
lines changed

src/ZMidi/Read.fs

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ namespace ZMidi
33
open ZMidi.DataTypes
44

55
module ReadFile =
6-
//let readMidi filename =
7-
//let midiFile : Parser = ()
86
open ZMidi.Internal.ParserMonad
97
open ZMidi.Internal.Utils
108
open ZMidi.Internal.ExtraTypes
@@ -20,9 +18,6 @@ module ReadFile =
2018
return! fatalError errorMessage
2119
}
2220

23-
24-
25-
2621
let inline (|TestBit|_|) (bit: int) (i: ^T) =
2722
let mask = LanguagePrimitives.GenericOne <<< bit
2823
if mask &&& i = mask then Some () else None
@@ -47,60 +42,16 @@ module ReadFile =
4742
let rec loop acc =
4843
parseMidi {
4944
let! b = readByte
50-
45+
let acc = acc <<< 7
5146
if msbHigh b then
52-
let result = (b &&& 0x7fuy)
53-
return! loop (acc + ((uint64 (result)) * 128UL ))
47+
let result = uint64 (b &&& 0b01111111uy)
48+
return! loop (acc + result)
5449
else
5550
return (acc + (uint64 b)) }
5651
parseMidi {
5752
let! result = loop 0UL
5853
return (uint32 result) }
5954

60-
61-
(*
62-
let step3 a b =
63-
parseMidi {
64-
let! c = readByte
65-
if msbHigh c then
66-
let! d = readByte
67-
return V4 (a,b,c,d)
68-
else
69-
return V3 (a,b,c) }
70-
let step2 a = parseMidi {
71-
let! b = readByte
72-
if msbHigh b then
73-
return! step3 a b
74-
else
75-
return V2 (a,b) }
76-
77-
parseMidi {
78-
let! a = readByte
79-
if msbHigh a then
80-
let! r = step2 a
81-
return (ZMidi.Internal.ExtraTypes.fromVarlen r)
82-
else
83-
return (ZMidi.Internal.ExtraTypes.fromVarlen (V1 a))
84-
85-
//return result
86-
//>>= (fun a ->)
87-
//let! a = readByte
88-
//if msbHigh a then
89-
// let! b = readByte
90-
// if msbHigh b then
91-
// let! c = readByte
92-
// if msbHigh c then
93-
// let! d = readByte
94-
// return fromVarlen (V4(a,b,c,d))
95-
// else
96-
// return fromVarlen (V3(a,b,c))
97-
// else
98-
// return fromVarlen (V2(a, b))
99-
//else
100-
// return fromVarlen (V1 a)
101-
102-
}*)
103-
10455
let getVarlenText = gencount getVarlen readChar (fun _ b -> System.String b)
10556

10657
let fileFormat =

0 commit comments

Comments
 (0)