musif.cache.utils module

class musif.cache.utils.FileCacheIntoRAM(capacity: int)[source]

Bases: object

This class simply stores a dictionary of key-value. In musiF, it is used to cache the objects (values) coming from the parsing of files (whose names are the keys). It is never written to disk and only kept into RAM.

clear() None[source]
property full: bool
get(key: str) Optional[Any][source]
put(key: str, value: Any)[source]
musif.cache.utils.hasattr(obj1, attr)[source]

Check if obj1 has attr. This function grants that SmartModuleCache objects are checked against their cache or reference objects.

musif.cache.utils.iscache(obj1)[source]

Check if obj1 is a SmartModuleCache or a MethodCache object

musif.cache.utils.isinstance(obj1, cls)[source]

Check if obj1 is instance of cls. This function grants that SmartModuleCache objects are checked against their reference objects.

musif.cache.utils.load_score_df(fname)[source]

Loads a score object saved with store_score_df from a string or Path pointing to the file or from a file-like object. Return a dictionary of dataframes

musif.cache.utils.store_score_df(score, fname)[source]

Stores score into fname (a file-like object, a string or a Path object) using dataframes and returns the object saved.

The returned object is a dictionary with keys the name of the parts and values dataframes with the following columns:

  • “Type”: A string identifying the type of object. Possible values: "Note",

"Rest", "Measure", "Time Signature" * “Name”: A string with the name of the note in Common Western Notation or with the time signature string for time signatures; for measures and rests, the value "-" is used. * “Value”: The midi pitch for notes, -1 for others * “Measure Onset”: The beat position of the object in reference to the beginning of the measure, -1 for measures * “Part Onset”: The onset position of the object in reference to the beginning of the part * “Duration”: The duration of the object, -1 for time signatures * “Tie”: If a tie is applied to the note, its type is there (one of "start", "continue", "stop"), otherwise "-" is used

musif.cache.utils.wrap_module_objects(obj: Any, target_addresses: List[str] = ['music21'], resurrect_reference: Optional[Tuple] = None, parent: Optional[ObjectReference] = None, name: Tuple[str] = ('',), args: Tuple[Optional[Tuple]] = (None,))[source]

Returns the object wrapped with SmartModuleCache class if it was defined in one of the target_addresses

If obj is a list or a tuple, e new list/tuple this function works recursively on their objects.