-
Notifications
You must be signed in to change notification settings - Fork 142
/
ControlP5propertiesSets.pde
133 lines (103 loc) · 4.39 KB
/
ControlP5propertiesSets.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* ControlP5 properties sets.
*
* saves/loads controller values into/from properties-file.
* this example shows how to make property sets of controllers that can be loaded and
* saved individually. By default property files come in a serialized format
* with a .ser extension.
*
*
* default properties load/save key combinations are
* alt+shift+l to load properties
* alt+shift+s to save properties
*
*
* find a list of public methods available for the ControllerPropererties Controller
* at the bottom of this sketch's source code
*
* by andreas schlegel, 2011
* www.sojamo.de/libraries/controlp5
*
*/
import controlP5.*;
ControlP5 cp5;
public int slider1 = 32;
public int slider2 = 64;
public int slider3 = 128;
public int slider4 = 255;
void setup() {
size(400, 600);
cp5 = new ControlP5(this);
// add a vertical slider
cp5.addSlider("slider1", 0, 255, 20, 100, 128, 20);
cp5.addSlider("slider2", 0, 255, 20, 150, 128, 20);
cp5.addSlider("slider3", 0, 255, 20, 200, 128, 20);
cp5.addSlider("slider4", 0, 255, 20, 250, 128, 20);
cp5.addButton("b1", 0, 20, 350, 80, 12).setCaptionLabel("save setA");
cp5.addButton("b2", 0, 101, 350, 80, 12).setCaptionLabel("load setA").setColorBackground(color(0, 100, 50));
cp5.addButton("b3", 0, 200, 350, 80, 12).setCaptionLabel("save default");
cp5.addButton("b4", 0, 281, 350, 80, 12).setCaptionLabel("load default").setColorBackground(color(0, 100, 50));
// add a new properties set 'setA'
cp5.getProperties().addSet("setA");
// move controller 'slider' from the default set to setA
// the 3 parameters read like this: move controller(1) from set(2) to set(3)
cp5.getProperties().move(cp5.getController("slider1"), "default", "setA");
// use copy instead of move to register 'slider' with both sets (default and setA)
// prints the current list of properties registered and the set(s) they belong to
cp5.getProperties().print();
/* by default properties are saved in JSON format, if you want to change to the old default (java's serialized format), un-comment line below*/
// cp5.getProperties().setFormat(ControlP5.SERIALIZED);
}
void draw() {
background(0);
fill(slider1);
rect(250, 100, 100, 20);
fill(slider2);
rect(250, 150, 100, 20);
fill(slider3);
rect(250, 200, 100, 20);
fill(slider4);
rect(250, 250, 100, 20);
}
void b1(float v) {
cp5.saveProperties("setA", "setA");
}
void b2(float v) {
cp5.loadProperties(("setA"));
}
void b3(float v) {
cp5.saveProperties("default", "default");
}
void b4(float v) {
cp5.loadProperties(("default.json"));
}
/*
a list of all methods available for the ControllerProperties class
use ControlP5.printPublicMethodsFor(ControllerProperties.class);
to print the following list into the console.
You can find further details about class ControllerProperties in the javadoc.
Format:
ClassName : returnType methodName(parameter type)
controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface)
controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface, String)
controlP5.ControllerProperties : ControllerProperties remove(ControllerInterface, String, String)
controlP5.ControllerProperties : ControllerProperty getProperty(ControllerInterface, String)
controlP5.ControllerProperties : ControllerProperty getProperty(ControllerInterface, String, String)
controlP5.ControllerProperties : ControllerProperty register(ControllerInterface, String)
controlP5.ControllerProperties : ControllerProperty register(ControllerInterface, String, String)
controlP5.ControllerProperties : HashSet addSet(String)
controlP5.ControllerProperties : HashSet getPropertySet(ControllerInterface)
controlP5.ControllerProperties : List get(ControllerInterface)
controlP5.ControllerProperties : Map get()
controlP5.ControllerProperties : String toString()
controlP5.ControllerProperties : boolean load()
controlP5.ControllerProperties : boolean load(String)
controlP5.ControllerProperties : void delete(ControllerProperty)
controlP5.ControllerProperties : void move(ControllerInterface, String, String)
controlP5.ControllerProperties : void move(ControllerProperty, String, String)
controlP5.ControllerProperties : void only(ControllerProperty, String)
controlP5.ControllerProperties : void print()
controlP5.ControllerProperties : void setFormat(Format)
java.lang.Object : String toString()
java.lang.Object : boolean equals(Object)
*/