forked from marierm/mmExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpongeGui.sc
113 lines (106 loc) · 2.86 KB
/
SpongeGui.sc
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
SpongeGui : ObjectGui {
var <>actions, listInactive, listActive, viewActive, viewInactive,
prefixView, portView, addrView;
*new { arg model;
var new;
new = super.new;
new.model_(model);
^new.init;
}
init {
this.prUpdateLists;
actions = IdentityDictionary[
\featureActivated -> {|model, what, featureDef|
this.prUpdateLists;
viewActive.items_(listActive);
viewInactive.items_(listInactive);
},
\featureDeactivated -> {|model, what, featureDef|
this.prUpdateLists;
viewActive.items_(listActive);
viewInactive.items_(listInactive);
}
];
}
prUpdateLists {
listActive = model.features.collect({ |i| i.name });
listInactive = Sponge.featureList.collect(
{ |i| i[\name] } ).removeAll(listActive);
}
update { arg model, what ... args;
var action;
action = actions.at(what);
if (action.notNil, {
action.valueArray(model, what, args);
});
}
gui { arg ... args;
var w;
w = Window("A Sponge GUI");
// w = ScrollView(x, Rect(0,0,x.bounds.width, x.bounds.height));
w.layout_(QVLayout());
w.layout.add(
QHLayout(
StaticText(w).string_(
"Sponge" + model.portName
).align_(\center).font_(Font.default.size_(24))
)
);
w.layout.add(
QHLayout(
StaticText(w).string_("OSC Prefix").align_(\right).minWidth_(80),
prefixView = TextField(w).string_("/sponge/01"),
Button(w).states_([["Set For All Features"]]).action_({
model.setOSCprefix(prefixView.value);
})
)
);
w.layout.add(
QHLayout(
StaticText(w).string_("OSC Address").align_(\right).minWidth_(80),
addrView = TextField(w).string_(NetAddr.localAddr.hostname),
Button(w).states_([["Set For All Features"]]).action_({
model.setOSCaddr(addrView.value);
})
)
);
w.layout.add(
QHLayout(
StaticText(w).string_("OSC Port").align_(\right).minWidth_(80),
portView = TextField(w).string_(NetAddr.localAddr.port),
Button(w).states_([["Set For All Features"]]).action_({
model.setOSCport(portView.value.asInteger);
})
)
);
w.layout.add(
QHLayout(
StaticText(w).string_("Available Features"),
StaticText(w).string_("Active Features")
);
);
w.layout.add(
QHLayout(
viewInactive = ListView(w).items_(listInactive).mouseDownAction_({
|view, x, y, modifiers, buttonNumber, clickCount|
(buttonNumber == 0 and: clickCount == 2).if {
model.activateFeature(view.items[view.value]);
};
}),
viewActive = ListView(w).items_(listActive).mouseDownAction_({
|view, x, y, modifiers, buttonNumber, clickCount|
(buttonNumber == 0 and: clickCount == 2).if {
model.features[
model.featureNames.indexOf(view.items[view.value])
].gui;
};
}).keyDownAction_({ |view, key|
((key == 8.asAscii) or: (key == 127.asAscii)).if{
model.deactivateFeature(view.items[view.value]);
}
})
);
);
w.front;
}
}