I have 13 Text DATs, each containing a single letter (A–M). All of these feed into a Switch DAT, so based on a CHOP index value (1–13), the Switch DAT always outputs the currently selected letter at cell [0,0]. I also have a trigger CHOP that goes from 0 to 1 whenever I want to “confirm” or “type” the selected letter.
What Im trying to do is: when the trigger CHOP pulses from off to on, I need to read the letter currently output by the Switch DAT and append that letter into another Text DAT. This should work like typing a character each time the trigger fires, building a word letter by letter.
this might be best solved with a CHOP Execute DAT, using the index value from the CHOP as a lookup into a list of characters and writing the character out into a Text DAT.
A script could look something like this:
def onOffToOn(channel: Channel, sampleIndex: int, val: float,
prev: float):
"""
Called when a channel changes from 0 to non-zero.
Args:
channel: The Channel object which has changed
sampleIndex: The index of the changed sample
val: The numeric value of the changed sample
prev: The previous sample value
"""
# create a list with the characters
charList = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'. 'L', 'M']
# get the index channel - make sure it's 0 based
indexVal = op('null_chopWithIndexVal')['indexValChannel']
# append the character to the content of the Text DAT
op('text1').text += charList[int(indexVal)]
return
If you want to avoid writing out the list, you can also check out the chr() and ord() functions of python. The chr() function takes an integer and returns the corresponding character. ord() takes a character and returns the corresponding integer Unicode code point.
So when using this, the script can look like the following:
def onOffToOn(channel: Channel, sampleIndex: int, val: float,
prev: float):
"""
Called when a channel changes from 0 to non-zero.
Args:
channel: The Channel object which has changed
sampleIndex: The index of the changed sample
val: The numeric value of the changed sample
prev: The previous sample value
"""
# ord('A') returns the number 65, so we need to add 65 to our index to get the right characters
# get the index channel - make sure it's 0 based and add 65
indexVal = op('null_chopWithIndexVal')['indexValChannel'] + 65
op('text1').text += chr(int(indexVal))
return