{ "metadata": { "name": "", "signature": "sha256:923af621b92260755e0e1e12ce83752d47592bbaea3474fa430d21df1305fa4a" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": [], "source": [ "> This is one of the 100 recipes of the [IPython Cookbook](http://ipython-books.github.io/), the definitive guide to high-performance scientific computing and data science in Python.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 3.5. Using interactive widgets: a piano in the notebook" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You need to download the *Piano* dataset on the book's website. (http://ipython-books.github.io)\n", "\n", "This dataset contains synthetized piano notes obtained on `archive.org` (CC0 1.0 Universal licence). (https://archive.org/details/SynthesizedPianoNotes)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Let's import a few modules." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "import os\n", "from IPython.display import Audio, display, clear_output\n", "from IPython.html import widgets\n", "from functools import partial" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "2. To create a piano, we will draw one button per note. The corresponding note plays when the user clicks on the button. This is implemented by displaying an `