{ "metadata": { "name": "", "signature": "sha256:a79102007e5e35d117b066c98608140d1b46edf44c008be978c5e03fe2614b79" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Previously, your non-iPython script oscar.py gave you a text file oscar2chords.txt, in the form:\n", "\n", "Chord{....}..., c minor 7, 0.125, 0.800\n", "\n", "In this notebook, you extract this information and build a possible \"chord bank\" of possible chords\n", "and what triggers there are (e.g. certain note sequences) to play them. This is necessary because\n", "you need to get a unique collection of chords Oscar Peterson played, and your text file oscar2chords.txt\n", "is insufficient because it lists all chords that are played rather than only the unique ones.\n", "\n", "Output: a chord bank as a .txt file that you can use with the clustering algorithms and playback in \n", "the other notesbooks.\n", "\n", "Dependencies:\n", "\n", "--2. N-Gram" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from collections import Counter, defaultdict\n", "from sklearn.cluster import KMeans\n", "from mingus.midi import fluidsynth\n", "from mingus.containers import NoteContainer\n", "from mingus.containers.Bar import Bar\n", "import mingus.core.value as value\n", "import pandas as pd\n", "import numpy as np\n", "import sys, re, itertools, random\n", "sys.path.append('C:/Python27/Lib/site-packages')\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 the chord data.\n", "allchords = pd.read_csv('oscar2chords.txt', skiprows=2)[:].sort(\"Offset\")\n", "allchords.index = xrange(1, len(allchords) + 1)\n", "with open('oscar2chords.txt', 'rb') as f:\n", " metmark = float(f.readline())\n", " tsig_num, tsig_den = [i for i in f.readline().replace(' /', '').split()]\n", " \n", "print \"Metronome, Timesig Numerator, Timesig Denominator, # chords played\"\n", "print metmark, tsig_num, tsig_den, len(allchords)\n", "allchords.sort(columns=\"Offset\", ascending=True)[:10]\n", "allchords.head()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Metronome, Timesig Numerator, Timesig Denominator, # chords played\n", "176.0 4 4 297\n" ] }, { "html": [ "
\n", " | FullName | \n", "CommonName | \n", "Len | \n", "Offset | \n", "
---|---|---|---|---|
1 | \n", "Chord {D in octave 5 | C in octave 4 | E in oc... | \n", "A6-perfect-fourth minor tetrachord | \n", "1.125000 | \n", "8.000 | \n", "
2 | \n", "Chord {A in octave 3 | G in octave 3 | E in oc... | \n", "A3-incomplete dominant-seventh chord | \n", "1.250000 | \n", "8.000 | \n", "
3 | \n", "Chord {E in octave 6 | E in octave 4 | D in oc... | \n", "D6-quartal trichord | \n", "1.375000 | \n", "9.625 | \n", "
4 | \n", "Chord {C in octave 4 | A in octave 5} Dotted Q... | \n", "A5-interval class 3 | \n", "1.500000 | \n", "9.625 | \n", "
5 | \n", "Chord {G in octave 3 | A in octave 3} Quarter ... | \n", "A3-interval class 2 | \n", "1.666667 | \n", "9.625 | \n", "
5 rows \u00d7 4 columns
\n", "