This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoteTimingOffsets.agc
executable file
·81 lines (72 loc) · 2.54 KB
/
NoteTimingOffsets.agc
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Type _NoteTimingOffsetsItem
Key As String
Value As Integer
EndType
Global _NoteTimingOffsetsList As _NoteTimingOffsetsItem[]
Function ReadNoteTimingOffsetsFromFile()
If Not GetFileExists("raw:" + GetReadPath() + "notetimingoffsets.txt") Then ExitFunction
fileId = OpenToRead("/notetimingoffsets.txt")
CheckError()
If fileId = 0 Then ExitFunction
While _NoteTimingOffsetsList.Length >= 0
_NoteTimingOffsetsList.Remove()
EndWhile
line As String
While Not FileEOF(fileId)
offsetItem As _NoteTimingOffsetsItem
line = ReadLine(fileId)
// Remove Comment (//)
commentIndex = FindString(line, "//")
If commentIndex > 0 Then line = Left(line, commentIndex - 1)
// If a=b type
If FindStringCount(line, "=") >= 1
offsetItem.Key = Lower(Trim(Left(line, FindString(line, "=") - 1)))
offsetItem.Value = Val(Trim(Right(line, Len(line) - FindString(line, "="))))
_NoteTimingOffsetsList.InsertSorted(offsetItem)
EndIf
EndWhile
CloseFile(fileId)
EndFunction
Function WriteNoteTimingOffsetsToFile()
If _NoteTimingOffsetsList.Length < 0
If GetFileExists("raw:" + GetReadPath() + "notetimingoffsets.txt") Then DeleteFile("raw:" + GetReadPath() + "notetimingoffsets.txt")
ExitFunction
EndIf
file = OpenToWrite("raw:" + GetReadPath() + "notetimingoffsets.txt")
CheckError()
If file = 0
InvokeError("Failed to write note timing offsets file.")
ExitFunction
EndIf
For i = 0 To _NoteTimingOffsetsList.Length
shaItemIdx = _MusicLibraryShaList.Find(_NoteTimingOffsetsList[i].Key)
If shaItemIdx < 0 /*Or _NoteTimingOffsetsList[i].Value = 0*/ Then Continue
shaItem As MusicLibraryShaListItem
shaItem = _MusicLibraryShaList[shaItemIdx]
//WriteString(file, shaItem.Sha256String + " = " + Str(_NoteTimingOffsetsList[i].Value) + " // " + shaItem.Title + " - " + shaItem.Artist)
WriteString(file, shaItem.Sha256String + " = " + Str(_NoteTimingOffsetsList[i].Value) + " // " + shaItem.FileName)
Next
CloseFile(file)
EndFunction
Function GetNoteTimingOffset(szSha As String)
idx = _NoteTimingOffsetsList.Find(szSha)
If idx < 0 Then ExitFunction 0
EndFunction _NoteTimingOffsetsList[idx].Value
Function SetNoteTimingOffset(szSha As String, iValue As Integer)
If szSha = "" Then ExitFunction
idx = _NoteTimingOffsetsList.Find(szSha)
If idx >= 0
If iValue <> 0
_NoteTimingOffsetsList[idx].Value = iValue
Else
_NoteTimingOffsetsList.Remove(idx)
EndIf
Else
If iValue <> 0
offsetItem As _NoteTimingOffsetsItem
offsetItem.Key = szSha
offsetItem.Value = iValue
_NoteTimingOffsetsList.InsertSorted(offsetItem)
EndIf
EndIf
EndFunction