Skip to content

Commit c0cfda7

Browse files
author
adc
committed
add MHexPad and MRoundPad views for Manta and similar.
1 parent 24f0082 commit c0cfda7

File tree

4 files changed

+221
-14
lines changed

4 files changed

+221
-14
lines changed

Modality/Classes/GUI/MHexPad.sc

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
2+
MHexPad : MPadView {
3+
var <>hexColor, <>ledColors, <ledVal = 0, <angle = 0.5pi;
4+
var <upDoesAction = true;
5+
6+
*initClass {
7+
Class.initClassTree(MPadView);
8+
modes.put(\noteOnLed, [true, false, true, inf]);
9+
}
10+
11+
setColors {
12+
baseColor = Color.clear;
13+
hexColor = Color.grey(0.5, 0.5);
14+
hiliteColor = Color.white.alpha_(0.5);
15+
ledColors = [baseColor, Color(1.0, 0.75, 0, 0.7), Color(1.0, 0.25, 0, 0.7)];
16+
ledVal = 0;
17+
}
18+
19+
ledVal_ { |val| ledVal = val; this.refresh }
20+
angle_ { |val| angle = val; this.refresh }
21+
22+
upDoesAction_ { |bool = true|
23+
upDoesAction = bool;
24+
if (bool.not) {
25+
this.view.mouseUpAction = { |vw, x, y|
26+
if( autoUpTime == inf ) {
27+
this.upValueAction = y.linlin( 0, vw.bounds.height, 1, 0 );
28+
};
29+
};
30+
} {
31+
this.view.mouseUpAction = { |vw, x, y|
32+
this.upValue_(0);
33+
this.valueAction = 0;
34+
this.pressed = false;
35+
};
36+
}
37+
}
38+
39+
baseDrawFunc {
40+
^{ |vw|
41+
var bounds = vw.bounds, center = (bounds.extent * 0.5);
42+
var halfColor = hiliteColor.copy.alpha_( hiliteColor.alpha * 0.5 );
43+
var rect, fillRect, fillRect2, fillColor;
44+
45+
var hexPoints = 7.collect { |i| Polar(center.y, 2pi * (i/6) + angle).asPoint + center };
46+
Pen.fillColor = hexColor;
47+
Pen.moveTo(hexPoints.last); hexPoints.do(Pen.lineTo(_));
48+
Pen.fill;
49+
50+
if( pressed ) {
51+
Pen.width = 4;
52+
Pen.strokeColor_(hiliteColor);
53+
Pen.addArc(center, value * center.y, 0, 2pi);
54+
Pen.stroke;
55+
if (useMoveValue) {
56+
Pen.fillColor_(halfColor);
57+
Pen.addArc(center, moveValue * center.y, 0, 2pi);
58+
Pen.fill;
59+
};
60+
};
61+
if (ledVal > 0) {
62+
Pen.addArc(center, center.y * 0.25, 0, 2pi);
63+
Pen.fillColor_(ledColors[ledVal]);
64+
Pen.fill;
65+
};
66+
if( label.notNil ) {
67+
Pen.use({
68+
Pen.font = font;
69+
Pen.color = baseColor.complementary.alpha_(1.0);
70+
Pen.stringCenteredIn(
71+
MKtlGUI.splitLabel(label),
72+
bounds.moveTo(0,vShiftLabel);
73+
);
74+
});
75+
};
76+
};
77+
}
78+
}
79+
80+
MRoundPad : MHexPad {
81+
baseDrawFunc {
82+
^{ |vw|
83+
var bounds = vw.bounds, center = (bounds.extent * 0.5);
84+
var halfColor = hiliteColor.copy.alpha_( hiliteColor.alpha * 0.5 );
85+
var rect, fillRect, fillRect2, fillColor;
86+
87+
// only background shape is different
88+
Pen.fillColor = hexColor;
89+
Pen.addArc(center, center.y, 0, 2pi);
90+
Pen.fill;
91+
92+
if( pressed ) {
93+
Pen.width = 4;
94+
Pen.strokeColor_(hiliteColor);
95+
Pen.addArc(center, value * center.y, 0, 2pi);
96+
Pen.stroke;
97+
if (useMoveValue) {
98+
Pen.fillColor_(halfColor);
99+
Pen.addArc(center, moveValue * center.y, 0, 2pi);
100+
Pen.fill;
101+
};
102+
};
103+
if (ledVal > 0) {
104+
Pen.addArc(center, center.y * 0.25, 0, 2pi);
105+
Pen.fillColor_(ledColors[ledVal]);
106+
Pen.fill;
107+
};
108+
if( label.notNil ) {
109+
Pen.use({
110+
Pen.font = font;
111+
Pen.color = baseColor.complementary.alpha_(1.0);
112+
Pen.stringCenteredIn(
113+
MKtlGUI.splitLabel(label),
114+
bounds.moveTo(0,vShiftLabel);
115+
);
116+
});
117+
};
118+
};
119+
}
120+
}

