def encode_to(self, bytecode): bytecode.obj_list.append(self) bytecode.write(util.hex_pad(self.classnum, 8)) for each_field in self.data: bytecode.write(util.hex_pad(util.extract_num(each_field), 8)) self.encode_field(bytecode, each_field) bytecode.write('00000000')
def write_str(self, string): if self.string_mode == "PREPEND_LEN": try: string.encode("ascii") except UnicodeEncodeError: self.contents += bytes.fromhex(hex(0x80000000 + len(string))[2:]) self.contents += string.encode('utf-16be') else: self.contents += util.hex_pad(len(string), 8) self.contents += string.encode('utf-8') elif self.string_mode == "NULL_TERMINATED": self.contents += string.encode('utf-8') self.contents += bytes([0]) else: raise SyntaxError("Invalid string mode")
def encode(self): """Encodes the color object into Bitwig bytecode. Returns: bytes: Bitwig bytecode representation of the Color object. """ output = b'' count = 0 for item in self.data: flVal = struct.unpack('>I', struct.pack('>f', item))[0] output += util.hex_pad(flVal, 8) count += 1 if count == 3: output += struct.pack('>f', 1.0) return output
def write_int(self, num, pad=8): self.contents += util.hex_pad(num, pad) self.contents_len = len(self.contents)