<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<chapter name="Max Basic Tutorial 1: Hello">

<setdocpatch name="01mHello" patch="01mHello.maxpat"/>
<next name="basicchapter02">Bang!</next>
<parent name="00_maxindex">Max Tutorials</parent>

<indexinfo category="Basics" title="Hello">Creating objects and connections</indexinfo>

<h1>Tutorial 1: Hello</h1>

<h2>Max patcher basics</h2>

<p>In this tutorial, we will examine the building blocks of a Max patcher: the <b>object</b> box, the <o>message</o> box and the <o>comment</o> box.  We will also delve into some of the basic editing functions provided by the Max environment.</p>

<p>This brief tour of a simple patcher will show the basic typology of simple programs written in Max: <b>object</b> boxes that perform command actions within a patch; <o>message</o> boxes that allow us to create messages that can be sent to the objects; <o>comment</o> boxes that allow us to document our patchers to make them easier to understand.</p>

<p>To open the tutorial patch, click on the blue <b>Open Tutorial</b> button in the upper right-hand corner of the documentation window.</p>

<h2>Looking around</h2>

<p>Take a look at the patcher 01mHello.  At the top-center of the patcher window, we can see three types of boxes.</p>

<p>The first element is the box labeled <o>print</o>.  This is an <b>object</b> box, and can be recognized by its light grey border and (in this case) a small "port" at the top left that we call an <i>inlet</i>.  <b>Object</b> boxes are the basic logic element of Max – they contain functions that perform some sort of task, and operate like miniature programs within the larger environment.</p>

<p>Just below the object box is a <o>message</o> box (labelled with the word "message").  These are visually different from the object box – they have a gray background, and do not have a border. Message boxes contain some information (called a <i>message</i>) that can be sent to objects, and can operate as either commands or control data.</p>

<p>The third box doesn’t look like a box at all – it appears to be text on the background of patcher window. This is a <o>comment</o>. There is actually a box around this text, but it is not visible until we decide to edit our patch. A comment box is used to add text for labeling controls (e.g. "click me"), or for adding information to your patch to make its operation more apparent to you or anyone you might share your patch with.</p>

<p>Max programs function by passing messages between objects.  Object boxes can be connected to one another, and message boxes can be used to originate or, in some cases, process messages that are used to control other objects.</p>


<h2>Unlocking the patcher</h2>

<p>When you first opened this patcher, it was in a "locked" state – meaning that you cannot edit any of the objects or text in the window.  When a patcher is locked, the intention is that it be used as a program.  Since the power of Max is that we can edit and manipulate these programs to do whatever we like, let's unlock this patch and do some editing.</p>

<p>Choose <b>Edit</b> from the View menu.  You will see several changes in the patcher.  First, the boxes surrounding the <o>comment</o> boxes are revealed (we told you they were there).  Secondly, the <o>message</o> and comment boxes show inlets that were hidden in the locked state.  In addition, a port on the <i>bottom</i> of the message box is revealed; this is an <i>outlet</i>.  Finally, many more of the icons at the bottom of the patcher window are now available for our use.</p>

<p>In addition to the visible changes, we are now free to edit the contents of the window. Double-click inside the object box in the upper-right that says <o>print</o>; the text is selected, and you can type another object name into that box. Type "metro" (without the quotes), and click outside the <b>object</b> box to complete the edit. We have now changed the function of that object - it is now a <o>metro</o> object. You will see the <b>object</b> box change size, and the number of inlets and outlets will change as the function of the object has changed.  We learn Max by building up a vocabulary of objects, including how they connect to other objects and what messages they understand and transmit.</p>

<p>Double-click inside the <o>message</o> box on the right. Change the message text to anything (for example, type in the word "anything"), then click outside the box to accept the change.  Note that changing the message text does not change the inlets or outlets, since only the contents (but not the function) of the message box has changed.</p>

<p>Finally, double-click inside the comment box and change its text. Since the comment box has no function other than adding text to the patch, you are free to put in any text that pleases you.</p>

<h2>Interacting with a locked patcher</h2>

<p><b>Lock</b> the patch by unchecking <b>Edit</b> in the <b>View</b> menu. Let’s see what happens when we click on each of the box types.
In the top-center of the patch, click on the object box (which we changed from <o>print</o> to <o>metro</o>) – nothing
happens. Clicking on the <o>message</o> box directly below it, however, acts like a button – you can see the text get pushed back when you click it.</p>

<p>Click on the Max console icon on the right-hand side of the window to open the sidebar. On the left side of our patcher, there are three <o>message</o> boxes connected (with lines called <i>patchcords</i>) to a <o>print</o> object . Click on each of these message boxes in turn, then look at the Max Console; you will see that the contents of the message boxes we clicked are displayed there.  This was a result of clicking on the message boxes: they generated a message (the content of the message box) and sent it down the patchcord to the print object.  The print object takes any message it receives in its inlet and displays it in the Max Console. </p>

