import simfile from simfile.timing import TimingData, Beat from simfile.notes import NoteData from simfile.timing.engine import TimingEngine from simfile.notes.timed import time_notes SIMFILE_PATH = "../assets/Xepher/Xepher.sm" def export_timed_notes_plaintext(sm_filename, out_filename=None, chart_index=0): """ Export all timed notes from the specified chart to a plaintext file. Output format: # time(ms) dir note_type 1000 0 1 dir = arrow direction: 0 for left, 1 for down, 2 for up, 3 for right note_type is an enum: https://simfile.readthedocs.io/en/main/autoapi/simfile/notes/index.html#simfile.notes.NoteType """ sim = simfile.open(sm_filename) # If no output filename is provided, default to {title}_{chart_index}.txt if out_filename is None: # Sanitize title for filesystem use safe_title = "".join(c if (c.isalnum() or c in (" ", "_", "-")) else "_" for c in sim.title) safe_title = safe_title.strip().replace(" ", "_") out_filename = f"{safe_title}_{chart_index}.txt" chart = sim.charts[chart_index] timing_data = TimingData(sim) note_data = NoteData(chart) with open(out_filename, "w", encoding="utf-8") as f: f.write("# time(ms) dir note_type\n") for timed_note in time_notes(note_data, timing_data): time_ms = int(round(timed_note.time * 1000)) direction = timed_note.note.column note_type_value = getattr(timed_note.note.note_type, "value", timed_note.note.note_type) f.write(f"{time_ms} {direction} {note_type_value}\n") if __name__ == "__main__": export_timed_notes_plaintext(SIMFILE_PATH)