diff --git a/README.md b/README.md index b3641f4..b95a586 100644 --- a/README.md +++ b/README.md @@ -24,24 +24,24 @@ As long as you're in the python environment, you can execute `mei2volpiano` or t | Flag | Use | | ------------- |:-------------:| | `-W` or `-N` | Used to specify the type of MEI to converted (Neume or CWN) | -| `-t txt` or `-t mei`| Used to specify whether the user is inputtng MEI files or a text file containing MEI paths | +| `txt`| Used to specify whether the user is inputtng MEI files or a text file containing MEI paths | | `--export` | Signifies that the converted Volpiano string(s) should be outputted to '.txt' files | ### Standard Usage (Neume notation) To output the MEI file's volpiano string to the terminal, run -`mei2vol -N -t mei filename1.mei` +`mei2vol -N mei filename1.mei` Multiple files can be passed in at once -`mei2vol -N -t mei filename1.mei filename2.mei` +`mei2vol -N mei filename1.mei filename2.mei` ### Western To convert MEI files written in Common Western Music Notation (CWMN), run -`mei2vol -W -t mei filename1.mei` +`mei2vol -W mei filename1.mei` All of the CWMN files processed by this library (so far) come from [this collection](https://github.com/DDMAL/Andrew-Hughes-Chant/tree/master/file_structure_text_file_MEI_file). Thus, we followed the conventions of those files. Namely: @@ -49,6 +49,8 @@ All of the CWMN files processed by this library (so far) come from [this collect - Stemless notes - Syllables are preceded by their notes - All notes must have syllables after them + * If there are notes that are not followed by a syllable, the script will display a message containing these notes. They will not be recorded in the volpiano + * This can only happen at the end of an MEI file The resulting volpiano string will have multiple notes seperated by two hyphens. This seperation is dictated by the syllables, representented by: ``. The notes themselves are located with the `` tag and represented by the `pname` attribute. @@ -56,7 +58,7 @@ The resulting volpiano string will have multiple notes seperated by two hyphens. To make it easier to pass in multiple MEI files, the `-t` flag can be specified as `txt`: -`mei2vol -t txt filename1.txt` or `mei2vol -t txt filename1.txt filename2.txt ...` +`mei2vol -W txt filename1.txt` or `mei2vol -N txt filename1.txt filename2.txt ...` where the ".txt" file being passed in must hold the name/relative path of the required MEI files on distinct lines. @@ -66,7 +68,7 @@ where the ".txt" file being passed in must hold the name/relative path of the re The `--export` tag can be used on any valid input to the program. Simply tack it on to the end of your command like so -`mei2vol -N -t mei filename1.mei --export` +`mei2vol -N mei filename1.mei --export` and the program will output each mei file's volpiano to a similarly named file as its input. diff --git a/mei2volpiano/__init__.py b/mei2volpiano/__init__.py index d2affb8..9dedb66 100644 --- a/mei2volpiano/__init__.py +++ b/mei2volpiano/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.5.0' +__version__ = '0.6.0' from .driver import main from .mei2volpiano import MEItoVolpiano diff --git a/mei2volpiano/driver.py b/mei2volpiano/driver.py index cdb3827..0f06c00 100644 --- a/mei2volpiano/driver.py +++ b/mei2volpiano/driver.py @@ -13,41 +13,22 @@ def main(): """ This is the command line application MEI2Volpiano - usage: driver.py [-h] (-N | -W) -t [T] [--export] mei [mei ...] + usage: driver.py [-h] (-N | -W) [--export] [{txt,mei}] mei [mei ...] positional arguments: + {txt,mei} Choice indicating whether the inputs will be mei or txt files mei One or multiple MEI, or text file(s) with each relative MEI file/path to be converted per line optional arguments: -h, --help show this help message and exit -N An MEI neume encoded music file representing neume notation -W An MEI western encoded music file representing western notation - -t [T] Flag indicating whether the inputs will be mei or txt files --export flag indicating output to be sent to a .txt file (name corresponding with input mei) """ start = timer() parser = argparse.ArgumentParser() option = parser.add_mutually_exclusive_group(required=True) - # check the validity of file(s) being passed into program - def check_file_validity(fname, valid_ext): - - if isinstance(valid_ext, list): - if fname in valid_ext: - return fname - else: - print(fname) - parser.error( - "Invalid choice for type -t. Please choose from 'mei' or 'txt'" - ) - else: - ext = os.path.splitext(fname)[1][1:] - if ext != valid_ext: - parser.error( - f"Unexpected file type for the specified flag\nInput Type: {ext} \nExpected Type: {valid_ext}" - ) - return fname - # options for either neume or CWN option.add_argument( "-N", @@ -62,17 +43,17 @@ def check_file_validity(fname, valid_ext): ) parser.add_argument( - "-t", + "t", + # default="mei", + # const="mei", nargs="?", - required=True, - type=lambda fname: check_file_validity(fname, ["txt", "mei"]), - help="Flag indicating whether the inputs will be mei or txt files", + choices=["txt", "mei"], + help="Choice indicating whether the inputs will be mei or txt files", ) parser.add_argument( "mei", nargs="+", - # type=lambda fname: check_file_validity(fname, "txt"), help="One or multiple MEI, or text file(s) with each relative MEI file/path to be converted per line", ) @@ -88,12 +69,13 @@ def check_file_validity(fname, valid_ext): f_names = [] # verify each file input matches (no mismatch extensions) - ftype = None - for pos_args in args["mei"]: - if not ftype: - ftype = os.path.splitext(pos_args)[1][1:] - else: - check_file_validity(pos_args, ftype) + for pos_arg in args["mei"]: + cur_type = os.path.splitext(pos_arg)[1][1:] + + if cur_type != args["t"]: + parser.error( + f"Unexpected file type for the specified flag\nInput Type: {cur_type} \nExpected Type: {args['t']}" + ) if args["W"]: if args["t"] == "mei": @@ -125,10 +107,10 @@ def check_file_validity(fname, valid_ext): if args["export"]: for pair in name_vol_pairs: - basename = os.path.basename(pair[0]) - out_name = os.path.splitext(basename)[0] - with open(f"{out_name}.txt", "a") as out: - out.write(out_name + "\n") + # basename = os.path.basename(pair[0]) + # out_name = os.path.splitext(basename)[0] + with open(f"{os.path.splitext(pair[0])[0]}.txt", "w") as out: + out.write(os.path.splitext(pair[0])[0] + "\n") out.write(pair[1]) for pair in name_vol_pairs: diff --git a/mei2volpiano/mei2volpiano.py b/mei2volpiano/mei2volpiano.py index 55da742..83198fc 100644 --- a/mei2volpiano/mei2volpiano.py +++ b/mei2volpiano/mei2volpiano.py @@ -204,6 +204,7 @@ 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 last = "dummy" num = True for element in elements: @@ -220,7 +221,7 @@ def Wsylb_volpiano_map(self, elements: list) -> dict: if element.tag == f"{NAMESPACE}note": note = element.attrib["pname"] ocv = element.attrib["oct"] - ocv = int(ocv) - 2 + ocv = int(ocv) - octave_converter_weight ocv = f"{ocv}" volpiano = self.get_volpiano(note, ocv) syl_note[last] = f"{syl_note[last]}{volpiano}" @@ -291,10 +292,18 @@ 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()) + values = list(mapping_dictionary.values())[1::] clef = "1---" vol_string = "".join(values) - return f"{clef}{vol_string}" + floating_notes = mapping_dictionary["dummy"] + 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}" + 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}" def convert_mei_volpiano(self, filename: str) -> str: """All-in-one method for converting MEI file to valid volpiano string. diff --git a/pyproject.toml b/pyproject.toml index a5dfc96..7130690 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "MEI2Volpiano" -version = "0.5.0" +version = "0.6.0" description = "" authors = ["DDMAL"]