Modality/Classes/GUI/MKtlGUI.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ MKtlGUI {
256256
// elemsToShow = mktl.elementGroup.flat;
257257
// keep groups with a groupType together
258258
elemsToShow = mktl.elementGroup.elements.flatIf { |el| el.groupType.isNil };
259-
"%: will show % elements of % in % views.\n".postf(thisMethod, mktl,
259+
"%: will show %'s % elements in % views.\n".postf(thisMethod, mktl,
260260
mktl.elementsDict.size, elemsToShow.size);
261261

262262
views = elemsToShow.collect({ |item|

Modality/Classes/GUI/MPadView.sc

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,8 @@ MPadView : SCViewHolder {
5252
mode = modeName;
5353
}
5454

55-
init { |parent, bounds, argMode = \noteOnOff|
56-
baseColor = Color.white;
57-
hiliteColor = Color.red(0.75,0.5);
58-
this.view = UserView( parent, bounds );
59-
60-
this.view.drawFunc = { |vw|
55+
baseDrawFunc {
56+
^{ |vw|
6157
var rect, fillRect, fillRect2, fillColor;
6258
var halfColor = hiliteColor.copy.alpha_( hiliteColor.alpha * 0.5 );
6359
var name;
@@ -102,25 +98,34 @@ MPadView : SCViewHolder {
10298
});
10399
};
104100
};
101+
}
102+
103+
setColors {
104+
baseColor = Color.white;
105+
hiliteColor = Color.red(0.75,0.5);
106+
}
107+
108+
init { |parent, bounds, argMode = \noteOnOff|
109+
this.setColors;
110+
111+
this.view = UserView( parent, bounds );
112+
this.view.drawFunc = this.baseDrawFunc;
105113

106114
this.view.mouseDownAction = { |vw, x, y|
107-
var rect = vw.bounds.moveTo(0, 0).insetBy(1,1);
108-
this.valueAction = y.linlin( 0, rect.height, 1, 0 );
115+
this.valueAction = y.linlin( 0, vw.bounds.height, 1, 0 );
109116
};
110117
this.view.mouseMoveAction = { |vw, x, y|
111-
var rect = vw.bounds.moveTo(0, 0).insetBy(1,1);
112118
if (useMoveValue) {
113-
this.moveValueAction = y.linlin( 0, rect.height, 1, 0 );
119+
this.moveValueAction = y.linlin( 0, vw.bounds.height, 1, 0 );
114120
};
115121
};
116122

117123
this.view.mouseUpAction = { |vw, x, y|
118-
var rect;
119124
if( autoUpTime == inf ) {
120-
rect = vw.bounds.moveTo(0, 0).insetBy(1,1);
121-
this.upValueAction = y.linlin( 0, rect.height, 1, 0 );
125+
this.upValueAction = y.linlin( 0, vw.bounds.height, 1, 0 );
122126
};
123127
};
128+
124129
this.mode_(argMode);
125130

126131
this.refresh;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
TITLE:: MHexPad
2+
summary:: extends MPadView for Hexagonal and round pads
3+
categories:: GUI
4+
related:: Classes/MKtl, Classes/MKtlGUI, Overviews/MOdality
5+
6+
DESCRIPTION::
7+
code::MHexPad:: and code::MRoundPad:: allow more different shapes and behaviors than its superclass, MPadView.
8+
9+
10+
First code examples:
11+
12+
code::
13+
// make a window with some MPadViews
14+
15+
w = Window("manta").front;
16+
h = 6.collect { |j|
17+
8.collect { |i|
18+
var h = MHexPad(w, Rect(i * 45 + (j % 2 * 22), j * 40, 45, 45)).mode_(\noteOnLed);
19+
h.action = { |el| "pad %, % vel % \n".postf(j, i, el.value.round(0.01)) };
20+
h.upDoesAction = true;
21+
h.label = "p_%_%".format(j, i);
22+
h.moveAction = { |el| "pad %, % move % \n".postf(j, i, el.moveValue.round(0.01)) };
23+
}};
24+
25+
h.flat.do(_.ledVal_(2));
26+
h.flat.do(_.ledVal_(1));
27+
h.flat.do(_.ledVal_(0));
28+
29+
h.flat.do(_.vShiftLabel_(10));
30+
31+
32+
Task {
33+
100.do { |i|
34+
defer { h.flat.do(_.angle_(i * 0.1)) };
35+
0.1.wait;
36+
}
37+
}.play;
38+
39+
h[0][0].ledColors.put(0, Color.black); h[0][0].refresh;
40+
h[0][0].ledVal = 3.rand;
41+
h[0][0].label = "";
42+
43+
h.flat.do { |m| m.hexColor_(Color.rand).refresh };
44+
45+
Task {
46+
100.do { |i|
47+
defer { h.flat.do { |m| m.angle_(m.angle + 0.1.bilinrand) } };
48+
0.1.wait;
49+
}
50+
}.play;
51+
52+
::
53+
54+
55+
CLASSMETHODS::
56+
57+
private:: initClass
58+
59+
60+
INSTANCEMETHODS::
61+
62+
private:: baseDrawFunc, setColors
63+
64+
METHOD:: upDoesAction
65+
66+
argument:: bool
67+
get and set flag whether mouseUp also triggers the pads action or not.
68+
this allows using noteOn with value 1-127, and noteOn with value 0 to signal note end
69+
(which is the standard the Manta uses).
70+
71+
METHOD:: angle
72+
rotate the pad by an angle
73+
74+
METHOD:: ledColors
75+
get and set the colors to use for the led display
76+
77+
METHOD:: ledVal
78+
get and set the value which led color to show.
79+
80+
METHOD:: hexColor
81+
the color for the background hexagon shape.
82+

0 commit comments

Comments
 (0)