> ## Documentation Index
> Fetch the complete documentation index at: https://pkhambat.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Jupyter

> Play composer-nb cells in Jupyter with %%music and the Song class.

## Install

```bash theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
pip install composer-nb
```

It needs Python 3.9 or later and JupyterLab, Jupyter Notebook 7, VS Code or Colab. Load the extension once per kernel:

```python theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
%load_ext composer_nb
```

## %%music

A cell that starts with `%%music` is evaluated as composer-nb, and each `play` renders below it. Tab completes inside the cell.

```text theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
%%music [name] [after <name>]
```

| Argument | Does |
| - | - |
| `name` | Stores the cell as a `Song` under that Python name. |
| `after <name>` | Starts the cell from the settings and names that cell ended with. |

## Cells that continue

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
%%music intro
set tempo 75
set transpose 2
chords riff = Am E7|G D
play guitar: chords riff
```

```composer-nb theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
%%music verse after intro
play guitar: chords F C|Dm E7 riff
```

`verse` plays at tempo 75, two semitones up, and can use `riff`. The link is by name, so cell order doesn't matter.

## Song

```python theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
Song(source, *, after=None, name=None)
```

`%%music` creates a `Song`. Build one in Python to generate source. `after` is the `Song` it continues from, and `name` labels the output. Errors in the source show in the output and aren't raised.

```python theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/composer-nb.json"]}}
from composer_nb import Song

groove = "pattern groove = {\n  hat: x-\n  kick: 1 3\n  snare: 2 4\n}\n"
rungs = "\n".join(f"with tempo {t} {{ play groove for 2 bars }}" for t in (70, 80, 90))
Song(groove + rungs, name="ladder")
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.