Strategies for storing music21 data
mastermusic21 does not have a single native data format; it is designed to manipulate existing data. Depending on your needs, use the following strategies for storage:
- Recreatable data: Store the script used to generate the data and rerun it.
- Music notation: Use MusicXML for high-fidelity notation, or MIDI / Lilypond->PNG for audio or graphics.
- Non-recreatable data (Short-term): Use Python's
picklemodule. To ensure maximum preservation of the object structure, uses.freeze()before pickling ands.thaw()after loading. For more complex needs, uses.setupSerializationScaffold()beforepickle.dump()ands.teardownSerializationScaffold()afterpickle.load(). - Non-recreatable data (Long-term/Sharing): Save relevant parts in XML, JSON, or CSV. While music21 has partial support for JSON storage of Streams, it is not complete.