{
"cells": [
{
"cell_type": "markdown",
"id": "4251b47a-0072-4f33-9e5e-e4b0007732b7",
"metadata": {},
"source": [
"# First Steps\n",
"\n",
"\n",
"### Table of Contents\n",
"\n",
"* [1. Notes](#Notes)\n",
" * [Playback](#Playback)\n",
" * [Pitch](#Pitch)\n",
" * [Duration](#Duration)\n",
" * [Shorthand](#Entering-durations-in-shorthand)\n",
" * [Explicit Offset](#Explicit-Offset)\n",
" * [Notation](#Notation)\n",
"* [2. Chords](#Chords)\n",
"* [3. Sidenote: Enharmonic Spelling](#Enharmonic-Spelling)\n",
"* [4. Glissando](#Glissandi)\n",
"* [5. Chain: a sequence of notes/chords](#Chain)\n",
" * [Operations on Chains (inverse, reverse, ...)](#Operations-on-Chains)\n",
" * [Offset](#Offset)\n",
"* [6. Multiple Voices](#Multiple-Voices)\n",
"\n",
"-------------------"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "301a7187-488d-4732-8e7e-fb80fda747d2",
"metadata": {},
"outputs": [],
"source": [
"# Import everyting in the maelzel.core namespace\n",
"from maelzel.core import *\n",
"\n",
"# pitchtools defines many useful conversion functions from/to notenames, frequencies, midinotes, etc\n",
"from pitchtools import f2m\n",
"\n",
"# the display function allows to display the html representation of objects\n",
"from IPython.display import display"
]
},
{
"cell_type": "markdown",
"id": "7e92dc34-ef48-4dc3-a010-0434bd8c607e",
"metadata": {},
"source": [
"## Notes"
]
},
{
"cell_type": "markdown",
"id": "40874a45-fe4f-4b5d-b89c-cb7a4a85b1f0",
"metadata": {},
"source": [
"The simplest note possible is just a pitch.\n",
"\n",
"For notation/playback a default duration will be assumed if no duration is given"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7b5b3b72-890e-423f-b9b9-bfc1e976818c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"4C:1♩
\n",
" "
],
"text/plain": [
"4C:1♩"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Note(\"C4\")"
]
},
{
"cell_type": "markdown",
"id": "b5767481-b0bc-4b5f-ab96-5ff304919dd6",
"metadata": {},
"source": [
"### Playback\n",
"\n",
"A Note can be played via its `.play` method. By default, a piano soundfont (distributed with *maelzel*) will be used as the default instrument.\n",
"\n",
"> **NB**: when this notebook is displayed as part of the documentation it is made static so any \n",
"> interactive elements are removed. For that purpose we render the results in order for the \n",
"> generated audio to be embedded in the html"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "ebbed35b-034f-4f4f-9269-8c2f7c9c663e",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "28bfa881c4c24476bb07429b88ef5563",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Stop', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "024c6f16fb0741628a5ba79dd77dfff5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"SynthGroup - start: 0.038, dur: 1.000, synths: 1\n",
"
instr: preset:piano - 1 synths
\n", "| p1 | start | dur | 4 | 5:idataidx_ | 6:inumbps | 7:ibplen | 8:igain | 9:ichan | 10:ipos | 11:ifadein | 12:ifadeout | 13:ipchintrp_ | 14:ifadekind | 15 | 16 | ... |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 501.0003 𝍪 | 0.038 | 1.000 | 0 | 15 | 2 | 3 | 1 | 1 | -1 | 0.02 | 0.02 | 0 | 1 | 0 | ... |
\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T15:17:29.603.wav\", 2 channels, 1.02 secs, 44100 Hz)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T15:17:32.545.wav\", 1 channels, 6.60 secs, 44100 Hz)4D:1♩3B+:1♩\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T15:17:35.930.wav\", 1 channels, 2.52 secs, 44100 Hz)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T15:17:37.246.wav\", 1 channels, 1.69 secs, 44100 Hz)Chain([4C:0.5♩, 4C>:0.5♩, 4C#:0.5♩, 4D+:0.5♩, 4D#:0.5♩, 4G+27:0.5♩], dur=3)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T15:17:38.521.wav\", 1 channels, 7.02 secs, 44100 Hz)Chain([4C:0.333♩, 4C>:0.333♩, 4C#:0.333♩, 4D+:0.333♩, 4D#:0.333♩, 4G+27:0.333♩], dur=2)Chain([4C:0.5♩, 4C:0.5♩, 4C:0.5♩, 4D:0.75♩, 4D:0.75♩, 4D:0.75♩, 4E:0.25♩, 4E:0.25♩, 4E:0.25♩], dur=4.5)4F>:1.4♩:offset=0.2:symbols=[Color(value=#0000f0), Notehead(square, size=1.3), Articulation(kind=accent)]4G:0.8♩:offset=0.2:symbols=[Notehead(slash, color=green), Articulation(kind=snappizz)]\"/home/em/dev/python/maelzel/docs/notebooks/tmp/stravinsky.ogg\", 2 channels, 4.20 secs, 44100 Hz)\"/home/em/dev/python/maelzel/docs/notebooks/tmp/tristan.ogg\", 2 channels, 4.02 secs, 44100 Hz)\"/home/em/dev/python/maelzel/docs/notebooks/tmp/chord-with-different-amplitudes.ogg\", 2 channels, 4.02 secs, 44100 Hz)‹4Eb 4G 4Bb 4♩›4G:1♩:gliss=4B\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T15:41:04.547.wav\", 1 channels, 2.02 secs, 44100 Hz)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T15:41:07.342.wav\", 1 channels, 3.55 secs, 44100 Hz)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T15:41:12.169.wav\", 1 channels, 3.15 secs, 44100 Hz)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-24T21:08:35.367.wav\", 1 channels, 4.22 secs, 44100 Hz)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T13:36:14.239.wav\", 2 channels, 7.30 secs, 44100 Hz)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-28T13:36:19.726.wav\", 2 channels, 13.00 secs, 44100 Hz)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-03T09:48:53.111.wav\", 2 channels, 7.20 secs, 44100 Hz)Chain([4C:1♩, 4D:0.5♩, 4F:2♩:offset=5], dur=7)Chain([4C:1♩, 4D:0.5♩, 4F:2♩:offset=5, Chain([4G:1♩:symbols=[Slur(kind=start, uuid=r33b92cj, linetype=solid)], 4D#:1♩:symbols=[Slur(kind=end, uuid=r33b92cj, linetype=solid)]])], dur=9, offset=2)\"/home/em/.local/share/maelzel/recordings/rec-2023-03-24T21:11:41.437.wav\", 2 channels, 5.20 secs, 44100 Hz)