ChucK input / output

^ programmer's guide | std classes | basic ugen

IO | FileIO | StdOut/StdError
OscIn | OscOut | OscMsg
Hid | HidMsg | SerialIO
MidiIn | MidiOut | MidiMsg | MidiFileIn


IO

IO is a subclass of Event that also serves as a base class for various means to communicate non-audio information with external devices and processes. Thus, methods here are generally to be thought of a "pure virtual" and whose meaning depends on the subclass.

IO.constants Description
int INT16 number of bytes in this type
int INT32 number of bytes in this type
int INT8 number of bytes in this type
int MODE_ASYNC enumeration constant
int MODE_SYNC enumeration constant
int READ_INT16 enumeration constant
int READ_INT32 enumeration constant
int READ_INT8 enumeration constant
IO.functions Description
static string newline() n/a
static string nl() n/a
static string newlineEx2VistaHWNDVisualFoxProA n/a
void close() close the IO dchanngel/a
int eof() n/a
void flush() flush the output buffers
int good() n/a
int mode(), mode(int flag) Get/set the mode.
int more() n/a
int readInt(int flags) read and return an int
string readLine(int flags) read and return a line of text
void write(string val) write a string
void write(int val) write an int
void write(float val) write a float

FileIO

FileIO is a subclass of IO and Event that implements basic file system reading and writing.

FileIO.constants Description
int APPEND enumeration constant
int ASCII enumeration constant
int BINARY enumeration constant
int READ enumeration constant
int WRITE enumeration constant
FileIO.functions Description
void close() closes the open file
string[] dirList() returns the list of filenames in the opened directory
int eof() returns 1 if the current file location is at the end
void flush() flushes the output buffer associated with the open (and writing file)
int good() returns 1 if the current FileIO state is valid
int isDir() returns 1 is the current open file is a directory
int mode(), mode(int flag) Get/set the current file mode
int more() Indicates whether there is more to read in the current file.
int open(string path) opens for reading the file or directory given by path. Returns 1 on success.
int open(string path, int flags) opens the file or directory given by path according to the mode flags. Returns 1 on success.
int readInt(int flags) reads and returns an int from the currently opened file
string readLine(int flags) read and return a line of text
void seek(int pos) move the current file position to the requested position
int size() return the size of the currently openen file
int tell() return the current file position
void write(string val) write a string to the currently opened file
void write(int val) write an int to the currently opened file
void write(int val, int flags) write an int to the currently opened file
void write(float val) write a float to the currently opened file

See write2.ck, read-line.ck

StdOut, StdErr

StdOut and StdErr are subclasses of IO and Event that implements basic output via the standard output channel or the standard output error channel associated with the chuck process.

StdOut.functions
void close()
int eof()
void flush()
int good()
int mode(int flag)
int mode()
int more()
int readInt(int flags)
string readLine()
void write(string val)
void write(int val)
void write(float val)

OSC

Open Sound Control (OSC) is a communication protocol for networking sythesizers, ChucK instances, computers or other multimedia devices for purposes such as musical performance or show control.

ChucK offers three related classes for OSC interoperability.

OscIn

OscIn is a subclass of IO and Event that implements basic reading of one or more OSC I/O channels.

The mechanics of OscIn are:

  1. instantiate OscIn and OsgMsg objects
  2. establish the port
  3. express interest in an osc address (endpoint)
  4. use Events to wait on activity
  5. receive the OscMsg when it arrives
  6. interpret and act upon the OscMsg contents
OscIn.fuctions Description
void addAddress(string address) Add the IP address of a OSC broadcaster to our listening queue
void listenAll()
int port(), port(int port) Get/set the TCP/UDP port
int recv(OscMsg msg) read an OscMsg from a socket
void removeAddress(string address) Remove the IP address from the listening queue.
void removeAllAddresses() remove all addresses from our listening queue

See osc/r.ck.

OscOut

OscOut is a subclass of IO and Event that implements basic writing to OSC I/O channels. You can choose to broadcast to any hosts or to a specific host.

The mechanics of OscOut are:

  1. instantiate an OscOut object
  2. identify a msg target and msg method via send() (ie: an OSC endpoint)
  3. emit the fields of the msg via add()
  4. emit send().
OscOut.fuctions
OscOut add(int i)
OscOut add(float f)
OscOut add(string s)
OscOut dest(string host, int port)
OscOut send()
OscOut start(string method)
OscOut start(string method, string host, int port)

See osc/s.ck.

OscMsg

OscMsg is produced by the OscIn recv methods and represents the payload of a single OSC transmission.

OscMsg.members
string address
OscArg[] args
string typetag
OscMsg.methods
float getFloat(int i)
int getInt(int i)
string getString(int i)
int numArgs()

See OSC_dump.ck to see OSC msg parsing in action.


Human Interface Devices (HID)

Your computer connects over USB to communicate with HIDs like a mouse, keyboard or joystick. ChucK can intercept these msgs from your devices and these can trigger Events in your programs.

Hid

Hid is a subclass of Event and this makes it easy to asynchronously await events triggered by your devices.

See mouse.ck, keyboard.ck

