Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
- Imports: standard library first, then music21 modules, one per line, alphabetical.
- New modules open with the `# Name: / # Purpose: / # Authors: / # Copyright: / # License:`
banner (copy a neighboring module's), then the module docstring, then imports. Update the Copyright date end to current year when changing the module.
When a file is edited only incidentally, as one of many touched by a sweep, leave its
Copyright alone; bump only the files the change is really about.
- No `print()`. Use `environLocal = environment.Environment('moduleName')` and
`environLocal.printDebug(...)`, or `environLocal.warn(...)` when the user should hear
about it every time. `test/toggleDebug.py` switches debug output on and off.
Expand Down
9 changes: 4 additions & 5 deletions music21/abcFormat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3935,8 +3935,7 @@ def testBow(self):

def testAcc(self):
from music21.abcFormat import testFiles
from music21 import abcFormat
ah = abcFormat.ABCHandler()
ah = ABCHandler()
ah.process(testFiles.accTest)
# noinspection SpellCheckingInspection
tokensCorrect = '''<music21.abcFormat.ABCMetadata 'X: 979'>
Expand Down Expand Up @@ -4035,11 +4034,11 @@ def testAcc(self):
j = 0
k = 0
for token in tokens:
if isinstance(token, abcFormat.ABCAccent):
if isinstance(token, ABCAccent):
i += 1
elif isinstance(token, abcFormat.ABCStraccent):
elif isinstance(token, ABCStraccent):
j += 1
elif isinstance(token, abcFormat.ABCTenuto):
elif isinstance(token, ABCTenuto):
k += 1
self.assertEqual(i, 2)
self.assertEqual(j, 2)
Expand Down
2 changes: 0 additions & 2 deletions music21/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ def testSortOrder(self):
def testFreezeThaw(self):
from music21 import converter
from music21 import stream
# pylint: disable=redefined-outer-name
from music21.bar import Barline # avoid not same class error

b = Barline()
self.assertNotIn('StyleMixin', b.classes)
Expand Down
14 changes: 5 additions & 9 deletions music21/clef.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Christopher Ariza
# Michael Bodenbach
#
# Copyright: Copyright © 2009-2024 Michael Scott Asato Cuthbert
# Copyright: Copyright © 2009-2026 Michael Scott Asato Cuthbert
# License: BSD, see license.txt
# ------------------------------------------------------------------------------
'''
Expand Down Expand Up @@ -824,16 +824,12 @@ def clefFromString(clefString, octaveShift=0) -> Clef:
else:
lineNum = False
elif len(xnStr) > 2:
from music21 import clef as myself
xnLower = xnStr.lower()
for x in dir(myself):
if 'Clef' not in x:
for className, classObj in globals().items():
if not isinstance(classObj, type) or not issubclass(classObj, Clef):
continue
if xnLower != x.lower() and xnLower + 'clef' != x.lower():
continue
objType = getattr(myself, x)
if isinstance(objType, type):
return objType()
if className.lower() in (xnLower, xnLower + 'clef'):
return classObj()

raise ClefException('Could not find clef ' + xnStr)
else:
Expand Down
3 changes: 0 additions & 3 deletions music21/common/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,8 @@ def _countUnpacked(i: int, filename: str) -> bool:


class Test(unittest.TestCase):
# pylint: disable=redefined-outer-name
def x_figure_out_segfault_testMultiprocess(self) -> None:
files = ['bach/bwv66.6', 'schoenberg/opus19', 'AcaciaReel']
# for importing into testSingleCoreAll we need the full path to the modules
from music21.common.parallel import _countN, _countUnpacked
output = runParallel(files, _countN)
self.assertEqual(output, [165, 50, 131])
runParallel(files,
Expand Down
18 changes: 7 additions & 11 deletions music21/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ def _rawQueryPrepareHeader(self, msg=''):
'''
Prepare the header, given a string.

>>> from music21 import configure
>>> d = configure.Dialog()
>>> d._rawQueryPrepareHeader('test')
'test'
Expand Down Expand Up @@ -1545,9 +1544,8 @@ def testConfigurationAssistant(self):
class Test(unittest.TestCase):

def testYesOrNo(self):
from music21 import configure
d = configure.YesOrNo(default=True, tryAgain=False,
promptHeader='Are you ready to continue?')
d = YesOrNo(default=True, tryAgain=False,
promptHeader='Are you ready to continue?')
d.askUser('n')
self.assertEqual(str(d.getResult()), 'False')
d.askUser('y')
Expand All @@ -1557,8 +1555,8 @@ def testYesOrNo(self):
d.askUser('blah') # gets default
self.assertEqual(str(d.getResult()), '<music21.configure.IncompleteInput: blah>')

d = configure.YesOrNo(default=None, tryAgain=False,
promptHeader='Are you ready to continue?')
d = YesOrNo(default=None, tryAgain=False,
promptHeader='Are you ready to continue?')
d.askUser('n')
self.assertEqual(str(d.getResult()), 'False')
d.askUser('y')
Expand All @@ -1569,13 +1567,11 @@ def testYesOrNo(self):
self.assertEqual(str(d.getResult()), '<music21.configure.IncompleteInput: blah>')

def testSelectFromList(self):
from music21 import configure
d = configure.SelectFromList(default=1)
d = SelectFromList(default=1)
self.assertEqual(d._default, 1)

def testSelectMusicXMLReaders(self):
from music21 import configure
d = configure.SelectMusicXMLReader()
d = SelectMusicXMLReader()
# force request to user by returning no valid results

def getValidResults(force=None):
Expand All @@ -1585,7 +1581,7 @@ def getValidResults(force=None):
d.askUser(force='n', skipIntro=True) # reject option to open in a browser
post = d.getResult()
# returns a bad condition b/c there are no options and user entered 'n'
self.assertIsInstance(post, configure.BadConditions)
self.assertIsInstance(post, BadConditions)

def testMuseScoreNameRe(self):
'''
Expand Down
6 changes: 2 additions & 4 deletions music21/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3915,16 +3915,14 @@ def testAugmentOrDiminish(self):
"DurationTuple(type='16th', dots=0, quarterLength=0.25)")

def testUnlinkedTypeA(self):
from music21 import duration

du = duration.Duration()
du = Duration()
du.linked = False
du.quarterLength = 5.0
du.type = 'quarter'
self.assertEqual(du.quarterLength, 5.0)
self.assertEqual(du.type, 'quarter')

d = duration.Duration()
d = Duration()
self.assertTrue(d.linked) # note set
d.linked = False
d.type = 'quarter'
Expand Down
5 changes: 2 additions & 3 deletions music21/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,12 @@ def testBasic(self):

def testCorpusDynamicsWedge(self):
from music21 import corpus
from music21 import dynamics

a = corpus.parse('opus41no1/movement2') # has dynamics!
b = a.parts[0].flatten().getElementsByClass(dynamics.Dynamic)
b = a.parts[0].flatten().getElementsByClass(Dynamic)
self.assertEqual(len(b), 35)

b = a.parts[0].flatten().getElementsByClass(dynamics.DynamicWedge)
b = a.parts[0].flatten().getElementsByClass(DynamicWedge)
self.assertEqual(len(b), 2)

def testMusicxmlOutput(self):
Expand Down
21 changes: 8 additions & 13 deletions music21/freezeThaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,6 @@ def testFreezeThawCorpusFileWithSpanners(self):
self.assertEqual(len(s.parts[0].measure(7).notes), 6)

def x_testSimplePickle(self):
from music21 import freezeThaw
from music21 import corpus

c = corpus.parse('bwv66.6').parts[0].measure(0).notes
Expand All @@ -1061,7 +1060,7 @@ def x_testSimplePickle(self):

n1 = c[0]
n2 = c[1]
sf = freezeThaw.StreamFreezer(c, fastButUnsafe=True)
sf = StreamFreezer(c, fastButUnsafe=True)
sf.setupSerializationScaffold()
for dummy in n1.sites.siteDict:
pass
Expand All @@ -1088,17 +1087,16 @@ def x_testSimplePickle(self):
# s.show('t')

def x_testFreezeThawPickle(self):
from music21 import freezeThaw
from music21 import corpus

c = corpus.parse('luca/gloria')
# c.show('t')

sf = freezeThaw.StreamFreezer(c, fastButUnsafe=True)
sf = StreamFreezer(c, fastButUnsafe=True)
d = sf.writeStr()
# print(d)

st = freezeThaw.StreamThawer()
st = StreamThawer()
st.openStr(d)
s = st.stream

Expand All @@ -1107,7 +1105,6 @@ def x_testFreezeThawPickle(self):
pass

def testFreezeThawSimpleVariant(self):
from music21 import freezeThaw
from music21 import stream
from music21 import note

Expand All @@ -1126,15 +1123,14 @@ def testFreezeThawSimpleVariant(self):

s.insert(0, v)

sf = freezeThaw.StreamFreezer(s)
sf = StreamFreezer(s)
d = sf.writeStr()

st = freezeThaw.StreamThawer()
st = StreamThawer()
st.openStr(d)
s = st.stream

def testFreezeThawVariant(self):
from music21 import freezeThaw
from music21 import corpus
from music21 import stream
from music21 import note
Expand All @@ -1156,14 +1152,14 @@ def testFreezeThawVariant(self):
# test Variant is in stream
unused_v1 = c.parts.first().getElementsByClass(variant.Variant).first()

sf = freezeThaw.StreamFreezer(c, fastButUnsafe=True)
sf = StreamFreezer(c, fastButUnsafe=True)
# sf.v = v
d = sf.writeStr()
# print(d)

# print('thawing.')

st = freezeThaw.StreamThawer()
st = StreamThawer()
st.openStr(d)
s = st.stream
# s.show('lily.pdf')
Expand All @@ -1176,7 +1172,6 @@ def testFreezeThawVariant(self):
def testSerializationScaffoldA(self):
from music21 import note
from music21 import stream
from music21 import freezeThaw

n1 = note.Note()

Expand All @@ -1186,7 +1181,7 @@ def testSerializationScaffoldA(self):
s1.append(n1)
s2.append(n1)

sf = freezeThaw.StreamFreezer(s2, fastButUnsafe=False)
sf = StreamFreezer(s2, fastButUnsafe=False)
sf.setupSerializationScaffold()

# test safety
Expand Down
Loading
Loading