Thursday, December 31, 2020

Music21 v6.5 Released

Happy New Year! I am pleased to announce that the newest Version of music21, version 6.5 has been released. It is nearly completely backwards compatible with other v6 releases and runs on Python 3.6–3.8.  Music21 is an open-source toolkit for computational music theory and musicology, and also used in composition and music production. Download it via pip with:

pip install --upgrade music21

Version 6.5 adds several important new features since the bug-fix version 6.3 (from mid-November 2020) while squashing many bugs and speeding up a number of parts of the system. Many of the contributions were made by members of the open source community, including major contributions by Jacob Tyler Walls (JTW), Mark Gotham (MG), Néstor Nápoles López (NNL), and Paula Muñoz Lago.

Highlights include:

  • PartStaff objects such as a staff of a piano part now export properly back to MusicXML as one part with <staff> tags. Huge work by JTW!
  • RomanText is now a valid output format in addition to input! Save your analyses for later! Thanks Mark Gotham!
  • search/lyrics now finds second and subsequent lyrics (thanks to Paula ML and DIDONE project)
  • Improvements to VI and VII roman numerals in minor (JTW)
  • MIDI tries to import part names from instruments (JTW)
  • MIDI properly reads and writes conductor tracks (JTW)
  • Doc improvements for many places including RomanNumerals, insertIntoNoteOrChord, chordify with GraceNote (MSC)
  • Major speedups for many chord actions including getLeadingTone, isTriad, isMajorTriad, etc. (NNL + MSC w/ JTW)
  • music21 loads or starts up in 1/3 the time as before. (MSC)
  • Opus.write() improvements -- now all filenames of an Opus write call have similar names and only the last filename is returned (JTW)
  • All properties in music21 are readable without raising an exception. This will help inspection/debugging software. (MSC)
  • Staff-type is imported and exported properly to/from musicxml as the .staffType attribute on layout.StaffLayout objects. .staffLines is now settable on all Stream types (not just Parts) as a shortcut to manipulating layout.StaffLayout().staffLines at the start of the Stream. (MSC)
  • roman.RomanNumeral.isNeapolitan() (MG)

Smaller features and bug fixes:

  • midi.realtime.StreamPlayer now allows for non-blocking playing and for stopping at various points. (antran22)
  • If scratch/temp directory is not writable or does not exist, use backup directories (JTW + Tanchihpin0517 )
  • Use subprocess.run() for launching external tools (JTW)
  • Deprecated method Environment.launch() is removed. (JTW)
  • MusicXML reader selection improved, especially on Windows (MSC)
  • Refactor of the musicxml subpackage for smaller files and more expandability (MSC)
  • Default readers set for Unix (Thomas Wilson).
  • RomanNumeral parsing improvements, esp. for chords like V7b5. (MSC)
  • testing is moved to Github Actions for faster responses. Thanks to Travis-CI for years of support (MSC)
  • works on Python 3.9 -- v6 is likely the last version to support py 3.6. (MSC)
  • Instruments outside of voices are retained when making measures (JTW)
  • all tests pass on Windows for windows developers. (JTW)
  • better installation on conda-forge w/ a webcolors change (JTW)
  • unmeasured scores export to MusicXML better (JTW)
  • MIDI instruments no longer get incorrect durations (JTW)
  • MIDI pitch bends are easier to understand (JTW)
  • Improved tuplet brackets when number is not shown (JTW)
  • Coverage improved (MSC + JTW)
  • Better commonName for 0, 1, 2 note chords, and microtonal chords (MSC)
  • .show('scala') works on more scales. (JTW)
  • More XML Chord symbols import (JTW)
  • Fixes for aadd6 and other chord symbols where the name of the note ("A") is also present in the modifier ("Add") (JTW)
  • Chord.quality returns "other" for C C# E G (MG)
  • An empty degree-alter now matches MusicXML spec (JTW)
  • ABC and MIDI parsing cleanups to make it easier for developers to extend (MSC)
  • Very old musicxml files with empty "tie" elements parse better. (JTW)
  • Improved handling of omitted pitches in RomanNumerals (JTW)
  • instrument.deduplicate() removes duplicate instruments at the same offset in a stream (JTW)
  • Repeat endings with no number displayed now export to musicxml properly (JTW)
  • Several routines such as findGaps were leaving Streams in corrupt states -- fixed (MSC)
  • partitionByInstrument() no longer leaves instruments with non-zero durations (MSC)
  • MuseData reading works properly on zip files created on an OS with different line breaks (MSC)

Thanks always to the Seaver Institute, the NEH, and MIT for support on creating music21.

I'm not sure if the next release will be v7 (with some backwards incompatible changes) or another v6 release (6.7). I do know that better piano support and percussion support are high on my lists. However, I'll be taking a bit of a break from music21 over January at least in order to get other publications out and work with my other projects. Happily, the community engagement with music21 has never been stronger and I'll still be here reviewing Pull Requests and thinking about the next steps!

-- Myke Cuthbert

Wednesday, November 18, 2020

Music21 v6.3 released

 Music21 version 6.3 has been released. Biggest new feature is compatibility with macOS 11.0 Big Sur, whose numbering system change broke music21. Major bug of corpus.search() on Windows not working should be fixed also. Chordify users get a nice upgrade also.

Update with

pip install --upgrade music21

This is primarily a bug fix release, so let's list the major bugs squashed first:

Bug fixes

  • Music21 gets the proper mac version and runs in Big Sur (thanks Daniel Fürst)
  • corpus.search() should work on PC now. Sharing music21 scores that have been frozen and thawed should also work across Mac and PC.
  • ChordSymbols preserve root and bass (thanks to Jacob Tayler Walls = JTW for this and so much else in this release!)
  • Instrument names that cannot be decoded from MIDI do not crash MIDI parsing (JTW)
  • Audio searches and other searches on empty streams are improved. (JTW)
  • Non existent user scratch directory does not raise major bugs any more (David Garfinkle and JTW)
  • New location for System/Preview on macOS since Catalina and musescore on Windows (MSC + JTW)
  • remove() now searches endElements as well.
  • Corrected octaves on pitches derived in IntervalNetwork.nextPitch() (JTW) -- should fix some weird scale pitch octaves.
  • TextExpressions now have correct offsets when derived from a tempo indication or coda (JTW)
  • MIDI files parsed multiple times with different quantization settings work properly (JTW)
  • MIDI files with zero-length notes now create zero-length GraceNotes and not 1.0 length notes in music21 (JTW)
  • All tests pass in Python 3.8 (now on to 3.9!)
  • Beethoven Opus 59 no 3 mvmt 4 contained all 4 movements in it. Now it only contains movement 4.
  • MIDI's matchedNoteOff was not working properly. Works now (Thanks SunWoong KIM)
  • If two keys had the same likelihood in probe-tone analysis then only one appeared in .alterateInterpretations. Now there will always be a 23-element list. (ZM-J + JTW)
  • C-version of Python Levenshtein was sometimes not being called even if installed. This will greatly speed up similarity searching.
  • Harmony.addChordStepModification gets an updatePitches=True attribute that will immediately apply the chordStepModification to the computed pitches. The default of False remains for now, but will become True in music21 v.7.

Improvements:

  • Chordify and Verticality.makeChords gets a new keyword attribute "copyPitches=False" which makes it so that the original pitches (and not deepcopies) from the score appear in the chordified score. This can make it MUCH easier to see which pitches in a chordified score relate to the pitches in the original. However, they are identical objects, so changing one later will change the other. Default behavior is unchanged.
  • Repeats play back properly in MIDI (JTW)
  • Improved Docs (configuration instructions, typos, examples) (many people but especially JTW)
  • Much better typing all around for developers
  • math.log2 used instead of math.log(x, 2) for no more floating point confusion in many quarterLengths (JTW)
  • Braille keeps its debugging information in Note.editorial instead of custom attributes (backwards incompatible change, but okay)
  • Braille/runAllBrailleTests improved for non-sighted developers.
  • Incomplete 7th/9th/11th chords find roots better (JTW)
  • Legacy code for Python 3.5 removed (JTW)
  • Augmented sixth RomanNumerals work w/o needing a key. Also work with secondary numerals (JTW)
  • Bach chorales sort by BWV as a number rather than a string (JTW)
  • Beethoven quartets from Project Gutenberg had hidden voices w/ incorrect durations to show playback of trills, etc. Those voices have been removed. Speeds up the parsing of those pieces greatly, and gives better feature extractions. Affected pieces are opus 59.1.3, 59.1.4, 59.2.1, 59.2.2, 59.3.2, 59.3.3, 59.3.4, and opus 133.
  • Improvements to instrument name lookups (Thanks Mark Gotham)
  • Unnecessary list comprehensions are removed.
  • For running tests, missing optional modules and Lilypond. will cause import errors.
  • ABC module has been partially cleaned up, and made easier for developers to hack new ABC extensions to.

Changes:

as this is a 6.X release, we have tried to keep backwards incompatible changes to a bare minimum, but a few obscure cases are changed:

  • .seconds.beat.beatStrength on notes without a TimeSignature or MetronomeMark context now return nan instead of raising an exception.  .beatStr returns the string "nan". Python 3.8's mock methods iterate through all properties before setting up the mocked object and properties that might raise exceptions cause problems. This seems like a good direction to go in, so please expect that all property getters will switch to never raising an exception but giving nan or another failure indicator in the future.
  • KrumhanslSchmucker and KrumhanslKessler probe tone analysis are now identical. The difference before was probably a typo. They are now synonyms for each other.

Thanks always to the Seaver Institute, the National Endowment for the Humanities, and the School of Humanities, Arts, and Social Sciences and the Music and Theater Arts Section of MIT for their support in making music21 possible. And can we all give applause to Jacob Tayler Walls for all the great work done on this release!

Tuesday, September 1, 2020

Music21 v6 Released!

Music21 v6 is OUT as v6.1.0! This represents over 500 commits over the past 14 months since v5.7 was released.

Many thanks to Jacob Tyler Walls (JTW below) who made so many contributions to the v6 branch, both big and small. Mad props and round of applause!

v6 fully supports Python 3.8 and removes support for Python 3.5. v6 will be the last major release to support Python 3.6 and we will work on Python 3.9 support immediately.

As with all new v.X releases of music21 there are improvements and some backwards incompatible changes (not too many)

In no particular order, here are the things to look for in the new music21 v6:

  • Type hints throughout music21 -- when you program with a sophisticated IDE you will be able to see what is returned and required as attributes in much of music21.

  • music21 is no longer packaged with external modules; these will be installed when installing music21 via pip (otherwise run pip install -r requirements.txt). Speed and security improvements come with this.

  • converter.parse('file.mid', quantizePost=False) will let you load in a MIDI file without any quantizing. (Thanks JTW)

  • Lots more values cached = faster music21; RomanNumerals in particular are over an order of magnitude faster, and Chords are faster too. If you ever have a problem, all Music21Objects have a .clearCache() function. Just add @cacheMethod as a decorator to a method and it will use the caching routine.

  • Intervals have been rewritten to use properties entirely. So whatever happens to an Interval, its semiSimpleNiceName (to take one of dozens of examples) will always be up to date. Intervals use Specifiers that are enums like interval. Specifier.PERFECTinstead of inscrutable numbers. (those inscrutable numbers still work though) Specifiers are more than just standard enums -- they can invert themselves, do semitonesAboveMajor() etc. Interval geeks rejoice.

  • Intervals given a noteStart and a name will generate noteEnd automagically. They also get transposePitch() improvements along the way.

  • KeySignature gets transposePitchFromC() which takes a pitch in C major and returns the pitch in the same scale degree in this key..

  • Voices with gaps in them work way better in MusicXML. Repeat endings with multiple numbers like 1,2 r/t with musicxml (JTW)

  • TSV files which encode harmonic analysis can now be parsed (Thanks Mark Gotham)

  • Humdrum harm spines parse now, giving another way of encoding harmonic analysis. (Thanks Néstor Nápoles López)

  • MIDI refactor: easier to subclass and extend and with many docs -- keeps a clear distinction between strings and bytes. MIDI values are all Enum classes (but IntEnums so they compare well with pure numbers)

  • StripTies works much better thanks to JTW -- and does not filter out non-Notes anymore (technically an incompatibility, but really a bug fix). Voices, etc. don't faze .stripTies() any more. Stream.voicesToParts() also preserves more elements. Chords with some notes tied and some don't no longer get merged. Note that stripTies retainContainers defaults to True now, because getting the opposite behavior is as easy as a .flat

  • Internal but important: lots of parts of music21 code that used abbreviations now spell out the whole word. This is important for our friends using screen readers. While music21 will (for historical/compatibility reasons) still use camelCase for all method names, attribute names, etc., internal variables may now use underscore_case which helps with screen readers.

  • Stream().write('mxl') will write compressed musicxml (JTW). Or write('...', format='musicxml', compress=True)

  • Improvements to VoiceLeadingQuartets (thanks Ryaan Ahmed), including finding parallel intervals with octave displacement. voiceCrossing and voiceOverlap detection.

  • Substantial improvements to RomanText: see https://dmitri.mycpanel.princeton.edu/romantext.pdf

  • RomanNumerals can specify how they represent ^6 and ^7 in minor with sixthMinor and seventhMinor keywords)

  • OMR fixers can recognize Turns and other ornaments. More merging here to come. Thanks Janelle Sands!

  • Substantial improvements to beaming routines and tests (thanks Almog Cohen!)

  • Keys now have .deriveByDegree() like Scales, so "What minor key has scale degree 3 as B-flat?" can easily be answered.

  • Improvements to dotted tuplets (Almog Cohen)

  • Chord.name/fullName now gives better names for common chords like Major/Minor triads -- no longer relies entirely on chord.tables. But even there many improvements and spelling corrections.

  • Chords expose .notes to get at the notes that make up a chord, in a different way than Chord[0] or for n in Chord -- I'm still an old Perl guy, sometimes There's More Than One Way to Do It, and this way makes some things conceptually much easier and faster.

  • More Bach Chorale fixes from Doctor Schmidt (thanks!)

  • Stream.replace(recurse=True) finally works!

  • StringIndication, FretIndication work in musicxml (thanks Peter Mitrano)

  • For those who are adventurous -- intervalNetworks are now exposed on scales.

  • prebase.ProtoM21Object -- an idea ported back from music21j: nearly every object in music21, including all Music21Objects, inherits from this super-lightweight base class which allows for querying classes and giving consistent representations. It makes working in music21 a lot more fun.

Incompatible Changes

  • Stream filters now return a new StreamIterator. So old code like:
s = stream.Stream()
sIter = s.iter
sIter.getElementsByClass('Chord')
list(sIter)

should now be written as:

s = stream.Stream()
sIter = s.iter
sIter2 = sIter.getElementsByClass('Chord')
list(sIter2)

For most people using filters within a for-loop, nothing will appear to have changed.

  • if element in stream now only returns True if the element is actually in the Stream, not if element is equal to something in the Stream. This is not normal Python behavior for __contains__ but it is something music21 users have counted on for a decade, and now it is assured.

  • MIDI has been completely refactored, so if you are mucking with MIDI internals, it's going to be completely different. If you're just using converter.parse and .write('midi') it won't have changed much.

Also

  • Setting a pitch's accidental to a number is deprecated and to be removed soon. use b = pitch.Pitch('B4'); b.accidental = pitch.Accidental(-1).
  • some long deprecated functions removed, such as Stream.restoreActiveSites, Stream. _yieldReverseUpwardsSearch, common.standardDeviation (use statistics.stdev instead).
  • Chord sort methods no longer return the chord itself if inPlace=True
  • interval.convertSemitoneToSpecifierGenericMicrotone, convertSemitoneToSpecifierGeneric now return a Specifier Enum as their first value
  • Spelling corrections that are technically incompatible: Interval.perfectable replaces typo Interval.prefectable. Appoggiatura is spelled correctly with two-gs everywhere it's used (JTW)
  • stripTies(retainContainers=True) is now the default.
  • Half-diminished chords have ø7 etc. as their default representation.
  • MIDI.intsToHexString has become MIDI.intsToHexBytes which does what is says it does.

Small Changes/Bugs squashed:

  • A malformed spanner in musicxml will no longer crash parsing.
  • Tuplets are equal if their durations are equal. Better docs for duration equality.
  • contextSitesnextprevious, and getContextByClass have a priorityTargetOnly or activeSiteOnly keyword for searching activeSite only. Speed!
  • From music21.X import * works much more reliably.
  • Bugs fixed in feature extraction of keys.
  • serial allows "P" or "T" to be used for transpositions
  • Tone-Rows give their row in the repr.
  • Historical tone-rows no longer have Row in their name. For instance: serial.getHistoricalRowByName('SchoenbergOp37').matrix() -- the old form still works though.
  • Feature extraction on empty streams (or ones that don't have instruments or something else) works properly (JTW)
  • Feature output formats can set .ext directly, in case you need a different extension.
  • viio7 can be specified as vii07
  • Interval: reverse=True works properly
  • subprocess.run is used instead of os.system for PNG generation. Thanks Uğur Güney. Fixes using musescore with music21 in Jupyter when spaces appear in filenames. (also thanks to Frank Zalkow)
  • Better representation for many objects
  • Error handling for incorrect chord abbreviation is improved. Thanks Vikram Natarajan
  • Librettists and lyricists can be searched in metadata.  .age() works properly for living composers.
  • MIDI plays back properly in Jupyter again BUT also does not add a delay when writing out a file.
  • Voice numbers in generated musicxml are now low numbers
  • pitch.Accidental gets . setAttributeIndependently() in case you want something to look like a flat but only alter 0.8 semitones. (This appeared in v.5 at some point but was never announced)
  • Note gets a pitchChanged() method which is called by its attached pitch anytime it changes so that caches can be used. Pitch gets an informClient() method which is called anytime the pitch itself changes. There is something similar in Chords too. This squashes a lot of bugs where pitches were changing but notes/chords/scales/etc. did not act like they had changed.
  • makeAccidentals works properly in Voices (JTW)
  • MIDI parsing gets more instrument objects from more places (JTW)
  • zero-length objects at the end of streams were being ignored by makeNotation (JTW)
  • Show formats: MuseScore 3.5 compatibility. (JTW). Preview is found by default on macOS Catalina/Big Sur -- still works for older OSes. No more 'is your doc > 999 pages?' bugs!
  • Some Neo-Riemannian docs weren't showing (thanks Adam Spiers)
  • Tone profiles for key analysis have been corrected. (thanks Micah Walter)
  • scaleDegreeWithAlteration on Augmented 6th chords works.
  • .musicxml is fully recognized as a suffix.
  • Improvements to analysis.windowed (thanks Sandro Luck)
  • RepeatExpander now does nothing on a score with no repeats. Before, it crashed.
  • Sousa example couldn't show before (thanks David H. Gutteridge)
  • Verticality.removeVerticalDissonances now works (also thanks to Gutteridge)
  • Z-relation for 5Z37 (5Z17) was incorrect (thanks Rodrigo Balthar Furman for spotting this)
  • Power-users who subclass Stream to be standard storage variants: Stream().coreSelfActiveSite(el) allows for subclassing what happens when an element should normally have its activeSite set to the stream.
  • Lilypond output with UTF-8 works. Grace notes no longer crash Lilypond. Now that there is a 64-bit binary Mac version of Lilypond, it will not be removed from music21.
  • RomanNumerals compare with each other. __eq__ logically defined.
  • Modest performance improvements in sorting (Thanks Alexander Morgan)
  • Documentation and test improvements and a few bugs squashed in ABC parsing.
  • f-strings used throughout music21 allowing for more detailed error messages and many bugs to be detected and removed.

Deprecations

  • interval.Interval.convertSpecifier() deprecated. use parseSpecifier instead.
  • Humdrum parseData() and parseFile() are deprecated. use the general converter.parse() instead.
  • .editorial.misc is deprecated, just stick whatever you want on the .editorial object itself.

Gratitude

As always, I want to thank MIT, the NEH, and the Seaver Institute for supporting music21 over the years along with the community of developers who use and give back to music21.