{"library":"music21","title":"music21","description":"music21 is a Toolkit for Computer-Aided Musical Analysis and Computational Musicology. It provides objects and methods to represent musical notation and analytical concepts, allowing for programmatic manipulation, analysis, and generation of musical data. Version 9.9.1 is the latest release, with a frequent release cadence, often addressing Python compatibility and adding new features for import/export.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install music21"],"cli":null},"imports":["from music21.stream import Stream","from music21.note import Note","from music21 import converter","from music21 import environment"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import music21\nfrom music21 import note, stream, tempo\n\n# Create a musical stream (like a score or a part)\ns = stream.Stream()\ns.append(tempo.MetronomeMark(number=120))\n\n# Add some notes\nn1 = note.Note('C4')\nn1.duration.type = 'quarter'\ns.append(n1)\n\nn2 = note.Note('D4')\nn2.duration.type = 'quarter'\ns.append(n2)\n\nn3 = note.Note('E4')\nn3.duration.type = 'half'\ns.append(n3)\n\n# Display the stream (requires an external MusicXML viewer like MuseScore)\n# If no viewer is installed, this might open a browser with an XML file or fail.\n# For headless environments, consider s.write('midi') or s.write('musicxml').\ntry:\n    s.show()\nexcept Exception as e:\n    print(f\"Could not display score: {e}\")\n    print(\"Try installing MuseScore or using s.write('musicxml', fp='my_score.xml')\")\n","lang":"python","description":"This quickstart demonstrates creating a simple musical stream with a few notes and displaying it. The `s.show()` method relies on external applications like MuseScore or LilyPond to render scores. Ensure you have one installed and configured for optimal results. Alternatively, you can save the output to a file (e.g., MusicXML or MIDI).","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}