<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<chapter name="Max Data Tutorial 1: Data Viewing">

<setdocpatch name="01dDataViewing" patch="01dDataViewing.maxpat"/>
<previous name="midichapter05">Advanced Sequencing</previous>
<next name="datachapter02">Data Scaling</next>
<parent name="00_maxindex">Max Tutorials</parent>

<indexinfo category="Data" title="Data Viewing">Visualizing data streams</indexinfo>

<h1>Data Tutorial 1: Data Viewing</h1>

<h2>Introduction</h2>

<p>This tutorial will examine different techniques for creating and viewing streams of numeric data in the Max environment.  We will look at the <o>multislider</o> object, which has modes for both <i>creating</i> and <i>monitoring</i> data values.  We will also look at monitor <b>Watchpoints</b>, a debugging tool that you can use to view the messages running through patch cords as they are being generated.</p>

<p>When working with a modular system like Max, it is sometimes difficult to keep track of all of the messages that are being sent between objects. Using the available tools for monitoring messages and values can help you fine tune a patch, or to track down problems in a patch’s operation. The two tools we will use – <o>multislider</o> objects and watchpoints – provide two different mechanisms for tracking data: <o>multislider</o> is a good option for runtime (performance) monitoring, while watchpoints are valuable during programming and debugging.</p>

<p>To open the tutorial patch, click on the <b>Open Tutorial</b> button in the upper right-hand corner of the documentation window.</p>

<h2><o>multislider</o> as a data generator</h2>

<p>Take a look at our tutorial. This patch contains a lot of objects that display and generate different types of graphs - in fact, they are all versions of the same object, a <o>multislider</o>. We will start with the patch labeled <b>1</b>, which contains a <o>counter</o> that will step through the various sliders of the <o>multislider</o>, and produce a note for each step using MIDI.  The output of the <o>multislider</o> is between <m>0</m> and <m>127</m> (the standard MIDI note range), and provides <m>16</m> steps of sequenced data.  If you turn on the <o>metro</o> with the <o>toggle</o>, you will see the step number being generated by the <o>counter</o> object, <o>prepend</o>ed with the <m>fetch</m> message, and used to query the sixteen sliders in the <o>multislider</o>.  This is the basis for most step-sequencing patches, with either auto-generated contents (which is what the <o>uzi</o>-and-<o>drunk</o>-based section of the patch does), or by directly manipulating the individual sliders in the object.</p>

<p>The right output of the <o>multislider</o> is used for this application.  When used as a <i>bank</i> of sliders (meaning that the <m>Slider Style</m> attribute is set to either <m>Thin Line</m> or <m>Bar</m>), the <i>left</i> outlet will send all of the slider values as a single list, and only when a <m>bang</m> message or complete new dataset is received.  The <m>fetch</m> message sends the value of an individual slider (numbered starting at <m>1</m>) out the right outlet.</p>

<p>Take a look at the <o>multislider</o> object's <b>Inspector</b> and note the different settings.  Our object has a set of colors selected and <m>4</m> levels of alternating "candycane" colors selected.  If you lock the patcher and draw in the <o>multislider</o>, you can change the melody that plays in the sequence.  Clicking the <o>button</o> object connected to the <o>uzi</o> will generate a new drunken melody.</p>

<h2><o>multislider</o> for data viewing</h2>

<p>Now look at the patcher area labeled <b>2</b>, which is a monitoring patch for our mouse.  Start the <o>metro</o> at the top of the patch with the <o>toggle</o>, then move your mouse around the screen.  You will see that the two drawing areas on the top track the current X and Y mouse locations (output by our <m>WTHITM</m> abstraction), while the larger graph area at the bottom displays a four-line running display, scaled and modified by the logic above it.</p>

<p>In previous tutorials, we’ve used the <o>lcd</o> object for drawing our tracking information in creative ways.  However, in this case, we are using the <o>multislider</o> object instead.  The most common use for <o>multislider</o> is as a bank of sliders, but it has a few modes that are useful for displaying a stream of data.  These modes are listed as options for the <m>Slider Style</m> attribute (in the inspector); they are the <m>Scroll</m> options, which accept incoming values, append them to the end of the displayed data, then scroll the display to make them visible.  It provides a simple interface that is similar to the scrolling graphical displays commonly seen on electronic test equipment.</p>

<p>The two smaller <o>multislider</o> objects at the top of the patch display the data coming from our <m>WTHITM</m> abstraction (which we used in earlier tutorials) – turning our scaled mouse movements into numbers ranging from <m>0.0</m> to <m>1.0</m>. This value goes into the <o>multislider</o> (to be displayed), then is output from the <o>multislider</o> into a bit of patching that produces four values from that data (the X position, the Y position, and a pair of <i>polar</i> coordinates for the distance and angle of the mouse from the center of the screen).  This is sent into the lower <o>multislider</o>, which is both graphically jarring (red on green!) and peculiar in its display: it shows four data streams simultaneously.</p>

<p>Attempting to do something like this in an <o>lcd</o> object would be very difficult, but to accomplish a multiline display in a <o>multislider</o> is a simple matter of saying that there are four sliders, setting the display range (in this case, from <m>-1.0</m> to <m>1.0</m>), and letting the object work its magic.  In this case, the X and Y coordinates of the mouse are used to create four different data streams, each displayed in its own section of the graphic.</p>

<h2>Watching data streams with Watchpoints</h2>

<p>While the <o>multislider</o> is useful for displaying numeric data streams, Max has a number of built-in systems for monitoring data as well.  If you already have a screen full of objects and patch cords, you probably wouldn’t want to use the onscreen real estate for a large graphic display like a <o>multislider</o>.  And if the data is being generated too quickly, or from too many locations, you may not want to <o>print</o> things to the Max Console either.  What is a better option?  Watchpoints!</p>

<p>A <b>Watchpoint</b> is an attachment that you make to a patch cord that allows you to view the messages it carries without having to change your patch.  If you right-click on a patch cord and bring up the <i>patchcord menu</i>, there are two Watchpoint options: “Add Watchpoint – Monitor” and “Add Watchpoint – Break”.  The first option sets a watchpoint that allows you to monitor the message values, while the second will force the patch to stop running when ever a message is seen on the selected patch cord - we used this in a previous tutorial to look at message order.  Let’s watch some values run through the patch cords.</p>

<p>You can manage and view the watchpoints by selecting <b>Watchpoints</b> from the <b>Debug</b> menu. This brings up a window with one row for each watchpoint (identified by the colored and numbered circles on the patch cords). If you start the <o>metro</o> object in one of the patch sections using the <o>toggle</o> objects, you will begin generating messages – and you will see the results in the Watchpoints window. Both the window and the columns are resizable, so if you need to see more data than is visible, you can make the window larger or the columns wider.  You will probably need to increase the size of the <i>Value</i> column to see all of the values for watchpoint <b>3</b> – you can widen it by selecting the header separator between the Value and Count columns and moving it to the right.</p>

<p>The columns in the Watchpoints window are mostly self-explanatory:<br/>
-	The first column shows the watchpoint <b>identifier</b>.<br/>
-	The second column displays the <b>type</b> of action assigned to the watchpoint.<br/>
-	The third column displays the <b>class</b> of the object sending the message.<br/>
-	The fourth column shows the <b>name</b> of the subpatcher containing the watchpoint (or is blank if it is on the main patch).<br/>
-	The fifth column displays the <b>value</b> or values associated with the last received message.<br/>
-	The sixth column displays the <b>count</b> of messages received by this watchpoint.<br/>
-	The seventh (and final) column shows a <b>history</b> of the last three values seen at this watchpoint.</p>

<p>If you start patcher section <b>2</b> and move your mouse around with the Watchpoints window visible, you will see the first three watchpoints tracking your mouse movement.  The format of the window (and the location of the watchpoints) helps you quickly see that the X and Y coordinates, viewed with watchpoints <b>1</b> and <b>2</b>, are properly scaled floating-point numbers from <m>0.0</m> to <m>1.0</m>.  You can also see the effect of the <o>cartopol</o> object and “divide by pi” (<o>/</o> <m>3.1415</m>) math objects on the X/Y coordinates by viewing the third and fourth value in watchpoint <b>3</b> (driven by the <o>pack</o> object). Watchpoints can provide a quick and easy way to verify that the results of your calculations match the ranges that you expect.</p>

<p>As we saw in an earlier tutorial, changing a watchpoint to either “break” or “break/watch” will have a special effect when <b>Debugging</b> is enabled: any message seen by the watchpoint will cause the program to pause. Once the patch is paused, the <b>Debug Window</b> is displayed and you can step through the patch one message at a time, watching the patch operating while the <b>Debug Window</b> displays your patcher's stack trace.</p>

<h2>Summary</h2>

<p>While only revealing one new object (<o>multislider</o>), this tutorial introduced a number of important techniques for both creating and tracking values in a data stream.  We saw how <o>multislider</o> has built-in data display options that can greatly simplify the tracking of live numeric data.  For debugging purposes, we also saw how watchpoints can be used to track any message on any patch cord without changing our programming.</p>

<seealsolist>
<seealso name="multislider">an array of sliders or a scrolling display</seealso>
</seealsolist>

</chapter>
