5 def __init__(self
, group
):
10 if self
.group
is None:
17 return "(" + str(self
.group
) + ") : " + dict.__str
__(self
.merged())
28 def load(self
, fname
):
29 self
.parse(open(fname
, "r").read())
31 def parse(self
, data
):
32 context
= SFZContext()
33 for ptype
, pdata
in re
.findall("<(region|group)>\s*([^<]*)", data
, re
.S
):
34 self
.parse_part(ptype
, pdata
.strip(), context
)
36 def parse_part(self
, ptype
, pdata
, context
):
40 target
= context
.group
42 context
.region
= SFZRegion(context
.group
)
43 target
= context
.region
45 pairs
= re
.split("\s+([a-zA-Z_0-9]+)=", " "+pdata
)[1:]
46 for i
in range(0, len(pairs
), 2):
47 target
[pairs
[i
]] = pairs
[i
+ 1]
49 self
.regions
.append(target
)
51 def find_sample_in_path(path
, sample
):
52 jpath
= os
.path
.join(path
, sample
)
53 if os
.path
.exists(jpath
):
55 path
, sample
= os
.path
.split(jpath
)
56 sample
= sample
.lower()
57 files
= os
.path
.listdir(path
)
59 if f
.lower() == sample
:
60 return os
.path
.join(path
, f
)