{
"metadata": {
"name": "",
"signature": "sha256:7cc924714f2fe9c734fe75fe21f543c2e6ecd9fd917c3d78d714480310779bbc"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook takes a txt file where each line is of the form (\"%s,%s\" % (G5,1.25)) and plays it to stdout.\n",
"\n",
"IMPORTANT:
\n",
"This is an independent client that doesn't create output to be piped into the other programs. It just relies on 2. N-Gram. Also, this takes only notes in the input file and not chords.\n",
"\n",
"NOTE: You need to write a function to convert a music21 length to a mingus length, given the time signature.\n",
"\n",
"Dependencies:\n",
"\n",
"--2. N-Gram"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import sys, time, re\n",
"import music21\n",
"import mingus.core.notes as notes\n",
"import mingus.core.value as value\n",
"sys.path.append('/usr/local/lib/python2.7/dist-packages/fluidsynth/')\n",
"from mingus.midi import fluidsynth\n",
"from mingus.containers.Note import Note\n",
"from mingus.containers.Bar import Bar\n",
"fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',\"alsa\")"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"True\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"print len(allnotes)\n",
"print sum(alldurations)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'allnotes' is not defined",
"output_type": "pyerr",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mallnotes\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0malldurations\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mNameError\u001b[0m: name 'allnotes' is not defined"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Put notes into one huge bar.\n",
"b = Bar()\n",
"b.set_meter((len(allnotes) * 4, 4))\n",
"for note in allnotes:\n",
" b.place_notes(note, value.eighth)\n",
"print len(b)\n",
"fluidsynth.play_Bar(b, 1, 375)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"490\n"
]
},
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 21,
"text": [
"{'bpm': 375}"
]
}
],
"prompt_number": 21
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# You really should keep rhythm within clusters consistent (either straight eighths or alternating between\n",
"# long/short to get that 'swung' feel)."
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
}
],
"metadata": {}
}
]
}