diff --git a/splashbuilder.py b/splashbuilder.py index 285505b..47b9beb 100644 --- a/splashbuilder.py +++ b/splashbuilder.py @@ -165,29 +165,55 @@ class Sound(object): channeldata = config["channelbin"] self.chdata = {} - self.chdata[0] = None - self.chdata[1] = None - self.chdata[2] = None - self.chdata[3] = None + self.channel_count = 0 - #if channeldata["ch0"] is not "": - # binfile = os.path.abspath(channeldata["ch0"]) - # self.chdata[0] = open(binfile, "rb").read() - #if channeldata["ch1"] is not "": - # self.chdata[1] = open(channeldata["ch1"], "rb").read() - #if channeldata["ch2"] is not "": - # self.chdata[2] = open(channeldata["ch2"], "rb").read() - #if channeldata["ch3"] is not "": - # self.chdata[3] = open(channeldata["ch3"], "rb").read() + for i in range(4): + self.chdata[i] = None + tag = "ch{i}".format(i=i) + if channeldata[tag] is not "": + self.channel_count += 1 + binfile = os.path.abspath(channeldata[tag]) + self.chdata[i] = open(binfile, "rb").read() + + if self.channel_count == 0: + raise Exception("You need at least one channel") def get_size(self): return len(self.waves) - #+ len(self.chdata[0]) + len(self.chdata[1]) + \ - #len(self.chdata[2]) + len(self.chdata[3]) + 4 * 2 + + def get_ch_size(self): + current_len = 0 + for i in range(4): + if self.chdata[i]: + current_len += len(self.chdata[i]) + + return current_len + + def get_list_size(self): + current_len = 2 # We always have a tag to show the end of list + for i in range(4): + if self.chdata[i]: + current_len += 2 + + return current_len def write(self, f): f.write(self.waves) + def write_list(self, f, offset): + for i in range(4): + if self.chdata[i]: + f.write(struct.pack("