<jupyter_start><jupyter_text>What is `music21`? `Music21` is a Python-based toolkit for computer-aided musicology.People use `music21` to answer questions from musicology using computers, to study large datasets of music, to generate musical examples, to teach fundamentals of music theory, to edit musical notation, study music and the brain, and to compose music (both algorithmically and directly).One of `music21`'s mottos is "Listen Faster." With the toolkit you should be able to find interesting moments and get a sense of the overall profile of a piece or a repertory of pieces. We hope that with the computer you'll have more time for listening and playing for enjoyment and use less of your time listening for work.The system has been around since 2008 and is constantly growing and expanding. The approaches and traditions in `music21` have been used in many previous software systems.  See :ref:`about` for information on the authors and background of the project.The *21* in `music21` refers to its origins as a project nurtured at MIT.  At MIT all courses have numbers and music, along with some other humanities departments, are numbered `21`. The music departments of MIT, along with Harvard, Smith, and Mount Holyoke Colleges, helped bring this toolkit from its easiest roots to a mature system.  Finding solutions in a hurry With `music21` adds a collection of specialized tools and objects to the general-purpose and easy to understand "Python" programming language.  Install `music21` and type `python3` (or, better, `ipython`) and load it by typing:<jupyter_code>from music21 import *<jupyter_output><empty_output><jupyter_text>...and thousands of musical tools become available to you. For instance, want to see a note on the screen? Type these lines:<jupyter_code>n = note.Note("D#3")
n.duration.type = 'half'
n.show()<jupyter_output><empty_output><jupyter_text>Need a whole line of notes? Even easier:<jupyter_code>littleMelody = converter.parse("tinynotation: 3/4 c4 d8 f g16 a g f#")
littleMelody.show()<jupyter_output><empty_output><jupyter_text>Want to hear the melody? It's just as easy! (Please give it a second or two after hitting play for the piano sounds to load):<jupyter_code>littleMelody.show('midi')<jupyter_output><empty_output><jupyter_text>Want to view the opening tone-row of Schoenberg's Fourth String quartet as a matrix?<jupyter_code>print(serial.rowToMatrix([2, 1, 9, 10, 5, 3, 4, 0, 8, 7, 6, 11]) )<jupyter_output>0 11  7  8  3  1  2 10  6  5  4  9
  1  0  8  9  4  2  3 11  7  6  5 10
  5  4  0  1  8  6  7  3 11 10  9  2
  4  3 11  0  7  5  6  2 10  9  8  1
  9  8  4  5  0 10 11  7  3  2  1  6
 11 10  6  7  2  0  1  9  5  4  3  8
 10  9  5  6  1 11  0  8  4  3  2  7
  2  1  9 10  5  3  4  0  8  7  6 11
  6  5  1  2  9  7  8  4  0 11 10  3
  7  6  2  3 10  8  9  5  1  0 11  4
  8  7  3  4 11  9 10  6  2  1  0  5
  3  2 10 11  6  4  5  1  9  8  7  0<jupyter_text>Get a quick graph showing how common various pitches are in a fourteenth century piece:<jupyter_code>dicant = corpus.parse('trecento/Fava_Dicant_nunc_iudei')
dicant.plot('histogram', 'pitch')
dicant.show()<jupyter_output><empty_output><jupyter_text>This example, and many below, come from the `music21` built-in corpus of thousands of pieces that come with the system to help you get started right from the beginning.  We believe in "Batteries Included" as a core principle.  So for instance, every Bach chorale is included, so that you can do things like add the note name in german to every note in Bach chorale, BWV295:<jupyter_code>bwv295 = corpus.parse('bach/bwv295')
bwv295 = bwv295.measures(0,5) #_DOCS_HIDE
for thisNote in bwv295.recurse().notes:
  thisNote.addLyric(thisNote.pitch.german)
bwv295.show()<jupyter_output><empty_output><jupyter_text>Prepare an incipit index (thematic catalog) of every Bach chorale that is in 3/4: (we'll just look at the first 25 here)<jupyter_code>catalog = stream.Opus()
for work in corpus.chorales.Iterator(1, 26):
    firstTimeSignature = work.parts[0].measure(1).getTimeSignatures()[0]
    if firstTimeSignature.ratioString == '3/4':
        incipit = work.measures(0,2)
        catalog.insert(0, incipit.implode())

catalog.show()<jupyter_output><empty_output><jupyter_text>Advanced analysis tools are included.  Want to know how unstable the rhythmic profile of a piece is?  Use Ani Patel's nPVI function on it:<jupyter_code>s = corpus.parse('AlhambraReel')
analysis.patel.nPVI(s.flatten())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0749498103948249, 'fraction_numerical': 0.05710461744367611, 'mean_word_length': 4.13631156930126, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '581416', 'license': 'MIT', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1487, 'n_words': 634, 'path': 'documentation/source/about/what.ipynb', 'repo_name': 'cuthbertLab/music21', 'size': '4483'}