trigger value

It is quite a simple thing I guess, But I just cannot figure it out.
I want to trigger specific values and pass them e.g. to a constant. So if I press “1” on my keyboard, value 35 is passed, and if I press “2”, value 88 is passed to the same destination. How could you do this?

A keyboard in DAT or CHOP would be a good step in the right direction here.

If you’re looking for highly specific mappings I might opt for the DAT version, though that’s a little more legwork to set up correctly.

Here’s a fast example of just what you’re describing:
base_keyboard_example.tox (1022 Bytes)

Take a look at the callbacks DAT to see what’s happening:

It’s worth knowing that the state that’s described in the callbacks can be used to capture only the key down event - otherwise you’ll execute your change both when pressing down on and when releasing the key. Next you can describe what happens. A more extensible approach here would be to build a for loop that looks at a correspondence table, but unless you’re mapping a lot of keys with values that are going to change a lot that might be a little overkill.

Anyway, hopefully this will help you get started.

[code]# me - this DAT

dat - the DAT that received the key event

key - the name of the key attached to the event

character - the ASCII value of the pressed key as a string

alt - True if the alt modifier is pressed

ctrl - True if the ctrl modifier is pressed

shift - True if the shift modifier is pressed

state - True if the event is a key press event

time - the time when the event came in milliseconds

def onKey(dat, key, character, alt, lAlt, rAlt, ctrl, lCtrl, rCtrl, shift, lShift, rShift, state, time):

target = op( 'constant1' )

# first limit our scirpt to only down presses on the keyboard
if state:
	
	# check for specific keys and pass specific vals
	if key == "1":
		target.par.value0 	= 35

	elif key == "2":
		target.par.value0 	= 88

	# do nothing in all other cases
	else:
		pass

# do nothing when the key is realeased 
else:
	pass

return

shortcutName is the name of the shortcut

def onShortcut(dat, shortcutName, time):
return;
[/code]

Thanks for the detailed description. But what I am trying to understand is the principle for triggering a value. I guess its much more basic. So if I press the letter “y” then the value “2” is passed to the brightness og a LUMA LEVEL TOP . Just the simple trigger value node, like in Isadora. Or is it the wrong way to think in Touch?

Its not that I only want to trigger the value by a keyboardin-CHOP, e.g. also through a “done”-signal from a Timer-CHOP

No chance to work with keyboardin CHOPS?

There’s a fair bit that Isadora obscures (often helpfully) from the programmer. In some respects it’s useful to think about how something works in another environment, but it’s also worth remembering that any environment or language requires that you conform to a particular perspective about how to solve problems. I guess that is to say that it is and isn’t helpful to think about how things work in another environment. Touch generally has a more granular approach than Isadora. That gives more flexibility in what you’re building, but also means that the programmer is responsible for managing more base level operations / functions than you find in Izzy.

Thinking more generally about how to change parameters in touch one usually targets parameters of operators. One can change these parameters directly with python, or indirectly through changing values in DATs or CHOPs. CHOPs and DATs are either referenced or exported in/to parameters (references happen at the target of an intended parameter, exports happen at the source of the value).

Networks of CHOPs or DATs can have their values changed by other operators inline. For example a constant CHOP can have its value changed by a Math CHOP - constant value of 1, for example, can be changed to another value with a Math CHOP’s multiply parameter. If you’re working with native ops, you need to think through the possible parameters that you’ll want to target and build a set of channels or table entries that are linked to those parameters. How you change them is then in the logic you build in your networks.

With that in mind, how do yo use multiple sources of possible changes to alter a target? If the idea is that both “y” and “done” can both target the same parameter how does one go about solving this problem? Many use python for exactly this kind of problem solving using as once you have a handle on now this works you’ll find that you can target the parameter of any operator - which is a blessing and a curse. Using native operators you’ll find some built in ops to solve this problem. Override CHOPs can be helpful for addressing this issue (for example), as can Switch or Blend CHOPs - though at the end of the day there are lots of ways that these problems can be addressed. There’s not one good way to solve a problem in Touch - more often than not there are only efficient and inefficient ways of tackling challenges.

That’s a little more esoteric than might be useful, but it’s a valuable perspective when working in this particular environment.

I guess thats a fact that accept, since I want to try to find my way through TD. I understand that will have to go away from the thinking that there are always “graphical” solutions like in Isadora, I just thought that there should be a simple solution for such a simple task. And I guess there is. Just with python. I will try to do my best in python now, especially with the help of your tutorials. :wink:

I think the trick to keep in mind is that while many problems seem simple initially, there are often layers of complexity that pretend to be invisible.

For example, here’s an example of a network using only touch ops that will export a value of 2 to the brightness par of a luma level TOP when “y” is pressed, or when a timer reaches “done”.

base_keyboard_val.tox (1.37 KB)

That’s pretty straightforward, but there’s an interesting issue here - the keyboard operates input as a toggle button. That is, that the channel for the “y” key is true only when depressed, but goes back to 0 when released. The timer CHOP’s “done” channel will stay as true until re-triggered. So here we have a situation where it becomes important to know which behavior is intended.

You’ll also notice that the override takes the last value passed. So if you run the timer, the luma level will go to 2. When you press the y key the value stays at 2, but when you release the y key the value will drop back to 0 (as the state of the y key is now at 0).

Another question that begins to develop here is “what does a neutral state look like, and what resets your system to the neutral state?” Isadora makes a few assumptions for you about how you’re likely going to work - which is great, but it also hides from you the nuance of what’s really happening behind the scenes.

From a theatrical perspective I would think of these kinds of situations as state functions that were tied to cues - in cue 01 I want the value to be 2.4, in cue 02 I want the value to be 1.0. In this paradigm the the current cue denotes desired state of the end value (tweening and transitions are of course another thought all together). For installations these days I often think of these problems in terms of state machines that need to navigate between previous, current, and next values.

When I was first making the change from Izzy to Touch I found these kinds of issues very frustrating as it seemed logical that a system should behave in a particular way - now I appreciate the granularity in this regard as it frees the designer to make choices about exactly what should happen and when.

Another good example of this kind of granularity is in this thread:
derivative.ca/Forum/viewtopic.ph … lit=buzzer
The problem seems light a pretty straightforward one, but the more conversation happened the more important it became important to really understand the specific details about what the entire series of events needed to look like.

I’m sure there’s an ops only solution - it just comes down to what the exact logic behind state changes needs to look like.

2 Likes