Hid.functions Hid.constants
static dur globalTiltPollRate(dur d) int ACCELEROMETER
static dur globalTiltPollRate() int AXIS_MOTION
static int[] readTiltSensor() int BUTTON_DOWN
static int startCursorTrack() int BUTTON_UP
static int stopCursorTrack() int DEVICE_CONNECTED
int can_wait() int DEVICE_DISCONNECTED
int good() int FORCE_FEEDBACK
string name() int JOYSTICK
int num() int JOYSTICK_BALL
int open(int type, int num) int JOYSTICK_HAT
int open(string name) int KEYBOARD
int openJoystick(int num) int LED
int openKeyboard(int num) int MOUSE
int openMouse(int num) int MOUSE_MOTION
int openTiltSensor() int MOUSE_WHEEL
void printerr(int print_or_not) int TABLET
int read(int type, int which, HidMsg msg) int TILT_SENSOR
int recv(HidMsg msg) int WII_REMOTE
int send(HidMsg msg)

HidMsg

HidMsg is used to receive and encapsulate HID device messages. Different devices return different data, so a certain amount of device-targeting is inevitable in your ChucK programs. The HidMsg methods can narrow down the source of an individual HID message. This information is crucial in determining which of the HidMsg members contain the data of interest.

HidMsg.functions
int isAxisMotion()
int isButtonDown()
int isButtonUp()
int isHatMotion()
int isMouseMotion()
int isWheelMotion()
int is_axis_motion()
int is_button_down()
int is_button_up()
int is_hat_motion()
int is_mouse_motion()
HidMsg.members
int ascii
float axisPosition
int axis_position
int cursorX
int cursorY
int deltaX
int deltaY
int deviceNum
int deviceType
float fdata
int hatPosition
int idata
int key
float scaledCursorX
float scaledCursorY
float scaled_axis_position
float touchSize
float touchX
float touchY
int type
time when
int which
int x
int y
int z

SerialIO

SerialIO is a subclass of IO and Event. It handles reading and writing for serial input/output devices, such as Arduino.

byte.ck, bytes.ck, ints-bin.ck, ints.ck, lines.ck, list.ck, write-bytes.ck, write.ck,

SerialIO.constants
int ASCII
int BINARY
int B230400
int B115200
int B76800
int B57600
int B38400
int B28800
int B19200
int B14400
int B9600
int B7200
int B4800
int B2400
SerialIO.functions Description
__`static string[] list() Return list of available serial devices.
int baudRate(), baudRate(int r) Get/set baud rate.
void close()
int dataAvailable()
void flush() Flush the IO buffer.
int getByte() Get next requested byte.
int[] getBytes() Get next requested number of bytes.
int[] getInts() Get next requested number of integers.
string getLine() Get next requested line.
SerialIO onByte() Wait for one byte (binary mode only).
SerialIO onBytes(int num) Wait for requested number of bytes (binary mode only).
SerialIO onFloats(int num) Wait for requested number of floats (ASCII or binary mode).
SerialIO onInts(int num) Wait for requested number of ints (ASCII or binary mode).
SerialIO onLine() Wait for one line (ASCII mode only).
int open(int i, int baud, int mode) Open serial device i with specified baud rate and mode (binary or ASCII).
string readLine()
void writeByte(int b) Write a single byte.
void writeBytes(int[] b) Write array of bytes.

Midi

MidiIn

MidiIn is a subclass of Event that allows your ChucK program to be triggers by connected Midi devices.

See gomidi.ck, playmidi.ck, polyphony.ck,

MidiIn.functions Description
int can_wait()
int good()
string name() Return the Midi device's name as string.
int num()
int open(int port) Open Midi device using a port number.
int open(string name) Open Midi device using the device's name.
void printerr(int print_or_not) Set error printing (1 for on, 0 for off). On by default.
int recv(MidiMsg msg) receive a MidiMsg for action/interpretation

MidiOut

MidiOut is a subclass of Object and allows you to generate Midi events for consumption by an attached Midi device.

See midiout.ck, gomidi2.ck,

MidiOut.functions Description
int good()
string name() Return the Midi device's name as string.
int num()
int open(int port) Open Midi device using a port number.
int open(string name) Open Midi device using the device's name.
void printerr(int print_or_not) Set error printing (1 for on, 0 for off). On by default.
int send(MidiMsg msg) Send out a MidiMsg message.

MidiMsg

MidiMsg is a subclass of Object and encapsulates data about a single Midi message.

MidiMsg.members Description
int data1 First byte of a Midi message, usually a status byte or command byte.
int data2 Second byte of a Midi message, usually a note value.
int data3 Third byte of a Midi message, usually a velocity value.
dur when Relative time at which the msg occurs. Used to synchronize multiple msgs with one aother.

See playmidi.ck

MidiFileIn

MidiFileIn is a subclass of Object and facilitates the reading of a standard midi file.

MidiFileIn.functions Description
void close() n/a
int numTracks() n/a
int open(string path) n/a
int read(MidiMsg msg) n/a
int read(MidiMsg msg, int track) n/a
void rewind() n/a

See playmidi.ck

home .. language .. program .. examples