File: ParamView.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 (94 lines) | stat: -rw-r--r-- 2,375 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

ParamView {
	var <value, <label, <>action, <spec;
	var <zone, <zones, <slider, <ranger, <textview;
	var <ezviews, <currview, <viewType;
	var <>useRanger = true;

	*new { |parent, bounds, label, spec, action, initVal, initAction = false|
		^super.new.init(parent, bounds, label, spec, action, initVal, initAction);
	}

	bounds { ^zone.bounds }
	bounds_ { |bounds| zone.bounds_(bounds) }

	background { ^currview.labelView.background }
	background_ { |col|
		ezviews.do { |ez| ez.labelView.background_(col) }
	}

	label_ { |alabel|
		label = alabel;
		ezviews.do { |ez| ez.labelView.string_(alabel) };
	}

	enabled_ { |bool=true| zone.enabled_(bool) }
	enabled { ^zone.enabled }
	visible_ { |bool=true| zone.visible_(bool) }
	visible { ^zone.visible }

	init { |parent, bounds, argLabel, argSpec, argAction, initVal, initAction, initType = 0|
		var rect2 = bounds.moveTo(0,0);
		zone = CompositeView(parent, bounds);
		zones = 3.collect { |i| CompositeView(zone, rect2); };
		zone.resize_(2);
		zones.do(_.resize_(2));

		label = argLabel ? "-";
		spec = argSpec !? { argSpec.asSpec };
		action = argAction;

		slider = EZSlider(zones[0], rect2, label, spec);
		ranger = EZRanger(zones[1], rect2, label, spec);
		textview = EZText(zones[2], rect2, label);

		zones.do { |z| z.children[0].resize_(2) };

		ezviews = [slider, ranger, textview];
		ezviews.do { |ez|
			ez.action_({ |ez| this.valueAction_(ez.value) });
		};
		if (initVal.notNil) { this.value(initVal) };
		if (initAction) { this.doAction };
	}

	// types: 0 = slider, 1 = ranger, 2 = text
	viewType_ { |newType = 0, force = false|
		if (spec.isNil or: { useRanger.value != true }) {
			newType = newType.roundUp(2);
		};
		if (force or: { newType != viewType }) {
			if (newType.inclusivelyBetween(0, 2)) {
				zones.do { |z, i| z.visible_(newType == i) };
				viewType = newType;
				currview = ezviews[newType];
			};
		};
	}

	valueType { |newval|
		^case
		{ newval.isNumber } { 0 }
		{ newval.isKindOf(Array) and:
			{ newval.size == 2 and:
				{ newval.every(_.isNumber) }
			}
		} { 1 }
		{ 2 }
	}

	value_ { |val|
		this.viewType_(this.valueType(val));
		value = val;
		currview.value_(value);
	}

	doAction { action.value(this) }
	valueAction_ { |val| this.value_(val).doAction }

	spec_ { |newspec|
		spec = newspec !? { newspec.asSpec };
		slider.controlSpec_(spec);
		ranger.controlSpec_(spec);
	}
}