Adding checks if music21 is installed
Music21 is optional dependency
This commit is contained in:
@ -1,10 +1,18 @@
|
||||
"""Collection of converters"""
|
||||
from music21 import converter, note, stream, meter, chord, environment
|
||||
from ziffers import zparse, Ziffers, Pitch, Rest, Chord
|
||||
|
||||
try:
|
||||
from music21 import converter, note, stream, meter, chord, environment
|
||||
music21_imported: bool = True
|
||||
except ImportError:
|
||||
music21_imported: bool = False
|
||||
|
||||
def to_music21(expression: str | Ziffers, **options):
|
||||
"""Helper for passing options to the parser"""
|
||||
|
||||
if not music21_imported:
|
||||
raise ImportError("Install Music21 library")
|
||||
|
||||
converter.registerSubconverter(ZiffersMusic21)
|
||||
|
||||
if isinstance(expression, Ziffers):
|
||||
@ -32,6 +40,9 @@ def set_musescore_path(path: str):
|
||||
settings["musescoreDirectPNGPath"] = path
|
||||
|
||||
|
||||
if music21_imported:
|
||||
|
||||
# pylint: disable=locally-disabled, invalid-name, unused-argument, attribute-defined-outside-init
|
||||
class ZiffersMusic21(converter.subConverters.SubConverter):
|
||||
"""Ziffers converter to Music21"""
|
||||
|
||||
@ -68,4 +79,5 @@ class ZiffersMusic21(converter.subConverters.SubConverter):
|
||||
m_item = chord.Chord(item.notes)
|
||||
m_item.duration.quarterLength = item.duration * 4
|
||||
note_stream.append(m_item)
|
||||
# TODO: Is this ok?
|
||||
self.stream = note_stream.makeMeasures()
|
||||
Reference in New Issue
Block a user