{ "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", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "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" ] }, { "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 `