The official python library dedicated to reading, writing, and modifying the SSPM file format from the video game "Rhythia".
Note: Any version before 0.1.5 does not work in python.
The main library includes these features:
- Reading .SSPM files
- Modifying SSPM data
- Writing .SSPM files
Extras:
- Difficulty Calculation (W.I.P)
- Note Classification (semi-stable)
To install the library, run:
pip install pysspm-rythia
to start using the library, create a python script and load up pysspm.
from pysspm_rhythia import SSPMParser
parser = SSPMParser()
# Example of loading a SSPMfile
parser.ReadSSPM("*.sspm")
# Example of turning it into a roblox sound space file
with open("output.txt", "w") as f:
f.write(parser.NOTES2TEXT())
Functionality does not end there. When reading files, you have full access to all the metadata, and other information stored in the variables.
Some common variables you will find are:
coverBytes
the byteform of the image if cover was foundaudioBytes
the byteform of the audio in.mp3
form if audio was foundHeader
: {"Signature": ..., "Version": ...}Hash
: a SHA-1 hash of the markers (notes) in the mapmapID
: A unique combination using the mappers and map name*mappers
: a list containing each mapper.mapName
: The name given to the map.songName
: The original name of the audio before imported. Usually left as artist name - song namecustomValues
: NOT IMPLEMENTED | will return a dictionary of found custom blocks.isQuantum
: Determins if the level contains ANY float value notes.Notes
: A list of tuples containing all notes. | Example of what it Notes is:[(x, y, ms), (x, y, ms), (x, y, ms) . . .]
from pysspm_rhythia import SSPMParser
parser = SSPMParser()
# Example of loading a SSPMfile
parser.ReadSSPM("*.sspm")
# changing the decal to be a different image
if parser.hasCover[0] == 0: # hasCover is originally in byteform | Can be 0x00 or 0x01
with open("cover.png", 'rb') as f:
parser.coverBytes = f.read() # reading the BYTES of the image
# Finally save the sspm file with the newly configured settings
sspmFileBytes = parser.WriteSSPM()
with open('sspmfile.sspm', "wb") as f:
f.write(sspmFileBytes)
Alternativly, you can pass in arguments into WriteSSPM function directly
from pysspm_rhythia import SSPMParser
parser = SSPMParser()
parser.ReadSSPM("*.sspm")
mappers = parser.Mappers.extend('DigitalDemon') # adding another mapper to the mapper list
parser.WriteSSPM('./SSPMFile.sspm', mappers=mappers)
This shows the more advanced things you can do by giving examples of custom written code.
from pysspm_rhythia import SSPMParser
from random import randint
parser = SSPMParser()
parser.ReadSSPM("*.sspm") # reading the sspm file
sigHeader = parser.Header.get("Signature") # 4 byte header | should always be: b"\x53\x53\x2b\x6d"
ver = parser.Header.get("Version") # stored as 2 or 1
sspmHash = parser.Hash # Storing the hash
if randint(0, 5) == 5:
parser.Notes = parser.Notes.extend((1, 1, (parser.Notes[-1][2]+200))) # adding a center note (1,1), with ms of last note + 200
newSSPM = parser.WriteSSPM(mappers=["DigitalDemon", "Someone else"], mapName="Possibly modified map haha")
# comparing the note hashes
newSSPMHash = parser.Hash
if newSSPMHash == sspmhash:
with open("UnmodifiedMap.sspm", 'wb') as f:
f.write(newSSPM)
else:
raise Warning("Map does not match original hash. Map notes were modified from the original!!!")
Code shows off how hashes are calculated to prevent changes between levels. Could be used for security and integrity of the notes.
More advanced documentation will be added in the near future...
A in-depth list of things you can do with this library
SSPMParser()
Initializes the sspm library parser
def WriteSSPM(self, filename: str = None, debug: bool = False, **kwargs) -> bytearray | None:
Creates a SSPM v2 file based on variables passed in, or already set.
If no filepath is passed in, it will return file as bytes
Note: current version of pysspm-rhythia requires audio as a parameter for v2 filetype
Variables that need to be covered:
coverImage
: Cover image in bytes form, or NoneaudioBytes
: Audio in bytes form, or NoneDifficulty
: one of Difficulties dictionary options, or 0x00 - 05 OR "N/A", "Easy", "Medium", "Hard", "Logic", "Tasukete"mapName
: The name of the map. Rhythia guidelines suggestsartist name - song name
mappers
: a list of strings containing the mapper(s)notes
: a list of tuples as shown below
# (x, y, ms)
self.notes = [
(1, 2, 1685), # X, Y, MS
(1.22521, 0.156781, 2000)
]#...
Notes can sometimes be unordered
**kwargs
: pass in any of the variables shown above.
Example usage:
from pysspm_rhythia import SSPMParser
sspm = SSPMParser()
sspm.ReadSSPM("*.sspm") # reads
sspm.Difficulty = 5 # changes difficulty to Tasukete
with open(output_path+".sspm", "wb") as f:
f.write(sspm.WriteSSPM())
ReadSSPM
def ReadSSPM(self, file: str | BinaryIO, debug: bool = False):
Reads and processes any SSPM file.
File:
Takes in directory of sspm, or BinaryIO object stored in memory.
debug:
Useful for getting readable outputs of steps taken.
SSPM (Sound space plus map file) version 1 is not supported at this time. loading this file may raise errors
coverBytes
if cover was foundaudioBytes
if audio was foundHeader
: {"Signature": ..., "Version": ...}Hash
: a SHA-1 hash of the markers in the mapmapID
: A unique combination using the mappers and map name*mappers
: a list containing each mapper.mapName
: The name given to the map.songName
: The original name of the audio before imported. Usually left as artist name - song namecustomValues
: NOT IMPLEMENTED | will return a dictionary of found custom blocks.isQuantum
: Determins if the level contains ANY float value notes.Notes
: A list of tuples containing all notes.
Example of what it Notes is: [(x, y, ms), (x, y, ms), (x, y, ms) . . .]
Returns itself
TODO: (In order of priority)
- Add typing support for library ✔️
- add proper documentation on github
- add proper documentation in code ✔️
- add loading of sspmV2 ✔️
- add support for creating sspmV2 ✔️
- clean up unused variables from @self ✔️
- add support for sspmv1 loading ✔️ (Thank you fogsaturate)
- support multiple versions of sspm
- add custom block support in loading
- Drop numpy dependency
- Implement Extras difficulty calc
- Implement simple note ordering function
- Support for Pheonix Filetype (When I get my hands on the data structure)
Made with 💖 by DigitalDemon (David Jed)
Documentation last updated:
2024-12-12
|V0.2.2