-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"name": "Untitled0.ipynb", | ||
"provenance": [], | ||
"authorship_tag": "ABX9TyMxRQBczhrwrG+VKQ/hLEdw", | ||
"include_colab_link": true | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "view-in-github", | ||
"colab_type": "text" | ||
}, | ||
"source": [ | ||
"<a href=\"https://colab.research.google.com/github/rafael5/adoc/blob/master/music21.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"id": "wI2LYBHVAEou" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from music21 import *" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"note" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "LBJd5W-nAS-d", | ||
"outputId": "ecb76a33-01d3-4bc3-cd93-a29c2bd049f5" | ||
}, | ||
"execution_count": 2, | ||
"outputs": [ | ||
{ | ||
"output_type": "execute_result", | ||
"data": { | ||
"text/plain": [ | ||
"<module 'music21.note' from '/usr/local/lib/python3.7/dist-packages/music21/note.py'>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"execution_count": 2 | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"s = corpus.parse('bach/bwv65.2.xml')" | ||
], | ||
"metadata": { | ||
"id": "K7ZB0BXgAefZ" | ||
}, | ||
"execution_count": 4, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"dir(note)" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "mwXjolrKAk3O", | ||
"outputId": "e9751a87-243f-40b7-8a5f-ae9e86813b76" | ||
}, | ||
"execution_count": 5, | ||
"outputs": [ | ||
{ | ||
"output_type": "execute_result", | ||
"data": { | ||
"text/plain": [ | ||
"['GeneralNote',\n", | ||
" 'Lyric',\n", | ||
" 'LyricException',\n", | ||
" 'NotRest',\n", | ||
" 'NotRestException',\n", | ||
" 'Note',\n", | ||
" 'NoteException',\n", | ||
" 'Rest',\n", | ||
" 'SpacerRest',\n", | ||
" 'Test',\n", | ||
" 'TestExternal',\n", | ||
" 'Unpitched',\n", | ||
" '_DOC_ORDER',\n", | ||
" '_MOD',\n", | ||
" '__builtins__',\n", | ||
" '__cached__',\n", | ||
" '__doc__',\n", | ||
" '__file__',\n", | ||
" '__loader__',\n", | ||
" '__name__',\n", | ||
" '__package__',\n", | ||
" '__spec__',\n", | ||
" 'base',\n", | ||
" 'beam',\n", | ||
" 'common',\n", | ||
" 'copy',\n", | ||
" 'duration',\n", | ||
" 'environLocal',\n", | ||
" 'environment',\n", | ||
" 'exceptions21',\n", | ||
" 'expressions',\n", | ||
" 'interval',\n", | ||
" 'noteheadTypeNames',\n", | ||
" 'pitch',\n", | ||
" 'stemDirectionNames',\n", | ||
" 'style',\n", | ||
" 'tie',\n", | ||
" 'unittest',\n", | ||
" 'volume']" | ||
] | ||
}, | ||
"metadata": {}, | ||
"execution_count": 5 | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"music21.note " | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "4Lq06vYYBCLB", | ||
"outputId": "83c2d87e-ddb5-4fc3-b462-8a4982eda371" | ||
}, | ||
"execution_count": 7, | ||
"outputs": [ | ||
{ | ||
"output_type": "execute_result", | ||
"data": { | ||
"text/plain": [ | ||
"<module 'music21.note' from '/usr/local/lib/python3.7/dist-packages/music21/note.py'>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"execution_count": 7 | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"import music21\n", | ||
"s = corpus.parse('bach/bwv65.2.xml')\n" | ||
], | ||
"metadata": { | ||
"id": "JG3_iXJhBHxF" | ||
}, | ||
"execution_count": 12, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"s.analyze('key')" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "EAQJj-PhApW-", | ||
"outputId": "08081720-b654-456f-b27e-1fe06e0ab96d" | ||
}, | ||
"execution_count": 15, | ||
"outputs": [ | ||
{ | ||
"output_type": "execute_result", | ||
"data": { | ||
"text/plain": [ | ||
"<music21.key.Key of a minor>" | ||
] | ||
}, | ||
"metadata": {}, | ||
"execution_count": 15 | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"s.show()" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/", | ||
"height": 342 | ||
}, | ||
"id": "7Qr5qOJOBhKS", | ||
"outputId": "fc94713f-5fbe-4ab5-f8a9-b0cff4fe75d7" | ||
}, | ||
"execution_count": 19, | ||
"outputs": [ | ||
{ | ||
"output_type": "error", | ||
"ename": "SubConverterException", | ||
"evalue": "ignored", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mSubConverterException\u001b[0m Traceback (most recent call last)", | ||
"\u001b[0;32m<ipython-input-19-daffe8404596>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ms\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | ||
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/music21/stream/__init__.py\u001b[0m in \u001b[0;36mshow\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 256\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misSorted\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mFalse\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mautoSort\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 257\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 258\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 259\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 260\u001b[0m \u001b[0;31m#---------------------------------------------------------------------------\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/music21/base.py\u001b[0m in \u001b[0;36mshow\u001b[0;34m(self, fmt, app, **keywords)\u001b[0m\n\u001b[1;32m 2578\u001b[0m \u001b[0mapp\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mapp\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2579\u001b[0m \u001b[0msubformats\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msubformats\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2580\u001b[0;31m **keywords)\n\u001b[0m\u001b[1;32m 2581\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2582\u001b[0m \u001b[0;31m#--------------------------------------------------------------------------\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/music21/converter/subConverters.py\u001b[0m in \u001b[0;36mshow\u001b[0;34m(self, obj, fmt, app, subformats, **keywords)\u001b[0m\n\u001b[1;32m 358\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ms\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mscores\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 359\u001b[0m fp = helperSubConverter.write(s, helperFormat,\n\u001b[0;32m--> 360\u001b[0;31m subformats=helperSubformats, **keywords)\n\u001b[0m\u001b[1;32m 361\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 362\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mhelperSubformats\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m'png'\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/music21/converter/subConverters.py\u001b[0m in \u001b[0;36mwrite\u001b[0;34m(self, obj, fmt, fp, subformats, **keywords)\u001b[0m\n\u001b[1;32m 936\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m'png'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msubformats\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;34m'pdf'\u001b[0m \u001b[0;32min\u001b[0m \u001b[0msubformats\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 937\u001b[0m and not str(environLocal['musescoreDirectPNGPath']).startswith('/skip')):\n\u001b[0;32m--> 938\u001b[0;31m \u001b[0mfp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrunThroughMusescore\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfp\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msubformats\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkeywords\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 939\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 940\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mfp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;32m/usr/local/lib/python3.7/dist-packages/music21/converter/subConverters.py\u001b[0m in \u001b[0;36mrunThroughMusescore\u001b[0;34m(self, fp, subformats, **keywords)\u001b[0m\n\u001b[1;32m 863\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mmusescorePath\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 864\u001b[0m raise SubConverterException(\n\u001b[0;32m--> 865\u001b[0;31m \u001b[0;34m\"To create PNG files directly from MusicXML you need to download MuseScore and \"\u001b[0m \u001b[0;34m+\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 866\u001b[0m \"put a link to it in your .music21rc via Environment.\")\n\u001b[1;32m 867\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mmusescorePath\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexists\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | ||
"\u001b[0;31mSubConverterException\u001b[0m: To create PNG files directly from MusicXML you need to download MuseScore and put a link to it in your .music21rc via Environment." | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |