Skip to content

Commit 51d6a49

Browse files
committed
Compatibility with Python 3.8
1 parent 0b20a0b commit 51d6a49

File tree

9 files changed

+259
-122
lines changed

9 files changed

+259
-122
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
![Downloads](https://img.shields.io/pepy/dt/wii-music-editor)
66

77
## Installation
8-
[Download](https://www.python.org/downloads/) and install Python 3.9 or later.
8+
[Download](https://www.python.org/downloads/) and install Python 3.8 or later.
99

1010
Then, open a terminal and run the following command:
1111
```bash

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ authors = [
77
]
88
license = { file = "LICENSE" }
99
readme = "README.md"
10-
requires-python = ">=3.9,<3.13"
10+
requires-python = ">=3.8,<3.15"
1111
dependencies = [
1212
"importlib_metadata",
1313
"mido",

setup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ def has_ext_modules(self):
1515
class PostInstallCommand(install):
1616
def run(self):
1717
install.run(self)
18-
install_site = site.getsitepackages()[1]
19-
if not (Path(install_site) / "wii_music_editor").is_dir():
18+
install_site = None
19+
for sp in site.getsitepackages():
20+
if (Path(sp) / "wii_music_editor").is_dir():
21+
install_site = sp
22+
break
23+
if install_site is None:
2024
install_site = self.install_usersite
2125
make_shortcut(
2226
f"{install_site}/wii_music_editor/__main__.py",
@@ -44,6 +48,6 @@ def run(self):
4448
distclass=BinaryDistribution,
4549
package_data={"wii_music_editor": data},
4650
cmdclass={
47-
'install': PostInstallCommand,
51+
"install": PostInstallCommand,
4852
},
4953
)

wii_music_editor/editor/brsar.py

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from pathlib import Path
24

35

@@ -6,6 +8,7 @@ class BrsarGroup:
68
Each group in a brsar file holds a list of songs.
79
Different groups are used for different types of songs.
810
"""
11+
912
Regular = 2
1013
Maestro = 21
1114
Handbell = 23
@@ -20,14 +23,15 @@ class __BrsarSection:
2023
:param parent: The `parent` attribute is the parent section of the section.
2124
:param offset: The `offset` attribute is the offset of the section from the start of the file.
2225
"""
26+
2327
_referenceValueOffset = 0x04
2428
_referenceSize = 0x08
2529

26-
root: 'Brsar'
27-
parent: '__BrsarSection'
30+
root: "Brsar"
31+
parent: "__BrsarSection"
2832
offset: int
2933

30-
def __init__(self, parent: '__BrsarSection', offset: int):
34+
def __init__(self, parent: "__BrsarSection", offset: int):
3135
self.parent = parent
3236
self.root = parent.root
3337
self.offset = offset
@@ -39,7 +43,7 @@ def read_bytes(self, offset: int) -> int:
3943
"""
4044
length = 4
4145
offset += self.offset
42-
return int.from_bytes(self.root.data[offset:offset + length], "big")
46+
return int.from_bytes(self.root.data[offset : offset + length], "big")
4347

4448
def section_reference(self, offset: int) -> int:
4549
"""
@@ -61,7 +65,7 @@ def increment_value(self, value: str, increment: int) -> None:
6165
offset = getattr(self, f"_{value}") + self.offset
6266
val = getattr(self, value) + increment
6367
setattr(self, value, val)
64-
self.root.data[offset:offset + length] = val.to_bytes(length, "big")
68+
self.root.data[offset : offset + length] = val.to_bytes(length, "big")
6569

6670

6771
class Brsar(__BrsarSection):
@@ -70,6 +74,7 @@ class Brsar(__BrsarSection):
7074
A list of all the sections in a brsar file can be found at https://wiki.tockdom.com/wiki/BRSAR_(File_Format).
7175
:param path: The path to a brsar file.
7276
"""
77+
7378
_fileLength = 0x08
7479
_infoSectionOffset = 0x18
7580
_infoSectionSize = 0x1C
@@ -84,8 +89,8 @@ class Brsar(__BrsarSection):
8489

8590
brsarPath: Path
8691
data: bytearray
87-
infoSection: 'InfoSection'
88-
fileSection: 'FileSection'
92+
infoSection: "InfoSection"
93+
fileSection: "FileSection"
8994

9095
def __init__(self, path: Path):
9196
self.root = self
@@ -118,22 +123,24 @@ def replace_song(self, song: bytearray, group_index: int, item_index: int):
118123
incrementAmount = len(song) - itemGroup.rseqSize
119124

120125
# Replace song data
121-
self.data = self.data[:rseqOffset]+song+self.data[rseqOffset+itemGroup.rseqSize:]
126+
self.data = (
127+
self.data[:rseqOffset] + song + self.data[rseqOffset + itemGroup.rseqSize :]
128+
)
122129

123130
# Update Group Table
124-
songGroup.increment_value('rseqSize', incrementAmount)
125-
songGroup.increment_value('rwarOffset', incrementAmount)
126-
itemGroup.increment_value('rseqSize', incrementAmount)
127-
for item in songGroup.itemTable.entries[item_index+1:]:
128-
item.increment_value('rseqOffset', incrementAmount)
131+
songGroup.increment_value("rseqSize", incrementAmount)
132+
songGroup.increment_value("rwarOffset", incrementAmount)
133+
itemGroup.increment_value("rseqSize", incrementAmount)
134+
for item in songGroup.itemTable.entries[item_index + 1 :]:
135+
item.increment_value("rseqOffset", incrementAmount)
129136

130137
# Update other group tables
131-
for group in self.infoSection.groupDataTable.entries[group_index+1:]:
132-
group.increment_value('rseqOffset', incrementAmount)
133-
group.increment_value('rwarOffset', incrementAmount)
138+
for group in self.infoSection.groupDataTable.entries[group_index + 1 :]:
139+
group.increment_value("rseqOffset", incrementAmount)
140+
group.increment_value("rwarOffset", incrementAmount)
134141

135142
# Update Section Size
136-
self.increment_value('fileLength', incrementAmount)
143+
self.increment_value("fileLength", incrementAmount)
137144

138145
def get_song(self, group_index: int, item_index: int) -> bytearray:
139146
"""
@@ -145,7 +152,7 @@ def get_song(self, group_index: int, item_index: int) -> bytearray:
145152
songGroup = self.infoSection.groupDataTable.entries[group_index]
146153
itemGroup = songGroup.itemTable.entries[item_index]
147154
rseqOffset = songGroup.rseqOffset + itemGroup.rseqOffset
148-
return self.data[rseqOffset:rseqOffset+itemGroup.rseqSize]
155+
return self.data[rseqOffset : rseqOffset + itemGroup.rseqSize]
149156

150157
def save(self):
151158
with open(self.brsarPath, "wb") as file:
@@ -159,10 +166,11 @@ class InfoSection(__BrsarSection):
159166
:param parent: A reference to the brsar header.
160167
:param offset: The `offset` attribute is the offset of the section from the start of the file.
161168
"""
169+
162170
_groupTable = 0x28
163171

164172
parent: Brsar
165-
groupDataTable: 'GroupDataTable'
173+
groupDataTable: "GroupDataTable"
166174

167175
def __init__(self, parent: Brsar, offset: int):
168176
super().__init__(parent, offset)
@@ -177,6 +185,7 @@ class FileSection(__BrsarSection):
177185
:param parent: A reference to the brsar header.
178186
:param offset: The offset from the start of the file.
179187
"""
188+
180189
_sectionSize = 0x04
181190

182191
parent: Brsar
@@ -195,17 +204,20 @@ class GroupDataTable(__BrsarSection):
195204
:param parent: A reference to the info section.
196205
:param offset: The offset from the start of the file.
197206
"""
207+
198208
__numEntries = 0x00
199209
__entries = 0x04
200210

201211
parent: InfoSection
202-
entries: list['GroupDataEntry']
212+
entries: list["GroupDataEntry"]
203213

204214
def __init__(self, parent: InfoSection, offset: int):
205215
super().__init__(parent, offset)
206216
numEntries = self.read_bytes(self.__numEntries)
207217
self.entries = [
208-
GroupDataEntry(self, self.section_reference(self.__entries + i * self._referenceSize))
218+
GroupDataEntry(
219+
self, self.section_reference(self.__entries + i * self._referenceSize)
220+
)
209221
for i in range(numEntries)
210222
]
211223

@@ -219,20 +231,23 @@ class GroupDataEntry(__BrsarSection):
219231
:param parent: A reference to the group data table.
220232
:param offset: The offset from the start of the file.
221233
"""
234+
222235
_rseqOffset = 0x10
223236
_rseqSize = 0x14
224237
_rwarOffset = 0x18
225238
_groupItemEntry = 0x20
226239

227240
parent: GroupDataTable
228-
itemTable: 'GroupItemTable'
241+
itemTable: "GroupItemTable"
229242

230243
def __init__(self, parent: GroupDataTable, offset: int):
231244
super().__init__(parent, offset)
232245
self.rseqOffset = self.read_bytes(self._rseqOffset)
233246
self.rseqSize = self.read_bytes(self._rseqSize)
234247
self.rwarOffset = self.read_bytes(self._rwarOffset)
235-
self.itemTable = GroupItemTable(self, self.section_reference(self._groupItemEntry))
248+
self.itemTable = GroupItemTable(
249+
self, self.section_reference(self._groupItemEntry)
250+
)
236251

237252

238253
class GroupItemTable(__BrsarSection):
@@ -243,17 +258,20 @@ class GroupItemTable(__BrsarSection):
243258
:param parent: A reference to the group data entry.
244259
:param offset: The offset from the start of the file.
245260
"""
261+
246262
__numEntries = 0x00
247263
__entries = 0x04
248264

249265
parent: GroupDataEntry
250-
entries: list['GroupItemEntry']
266+
entries: list["GroupItemEntry"]
251267

252268
def __init__(self, parent: GroupDataEntry, offset: int):
253269
super().__init__(parent, offset)
254270
numEntries = self.read_bytes(self.__numEntries)
255271
self.entries = [
256-
GroupItemEntry(self, self.section_reference(self.__entries + i * self._referenceSize))
272+
GroupItemEntry(
273+
self, self.section_reference(self.__entries + i * self._referenceSize)
274+
)
257275
for i in range(numEntries)
258276
]
259277

@@ -265,6 +283,7 @@ class GroupItemEntry(__BrsarSection):
265283
Each rseqOffset is relative to the group offset.
266284
https://wiki.tockdom.com/wiki/BRSAR_(File_Format)#Group_Item_Info_Entry
267285
"""
286+
268287
_rseqOffset = 0x04
269288
_rseqSize = 0x08
270289

@@ -276,4 +295,3 @@ def __init__(self, parent: GroupItemTable, offset: int):
276295
super().__init__(parent, offset)
277296
self.rseqOffset = self.read_bytes(self._rseqOffset)
278297
self.rseqSize = self.read_bytes(self._rseqSize)
279-

wii_music_editor/editor/editor.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import logging
24

35
from wii_music_editor.data.songs import SongClass, SongType, song_list
@@ -51,19 +53,26 @@ def replace_song(song: SongClass, score_midi: Midi, song_midi: Midi):
5153
dol = MainDol(rom_folder.mainDolPath)
5254
dol.write_song_info(song, score_midi.length, dol.songSegmentLength)
5355
dol.write_song_info(song, score_midi.tempo, dol.songSegmentTempo)
54-
dol.write_song_info(song, score_midi.time_signature, dol.songSegmentTimeSignature, 0x01)
56+
dol.write_song_info(
57+
song, score_midi.time_signature, dol.songSegmentTimeSignature, 0x01
58+
)
5559
dol.save()
5660

5761

5862
def replace_song_text(song: SongClass, name: str, description: str, genre: str):
5963
logging.info(f"Changing text for song: {song.name}")
6064
index = song.mem_order
61-
if (rom_folder.text.songs[index] != name or rom_folder.text.descriptions[index] != description or
62-
rom_folder.text.genres[index] != genre):
65+
if (
66+
rom_folder.text.songs[index] != name
67+
or rom_folder.text.descriptions[index] != description
68+
or rom_folder.text.genres[index] != genre
69+
):
6370
rom_folder.text.change_name(song, [name, description, genre])
6471

6572

66-
def get_original_song(song: SongClass) -> tuple[Midi, Midi, str, str, str, int, int, int]:
73+
def get_original_song(
74+
song: SongClass,
75+
) -> tuple[Midi, Midi, str, str, str, int, int, int]:
6776
# Main Dol
6877
length = 0
6978
tempo = 0
@@ -82,7 +91,7 @@ def get_original_song(song: SongClass) -> tuple[Midi, Midi, str, str, str, int,
8291
rom_folder.textBackup.genres[song.list_order],
8392
length,
8493
tempo,
85-
time_signature
94+
time_signature,
8695
)
8796

8897

@@ -101,5 +110,7 @@ def replace_style_text(style: Style, name: str):
101110
def replace_default_style(song: SongClass, style: Style):
102111
logging.info(f"Changing default style for song '{song.name}' to '{style.name}'")
103112
rom_folder.default_styles[song.list_order] = style.style_id
104-
rom_folder.mainDol.write_song_info(song, style.style_id, rom_folder.mainDol.songSegmentDefaultStyle)
113+
rom_folder.mainDol.write_song_info(
114+
song, style.style_id, rom_folder.mainDol.songSegmentDefaultStyle
115+
)
105116
rom_folder.mainDol.save()

0 commit comments

Comments
 (0)