<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"
xmlns:ns1="" xmlns:ns0="urn:schemas-microsoft-com:office:smarttags">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
        {font-family:Verdana;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"\@MS Mincho";
        panose-1:2 2 6 9 4 2 5 8 3 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p.MsoAutoSig, li.MsoAutoSig, div.MsoAutoSig
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
p
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Currently, if a shred terminates, all of its child shreds
get terminated as well.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>This raises the following interesting question: why? <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Honestly, from a user&#8217;s perspective, I can&#8217;t
think of a compelling use of this feature. Whether there are internal implementation
issues that motivate this feature or not is a separate question, I guess; but I
can&#8217;t really think of a good reason to terminate child shreds from an
implementation perspective, either. (Unless you&#8217;re relying on shred
termination to garbage collect).<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>On the other hand, I can think of very compelling reasons
why shreds should not outlive their parents. <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I&#8217;ve been bitten by this several times &#8211; by shreds
silently being terminated because parent shreds have terminated.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Here&#8217;s my compelling use case <i><span
style='font-style:italic'>for </span></i>allowing shreds to outlive their
parents.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>I spent the weekend playing with chuck. With audio languages
(CSound, SAOL, Music-N, &amp;c), one of the constant challenges is how to
provide clean and modular integration between expensive control-rate
operations, fast audio-rate operations, and external events.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Having had exposure to MusicN based languages that provide
control-rate processing, I thought I&#8217;d try using the control concept in
chuck. <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Here&#8217;s the theory: write an IInstrument abstract class
that provides an abstract Tick() method which gets called at control-rate. Output
of the instrument is placed on the Instrument.Out ugen so that instruments can
then be routed onto an external output. Implementations of IInstrument then
call (for example)&nbsp; StartTick(16::samp), which causes the Tick method to
be called every 16 samples on a separate shred. This works very well. The end
result: an AnalogSynth class, implementing IInstrument, that provides two two control-rate
lfos, two control-rate envelopes, one band-limited oscillator ugen (private
build coming to a Chuck near you soon) and a filter ugen. AnalogSynth runs
about 12 voices in realtime on my lowly 800Mhz home machine, without any real attention
to optimization! So far so good. &nbsp;The purpose of the Tick() processing
is,of course, to run the LFOs and ADSrs at reduced rate (every 16 samples), and
then perform all of the expensive routing of lfos and ADSrs outputs onto UGens at
something less than audio rate. <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Well. It does work very well, as long as I drive the
IInstrument from midi or OSC input. It fails spectacularly if notes are
triggered from temporary shreds when writing scores in Chuck. Consider the
following: <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>function void PlayNote(IInstrument instr,
float midNote, dur length)<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>{<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instr.NoteOn(midiNote,1.0);<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; length
=&gt; now;<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; instr.NoteOff(midiNote);<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>}<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>spork ~ PlayNote(analogSynth,
Midi.C4, 1.5::beat);<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>This fails, spectacularly. Internally, the Tick shred gets
started up, but it shuts down as soon as the PlayNote shred terminates (causing
the note to get stuck).<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>In retrospect, I guess the answer is to create a tick shred
at the time the instrument is created, and then use events to synchronize the
tick shred. But that&#8217;s just so&#8230; so&#8230; inconvenient. Or another
approach: make PlayNote wait forever, after the note off. But that&#8217;s just
so&#8230; so&#8230;. ugly. Hmm. Or maybe a WaitForAllChildThreadsToDie()
function. <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>The event solution also runs into significant problems with
controlling the first tick after startup. Consider: An IInstrument receives a
note-on event. It initializes all of it&#8217;s control rate state variables
(reseting ADSRs, for example). Now it needs to start the tick shred up. So it
signals an event. The question is this: will the tick shred run in the current
cycle or not? If it doesn&#8217;t then StartTick() should call IInstrument.Tick().
But whether the shred ran in the current thread or not is non-deterministic. It
depends on whether the shreduler ran the current thread or the tick thread first
for the current value of Now. Even worse. The tick shred can no longer perform &#8220;16::samp
=&gt; now&#8221;, because the noteon event may have arrived at some
non-modulo-8 mutiple of now::samp. So this approach requires complicated and
expensive handshaking between the Instrument and its tick thread to get
everything lined up and operating deterministically. (&lt;thinking&gt;&#8230;
this is doable, and probably the way I&#8217;ll go)<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Or another use-case for the same:<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>function void PlayTheWholeSong() <o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>{<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Spork
~ PlayBassMotif1();<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Spork
~ PlayMelody1();<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 12::beat
=&gt; now;<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Spork
~ PlayBassMotif1();<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Spork
~ PlayMelody2();<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
oops. No more bass motif or melody shred.<o:p></o:p></span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>} <o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>The feature request; maybe a way to let shreds re-assign
their parent shred to the root shred. That would be nice. Or maybe just don&#8217;t
terminate child shreds at all.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoAutoSig><b><font size=2 face=Verdana><span style='font-size:10.0pt;
font-family:Verdana;font-weight:bold'><ns0:PersonName w:insAuthor="Robin Davies"
 w:insDate="2005-09-06T11:46:00Z" w:endInsAuthor="Robin Davies"
 w:endInsDate="2005-09-06T11:46:00Z"
 ns1:style="BACKGROUND-POSITION: left bottom; BACKGROUND-IMAGE: url(res://ietag.dll/#34/#1001); BACKGROUND-REPEAT: repeat-x"
 ns1:tabIndex="0">Robin Davies<br>
</ns0:PersonName></span></font></b><font size=1 face=Verdana><span
style='font-size:8.0pt;font-family:Verdana'>Lead Software Developer<br>
Quest Web Reports<br>
<font color=black><span style='color:black'>Quest Software<br>
</span></font>613.270.1569<o:p></o:p></span></font></p>

<p style='margin:0in;margin-bottom:.0001pt'><i><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial;font-style:italic'>&nbsp;<o:p></o:p></span></font></i></p>

<p class=MsoNormal><a name="OLE_LINK2"></a><a name="OLE_LINK1"></a><i><font
size=2 face=Arial><span style='font-size:10.0pt;font-family:Arial;font-style:
italic'><a href="http://wm.quest.com/reg/marketing/landing/identitymanagement/"
title="http://wm.quest.com/reg/marketing/landing/identitymanagement/"><font
size=3 face="Times New Roman"><span style='font-size:12.0pt;font-family:"Times New Roman"'>Identity
Management for the Windows Enterprise</span></font></a>: See how Quest helps
you leverage your existing investment to solve the identity management
challenge!<o:p></o:p></span></font></i></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

</div>

</body>

</html>