Presentation2

Download Report

Transcript Presentation2

Part 2: Interactivity
In this section
• Using the laptop’s
inputs
• Adding game
controllers and MIDI
controllers
• Interacting with
controllers, other
software, and other
computers using OSC
Interaction in ChucK: Event-based
• Many methods of interacting with ChucK work
within the same ChucK Event Framework.
– Keyboard, mouse, joystick, other HID
– MIDI and OSC allow communication:
• With controller devices
• With other computers
• With other software programs
3
Events
• One shred broadcasts an event
• Other shred(s) wait for an event by chucking “e => now;”
– See events.ck, events_sound.ck
//Parent shred:
Event e;
spork ~ shred2();
spork ~ shred3();
while (true) {
e.broadcast();
Std.rand2f(.1,.5)::second => now;
}
fun void shred2() {
while(true) {
e=> now;
<<< “Hi from shred2” >>>;
}
}
fun void shred3() {
while (true) {
e => now;
<<< “hi from shred 3” >>>;
}
}
4
Using the laptop’s native inputs
• SMELT:
– http://smelt.cs.princeton.edu
– Examples: kb-fret.ck, tp-cond.ck, motion-sing.ck,
ocarina
(Motion sensor and mic are not HID)
• Revisit FM_mouse.ck (#30)
5
Adding new controllers
• Most USB controllers speak HID
• Ex: joy of chant (on my computer)
• To add your own, run basic_hid.ck to peek at the HID
messages being generated
– See basic_hid_fm.ck for sound example
6
MIDI
• Use ChucK’s event structure to work with any
MIDI devices
– Use basic_midi.ck to see what messages are being
received from a device
– See midi_mandolin.ck for a standard use of MIDI
(synthesizing from noteOn messages)
7
Open Sound Control
• Open Sound Control
– More customizable than MIDI
• Each message has a path (like a name) and some data
(ints, floats, strings, etc.)
– Run on a single computer: speak to other software
– Run over ANY network: Communicate between
machines
8
Establishing OSC communication
• Each shred can listen for OSC messages on an open port (e.g.,
6565) and/or send OSC messages to a specific port.
– The destination machine is specified using an IP address or “localhost”
Machine X
Port 6449 on
Machine X
Shred A
Sends to
port 6449 on
Machine X
UDP
Shred B
Listens on port
6449
OSC Messages
• Each message has a path to distinguish it from
other messages
– E.g., “/Rebecca/Workshop/Message1”
– Path name is completely arbitrary
• Each message can contain integers, floats,
and/or strings
Communicating between shreds
• Event example from Part 1 (#47) required that
all communicating shreds share a namespace
– E.g., 2 player shreds were children of the
conductor
• With OSC: No namespace necessary
• Example: osc_conductor.ck, osc_player.ck
11
OSC with Processing
• Example: Simple webcam mapping:
processing_webcam_osc.pde +
use_processing_cam.ck
Communication Between
Machines
• Example: ChucK ChucK
Rocket
• Example: Clix
– See OSC messages
– See video:
http://plork.cs.princeton.
edu/listen/green/
Review: Interactivity
• Laptop’s native inputs: SMELT toolkit
• External controllers
– HID, MIDI
• Other software via OSC:
– Processing, Max/MSP, Jitter, C++, Java, …
• Other computers via OSC
– Anything on the same network, or with a reachable IP address
See my OSC handout for the details on how to use OSC with ChucK