Logic

If you have ever heard somebody talk about programming you might know that it involves a lot of if-else-than. When coding you often want to check if something is happening (the user presses a key) and then you want the computer to do something for you. 

We basically set conditions and write down what the computer should do when these conditions are met. This is called logic and this article will teach you how to use logic in Wire.

Before you start with this article you should understand what a Boolean is. If you don’t know this yet, make sure you check out our article on data types. 


Greater than thou!

The most basic logic operations are comparisons. You might want to check if a slider is above a certain value or within a given range. We have a lot of nodes that do this. These nodes all output a boolean (true or false) when the condition is met or not.


The Greater node outputs TRUE when its right inlet is higher than its left inlet and FALSE when this is not or no longer the case.

The Within node outputs TRUE when the incoming value lays within its min and max parameters.

Other nodes in this category are Less, Equal, Not Equal and Outside.


Logic Gates

At some point you might want to compare not one, but multiple values. For this we have a whole suite of nodes called logic gates. These nodes work only with booleans and are often placed after your comparison.  The most common two are And and Or.


The And node outputs TRUE when both its left and right inlet are TRUE. 

You might have an effect that depends on the BPM as well as oscillators. But as learned in our oscillator article you might want to limit the frequency at some point. Maybe you want to check if the BPM and the frequency are not greater than a certain value. Logic nodes are great for building in these kinds of safeties.

The Or node outputs TRUE when either its left or right inlet is TRUE. But outputs FALSE when both or neither inlets are TRUE.

Other nodes in this category are Xor, Nor and Nand.


Logic Conversion

There are a few ways you can convert your logic data. 


Toggle will turn triggers into booleans and If will turn booleans into triggers. 

This works great if you want to turn beat triggers into logic operations or use the result of a logic operation to blow up that Attack Release or Random node.


The Not gate can be used to inverse the boolean (true because false and vice versa). This can be useful to create reverse bypasses on video effect nodes.


On Change is a node that sends out a boolean when the incoming value changes.
This node is particularly useful when doing logic operations with a signal flow.


Example

In this example we use multiple simple logic operations to have a rectangle rotate, scale and change color based on its position.


--begin-wire-patch-- 2225.3oc4Zk0aiiiD9uBge1zf2hreSxGKVfEXGzcOX1EC5GTrni01xRo0QmNyf7eeKJ4yXYK4j3o8h0AH1lt3U8UGeEo9yAyyRSsyKiyRKF7ge+OGrHOaE7At2vAYUkOTUN3KCGTl4ZRObPbZcKOObmfpiEzrVPxgRZZcHKyCS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