<h2>Commas change everything</h2>

<p>You probably noticed that two of the <o>message</o> boxes have almost identical text, but the display in the Max Console is different. The message box with the text "Good morning, everybody!" caused the text to be displayed on two lines. The message  "Good morning\, everybody!" was displayed on a single line in the Max Console.  The difference is in the use of the <i>comma</i>, which has a special meaning in message boxes within Max. In a message box, the comma is used as a message separator; in essence, it turns a single line of text into two discrete messages.  Thus, the message "Good morning, everybody!" is really treated like two messages: "Good morning" is sent out the outlet of the message box, followed immediately by "everybody!". In order to treat the comma as text (rather than as a message separator), you need to let the message box know that you are overriding the comma’s special behavior.  You do this by preceding the comma with the backslash ("\") character, which tells the message box to ignore the comma’s special use, and treat it as a literal text character.  Those of you familiar with textual programming languages will be familiar with the use of a backslash character to "escape" a character that has special meaning.</p>

<p><b>Unlock</b> the patcher, click inside the lower <o>message</o> box (the one with the backslash) and remove the slash.  <b>Lock</b> the patch and click on the edited message box – you will see that it, too, now creates two lines of text in the Max Console. Edit the first message box, adding a backslash before its comma, and lock the patch; it now exhibits the expected behavior of printing the entire message on a single line.</p>

<h2>Getting help</h2>

<p>The <o>print</o> object is obviously doing something to send text to the Max Console. To determine what
function any object box performs, you can view several types of document to get help. <b>Unlock</b> the
patcher for these operations:</p>

<p>Select the <o>print</o> object box by either clicking into it or clicking and dragging the mouse over
it to <i>highlight</i> it. Select <b>Open print Help</b> from the <b>Help</b> menu. A new patcher
window (called a <i>Help</i> patcher) opens with an example that shows the print object in action.
Note that this is an <i>actual</i> Max patch, and can be unlocked, edited, or copied elsewhere,
retaining any of the displayed functionality.</p>

<p>Select the <o>print</o> object as before and then click on the <b>Reference</b> icon in the right patcher window toolbar to open the sidebar.
An abbreviated reference will appear with information  on the object's function, arguments, messages, attributes and links to similar objects.
You will have already seen this in the help patcher, which opens with the sidebar open.</p>

<p>Select the <o>print</o> object and choose <b>Open print Reference</b> from the <b>Help</b> menu. A browser window is displayed with the
<i>Reference Manual</i> page for the print object. This gives detailed information about the object, including
the function of all of its inlets and outlets, and how it responds to each message. It even provides an example patch for your reference.
This is the most detailed information available for any object.  Objects and topics relevant or similar to the object you're viewing
can be viewed by clicking on links in the <i>See Also</i> section at the bottom of the reference. The reference page is also available
via a right click on an object or in the "?" tab of an object's help file.</p>

<h2>Create some new messages</h2>

<p>Let’s add some objects to our patch, and create our own message passing logic.  First, with the patcher unlocked, click on the plain <b>Object</b>
icon in the top patcher window toolbar and drag it to the patching window. This will place an empty object box on your patcher window, ready for you
to enter its name.  Type "print", then either hit return or click outside the box to accept this name.  We need some clear space above it, so if
necessary move the object by dragging it.</p>

<p>Next, click on the <b>Message</b> icon in the top patcher window toolbar and drag it to the patching window.
When it appears, type in the message "Goodbye!".  Place this message box above the <o>print</o> object.  Finally,
connect the two boxes by clicking on the outlet of the message box, dragging the mouse to the inlet of the print
object, then releasing the mouse button.  This will create a patchcord between the two objects, allowing messages
to pass from the message box to the print object.</p>

<p><b>Lock</b> the patch and click on the new "Goodbye!" <o>message</o>.  You will see the text "Goodbye!" appear in the Max Console.  Congratulations – you’ve just done your first Max patching!</p>

<h2>Summary</h2>

<p>The three main elements of a Max patch (<b>object</b> boxes, <o>message</o> boxes and <o>comment</o> boxes), along with patchcords, are the core of all Max programs. Each type of element responds to a variety of messages and editing functions; these can be explored by viewing the help files and Reference Manual documents. Each of these aspects will be expanded upon in later tutorials.</p>

<seealsolist>
<seealso name="print">Print any message in the Max Console</seealso>

<seealso name="message">Display and send any message </seealso>

<seealso name="comment">Text comment in a Patcher</seealso>

</seealsolist>

</chapter>
