Skip to content

Commit

Permalink
Merge pull request #1592 from cuthbertLab/file_widget
Browse files Browse the repository at this point in the history
Jupyter: Lab compatibility & Display all pages, refactor MuseScore
  • Loading branch information
mscuthbert authored Jun 4, 2023
2 parents 048a384 + 3b6a927 commit 58f5495
Show file tree
Hide file tree
Showing 22 changed files with 1,864 additions and 494 deletions.
85 changes: 31 additions & 54 deletions documentation/source/developerReference/devTest_timespans.ipynb

Large diffs are not rendered by default.

997 changes: 997 additions & 0 deletions documentation/source/developerReference/devTest_widgets.ipynb

Large diffs are not rendered by default.

125 changes: 125 additions & 0 deletions documentation/source/developerReference/ipython_show_tests.ipynb

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions documentation/source/developerReference/startingOver.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"\n",
"6. Keep the core of the toolkit small and encourage an ecosystem of other add-ons.\n",
"\n",
"7. Don't try to encode every exception to standard music that your musicologist brain can conceive of. Put those in the `.editorial` or other special purpose attribute. \n",
"7. Don't try to encode every exception to standard music that your musicologist brain can conceive of. Put those in the `.editorial` or other special purpose attribute.\n",
"\n",
"8. Make every pitch have an accidental. The difference between Accidental('natural') and None has raised more problems than its worth. (added June 2023)\n",
"\n",
"There will be more here as I think of it. -- Michael Scott Asato Cuthbert, 2022 October."
]
Expand All @@ -47,7 +49,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
}
],
"source": [
"converter.Converter().subconvertersList('input')"
"converter.Converter().subConvertersList('input')"
]
},
{
Expand Down Expand Up @@ -293,7 +293,7 @@
}
],
"source": [
"converter.Converter().subconvertersList('output')"
"converter.Converter().subConvertersList('output')"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we tell the converter module that our subconverter exists and can handle 'singlebeat'/'singleBeat'/'.sb' files. "
"Next we tell the converter module that our subConverter exists and can handle 'singlebeat'/'singleBeat'/'.sb' files. "
]
},
{
Expand All @@ -71,7 +71,7 @@
"metadata": {},
"outputs": [],
"source": [
"converter.registerSubconverter(SingleBeat)"
"converter.registerSubConverter(SingleBeat)"
]
},
{
Expand Down Expand Up @@ -286,7 +286,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We can cleanup what we've done (always be a good citizen) by calling `converter.resetSubconverters`."
"We can cleanup what we've done (always be a good citizen) by calling `converter.resetSubConverters`."
]
},
{
Expand All @@ -295,7 +295,7 @@
"metadata": {},
"outputs": [],
"source": [
"converter.resetSubconverters()"
"converter.resetSubConverters()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion music21/alpha/analysis/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def calculateChangesList(self):
def showChanges(self, show=False):
'''
Visual and debugging feature to display which notes are changed.
Will open in musescore, unless show is set to False
Will open in MuseScore, unless show is set to False
'''
for (idx, (midiNoteRef, omrNoteRef, change)) in enumerate(self.changes):
if change == ChangeOps.NoChange:
Expand Down
3 changes: 3 additions & 0 deletions music21/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ def __eq__(self, other: object):


# -----------------------------------------------------------------------------
# these are two sentinel objects that are returned when getattr(self, attr) or
# getattr(other, attr) fail, that ensure that the two failed attributes will
# never equal each other.
_EQUALITY_SENTINEL_SELF = object()
_EQUALITY_SENTINEL_OTHER = object()

Expand Down
21 changes: 21 additions & 0 deletions music21/common/fileTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pathlib
import pickle
import os
import subprocess
import typing as t

from music21.exceptions21 import Music21Exception
Expand All @@ -31,6 +32,7 @@
'cd',
'preparePathClassesForUnpickling',
'restorePathClassesAfterUnpickling',
'runSubprocessCapturingStderr',
]


Expand Down Expand Up @@ -150,6 +152,25 @@ def restorePathClassesAfterUnpickling():
pathlib.WindowsPath = _storedPathlibClasses['windowsPath']


def runSubprocessCapturingStderr(subprocessCommand):
'''
Run a subprocess command, capturing stderr and
only show the error if an exception is raised.
'''
completed_process = subprocess.run(subprocessCommand, capture_output=True, check=False)
if completed_process.returncode != 0:
# Raise same exception class as findNumberedPNGPath()
# for backward compatibility
stderr_bytes = completed_process.stderr
try:
import locale
stderr_str = stderr_bytes.decode(locale.getpreferredencoding(do_setlocale=False))
except UnicodeDecodeError:
# not really a str, but best we can do.
stderr_str = stderr_bytes.decode('ascii', errors='ignore')
raise IOError(stderr_str)


# -----------------------------------------------------------------------------
if __name__ == '__main__':
import music21
Expand Down
12 changes: 6 additions & 6 deletions music21/common/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


# used for checking preferences, and for setting environment variables
# TODO: only check top-level. Let subconverters check sub formats.
# TODO: only check top-level. Let subConverters check sub formats.
VALID_SHOW_FORMATS = ['musicxml', 'lilypond', 'text', 'textline', 'midi',
'png', 'pdf', 'svg',
'lily.pdf', 'lily.png', 'lily.svg', 'braille',
Expand Down Expand Up @@ -72,15 +72,15 @@ def findSubConverterForFormat(fmt: str) -> type[SubConverter] | None:
>>> common.findSubConverterForFormat('romantext')
<class 'music21.converter.subConverters.ConverterRomanText'>
Some subconverters have format aliases
Some subConverters have format aliases
>>> common.findSubConverterForFormat('t')
<class 'music21.converter.subConverters.ConverterText'>
'''
fmt = fmt.lower().strip()
from music21 import converter
scl = converter.Converter().subconvertersList()
scl = converter.Converter().subConvertersList()
for sc in scl:
formats = sc.registerFormats
if fmt in formats:
Expand All @@ -99,7 +99,7 @@ def findFormat(fmt):
All but the first element of the tuple are deprecated for use, since
the extension can vary by subconverter (e.g., lily.png)
the extension can vary by subConverter (e.g., lily.png)
>>> common.findFormat('.mxl')
('musicxml', '.musicxml')
Expand Down Expand Up @@ -212,7 +212,7 @@ def findInputExtension(fmt: str) -> tuple[str, ...]:
if sc is None:
# file extension
post: list[str] = []
for sc in converter.Converter().subconvertersList():
for sc in converter.Converter().subConvertersList():
if fmt not in sc.registerInputExtensions:
continue
for ext in sc.registerInputExtensions:
Expand Down Expand Up @@ -333,7 +333,7 @@ def findFormatExtURL(url):
elif 'format=stage2' in url or 'format=stage1' in url:
ext = '.md'
else: # check for file that ends in all known input extensions
for sc in converter.Converter().subconvertersList():
for sc in converter.Converter().subConvertersList():
inputTypes = sc.registerInputExtensions
for extSample in inputTypes:
if url.endswith('.' + extSample):
Expand Down
2 changes: 1 addition & 1 deletion music21/common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __deepcopy__(self, memo):
Does a deepcopy of the state returned by `__reduce_ex__` for protocol 4.
* Changed in v9: callInit is removed, replaced with ignoreAttributes.
uses `__reduce_ex__` and `copy._reconstruct` internally.
uses `__reduce_ex__` internally.
'''
if memo is None:
memo = {}
Expand Down
Loading

0 comments on commit 58f5495

Please sign in to comment.