This repository was archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtility.cs
64 lines (60 loc) · 1.8 KB
/
Utility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Godot;
using System;
public class GodotMidiUtils
{
/// <summary>
/// Converts the big endian byte representation of
/// a 32-bit signed integer to an integer.
/// </summary>
/// <param name="buf"></param>
/// <param name="i"></param>
/// <returns></returns>
public static int ToInt32BigEndian(byte[] buf, int i)
{
return (buf[i]<<24) | (buf[i+1]<<16) | (buf[i+2]<<8) | buf[i+3];
}
/// <summary>
/// Converts the big endian byte representation of
/// a 16-bit signed integer to an integer.
/// </summary>
/// <param name="buf"></param>
/// <param name="i"></param>
/// <returns></returns>
public static int ToInt16BigEndian(byte[] buf, int i)
{
return (buf[i]<<8) | buf[i+1];
}
/// <summary>
/// Converts the big endian byte representation
/// of a VarInt (MIDI specification) to an integer.
/// </summary>
/// <param name="buf"></param>
/// <param name="i"></param>
/// <param name="bytes"></param>
/// <returns></returns>
public static int ToVarIntBigEndian(byte[] buf, int i, out int bytes)
{
int value = 0;
bytes = 0;
while (true)
{
value = (value << 7) | (buf[i] & 0x7F);
bytes++;
if ((buf[i] & 0x80) == 0)
break;
i++;
}
return value;
}
/// <summary>
/// Converts the big endian byte representation of
/// a 24-bit signed integer to an integer.
/// </summary>
/// <param name="buf"></param>
/// <param name="i"></param>
/// <returns></returns>
public static int ToInt24BigEndian(byte[] buf, int i)
{
return (buf[i]<<16) | (buf[i+1]<<8) | buf[i+2];
}
}