{ "metadata": { "name": "", "signature": "sha256:284654d870e4f3bdfa7e745725ed41b5cc34a9bc309ebb5621f60c4b494106ee" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "In this file, you read in Oscar's notes with their offsets, and create jazz grammar rules for them (and tag the individual units). Use whatever method you want to do this - KMeans clustering, RBM, etc. You'll probably return to a bit of what you did in Notebook 1: Oscar, Original Visualization." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sklearn.cluster import KMeans\n", "from mingus.containers.Bar import Bar\n", "from mingus.midi import fluidsynth\n", "import numpy as np\n", "import pandas as pd\n", "import re\n", "fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',\"alsa\")" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 1, "text": [ "True" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "# Import and order the original notes.\n", "oscar2 = pd.read_csv('oscar2notes.txt', skiprows=2)[:].sort(\"Offset\")\n", "oscar2.index = xrange(1, len(oscar2) + 1)\n", "oscar2 = oscar2[oscar2.Octave >= 4] # threshold >= octave 4 for melodies\n", "with open('oscar2notes.txt', 'rb') as f:\n", " metmark = float(f.readline())\n", " tsig_num, tsig_den = [i for i in f.readline().replace(' /', '').split()]\n", "print \"# of notes: %s\" % len(oscar2)\n", "oscar2.head()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "# of notes: 1078\n" ] }, { "html": [ "
\n", " | Note/Rest | \n", "Octave | \n", "Len | \n", "Offset | \n", "
---|---|---|---|---|
2 | \n", "D | \n", "5 | \n", "0.750000 | \n", "12.666667 | \n", "
3 | \n", "E | \n", "4 | \n", "0.666667 | \n", "14.000000 | \n", "
4 | \n", "C# | \n", "5 | \n", "0.875000 | \n", "14.000000 | \n", "
5 | \n", "A | \n", "5 | \n", "0.250000 | \n", "15.000000 | \n", "
6 | \n", "F | \n", "4 | \n", "3.125000 | \n", "16.000000 | \n", "
5 rows \u00d7 4 columns
\n", "