Debian Codegraph @

docs/gettingstarted.html

raw
1
2 <!DOCTYPE html>
3
4 <html lang="en">
5 <head>
6 <meta charset="utf-8"/>
7 <meta content="width=device-width, initial-scale=1.0" name="viewport"/><meta content="Docutils 0.17.1: http://docutils.sourceforge.net/" name="generator"/>
8 <title>Getting started — Pyo 1.0.5 documentation</title>
9 <link href="_static/pygments.css" rel="stylesheet" type="text/css"/>
10 <link href="_static/agogo.css" rel="stylesheet" type="text/css"/>
11 <link href="_static/sphinx-codeautolink.css" rel="stylesheet" type="text/css"/>
12 <link href="_static/autoclasstoc.css" rel="stylesheet" type="text/css"/>
13 <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
14 <script src="_static/jquery.js"></script>
15 <script src="_static/underscore.js"></script>
16 <script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
17 <script src="_static/doctools.js"></script>
18 <script src="_static/sphinx_highlight.js"></script>
19 <link href="_static/E-PyoIcon.ico" rel="shortcut icon"/>
20 <link href="about.html" rel="author" title="About these documents"/>
21 <link href="genindex.html" rel="index" title="Index"/>
22 <link href="search.html" rel="search" title="Search"/>
23 <link href="winaudioinspect.html" rel="next" title="Configuring the audio output (Windows)"/>
24 <link href="structure.html" rel="prev" title="Structure of the library"/>
25 </head><body>
26 <div class="header-wrapper" role="banner">
27 <div class="header">
28 <div class="headertitle"><a href="index.html">Pyo 1.0.5 documentation</a></div>
29 <div aria-label="related navigation" class="rel" role="navigation">
30 <a accesskey="P" href="structure.html" title="Structure of the library">previous</a> |
31 <a accesskey="N" href="winaudioinspect.html" title="Configuring the audio output (Windows)">next</a> |
32 <a accesskey="I" href="genindex.html" title="General Index">index</a>
33 </div>
34 </div>
35 </div>
36 <div class="content-wrapper">
37 <div class="content">
38 <div class="sidebar">
39 <h3>Table of Contents</h3>
40 <ul class="current">
41 <li class="toctree-l1"><a class="reference internal" href="about.html">About pyo</a></li>
42 <li class="toctree-l1"><a class="reference internal" href="download.html">Installing pyo with pip</a></li>
43 <li class="toctree-l1"><a class="reference internal" href="compiling.html">Compiling pyo from sources</a></li>
44 <li class="toctree-l1"><a class="reference internal" href="structure.html">Structure of the library</a></li>
45 <li class="toctree-l1 current"><a class="current reference internal" href="#">Getting started</a></li>
46 <li class="toctree-l1"><a class="reference internal" href="winaudioinspect.html">Configuring the audio output (Windows)</a></li>
47 <li class="toctree-l1"><a class="reference internal" href="perftips.html">Improve performance of pyo programs</a></li>
48 </ul>
49 <ul>
50 <li class="toctree-l1"><a class="reference internal" href="api/index.html">API documentation</a></li>
51 <li class="toctree-l1"><a class="reference internal" href="examples/index.html">Examples</a></li>
52 <li class="toctree-l1"><a class="reference internal" href="tutorials/index.html">Advanced tutorials</a></li>
53 </ul>
54 <div role="search">
55 <h3 style="margin-top: 1.5em;">Search</h3>
56 <form action="search.html" class="search" method="get">
57 <input name="q" type="text"/>
58 <input type="submit" value="Go"/>
59 </form>
60 </div>
61 </div>
62 <div class="document">
63 <div class="documentwrapper">
64 <div class="bodywrapper">
65 <div class="body" role="main">
66 <section id="getting-started">
67 <h1>Getting started<a class="headerlink" href="#getting-started" title="Permalink to this heading">¶</a></h1>
68 <p>Here is quick introduction to Pyo. It assumes you already know Python and
69 basics about OOP (Object-Oriented Programming).</p>
70 <section id="the-pyo-server-and-gui">
71 <h2>The Pyo Server and GUI<a class="headerlink" href="#the-pyo-server-and-gui" title="Permalink to this heading">¶</a></h2>
72 <p>The first thing you need to do to use Pyo is import the pyo python module and
73 boot the server. This audio server will open audio and midi interfaces and
74 will be ready to send to them the audio and MIDI produced by other pyo objects.
75 You then need to make some sound:</p>
76 <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
77 <span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">()</span><span class="o">.</span><span class="n">boot</span><span class="p">()</span>
78 <span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
79 <span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="n">mul</span><span class="o">=</span><span class="mf">0.01</span><span class="p">)</span><span class="o">.</span><span class="n">out</span><span class="p">()</span>
80 </pre></div>
81 </div>
82 <p>The <cite>s</cite> variable holds the Server instance, which has been booted, using the
83 boot function. Booting the server includes opening audio and MIDI interfaces,
84 and setting up the sample rate and number of channels, but the server will
85 not be processing audio until its start() method is called. Then we create a
86 Sine object, and store it in variable a, after calling its out method. The
87 Sine class defines a Sine wave oscillator. The out method from this class
88 connects the output of the oscillator to the server audio outputs. I have
89 set the mul attribute of the Sine object to make sure you don’t blow your
90 ears when you play this, as the default amplitude multiplier is 1, i.e. a
91 sine wave at the maximum amplitude before clipping! (But I’ll talk about
92 attributes later…) You can stop the server with:</p>
93 <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
94 </pre></div>
95 </div>
96 </section>
97 <section id="to-interact-or-not-to-interact">
98 <h2>To interact or not to interact<a class="headerlink" href="#to-interact-or-not-to-interact" title="Permalink to this heading">¶</a></h2>
99 <p>If you tried the above script from an interactive python shell you would have
100 heard a sine tone, but if you ran it from a python script non-interactively,
101 you are probably asking yourself why you haven’t heard anything. The reason
102 is that the script has finished before the server has sent any audio to the
103 outputs! So if you are using python non-interactively, the way to hear this
104 example is:</p>
105 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
106 <span class="n">s</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">()</span><span class="o">.</span><span class="n">boot</span><span class="p">()</span>
107 <span class="n">s</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
108 <span class="n">a</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="n">mul</span><span class="o">=</span><span class="mf">0.01</span><span class="p">)</span><span class="o">.</span><span class="n">out</span><span class="p">()</span>
109 <span class="n">s</span><span class="o">.</span><span class="n">gui</span><span class="p">(</span><span class="nb">locals</span><span class="p">())</span>
110 </pre></div>
111 </div>
112 <p>In the last line, you can see a very handy method from the Server class,
113 which creates a small control GUI for the current instance. The gui method
114 for the Server object, keeps a script running and allows you to start and
115 stop the server, control the output volume and record to an audio file the
116 sound generated in the server. A handy feature of the server GUI is the
117 interpreter text box in the bottom. From it you can send commands
118 interactively to the interpreter, to start and stop objects, create or
119 destroy them, etc.</p>
120 </section>
121 <section id="changing-object-characteristics">
122 <h2>Changing Object Characteristics<a class="headerlink" href="#changing-object-characteristics" title="Permalink to this heading">¶</a></h2>
123 <p>The Sine class constructor is defined as:</p>
124 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">freq</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="n">phase</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">mul</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">add</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
125 </pre></div>
126 </div>
127 <p>So you can give it a frequency, starting phase, multiplier and DC offset
128 value when you create it. Also, if you want to do without the server gui,
129 you can use the server method start() from your script, but you might need
130 to use the sleep function from the time module to have your script run the
131 server for a while if you are running Python non-interactively:</p>
132 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
133 <span class="kn">import</span> <span class="nn">time</span>
134 <span class="n">s</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">()</span><span class="o">.</span><span class="n">boot</span><span class="p">()</span>
135 <span class="n">a</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="mi">440</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">)</span><span class="o">.</span><span class="n">out</span><span class="p">()</span>
136 <span class="n">s</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
137 <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
138 <span class="n">s</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
139 </pre></div>
140 </div>
141 <p>Notice that you can set the parameters for Sine in the order in which they
142 are defined, but you can also give the parameters a name if you want to leave
143 the rest at their default:</p>
144 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">a</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="n">mul</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span><span class="o">.</span><span class="n">out</span><span class="p">()</span>
145 </pre></div>
146 </div>
147 <p>Once the object has been created, you can modify its attributes using the
148 access methods. For example, to modify the frequency of the a oscillator
149 object after it has been created you can use:</p>
150 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">a</span><span class="o">.</span><span class="n">setFreq</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span>
151 </pre></div>
152 </div>
153 <p>But you can also set the attributes directly:</p>
154 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">a</span><span class="o">.</span><span class="n">freq</span> <span class="o">=</span> <span class="mi">1000</span>
155 </pre></div>
156 </div>
157 </section>
158 <section id="chaining-objects">
159 <h2>Chaining objects<a class="headerlink" href="#chaining-objects" title="Permalink to this heading">¶</a></h2>
160 <p>Oscillators like the Sine class can be used as inputs to other classes, for
161 example for frequency modulation:</p>
162 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
163 <span class="n">s</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">()</span><span class="o">.</span><span class="n">boot</span><span class="p">()</span>
164 <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">mod</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="n">freq</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span> <span class="n">mul</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
165 <span class="n">a</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="n">freq</span><span class="o">=</span><a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">mod</span></a> <span class="o">+</span> <span class="mi">440</span><span class="p">,</span> <span class="n">mul</span><span class="o">=</span><span class="mf">0.1</span><span class="p">)</span><span class="o">.</span><span class="n">out</span><span class="p">()</span>
166 <span class="n">s</span><span class="o">.</span><span class="n">gui</span><span class="p">(</span><span class="nb">locals</span><span class="p">())</span>
167 </pre></div>
168 </div>
169 <p>You can create an envelope for a sine wave like this:</p>
170 <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
171 <span class="n">s</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/server.html#pyo.Server" title="pyo.lib.server.Server"><span class="n">Server</span></a><span class="p">()</span><span class="o">.</span><span class="n">boot</span><span class="p">()</span>
172 <a class="sphinx-codeautolink-a" href="api/classes/controls.html#pyo.Adsr" title="pyo.lib.controls.Adsr"><span class="n">f</span></a> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/controls.html#pyo.Adsr" title="pyo.lib.controls.Adsr"><span class="n">Adsr</span></a><span class="p">(</span><span class="n">attack</span><span class="o">=</span><span class="mf">.01</span><span class="p">,</span> <span class="n">decay</span><span class="o">=</span><span class="mf">.2</span><span class="p">,</span> <span class="n">sustain</span><span class="o">=</span><span class="mf">.5</span><span class="p">,</span> <span class="n">release</span><span class="o">=</span><span class="mf">.1</span><span class="p">,</span> <span class="n">dur</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">mul</span><span class="o">=</span><span class="mf">.5</span><span class="p">)</span>
173 <span class="n">a</span> <span class="o">=</span> <a class="sphinx-codeautolink-a" href="api/classes/generators.html#pyo.Sine" title="pyo.lib.generators.Sine"><span class="n">Sine</span></a><span class="p">(</span><span class="n">mul</span><span class="o">=</span><a class="sphinx-codeautolink-a" href="api/classes/controls.html#pyo.Adsr" title="pyo.lib.controls.Adsr"><span class="n">f</span></a><span class="p">)</span><span class="o">.</span><span class="n">out</span><span class="p">()</span>
174 <span class="n">f</span><span class="o">.</span><span class="n">play</span><span class="p">()</span>
175 <span class="n">s</span><span class="o">.</span><span class="n">gui</span><span class="p">(</span><span class="nb">locals</span><span class="p">())</span>
176 </pre></div>
177 </div>
178 </section>
179 <section id="class-examples">
180 <h2>Class examples<a class="headerlink" href="#class-examples" title="Permalink to this heading">¶</a></h2>
181 <p>All Classes in Pyo come with an example which shows how it can be used. To
182 execute the example you can do:</p>
183 <div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <a class="sphinx-codeautolink-a" href="api/alphabetical.html#module-pyo" title="pyo"><span class="nn">pyo</span></a> <span class="kn">import</span> <span class="o">*</span>
184 <span class="gp">&gt;&gt;&gt; </span><a class="sphinx-codeautolink-a" href="api/functions/util.html#pyo.example" title="pyo.example"><span class="n">example</span></a><span class="p">(</span><a class="sphinx-codeautolink-a" href="api/classes/effects.html#pyo.Harmonizer" title="pyo.lib.effects.Harmonizer"><span class="n">Harmonizer</span></a><span class="p">)</span>
185 </pre></div>
186 </div>
187 <p>This will show and execute the example for the Harmonizer class.</p>
188 </section>
189 </section>
190 <div class="clearer"></div>
191 </div>
192 </div>
193 </div>
194 </div>
195 <div class="clearer"></div>
196 </div>
197 </div>
198 <div class="footer-wrapper">
199 <div class="footer">
200 <div class="left">
201 <div aria-label="related navigaton" role="navigation">
202 <a href="structure.html" title="Structure of the library">previous</a> |
203 <a href="winaudioinspect.html" title="Configuring the audio output (Windows)">next</a> |
204 <a href="genindex.html" title="General Index">index</a>
205 </div>
206 <div aria-label="source link" role="note">
207 </div>
208 </div>
209 <div class="right">
210 <div class="footer" role="contentinfo">
211 © Copyright 2021, Olivier Bélanger.
212 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
213 </div>
214 </div>
215 <div class="clearer"></div>
216 </div>
217 </div>
218 </body>
219 </html>