-
Notifications
You must be signed in to change notification settings - Fork 0
/
thewriter.py
58 lines (43 loc) · 1.52 KB
/
thewriter.py
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
import numpy as np
import os
import scipy
import json
# utility
def secondsToBeat(inSeconds, lpb):
return (inSeconds/lpb)
jsonDump = {}
jsonDump["_version"] = "0.0.0"
jsonDump["_BPMChanges"] = []
jsonDump["_events"] = []
# loop through each file
for path, subdirs, files in os.walk('generated+data'):
results = []
sorted(files)
for name in files:
if (name == "data.json"):
print("-")
folderLookup = path.split('\\')[1] # gets the beat number
fileName = os.path.join(path, name)
filePath ="c:/Users/ladyvox/Documents/_lightlike" + "/generated+data/" + folderLookup + "/" + "data.json"
f = open(filePath,)
data = json.load(f)
f.close()
inTime = data['time']
convertedTimeToBeat = secondsToBeat(float(data['time']), 0.1335 * 4) # every quarter beat
inType = data['type']
inValue = data['value']
print ( str(inTime), str(convertedTimeToBeat), str(inType), str(inValue) )
frameObj = {
"_time": str(convertedTimeToBeat),
"_type": str(inType),
"_value": str(inValue)
}
jsonDump["_events"].append(frameObj)
print (jsonDump)
try:
# write the data out here
filePath = "final\\" + "Easy.dat"
with open(filePath, 'x') as f:
json.dump(jsonDump, f)
except:
print("failed to write data")