Download Tutorials and Topics
Transcript
expr and if Tutorial 38 • To see an example of an object-based solution to a programming problem, and a comparable solution using expr, double-click on the patcher expr_example object. For this example, we want to solve the following problem: as the modulation wheel progresses from 0 to 127, send pitch bend values from 64 to 127 and back down to 64. The patch on the left shows a standard Patcher way of doing this. The patch on the right shows the different tasks all combined into a single mathematical expression in expr. Notice that the changeable arguments in an expr object include a letter, as in $i1, to tell expr what data type to use for that argument (i for int, f for float). • Move the modulation wheel on your MIDI keyboard from 0 to 127, and you’ll see that both methods of stating the mathematical expression work equally well. However, it’s a bit more memory-efficient to use a single object instead of four. if Another staple of C programming is the if () ; else ; combination. In Pascal, this is expressed as IF condition THEN statement ELSE statement. In plain English this means: if a certain condition is met, do one thing, otherwise do another thing. Sometimes this way of thinking about the world just seems to make a lot more sense than a bunch of boxes connected together with wires! Max has an object called if which lets you express programming problems in an if/then/else format. If the comparison in the arguments is true (does not equal 0), then the message after the word then is sent out the outlet, otherwise, the message after the (optional) word else is sent out. So, the conditional statement if the received number is greater than or equal to 64, send out 127, otherwise send out the received number 171