├── LICENSE ├── .gitignore ├── README.md └── mscorepluginconverter.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Dmitri Ovodok 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mscorepluginconverter 2 | Simple converter of MuseScore 2 plugins to MuseScore 3 3 | 4 | The [MuseScore 3 plugin 5 | API](https://musescore.org/en/handbook/developers-handbook/plugins-3x) has a 6 | number of changes from that of MuseScore 2. Most of the changes are not very 7 | large though, so it is possible to resolve them with simple textual replacements 8 | (import statements, properties names/namespaces etc.) This repository contains a 9 | simple script automating such changes and thus allowing simple porting of 10 | MuseScore 2 plugins to MuseScore 3 in most cases. 11 | 12 | ## Usage 13 | Simply run 14 | ``` 15 | ./mscorepluginconverter.py plugin.qml plugin_converted.qml 16 | ``` 17 | where `plugin.qml` is the name of the MuseScore 2 plugin to convert, 18 | `plugin_converted.qml` is the name for the converted `.qml` file that should be 19 | (probably) usable with MuseScore 3. 20 | 21 | On Windows, you will need to install Python first and run the script with it: 22 | ``` 23 | python3.exe mscorepluginconverter.py plugin.qml plugin_converted.qml 24 | ``` 25 | 26 | ## On elements placement conversion 27 | In order to place the added elements, MuseScore 2 plugins often used assigning 28 | `pos.x` and `pos.y` element properties. Due to an introduction of the [automatic 29 | placement](https://musescore.org/en/handbook/3/automatic-placement) in MuseScore 30 | 3, it is no longer possible to specify exact element position. At least the 31 | following options are available here: 32 | 1. Remove `pos.x` and `pos.y` assignments letting the automatic placement do its 33 | job 34 | 2. Use `offsetX` and `offsetY` instead to specify position offsets (used by this 35 | converter) 36 | 3. Use `placement` property in case it was intended to specify the element 37 | placement above or below the staff: 38 | ```el.placement = Placement.BELOW``` 39 | 40 | This converter uses the option 2 but you may need to reconsider such cases 41 | manually in case setting position offsets does not match what is needed in a 42 | certain plugin's context. 43 | -------------------------------------------------------------------------------- /mscorepluginconverter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import argparse 5 | 6 | def get_line_ending(line): 7 | end = '\n' 8 | if line.endswith('\r\n'): 9 | end = '\r\n' 10 | return end 11 | 12 | def replace_imports(line): 13 | tokens = line.strip().split() 14 | if len(tokens) < 3: 15 | return line 16 | if tokens[0] == "import": 17 | if tokens[1] in ["MuseScore", "FileIO"] and tokens[2] == "1.0": 18 | tokens[2] = "3.0" 19 | return ' '.join(tokens) + get_line_ending(line) 20 | return line 21 | 22 | def replace_props(line): 23 | replacement_list = { 24 | ".pos.x ": ".offsetX ", 25 | ".pos.x=": ".offsetX=", 26 | ".pos.y ": ".offsetY ", 27 | ".pos.y=": ".offsetY=", 28 | ".setSig(": ".timesig = fraction(", 29 | } 30 | for orig, target in replacement_list.items(): 31 | line = line.replace(orig, target) 32 | return line 33 | 34 | def replace_enums(line): 35 | val_replace = [ 36 | { "orig": "Element", "target": "Placement", "values": ["ABOVE", "BELOW"] }, 37 | { "orig": "MScore", "target": "Direction", "values": ["UP", "DOWN"] }, 38 | { "orig": "MScore", "target": "DirectionH", "values": ["LEFT", "RIGHT"] }, 39 | { "orig": "MScore", "target": "OrnamentStyle", "values": ["DEFAULT", "BAROQUE"] }, 40 | { "orig": "MScore", "target": "GlissandoStyle", "values": ["CHROMATIC", "WHITE_KEYS", "BLACK_KEYS", "DIATONIC"] }, 41 | { "orig": "NoteHead", "target": "NoteHeadType", "values": ["HEAD_AUTO", "HEAD_WHOLE", "HEAD_HALF", "HEAD_QUARTER", "HEAD_BREVIS", "HEAD_TYPES"] }, 42 | { "orig": "Note", "target": "NoteValueType", "values": ["OFFSET_VAL", "USER_VAL"] }, 43 | ] 44 | # applied after val_replace 45 | any_replace = [ 46 | { "orig": "TextStyleType", "target": "Tid" }, 47 | { "orig": "NoteHead", "target": "NoteHeadGroup" }, 48 | ] 49 | ambiguous = ["MScore.AUTO"] 50 | 51 | def replace_enum_val(line, orig_name, target_name, val=""): 52 | orig_str = orig_name + '.' + val 53 | target_str = target_name + '.' + val 54 | return line.replace(orig_str, target_str) 55 | 56 | for item in val_replace: 57 | orig = item["orig"] 58 | target = item["target"] 59 | for val in item["values"]: 60 | line = replace_enum_val(line, orig, target, val) 61 | 62 | for item in any_replace: 63 | line = replace_enum_val(line, item["orig"], item["target"]) 64 | 65 | for s in ambiguous: 66 | if s in line: 67 | print("Ambiguous replacement:", s) 68 | 69 | return line 70 | 71 | if __name__ == "__main__": 72 | parser = argparse.ArgumentParser(description="Converts MuseScore 2 plugins for usage with MuseScore 3") 73 | parser.add_argument("source", help="Source plugin .qml file") 74 | parser.add_argument("destination", help="Destination .qml file") 75 | 76 | args = parser.parse_args() 77 | 78 | with open(args.source, newline='') as src: 79 | script = list(src) 80 | 81 | if not script: 82 | print("Empty script") 83 | sys.exit(1) 84 | 85 | script = map(replace_imports, script) 86 | script = map(replace_props, script) 87 | script = map(replace_enums, script) 88 | 89 | with open(args.destination, 'w') as out: 90 | for line in script: 91 | out.write(line) 92 | --------------------------------------------------------------------------------