Skip to content

Commit

Permalink
Map instrument names directly to className and add test (#1215)
Browse files Browse the repository at this point in the history
* Direct to className

NB: Leaving the now mostly redundant bestToClass for ease of diff comparison.

* Italian TamTam

* stromento (alt. to strumento)

* Test that all class names are real

* Integrate bestNameToInstrumentClass into englishToClassName

* Delete redundant bestNameToInstrumentClass

* ... fully

* Lint

* subTest

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
  • Loading branch information
MarkGotham and jacobtylerwalls authored Mar 3, 2022
1 parent ed165c2 commit db9fcb7
Show file tree
Hide file tree
Showing 2 changed files with 983 additions and 1,085 deletions.
8 changes: 2 additions & 6 deletions music21/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,7 @@ def fromString(instrumentString):

instrumentStringOrig = instrumentString
instrumentString = instrumentString.replace('.', ' ') # sic, before removePunctuation
instrumentString = instrumentString.lower() # previously run on each substring separately
instrumentString = common.removePunctuation(instrumentString)
allCombinations = _combinations(instrumentString)
# First task: Find the best instrument.
Expand All @@ -2397,13 +2398,8 @@ def fromString(instrumentString):

this_module = importlib.import_module('music21.instrument')
for substring in allCombinations:
substring = substring.lower()
try:
if substring in instrumentLookup.bestNameToInstrumentClass:
englishName = substring
else:
englishName = instrumentLookup.allToBestName[substring]
className = instrumentLookup.bestNameToInstrumentClass[englishName]
className = instrumentLookup.allToClassName[substring]
thisInstClass = getattr(this_module, className)
# In case users have overridden the module and imported more things
if base.Music21Object not in thisInstClass.__mro__: # pragma: no cover
Expand Down
Loading

0 comments on commit db9fcb7

Please sign in to comment.