Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #35 from DDMAL/dev
Browse files Browse the repository at this point in the history
Beta 5
  • Loading branch information
kemalkongar authored May 20, 2021
2 parents be428c6 + 76f541d commit 20ffe2d
Show file tree
Hide file tree
Showing 7 changed files with 383 additions and 33,209 deletions.
2 changes: 1 addition & 1 deletion mei2volpiano/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.6.1'
__version__ = '0.7.0'

from .driver import main
from .mei2volpiano import MEItoVolpiano
3 changes: 0 additions & 3 deletions mei2volpiano/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ def main():

parser.add_argument(
"t",
# default="mei",
# const="mei",
nargs="?",
choices=["txt", "mei"],
help="Choice indicating whether the inputs will be mei or txt files",
)
Expand Down
47 changes: 31 additions & 16 deletions mei2volpiano/mei2volpiano.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,11 @@ def Wsylb_volpiano_map(self, elements: list) -> dict:
"""
syl_note = {"dummy": ""}
dbase_bias = 0
octave_converter_weight = 2 #C4 in CWMN is octave 2 in volpiano
octave_converter_weight = 2 # C4 in CWMN is octave 2 in volpiano
invalid_notes = []
invalid_notes = set(invalid_notes)
last = "dummy"
syl_note["invalid"] = ""
num = True
for element in elements:
if element.tag == f"{NAMESPACE}syl":
Expand All @@ -224,7 +227,14 @@ def Wsylb_volpiano_map(self, elements: list) -> dict:
ocv = int(ocv) - octave_converter_weight
ocv = f"{ocv}"
volpiano = self.get_volpiano(note, ocv)
syl_note[last] = f"{syl_note[last]}{volpiano}"
if volpiano == "pname error":
invalid_notes.add(note)
else:
syl_note[last] = f"{syl_note[last]}{volpiano}"
if invalid_notes:
for val in invalid_notes:
invalid = "invalid"
syl_note["invalid"] = f"{syl_note[invalid]} {val}"
return syl_note

def get_syl_key(self, element: object, bias: int) -> str:
Expand Down Expand Up @@ -270,17 +280,13 @@ def get_volpiano(self, note: str, ocv: str) -> str:
"4": {"c": "r", "d": "s"},
}

oct_error = "OCTAVE_RANGE_ERROR"
note_error = "NOTE_NOT_IN_OCTAVE"
error = "pname error"

for key in octs:
if key == ocv:
if note in octs[key]:
return octs[key][note]
else:
return note_error

return oct_error
return error

def export_volpiano(self, mapping_dictionary: dict) -> str:
"""Creates volpiano string with clef attached.
Expand All @@ -292,18 +298,27 @@ def export_volpiano(self, mapping_dictionary: dict) -> str:
Returns:
(str): Final, valid volpiano with the clef attached in a single line.
"""
values = list(mapping_dictionary.values())[1::]
clef = "1---"
vol_string = "".join(values)
starting_index = 1
floating_notes = mapping_dictionary["dummy"]
invalid_notes = ''
if "invalid" in mapping_dictionary:
starting_index = 2
invalid_notes = mapping_dictionary["invalid"]
floating_string = ""
invalid_string = ""
values = list(mapping_dictionary.values())[starting_index::]
vol_string = "".join(values)
if len(invalid_notes) == 1:
invalid_string = f"\n\nWe found an invalid note (pname) inside the MEI file: {invalid_notes.lstrip()}"
if len(invalid_notes) > 1:
invalid_string = f"\n\nWe found numerous invalid notes (pnames) inside the MEI file: {invalid_notes.lstrip()}"
if len(floating_notes) == 1:
notes = f"We found one syllable-independent note at the end of the MEI file: {floating_notes}"
return f"{clef}{vol_string} \n\n{notes}"
floating_string = f"\n\nWe found one syllable-independent note at the end of the MEI file: {floating_notes}"
elif len(floating_notes) > 1:
notes = f"We found numerous syllable-independent notes at the end of the MEI file: {floating_notes}"
return f"{clef}{vol_string} \n\n{notes}"
else:
return f"{clef}{vol_string}"
floating_string = f"\n\nWe found numerous syllable-independent notes at the end of the MEI file: {floating_notes}"

return f"{clef}{vol_string}{invalid_string}{floating_string}"

def convert_mei_volpiano(self, filename: str) -> str:
"""All-in-one method for converting MEI file to valid volpiano string.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "MEI2Volpiano"
version = "0.6.1"
version = "0.7.0"
description = ""
authors = ["DDMAL"]

Expand Down
Loading

0 comments on commit 20ffe2d

Please sign in to comment.