Skip to content

Cheat Sheet

  • PUBLISHED: 2024-2-8
  • UPDATED: 2024-2-10

Why make this?

In my quest to master Touch OSC MKII, I've ventured deep into the labyrinth of its manual and formatted the information in a different way. Not only does creating this guide serve as a deep dive into learning the intricacies of Touch OSC, but it also became an essential tool in my arsenal, especially since my forays into editing Touch OSC templates aren't a daily ritual.

The journey into the world of Touch OSC is ongoing, and I’m excited to share the insights and tricks I've gathered along the way. Lua everywhere! ❤

Reference

Snippets


Per Frame Updates

Update Callback
function update()
  print(self.name, 'update') 
end

Values

Value Changed

function onValueChanged(key)
  if (key == "x") then

  end
  if (key == "touch") then

  end
  if (key == "x" and self.values.touch) then

  end
end
function onValueChanged(key)
  if key == "touch" and self.values.touch then

  end
end
function onValueChanged(key)
  if key == "x" and self.values.touch then

  end
end
function onValueChanged(key)
  print(key, self.values[key])
end

Set Value

self.parent.values.x = 1

Notify

Notify Receive

function onReceiveNotify(key, value)
  if key == "" then

  end
end
function onReceiveNotify(key, value)
  print(self.name, 'onReceiveNotify')
  print('\t key   =', key)
  print('\t value =', value)
end

Notify Send

self.parent:notify("update", 1)
self.parent:notify("update", {obj=self, value=1})

OSC

OSC Receive

OSC Callback - Single Value
function onReceiveOSC(message, connections)
  local path = message[1]
  local arguments = message[2]
  if path=="/" then
    local v = arguments[1].value

  end
end
OSC Callback - Loop Values
function onReceiveOSC(message, connections)
  local path = message[1]
  local arguments = message[2]
  if path=="/" then
    for i=1,#arguments do
      local tag = arguments[i].tag
      local v = arguments[i].value
    end
  end
end
function onReceiveOSC(message, connections)
  print(self.name, 'onReceiveOSC')
  local path = message[1]
  local arguments = message[2]
  print('\t path        =', path)
  for i=1,#arguments do
    print('\t argument    =', arguments[i].tag, arguments[i].value)
  end
  print('\t connections =', table.unpack(connections))
end

OSC Send

Simple Message
-- -----------------------------------------
-- Send simple OSC messages
--
-- arguments are auto-converted to
-- boolean, float or string (not integer!)
-- -----------------------------------------

-- send on all configured connections (1-5)
sendOSC('/simple')
sendOSC('/ping', 'pong')
sendOSC('/on', true)
sendOSC('/1/fader1', 0.5)
sendOSC('/3/xy1', 0.25, 0.75)
sendOSC('/mixedarguments', 'Hello', 1, true, 'World')

-- send only on connections 1 and 2
sendOSC('/1/fader1', 0.5, { true, true })

-- send only on connections 1 and 3
sendOSC('/3/xy1', 0.25, 0.75, { true, false, true })

-- send only on connections 1 and 5
sendOSC('/mixedarguments', 'Hello', 1, true, 'World', { true, false, false, false, true })
Complex Message
-- -----------------------------------------
-- Send complex OSC messages
-- with argument type tags
-- -----------------------------------------

sendOSC(
  -- message
  {
    -- path
    '/complex',

    -- argument list
    {
      { tag = 'T' },                                     -- true
      { tag = 'F' },                                     -- false
      { tag = 'N' },                                     -- nil
      { tag = 'I' },                                     -- infinitum
      { tag = 'i', value = 42 },                         -- int32
      { tag = 'f', value = 3.14 },                       -- float32
      { tag = 's', value = 'Goodbye Cruel World' },      -- string
      { tag = 'b', value = { 0xC0, 0x00, 0x10, 0xFF } }  -- blob
    }
  },
  -- connections
  {
    true, -- 1
    true, -- 2
    true, -- 3
    true, -- 4
    true  -- 5
  }
)

Midi

Midi Receive

MIDI Callback
function onReceiveMIDI(message, connections)
  print(self.name, 'onReceiveMIDI')
  print('\t message     =', table.unpack(message))
  print('\t connections =', table.unpack(connections))
end

Midi Send

Sending Midi
-- control change, controller 0, channel 1
-- all configured connections (1-5)
sendMIDI({ 176, 0, 102 })
sendMIDI({ MIDIMessageType.CONTROLCHANGE, 0, 102 })

-- control change, controller 0, channel 2
-- all configured connections (1-5)
sendMIDI({ 177, 0, 103 })
sendMIDI({ MIDIMessageType.CONTROLCHANGE + 1, 0, 103 })

-- control change, controller 2, channel 6
-- all configured connections (1-5)
sendMIDI({ 181, 2, 104 })
sendMIDI({ MIDIMessageType.CONTROLCHANGE + 5, 2, 104 })

-- send only on connections 1 and 2
sendMIDI({ MIDIMessageType.NOTE_ON, 12, 88 }, { true, true })
sendMIDI({ MIDIMessageType.NOTE_OFF, 12, 0 }, { true, true })

-- send only on connections 1 and 3
sendMIDI({ MIDIMessageType.NOTE_ON, 13, 88 }, { true, false, true })
sendMIDI({ MIDIMessageType.NOTE_OFF, 13, 0 }, { true, false, true })

-- send only on connections 1 and 5
sendMIDI({ MIDIMessageType.NOTE_ON, 14, 88 }, { true, false, false, false, true })
sendMIDI({ MIDIMessageType.NOTE_OFF, 14, 0 }, { true, false, false, false, true })

-- send system exlusive
sendMIDI({ 0xF0, 0x00, 0x01, 0xF7 })
sendMIDI({ MIDIMessageType.SYSTEMEXCLUSIVE, 0x00, 0x0D, 0xF7 })

Color

color.r
color.g
color.b
color.a 

Color()                               -- [1]
Color(color)                          -- [2]
Color(number)                         -- [3]
Color(number, number)                 -- [4]
Color(number, number, number)         -- [5]
Color(number, number, number, number) -- [6]

Color.toHexString(color)
Color.fromHexString(string)

-- multiplication
color * color
color * number

-- division
color / color
color / number

-- addition
color + color
color + number

-- subtraction
color - color
color - number

Functions

rectangle:contains(number, number)