Last active
December 19, 2017 08:48
-
-
Save nyanpasu64/c4ad5cd41340af7f07ce1383ed7eb572 to your computer and use it in GitHub Desktop.
0CC-Famitracker MML Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| HEX = ['0x', '$'] | |
| LOOP = '|' | |
| RELEASE = '/' | |
| class MML: | |
| def __init__(self, string): | |
| self.arr = [] | |
| self.loop = None | |
| self.release = None | |
| a = string.split() | |
| for word in a: | |
| word0 = word | |
| if word == LOOP: | |
| self.loop = len(self.arr) | |
| continue | |
| elif word == RELEASE: | |
| self.release = len(self.arr) | |
| continue | |
| base = 10 | |
| for hex in HEX: | |
| if word.startswith(hex): | |
| base = 16 | |
| word = word[len(hex):] | |
| try: | |
| self.arr.append(int(word, base)) | |
| except ValueError: | |
| print('warning invalid word', word0) | |
| def __str__(self): | |
| out = [] | |
| for i, el in enumerate(self.arr): | |
| if i == self.loop: | |
| out.append(LOOP) | |
| if i == self.release: | |
| out.append(RELEASE) | |
| out.append(str(el)) | |
| return ' '.join(out) | |
| m = MML('-3 -1 1 1 4 9 18 26 36 24 9 0 -1 -1 | 1 0 8 18 26 31 33 34 34 34 31 21 9 -4 -14 -21 -21 -21 -19 -19 -18 -18 -14 -8 ') | |
| m.arr = [-x for x in m.arr] | |
| print(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment