music21 | music21 is a Toolkit for Computational Musicology | Database library

 by   cuthbertLab Python Version: 9.1.0 License: Non-SPDX

kandi X-RAY | music21 Summary

kandi X-RAY | music21 Summary

music21 is a Python library typically used in Database applications. music21 has no bugs, it has no vulnerabilities, it has build file available and it has high support. However music21 has a Non-SPDX License. You can install using 'pip install music21' or download it from GitHub, PyPI.

music21 -- A Toolkit for Computational Musicology. Copyright 2006-2021, Michael Scott Cuthbert and cuthbertLab. For more information, visit: And to install, see: Music21 runs on Python 3.7+. Use version 4 on Python 2 or Py3.4, version 5 on Py3.5, version 6 on Py3.6. Released under the BSD (3-clause) license. Music21 may also be used under the LGPL license. See LICENSE. Externally provided software (including the MIT licensed Lilypond/MusicXML test Suite) and music encoding in the corpus may have different licenses. A no-corpus version of music21 is available also on GitHub.

            kandi-support Support

              music21 has a highly active ecosystem.
              It has 1791 star(s) with 358 fork(s). There are 75 watchers for this library.
              There were 2 major release(s) in the last 12 months.
              There are 112 open issues and 574 have been closed. On average issues are closed in 102 days. There are 10 open pull requests and 0 closed requests.
              It has a negative sentiment in the developer community.
              The latest version of music21 is 9.1.0

            kandi-Quality Quality

              music21 has 0 bugs and 0 code smells.

            kandi-Security Security

              music21 has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              music21 code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              music21 has a Non-SPDX License.
              Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.

            kandi-Reuse Reuse

              music21 releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              It has 1605373 lines of code, 7588 functions and 536 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed music21 and discovered the below as its top functions. This is intended to give you an instant insight into music21 implemented functionality, and help decide if they suit your requirements.
            • Test against verdi data
            • Converts a chord symbol to a chord symbol .
            • Recursively builds a stream .
            • Gets a context by class name .
            • Convert the list to a List .
            • Updates the accidental display .
            • Obtains a roman number from a chord object
            • Returns all times from a stream
            • This method is used to strip out ties .
            • Parse the given contents as a note .
            Get all kandi verified functions for this library.

            music21 Key Features

            No Key Features are available at this moment for music21.

            music21 Examples and Code Snippets

            Bach Violin Dataset,Contents
            Pythondot img1Lines of Code : 29dot img1License : Permissive (MIT)
            copy iconCopy
            ├─ README                                  README file
            ├─ audio.csv                               Metadata of the audio files
            ├─ info.csv                                Metadata of the processed files
            ├─ audio
            │  ├─ emil-telmanyi
            │  │  ├─ emil-telman  
            Pythondot img2Lines of Code : 8dot img2License : Strong Copyleft (GPL-3.0)
            copy iconCopy
              class: MinorScale
              tonic: d
                query: |
                  1 - avg(rate(node_cpu_seconds_total{mode="idle", instance="$instance"}[30s]))
                instrument: cello
            Primeira fase: Sonatas
            Pythondot img3Lines of Code : 6dot img3no licencesLicense : No License
            copy iconCopy
            sudo apt-get install python python-numpy python-pylab python-setuptools
            sudo easy_install music21
            sudo easy_install scikit-learn
            eog g1.png
            music21 : given midi input, output correctly-spelled pitches with octave numbers
            Pythondot img4Lines of Code : 7dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            for n in myStream.recurse().notes:
               print(n.offset, ' '.join(p.nameWithOctave for p in n.pitches))
            for n in myStream.recurse().notes:
              closest_key = n.getContextByClass(key.Key)
              n.pitches = pitch.simplifyMulti
            Silence music21 warnings
            Pythondot img5Lines of Code : 6dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            >>> from music21 import midi  # or your standard import
            >>> def noop(input):
            ...   pass
            >>> midi.translate.environLocal.warn = noop
            Silence music21 warnings
            Pythondot img6Lines of Code : 20dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from IPython.utils import io
            with io.capture_output():
                < ...your code... >
            import io
            import sys
            class MuteWarn:
                def __enter__(self):
                    self._init_stdout = sys.stdout
                    sys.stdout = open(
            Music21: remove percussion based on channel number
            Pythondot img7Lines of Code : 15dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            m = music21.midi.MidiFile()
            tracks = [t for t in m.tracks if not any([ == 10 for e in])]        
            score =
            Add a forEach or foor loop in python code
            Pythondot img8Lines of Code : 10dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import sys
            import os
            sample_folder_path = sys.argv[1]
            images = os.listdir(sample_folder_path) # getting all images stored in sample folder
            images_path = [os.path.abspath(f"{sample_folder_path}/{image}") for image in images] # gets absolute
            Converting piano roll to MIDI in music21?
            Pythondot img9Lines of Code : 47dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            from mido import Message, MidiFile, MidiTrack
            def stop_note(note, time):
                return Message('note_off', note = note,
                               velocity = 0, time = time)
            def start_note(note, time):
                return Message('note_on', note = note,
            How do you get the correct type of class in Python
            Pythondot img10Lines of Code : 2dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            type(consec_notes[0]) == music21.key.Key

            Community Discussions


            music21 write() function giving AttributeError: 'Rest' object has no attribute 'pitches' on python 3.9.1 and music21 version 7
            Asked 2022-Mar-18 at 13:41

            I'm using the code found on this gist: and when I run the script on MIDIs I have, including one from the author, I get the error



            Answered 2021-Sep-13 at 03:38

            Yes, this is a bug in version 7, but thanks to this report, I've opened a pull request to fix the issue.

            There might be a bug-fix release this fall, or you could also just pull from the development version once the PR is merged, e.g. pip uninstall music21 and pip install git+ Thanks again for reporting!



            music21 getElementsByClass not showing any output for class stream.Voice
            Asked 2021-Nov-23 at 04:08

            I am struggling to understand why the below code is throwing an error when it ran seamlessly about a year back. The code snippet is from a popular Coursera course. Does the Music21 package has some recent changes around stream.Voice?



            Answered 2021-Nov-23 at 04:08

            Yes, one of the improvements in music21 v.7 is that files imported from MIDI now have a similar representation to files imported from MusicXML and other formats. Specifically, Parts now have Measures, which may or may not have Voices, rather than Parts directly containing Voices. Code should not depend on finding Voices directly contained in Parts, which is what this example was doing.

            Instead, use this code to find all the measure-voices:



            Using music21j in node js, not in browser
            Asked 2021-Nov-09 at 14:51

            I'm attempting to run music21j in node js ( repo link , npm link ).

            I get ReferenceError: self is not defined

            When trying to simply initialize music21j:



            Answered 2021-Nov-09 at 14:51

            From the github repo:

            At present it's not possible to run outside of the browser. :-( But we're working on removing certain JQuery patches that should make it easier to do. You may however need to use ES6-style imports.



            Multipoint(df['geometry']) key error from dataframe but key exist. KeyError: 13 geopandas
            Asked 2021-Oct-11 at 14:51

            data source:

            I tried looking for a similar problem but I can't find an answer and the error does not help much. I'm kinda frustrated at this point. Thanks for the help. I'm calculating the closest distance from a point.



            Answered 2021-Oct-11 at 14:21

            geopandas 0.10.1

            • have noted that your data is on kaggle, so start by sourcing it
            • there really is only one issue shapely.geometry.MultiPoint() constructor does not work with a filtered series. Pass it a numpy array instead and it works.
            • full code below, have randomly selected a point to serve as gpdPoint



            music21 : given midi input, output correctly-spelled pitches with octave numbers
            Asked 2021-Sep-30 at 22:59

            See Edit below for a work-in-progress MRE

            I'm trying to transform the text output of music21 to include octave numbers and correct enharmonic spelling.

            As background, I'm a javascript programmer, new to music21 and python.

            The following



            Answered 2021-Sep-30 at 22:59


            .show() is nice at a glance when debugging but not ideal for structured output. Have a look at recurse(). music21 has a container ontology: objects are "in" voices, "in" measures, "in" parts, "in" scores. So if you start top-down from a score and want to walk every nested container, just use recurse():



            Silence music21 warnings
            Asked 2021-Sep-29 at 22:50

            I am getting an abundance of music21 warnings about zero-duration chords:



            Answered 2021-Sep-29 at 17:02

            If you're using ipython, you can try just muting the section you're trying to execute:



            Music21: remove percussion based on channel number
            Asked 2021-Sep-28 at 14:55

            I have some midi files [sample] from which I'd like to remove percussion.

            Here's what I've been using to read midi files and then save midi back to disk. The resulting sound is great:



            Answered 2021-Sep-28 at 14:55

            Lord have mercy I needed to pass forceSource=False into the midiTracksToStreams call as well:



            Music21: Strip empty data at end of written midi file
            Asked 2021-Sep-26 at 21:47

            I am writing a simple midi file using music21:



            Answered 2021-Sep-26 at 21:47

            The current version from PyPI (7.1.0) seems to always add one quarter note of silence at the end. This can be changed by setting music21.defaults.ticksAtStart, despite its name. The units are MIDI ticks defined by music21.defaults.ticksPerQuarter. The default value of both is 1024.

            Be aware that some MIDI players will stop synthesizing when the file ends, so the sound will stop dead when the last note is released instead of dying away if there is no padding.

            Also, some players may pad to a measure boundary no matter what you do. There is no way to encode a pickup measure in MIDI, other than inserting rests.



            Identifying time signature with music21
            Asked 2021-Sep-24 at 19:40

            I'm trying to determine the time signature of a midi file in Python using music21. I can obtain the time signature of this sample midi for instance with:



            Answered 2021-Sep-24 at 19:40

            music21 v.7.1 started making measures in parts parsed from MIDI files. For that reason, the .timeSignature property is not very useful when called on a Part (example from docs: "This property is not recursive, so a Part will not have the time signature of the measure within it"). The fact that this used to work for MIDI files was inconsistent with the rest of the system.

            If you just want the first time signature, perform a recursive search:

            Old syntax (still works): myPart.recurse().getElementsByClass(music21.meter.TimeSignature)[0]

            New shortcut syntax (v7): myPart[music21.meter.TimeSignature][0]

            Equivalently, you can use strings such as 'TimeSignature' in the getter instead of class names.

            You could also index into the first measure and access the .timeSignature property there: myPart['Measure'][0].timeSignature.



            Add a forEach or foor loop in python code
            Asked 2021-Sep-21 at 04:32

            I am using this library midi2img to generate midi from images

            From this library, this is the file am using:



            Answered 2021-Sep-21 at 04:32

            You can do this by getting list of images from directory and iterate over them.


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install music21

            You can install using 'pip install music21' or download it from GitHub, PyPI.
            You can use music21 like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • PyPI

            pip install music21

          • CLONE
          • HTTPS


          • CLI

            gh repo clone cuthbertLab/music21

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link