Custom OSC

From TidalCycles userbase
Jump to: navigation, search

Note the below requires at least version 1.0.6 of tidalcycles to be installed

It's possible to define your own Open Sound Control messages, to target software other than SuperDirt or Dirt. Here's some examples:

  customTarget = OSCTarget {oName = "MyStrangeSoftware", -- Give your target a name
                            oAddress = "", -- the target network address
                            oPort = 5050, -- the target network port
                            oPath = "/trigger/something", -- the OSC path
                            oShape = Nothing, -- The 'shape' - see below
                            oLatency = 0.02, -- the latency (to smooth network jitter)
                            oPreamble = [], -- Some fixed data to put at the start of messages
                            oTimestamp = BundleStamp -- The style of timestamp
  anotherTarget :: OSCTarget
  anotherTarget = OSCTarget {oName = "Another one",
                             oAddress = "",
                             oPort = 7771,
                             oPath = "/play",
                             oShape = Just [("note", Nothing),
                                            ("distortion", Just $ VF 0),
                                            ("loops", Just $ VI 1),
                                            ("vowel", Just $ VS "a"),
                                            ("sec", Just $ VI 0),
                                            ("usec", Just $ VI 0)
                             oLatency = 0.02,
                             oPreamble = [],
                             oTimestamp = MessageStamp

In the first example above, BundleStamp causes the message to be sent ahead of time in batches (at the rate defined by the cFrameTimespan config setting). Each OSC message will be placed inside a timestamped bundle. In this case, it's up to the receiving client to schedule accordingly.

The second example above instead uses MessageStamp, which is similar but instead of placing the message in a bundle, the timestamp is added as two integer values - sec and usec giving the number of seconds and microseconds since the UNIX epoch.

Note also that the first example doesn't give an oShape. This means that tidal will send whatever parameters you use in the pattern. It will do this as named parameters, that is, each parameter will be preceded by the name of the parameter, as a string.

The second example does give an oShape, as a list of names and default values. Note that the "s" control parameter doesn't have a default value. This means that OSC messages won't get sent unless the "s" control is defined in the pattern.

Using a target

Once you've defined your target, you can use it like this:

tidal <- startTidal customTarget defaultConfig

let p = streamReplace tidal

p 1 $ s "bd sn" # vowel "a"

If you want to send messages to more than one target at once, you can do it like this:

tidal <- startMulti [customTarget, anotherTarget] defaultConfig

let p = streamReplace tidal

p 1 $ s "bd sn" # vowel "a"

See the standard BootTidal.hs for how the usual functions for interacting with tidal are defined.


One way to debug OSC is to use a packet sniffer like wireshark. You can put "osc" in the filter field (no double quotes) to filter out everything except OSC packets. If you click on an OSC network packet and expand fields you can find a nicely formatted representation of your OSC message.