<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>codehop &#187; graph</title>
	<atom:link href="https://codehop.com/tag/graph/feed/" rel="self" type="application/rss+xml" />
	<link>https://codehop.com</link>
	<description>#code #art #music</description>
	<lastBuildDate>Mon, 23 Apr 2012 18:37:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>Operators Made Easy</title>
		<link>https://codehop.com/operators-made-easy/</link>
		<comments>https://codehop.com/operators-made-easy/#comments</comments>
		<pubDate>Sat, 01 May 2010 18:36:14 +0000</pubDate>
		<dc:creator><![CDATA[Jacob Joaquin]]></dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[iterator]]></category>
		<category><![CDATA[operator overloading]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[unit generator]]></category>

		<guid isPermaLink="false">http://slipmat.noisepages.com/?p=223</guid>
		<description><![CDATA[There was something that seriously annoyed me about yesterday&#8217;s instrument graph. The use of the Multiply() and the Sum() is bothersome; I&#8217;m used to expressing this functionality in a more concise manner using the * and + operators. Download today&#8217;s &#8230; <a href="https://codehop.com/operators-made-easy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>There was something that seriously annoyed me about yesterday&#8217;s <a href="http://slipmat.noisepages.com/2010/04/instruments-simplified-with-python-decorators/">instrument graph</a>. The use of the Multiply() and the Sum() is bothersome; I&#8217;m used to expressing this functionality in a more concise manner using the * and + operators. Download today&#8217;s code <a href="http://snipt.org/Mgno">here</a>.</p>
<p>This doesn&#8217;t work for me:</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
return Multiply(Sum(a1, a2), RiseFall(dur, 0.5))
</pre>
<p>Thankfully, Python allows us to <a href="http://en.wikipedia.org/wiki/Operator_overloading">overload the operators</a>, so we can express the same line as this:</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
return (a1 + a2) * RiseFall(dur, 0.5)
</pre>
<p>Less typing, easier to read. Let&#8217;s see it in the context of @Instr MyInstr:</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
@Instr
def MyInstr(dur=1.0, amp=1.0, freq=440, tune=12):
    a1 = Sine(amp * 0.5, freq)
    a2 = Sine(amp * 0.5, freq * 2 ** (tune / 12.0))
    return (a1 + a2) * RiseFall(dur, 0.5)
</pre>
<p>Here&#8217;s how I implemented it. I started by creating a generic iterator class called UnitGenerator:</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
class UnitGenerator:
    def __init__(self): pass
    def __iter__(self): pass                 
    def next(self): raise StopIteration    
    def __add__(self, i): return Add(self, i)
    def __mul__(self, i): return Mul(self, i)
</pre>
<p>The last two lines of the class redefine __add__() and __mul__(), which control the behaviors of + and *.  These functions use the custom classes Add() and Mul().  These were originally called Sum() and Multiply(), though I renamed them to follow Python naming conventions. The last thing I had to do was alter some of the existing classes to derive from class UnitGenerator, so they automatically incorporate the overloaded operators.</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
class Instr(UnitGenerator):  ...
class IterReduce(UnitGenerator):  ...
class Mul(IterReduce):  ...
class Add(IterReduce):  ...
class RiseFall(UnitGenerator):  ...
class Sine(UnitGenerator):  ...
</pre>
<p>Classes Mul and Add are also of type UnitGenerator. They inherit for class IterReduce which inherents from UnitGenerator.</p>
]]></content:encoded>
			<wfw:commentRss>https://codehop.com/operators-made-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Realm of the Practical</title>
		<link>https://codehop.com/realm-of-the-practical/</link>
		<comments>https://codehop.com/realm-of-the-practical/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 17:45:14 +0000</pubDate>
		<dc:creator><![CDATA[Jacob Joaquin]]></dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://slipmat.noisepages.com/?p=178</guid>
		<description><![CDATA[Brain storming is easy; I can make things up without being held accountable. However, I need to spend time in the realm of the practical. I won&#8217;t stop collecting ideas, but if Slipmat is going to be a reality, I &#8230; <a href="https://codehop.com/realm-of-the-practical/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Brain storming is easy; I can make things up without being held accountable. However, I need to spend time in the realm of the practical. I won&#8217;t stop collecting ideas, but if Slipmat is going to be a reality, I need to know what the issues are. This means lots of research and lots of prototyping and lots of little scripts that test various facets of Python.</p>
<p>For example, creating a graph of Python 3 generators:</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
#!/usr/bin/env python3

import operator

ksmp = 8
foo = (i * 2 for i in range(ksmp))
foo = (i + 1 for i in foo)
bar = (11 for i in range(ksmp))
foo = map(operator.mul, foo, bar)

print(*foo)
</pre>
<p>This is interesting to me because the names foo and bar do not receive an array/collect/list of numbers. Instead, they point to generator objects. These generators are not evaluated until print(*foo) is called.</p>
<p>By the way, if my understand or terminology is ever off, please correct me. I&#8217;m also here to learn.</p>
]]></content:encoded>
			<wfw:commentRss>https://codehop.com/realm-of-the-practical/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Patching &#8212; An Early Mockup</title>
		<link>https://codehop.com/patching-an-early-mockup/</link>
		<comments>https://codehop.com/patching-an-early-mockup/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 19:04:48 +0000</pubDate>
		<dc:creator><![CDATA[Jacob Joaquin]]></dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[patching]]></category>

		<guid isPermaLink="false">http://slipmat.noisepages.com/?p=58</guid>
		<description><![CDATA[Being able to patch together units is a fundamental principle of a modular environment. Though I&#8217;m far from figuring out what the syntax should look like in my faux music language, I have been writing some mock up code just &#8230; <a href="https://codehop.com/patching-an-early-mockup/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Being able to patch together units is a fundamental principle of a modular environment. Though I&#8217;m far from figuring out what the syntax should look like in my faux music language, I have been writing some mock up code just to get a sense of it.</p>
<p>Just a warning, the following example is ignorant of i/k/a-rates, along with pass-by-reference vs pass-by-value:</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
import FX
import Master
import Mixer
from Envelope import line
from TestLibrary.Instruments import SineTone

# Create instances of objects and patch together
st = SineTone()                             # Simple sine instrument
reverb = FX.Reverb(input=st.out, time=3.1)  # Reverb unit
mix = Mixer.pan(0, st.out, reverb.out)      # Dry/wet: value, sig 1, sig 2
output = Master.DAC(mix)                    # Main output

# Score
@0 turnon(reverb, mix, output)  # Turn on selected instances

@0 st.play(20, 1, 440)        # Play for 20 seconds, amp = 1, frequency = 440
@0 st.amp *= line(0, 10, 1)   # Amplitude rise
@10 st.amp *= line(1, 10, 0)  # Amplitude fall
@20 mix.pan = line(1, 20, 0)  # Dry to wet over 20 seconds

@10 reverb.time += line(0, 5, 8.1)  # Increase reverb time starting at 10
@20:
    @reverb.time turnoff(reverb, mix, output)  # Turnoff selected instances
</pre>
<p>The import section loads classes from existing instrument/unit generator libraries.</p>
<p>In the orchestra, instances are created from the imported classes, and patched together into a simple instrument graph.  There&#8217;s a simple sine instrument, which is plugged into a reverb unit. Next, there is the pan mixer, which has the dry sine instrument plugged into one side, and the wet reverb signal plugged into the other; It is initially set to 100% dry. The pan mixer is then patched into the output, which sends the audio to the DAC.</p>
<p>The first line in the score turns on three instruments: reverb, mix and output. There will be times when the duration is unknown. The ability to start and stop machines is a must.</p>
<p>The sine instrument starts with a duration of 20, an amplitude of 1 and a frequency of 440. The amplitude of the sine is modulated by two envelopes, creating a rise/fall shape. Line envelopes also modulate the dry/wet mixer and reverb time.</p>
<p>At the end, the turnoff function shuts down reverb, mix and output.</p>
<p><strong>Bonus round:</strong> Why do you suppose I wrote,</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
@20:
    @reverb.time turnoff(reverb, mix, output)  # Turnoff selected instances
</pre>
<p>instead of this?</p>
<pre style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 1.2em; padding-bottom: 16px">
@(20 + reverb.time) turnoff(reverb, mix, output)  # Turnoff selected instances
</pre>
]]></content:encoded>
			<wfw:commentRss>https://codehop.com/patching-an-early-mockup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Not Zork</title>
		<link>https://codehop.com/not-zork/</link>
		<comments>https://codehop.com/not-zork/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 17:28:06 +0000</pubDate>
		<dc:creator><![CDATA[Jacob Joaquin]]></dc:creator>
				<category><![CDATA[the cosmos]]></category>
		<category><![CDATA[csound]]></category>
		<category><![CDATA[drummachine]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[infocom]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[paper]]></category>
		<category><![CDATA[sketch]]></category>
		<category><![CDATA[zork]]></category>

		<guid isPermaLink="false">http://www.thumbuki.com/20080216/not-zork.html</guid>
		<description><![CDATA[Though this may look like a map to an Infocom text adventure, it is a sketch of the dseq drum machine micro-language interpreter, as implemented in Csound. Flickr Photo by me.]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/thumbuki/2269462934/" title="Not Zork by thumbuki, on Flickr"><img src="http://farm3.static.flickr.com/2080/2269462934_aa253c641a.jpg" width="500" height="375" alt="Not Zork" title="Not Zork" /></a></p>
<p>Though this may look like a map to an <a href="http://en.wikipedia.org/wiki/Infocom">Infocom</a> text adventure, it is a sketch of the dseq drum machine micro-language interpreter, as implemented in <a href="http://www.csounds.com/">Csound</a>.</p>
<p><a href="http://flickr.com/photos/thumbuki/2269462934/">Flickr Photo</a> by <a href="http://flickr.com/photos/thumbuki/">me</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://codehop.com/not-zork/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big Briar Etherwave Waveforms</title>
		<link>https://codehop.com/big-briar-etherwave-waveforms/</link>
		<comments>https://codehop.com/big-briar-etherwave-waveforms/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 17:58:02 +0000</pubDate>
		<dc:creator><![CDATA[Jacob Joaquin]]></dc:creator>
				<category><![CDATA[the cosmos]]></category>
		<category><![CDATA[bigbriar]]></category>
		<category><![CDATA[csound]]></category>
		<category><![CDATA[emulate]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[moog]]></category>
		<category><![CDATA[theremin]]></category>
		<category><![CDATA[waveform]]></category>

		<guid isPermaLink="false">http://www.thumbuki.com/20080116/big-briar-etherwave-waveforms.html</guid>
		<description><![CDATA[click for full size There is currently a discussion on the Csound mailing list about how to emulate a theremin waveform. I put together this chart that displays the output from the Big Briar Etherwave with various settings. As some &#8230; <a href="https://codehop.com/big-briar-etherwave-waveforms/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="postimage" class="right" style="width: 322px"><a href="http://www.thumbuki.com/images/fullsize/BigBriarEtherwaveWaveforms.gif"><img src="http://www.thumbuki.com/images/BigBriarEtherwaveWaveforms.jpg" width="320px" height="146px" alt="Big Briar Etherwave Waveforms" title="Big Briar Etherwave Waveforms" /></a>
<p><a href="http://www.thumbuki.com/images/fullsize/BigBriarEtherwaveWaveforms.gif">click for full size</a></p>
</div>
<p>There is currently a <a href="http://www.nabble.com/Theremin-sound-to14875977.html">discussion</a> on the Csound mailing list about how to emulate a <a href="http://en.wikipedia.org/wiki/Theremin">theremin</a> waveform.  I put together this chart that displays the output from the <a href="http://www.bigbriar.com/detail.php?main_product_id=14">Big Briar Etherwave</a> with various settings. As some of you already know, <a href="http://www.bigbriar.com/">Big Briar</a> is <a href="http://www.moogmusic.com/">Moog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://codehop.com/big-briar-etherwave-waveforms/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
