From 727d8e4edee88fce730159b01c8022138af531f4 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Fri, 10 Nov 2023 21:31:45 +0000 Subject: [PATCH] Add example notebooks --- .gitignore | 1 - examples/notebooks/01. Hello World.ipynb | 85 ++++++++++++++++++++++ examples/notebooks/02. Patch Example.ipynb | 73 +++++++++++++++++++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 examples/notebooks/01. Hello World.ipynb create mode 100644 examples/notebooks/02. Patch Example.ipynb diff --git a/.gitignore b/.gitignore index d80e7892..e78446fd 100644 --- a/.gitignore +++ b/.gitignore @@ -29,5 +29,4 @@ dist .cmake-* .coverage .ipynb_checkpoints -notebooks/ wheelhouse/ diff --git a/examples/notebooks/01. Hello World.ipynb b/examples/notebooks/01. Hello World.ipynb new file mode 100644 index 00000000..47807853 --- /dev/null +++ b/examples/notebooks/01. Hello World.ipynb @@ -0,0 +1,85 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from signalflow import *" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#--------------------------------------------------------------------------------\n", + "# Create and start the global processing graph\n", + "#--------------------------------------------------------------------------------\n", + "graph = AudioGraph()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#--------------------------------------------------------------------------------\n", + "# Create a stereo sine wave\n", + "#--------------------------------------------------------------------------------\n", + "sine = SineOscillator(440)\n", + "stereo = StereoPanner(sine, 0.0)\n", + "output = sine * 0.1\n", + "output.play()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#--------------------------------------------------------------------------------\n", + "# Change the frequency\n", + "#--------------------------------------------------------------------------------\n", + "sine.frequency = 880" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#--------------------------------------------------------------------------------\n", + "# Stop playback\n", + "#--------------------------------------------------------------------------------\n", + "output.stop()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/notebooks/02. Patch Example.ipynb b/examples/notebooks/02. Patch Example.ipynb new file mode 100644 index 00000000..86d4425f --- /dev/null +++ b/examples/notebooks/02. Patch Example.ipynb @@ -0,0 +1,73 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from signalflow import *" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "graph = AudioGraph()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "class Ping (Patch):\n", + " def __init__(self, frequency=440):\n", + " #--------------------------------------------------------------------------------\n", + " # It's vital to call the super().__init__ function to properly create the patch.\n", + " #--------------------------------------------------------------------------------\n", + " super().__init__()\n", + " frequency = self.add_input(\"frequency\", frequency)\n", + " square = SquareOscillator([frequency, frequency * 1.01])\n", + " lowpass = SVFilter(square, \"low_pass\", Line(frequency, frequency / 4, 0.1))\n", + " envelope = ASREnvelope(0.0, 0.0, 0.5)\n", + " output = lowpass * envelope * 0.1\n", + " self.set_output(output)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ping = Ping(frequency=440)\n", + "ping.play()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}