<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<chapter name="Video and Graphics 3: Control Jitter with Messages">

<previous name="jitterchapter00d_Live Capture">Live Capture</previous>
<next name="jitterchapter00f_Adding 3D Objects">Adding 3D Objects</next>
<parent name="jitindex">Jitter Tutorials</parent>

<openfile name="Live Capture" patch="jitter_core_-_3_-_control_jitter.maxpat"/>

<h1>Video and Graphics Tutorial 3: Control Jitter with Messages</h1>



<h2>Intro</h2>



<p>Messages are essential for controlling Jitter objects. We saw a little of that with <o>jit.movie</o> and <o>jit.grab</o>. In this tutorial, we’ll look at how to take control of Jitter effects with simple messages.
</p>

<h2>Setup</h2>

<p>We'll start where we left off in the last tutorial - a patch containing <o>jit.grab</o>, <o>jit.brcosa</o> and <o>jit.world</o> objects.</p>

<illustration><img src="images/jitter_core - 3a.png"/></illustration>

<h2>Adding Objects</h2>

<p>Now let’s add a few additional effects. Create a <o>jit.fluoride</o> and a <o>jit.slide</o> object below the <o>jit.brcosa</o>, and connect the new objects to the outlet of <o>jit.brcosa</o> and the inlet of  <o>jit.world</o>. </p>

<illustration><img src="images/jitter_core - 3b.png"/></illustration>

<p>Next, create some <o>attrui</o> objects for each effect. The <o>jit.slide</o> only needs two (<i>slide_up</i> and <i>slide_down</i>), while <o>jit.fluoride</o> will require 4 object-specific attributes (<i>glow</i>, <i>lum</i>, <i>mode</i> and <i>tol</i>). </p>

<h2>Messages</h2>

<p>While <o>attrui</o> objects are great for quick exploration, they have some limitations when it comes to sharing data with other objects and - more importantly - state saving using snapshots and the pattr system (which we'll want to do later on). For more robust control, we’ll look at how to construct <i>messages</i> to control objects.</p>

<p>We'll start by creating standard messages that duplicate the way that <o>attrui</o> objects let us control the <o>jit.brcosa</o> object. Most messages to Jitter objects consist of a list starting with the attribute name followed by the value(s) you want to set the attribute <i>to</i>. Create a new <o>message</o> box that contains the message <m>brightness $1</m>. Next add a floating point number box (<o>flonum</o>) and connect its outlet to the left inlet of the <o>message</o> box. In turn, connect the outlet of the <o>message</o> box to the inlet of  <o>jit.brcosa</o>.</p>


<illustration><img src="images/jitter_core - 3d.png"/></illustration>


<p>The <m>$1</m> part of the message acts as a variable and tells the <o>message</o> box to accept an incoming value in its place.</p>

<p>Repeat the process for the contrast and saturation attributes. </p>

<p>Next we’ll add some control messages for <o>jit.fluoride</o>. However, note that the <i>glow</i> attribute has <b>three</b> values (red, green, and blue). For this attribute, we need to put together a list of those red, green and blue values using a <o>pak</o> object. Make a new <o>pak</o> object with three floating point arguments. These can be any value, but the values we give will also act as defaults - so a <b>pak 0. 0. 0.</b> would default to black. Add and connect three <o>flonum</o> objects - one for each input of the <o>pak</o> object - and connect your <o>pak</o> object to a <o>message</o> box containing the message <m>glow $1 $2 $3</m>. Connect the <o>message</o> box outlet to the inlet of <o>jit.fluoride</o>.</p>


<illustration><img src="images/jitter_core - 3f.png"/></illustration>


<p>If you don’t like making color decisions based on number values, you can use the <o>swatch</o> object instead. Make a <o>swatch</o> object and connect it to an <o>unpack</o> object with the arguments <b>0. 0. 0.</b> Connect the three outlets of the <o>unpack</o> object to the three <o>flonum</o> objects. Now, you can easily select the color you want by moving the swatch cursor and also see the numerical values associated with the color you choose.</p>


<illustration><img src="images/jitter_core - 3g.png"/></illustration>

<p>Continue to convert the remaining <o>attrui</o> objects into messages, then adjust the values to see your messages in action.</p>




<div>
	<techdetail>

		<h2>Explore Further</h2>

		<p>You may want to go back and review some of the basic Max message and list tutorials as you go to get more ideas of how to control Jitter objects. Try driving object parameters with random number generators, counters, and other data sources (you’ll probably need to do some number scaling to get things into the right range).</p>


	</techdetail>
</div>





</chapter>
