-
Notifications
You must be signed in to change notification settings - Fork 1
/
daw.py
86 lines (56 loc) · 1.58 KB
/
daw.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*-coding:Utf-8 -*
import rpp_file
import os
class DawProject:
def __init__(self):
self.filePath = ""
self.tracks = []
def create_track(self):
t = DawTrack()
self.tracks.append(t)
return t
class DawTrack:
def __init__(self):
self.name = ""
self.items = []
def create_item(self):
i = DawTrackItem()
self.items.append(i)
return i
class DawTrackItem:
def __init__(self):
self.sourceFile = ""
self.name = ""
self.position = 0
self.length = 0
class UnsupportedFormat(Exception):
def __init__(self, filePath):
self.filePath = filePath
super().__init__(self, "Unsupported file format " + filePath)
def open_project(filePath):
fileName, ext = os.path.splitext(filePath)
ext = ext.lower()[1:]
if ext == "rpp":
return open_rpp_project(filePath)
else:
raise UnsupportedFormat(filePath)
def open_rpp_project(filePath):
rpp = rpp_file.parse_rpp_file(filePath)
project = DawProject()
project.filePath = filePath
rppTracks = rpp.get_nodes_by_tag("TRACK")
for rppTrack in rppTracks:
track = project.create_track()
track.name = rppTrack.get_node_by_tag("NAME").values[0]
rppItems = rppTrack.get_nodes_by_tag("ITEM")
for rppItem in rppItems:
item = track.create_item()
item.name = rppItem.get_node_by_tag("NAME").values[0]
item.position = rppItem.get_node_by_tag("POSITION").values[0]
item.length = rppItem.get_node_by_tag("LENGTH").values[0]
source = rppItem.get_node_by_tag("SOURCE")
if source:
sourceFile = source.get_node_by_tag("FILE")
if sourceFile:
item.sourceFile = sourceFile.values[0]
return project