Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 97 lines (71 sloc) 3.819 kb
3d375ae @s3g v1
authored
1 /**
2 * protoDrom tutorial 2: adding OSC communication to drom tutoral 1
3 * by Shawn Greenlee
4 *
5 * for this example, you will need these libraries:
6 * 1) libPd for Processing (puredataP5) - https://github.com/libpd/puredatap5
7 * 2) controlP5 - http://www.sojamo.de/libraries/controlP5/
8 * 3) oscP5 - http://www.sojamo.de/libraries/oscP5/
9 * consult documentation for these libaries for further info.
10 */
11
12 // OK, let's get started...
13
14 // first, import the libaries (these need to be installed in your libraries folder)
15
16 import org.puredata.processing.PureData;
17 import controlP5.*;
18 import oscP5.*;
19 import netP5.*; // netP5 is included with the oscP5 library
20
21 // then, declare variables for the libraries
22
23 PureData pd;
24 ControlP5 controlP5;
25 OscP5 oscP5;
26
27 // and we'll also need to declare two floats: one for frequency, another for volume
28
29 float freq = 0.02;
30 float vol = 0.5;
31
32 // ok, now we are ready for the setup function
33
34 void setup() {
35 size(680, 400);
36 frameRate(25);
37 pd = new PureData(this, 44100, 0, 2); // set sampling rate, input channels, & output channels
38 pd.openPatch("drom_t2.pd"); // open the Pd patch contained in the data folder
39 pd.start(); // get Pd ready
40 controlP5 = new ControlP5(this); // get controlP5 ready
41 oscP5 = new OscP5(this, 8000); // get oscP5 ready and set the incoming port for communication (this is the connection point for a mobile app)
42
43 // while we are here, let's change our colors for controlP5
44
45 controlP5.setColorForeground(#ffffff);
46 controlP5.setColorBackground(#999999);
47 controlP5.setColorLabel(#ffffff);
48 controlP5.setColorValue(#ffffff);
49 controlP5.setColorActive(#ffffff);
50
51 // and we must setup our sliders, one for the frequency and one for the volume
52
53 Slider freq = controlP5.addSlider("freq", 0, 1, 0.02, 40, 50, 30, 200); // name, range-lo, range-hi, start-val, pos-X, pos-Y, width, height
54 freq.setSliderMode(Slider.FLEXIBLE); // this gives us a fader-like interface
55
56 Slider vol = controlP5.addSlider("vol", 0, 1, 0.5, 100, 50, 30, 200); // name, range-lo, range-hi, start-val, pos-X, pos-Y, width, height
57 vol.setSliderMode(Slider.FLEXIBLE); // this gives us a fader-like interface
58 }
59
60 // OK, setup is done
61 // now to for the draw function which will send the slider values to the Pd patch
62
63 void draw() {
64 background(#77896C); // we need to set background color in the draw function, so that the slider values draw correctly, comment out to see the difference
65 pd.sendFloat("pd_freq", (float)freq); // send the freq value to a receive in Pd called "pd_freq"
66 pd.sendFloat("pd_vol", (float)vol); // send the vol value to a receive in Pd called "pd_vol"
67 }
68
69
70 /**
71 * now to set up OSC communication so that the sliders can be controlled remotely
72 * you'll need an app capable of sending custom OSC messages, mobile apps like TouchOSC and TB Midi Stuff are good options
73 * send your messages from your mobile app on outgoing port: 8000 (which we determined in the setup function)
74 * be sure also to set the IP address for the host on your mobile app
75 */
76
77
78 void oscEvent(OscMessage theOscMessage) {
79
80 String addr = theOscMessage.addrPattern();
81 float val1 = theOscMessage.get(0).floatValue();
82
83 if (addr.equals("/drom/freq")) {
84 freq = val1;
d94d4cb @s3g v1a
authored
85 } // the Osc message you are sending must be formated as "/drom/freq" and will need to be a float in the range of 0-1
3d375ae @s3g v1
authored
86 controlP5.controller("freq").setValue(freq); // send the freq value to the freq slider
87
88 if (addr.equals("/drom/vol")) {
89 vol = val1;
90 } // the Osc message you are sending must be formated as "/drom/vol" and will need to be a float in the range of 0-1
91 controlP5.controller("vol").setValue(vol); // send the vol value to the vol slider
92 }
93
94 // now that you have the fundamentals down, try exporting an application
95 // and on to tutorial 3 where a DR-OM is born...
96
Something went wrong with that request. Please try again.