File: EZSpecEditor.sc

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (105 lines) | stat: -rw-r--r-- 3,817 bytes parent folder | download | duplicates (5)
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
EZControlSpecEditor : EZGui {

	var <minView, <maxView, <warpView, <stepView, <controlSpec;

	*new { arg parent, bounds, label = "Mn/Mx/Wp/Stp", controlSpec, labelWidth=100, labelHeight=20, layout=\horz, gap, margin;

		^super.new.init(parent, bounds, label, controlSpec, labelWidth, labelHeight, layout, gap, margin)
	}

	init { arg parentView, bounds, label, argControlSpec, labelWidth, labelHeight, argLayout, argGap, argMargin;

		var labelBounds, minBounds, maxBounds, warpBounds, stepBounds;

		// Set Margin and Gap
		this.prMakeMarginGap(parentView, argMargin, argGap);

		layout=argLayout;
		bounds.isNil.if{bounds = 350@20};


		// if no parent, then pop up window
		#view,bounds = this.prMakeView(parentView, bounds);


		labelSize=labelWidth@labelHeight;

		// calculate bounds of all subviews
		#labelBounds, minBounds, maxBounds, warpBounds, stepBounds = this.prSubViewBounds(innerBounds);

		// instert the views
		labelView = StaticText.new(view, labelBounds);
		labelView.string = label;

//		(unitWidth>0).if{ //only add a unitLabel if desired
//			unitView = StaticText.new(view, unitBounds);
//		};

		minView = NumberBox.new(view, minBounds);
		maxView = NumberBox.new(view, maxBounds);
		warpView = TextField.new(view, warpBounds);
		stepView = NumberBox.new(view, stepBounds);

		// set view parameters and actions

		controlSpec = argControlSpec.asSpec;

		minView.value = controlSpec.minval;
		maxView.value = controlSpec.maxval;
		warpView.value = controlSpec.warp.asSpecifier.asCompileString;
		stepView.value = controlSpec.step;

		minView.action = { controlSpec.minval = minView.value };
		maxView.action = { controlSpec.maxval = maxView.value };
		warpView.action = { try { controlSpec.warp = warpView.value.interpret.asWarp(controlSpec) } };
		stepView.action = { controlSpec.step = stepView.value };

		//this.prSetViewParams;

	}

	prSubViewBounds{arg rect;  // calculate subview bounds
		var labelBounds, minBounds, maxBounds, warpBounds, stepBounds;
		var gap1, gap2, gap3, tmp, labelH, componentSize;
		gap1 = gap.copy;
		gap2 = gap.copy;
		gap3 = gap.copy;
		labelH=labelSize.y;//  needed for \vert

		switch (layout,
			\line2, {
				componentSize = ((rect.width - (3 * gap.x) - labelSize.x) / 4)@labelH;
				stepBounds = componentSize.asRect.left_(rect.width - componentSize.x);
				warpBounds = componentSize.asRect.left_(stepBounds.left-componentSize.x-gap.x);
				maxBounds = componentSize.asRect.left_(warpBounds.left-componentSize.x-gap.x);
				minBounds = componentSize.asRect.left_(maxBounds.left-componentSize.x-gap.x);
				labelBounds = (labelSize.x@labelSize.y).asRect.width_(minBounds.left-gap.x); //adjust width
			},

			\vert, {
				componentSize = labelSize.x@((rect.height - (3 * gap.y) - labelH) / 4);
				labelBounds = (rect.width@labelH).asRect; // to top
				minBounds = (rect.width@componentSize.y)
					.asRect.top_(labelBounds.bottom + gap.y);
				maxBounds = (rect.width@componentSize.y)
					.asRect.top_(minBounds.bottom + gap.y);
				warpBounds = (rect.width@componentSize.y)
					.asRect.top_(maxBounds.bottom + gap.y);
				stepBounds = (rect.width@componentSize.y)
					.asRect.top_(warpBounds.bottom + gap.y);
			},

			\horz, {
				componentSize = ((rect.width - (3 * gap.x) - labelSize.x) / 4)@labelH;
				stepBounds = componentSize.asRect.left_(rect.width - componentSize.x);
				warpBounds = componentSize.asRect.left_(stepBounds.left-componentSize.x-gap.x);
				maxBounds = componentSize.asRect.left_(warpBounds.left-componentSize.x-gap.x);
				minBounds = componentSize.asRect.left_(maxBounds.left-componentSize.x-gap.x);
				labelBounds = (labelSize.x@labelSize.y).asRect.width_(minBounds.left-gap.x); //adjust width
			}
		);


		^[labelBounds, minBounds, maxBounds, warpBounds, stepBounds].collect{arg v; v.moveBy(margin.x,margin.y)}
	}
}