Mathematical Expression Ternary Operator

This is cool! Toby is right, you CAN use the ternary operator in a Mathematical Expression patch. You can even use it to, for example, invert a boolean input. For example:

(Bool == true) ? false : true

works as a a boolean invert. The input and output aren’t recognised as boolean types, so you’ll get orange cables if you attach, say, a bool splitter to the input, and patch the output into the Enable input of a Billboard, for example. It’ll work fine though, and in fact, I often mix number and boolean types in my compositions.

toby*spark pointed out that for the particular case of a boolean invert, an even quicker way of doing it is to simply use


In this case, ‘Bool’ will be the input port name (you can use any name you like), and the patch will output true/1 when the input is false, and false/0 when the input is true. Very handy.


5 Responses to “Mathematical Expression Ternary Operator”

  1. July 16, 2008 at 7:28 am

    for that common use, you can do something even more concise and clear: just “!not”

  2. 2 toneburst
    July 16, 2008 at 8:24 am

    Hi toby.

    You can actually do ‘!Whateveryouwant’ I just discovered.
    ‘!Bool’ seems to make sense.


  3. July 17, 2008 at 9:23 am

    ah, but !not makes the purpose of the patch transparent: to me it makes easier to read patches to name the inputs by purpose rather than type. so using “!not” not only puts “not” in the title, but the input you want to ‘not’ is labeled as such.

    horses for courses, but i reckon i’d use the mathexp patch for the variable naming factor even if it wasn’t as wildly powerful as it is.

    when i give qc sessions, there is a matra: “m.a.t.h.e.enter” =]

    anyway, enough riffing on this!


  4. July 17, 2008 at 9:24 am

    oop – rather “apple-enter.m.a.t.h.e.enter”

  5. 5 toneburst
    July 17, 2008 at 9:33 am

    I tend to name inputs according to what’s going INTO them. I often rename the Mathematical Expression patches, anyway, so what’s in the titlebar isn’t necessarily the actual equation.

    You’re right, though, it’s more about what makes most sense to you when you’re working on your own stuff. Having said that, I do tend to get a bit obsessive about commenting and naming stuff in QC. For example, I spent most of yesterday going through quite a complex composition I’ve been working on, just tidying up patch positions and names, and adding notes everywhere. Not sure if anyone else is ever going to see them, but I like the idea that I’ll be able to come back to it myself at some point, and be able to tell what does what. Of course, all the plugins that drive the whole thing probably won’t work after the next couple of revisions of QC, anyway…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


July 2008
« Jun   Aug »


Blog Stats

  • 482,130 hits

%d bloggers like this: