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 #31 from DDMAL/dev
Browse files Browse the repository at this point in the history
Version 0.6.0
  • Loading branch information
kemalkongar authored May 20, 2021
2 parents 7c9a572 + 3fc0046 commit 8d3cc4c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 47 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,41 @@ 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:

- Every neume is encoded as a quarter note
- 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: `<syl>`. The notes themselves are located with the `<note>` tag and represented by the `pname` attribute.

### Mutiple MEI File Runs

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.

Expand All @@ -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.

Expand Down
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.5.0'
__version__ = '0.6.0'

from .driver import main
from .mei2volpiano import MEItoVolpiano
54 changes: 18 additions & 36 deletions mei2volpiano/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
)

Expand All @@ -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":
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions mei2volpiano/mei2volpiano.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}"
Expand Down Expand Up @@ -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.
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.5.0"
version = "0.6.0"
description = ""
authors = ["DDMAL"]

Expand Down

0 comments on commit 8d3cc4c

Please sign in to comment.