Skip to content

Commit

Permalink
Add specified key signature support (#11)
Browse files Browse the repository at this point in the history
* add ability for user to specify a key signature + adjust notes accordingly, finally use argparse for converter script

* add another test file

* simplify some logic

* adding some adjustments to account for some more potential flat notes + some more tests to check expected xml output and key signature notes

* support F-sharp and C-sharp key signatures + allow user to pass a minor key for determining key signature

* Define key signatures without overwriting the --key command-line option (#9)

* Define key signatures without overwriting the --key command-line option

* Add self.minor attribute to class

* Add self.opts attribute to class

* Replace check_notes with self.opts.check

* Add --master command-line option

* Add --title command-line option

* Add --instruments command-line option

* Add some build-in instrument names

* key signature support (new strategy) (#10)

* trying a new strategy for finding the right notes to use

* fill in some more enharmonics to satisfy some minor scales

* finish supporting some other melodic minor scales

* fix gitignore and add more test files

* move some note-finding logic to the notefinder instead of in the converter

* some fixes and improvements + more tests

---------

Co-authored-by: nicolai-rostov <[email protected]>
  • Loading branch information
syncopika and nicolai-rostov authored Jul 13, 2024
1 parent 4c29af5 commit a19c82a
Show file tree
Hide file tree
Showing 65 changed files with 7,137 additions and 76 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__pycache__/
.pytest_cache/
.pytest_cache/
/*.xml
/*.mmp
55 changes: 48 additions & 7 deletions convert-mmp.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
from mmp_to_musicxml.converter import MMP_MusicXML_Converter

import sys
import argparse

if __name__ == "__main__":

# allow user to pick a minor key for key signature
# thanks to @nicolai-rostov - https://github.com/syncopika/mmp-to-MusicXML/issues/7#issuecomment-2212604213
minor_to_major_map = {
"abm": "cb",
"ebm": "gb",
"bbm": "db",
"fm": "ab",
"cm": "eb",
"gm": "bb",
"dm": "f",
"am": "c",
"em": "g",
"bm": "d",
"fsm": "a",
"csm": "e",
"gsm": "b",
"dsm": "fs",
"asm": "cs",
}

parser = argparse.ArgumentParser(
prog='MMP to MusicXML',
description='Helps convert LMMS .mmp files to MusicXML')

parser.add_argument('filename')
parser.add_argument('-c', '--check', help='Check if any instrument notes fall out of the expected range (if applicable).', default=False, action='store_true') # check notes if any instrument notes fall out of expected range
parser.add_argument('-k', '--key', help=f'Specify the key signature for the piece. Options are: c (default), g, d, a, e, b, f, bb, eb, ab, db, gb, cb, fs, cs. You can also pass in a minor key: {", ".join(minor_to_major_map.keys())}.', default=None) # specify key signature for piece (default is key of C Major)
parser.add_argument('-m', '--master', metavar='i', help='Set master pitch')
parser.add_argument('-t', '--title', metavar='str', help='Set piece title')
parser.add_argument('-i', '--instruments', metavar='str', help='Select instrument tracks using the plus sign (+) as list separator: violin+cello')

args = parser.parse_args()

if args.key in minor_to_major_map:
minor = args.key
major = minor_to_major_map[minor]
else:
major = args.key
minor = None

# check notes of each instrument (if applicable) to catch any out-of-normal-range notes
converter = MMP_MusicXML_Converter(check_notes=True)
converter = MMP_MusicXML_Converter(key_signature=major,
params =
{
'opts': args,
'minor': minor,
})

file = 'testfiles/080415pianobgm3popver.mmp'
if len(sys.argv) > 1:
file = sys.argv[1]

converter.convert_file(file)
converter.convert_file(args.filename)
Loading

0 comments on commit a19c82a

Please sign in to comment.