Skip to content

Instantly share code, notes, and snippets.

@scztt
Last active February 29, 2024 12:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scztt/536ecc746d4afbfc4094d7e99f7e1c71 to your computer and use it in GitHub Desktop.
Save scztt/536ecc746d4afbfc4094d7e99f7e1c71 to your computer and use it in GitHub Desktop.
+ Bus {
debugScope {
| title, names |
var w, ms, listArray, size=380, sliderLoc=0, routine, bus,
min=1000.0, max=(-1000.0), minBox, maxBox, val=0, valBox, synth, m, n, bottom,
playSynthFunction, cmdPeriodFunction, layout;
cmdPeriodFunction = {};
title = title ? "bus %".format( index );
m = 0.0; n=0.0;
w = Window( title, scroll:true);
w.view.hasHorizontalScroller = false;
w.view.layout = layout = VLayout();
listArray = Array.fill(200,0.0) ! numChannels;
ms = Array.newClear( numChannels );
maxBox = Array.newClear( numChannels );
minBox = Array.newClear( numChannels );
valBox = Array.newClear( numChannels );
min = 0 ! numChannels;
max = 0 ! numChannels;
numChannels.do({
| i |
var comp, overlay;
comp = View()
.fixedHeight_(120)
.background_(Color.grey);
overlay = StaticText(bounds:350@50)
.font_( Font("M+ 1c", 34) )
.stringColor_( Color.grey(0.8, 0.2) )
.string_( " " ++ names.notNil.if({ names[i] }, { i + index }) );
ms[i] = MultiSliderView(bounds:400@120)
.value_(listArray[i])
.elasticMode_(true)
.editable_(false)
.background_(Color.clear)
.xOffset_(2)
.drawLines_(true)
.thumbSize_(1)
.drawRects_(false);
maxBox[i] = DragSink()
.fixedSize_(100@24)
.font_( Font("M+ 1c", 12) )
.mouseDownAction_({ |obj| max[i]=(-99999999) })
.string_(" " + 0.asString);
valBox[i] = DragSink()
.fixedSize_(100@24)
.font_( Font("M+ 1c", 12) )
.string_(" " + 0.asString)
.stringColor_(Color.green);
minBox[i] = DragSink()
.fixedSize_(100@24)
.font_( Font("M+ 1c", 12) )
.mouseDownAction_({ |obj| min[i]=(9999999) })
.string_(" " + 0.asString);
comp.layout_(HLayout(
StackLayout(overlay, ms[i]).mode_(\stackAll),
VLayout(
maxBox[i], valBox[i], minBox[i]
)
));
w.view.layout.add(comp);
});
routine = SkipJack({
var vals = this.getnSynchronous(this.numChannels).asArray;
vals.do({
| val, i |
var aMin, aMax;
if( val > max[i], {max[i] = val});
if( val < min[i], {min[i] = val});
minBox[i].string_( " " + min[i].asString[0..7] );
maxBox[i].string_( " " + max[i].asString[0..7] );
valBox[i].string_(" " + val.asString[0..7] );
listArray[i] = listArray[i].copyRange(1, 198) ++ [val];
ms[i].value_( (listArray[i]-min[i])/(max[i]-min[i]) );
})
},
dt: 1/30,
name: "debugScope",
clock: AppClock
);
routine.start;
CmdPeriod.add(cmdPeriodFunction);
w.onClose = {
routine.stop;
synth.free;
CmdPeriod.remove(cmdPeriodFunction);
};
w.front;
}
}
+NodeProxy {
debugScope {
this.bus.debugScope();
}
}
@elgiano
Copy link

elgiano commented Jan 16, 2021

I made a few little changes to improve layout management:

+ Bus {
	debugScope { |title, names|
		var ms, listArray, widgets, scroll, routine,
		min, max, minBox, maxBox, val=0, valBox,
		cmdPeriodFunction = {};

		if (this.rate == \audio) {
			("debugScope only works for control-rate busses").error;
			^nil
		};
		if (this.server.serverRunning.not) {
			("debugScope: server not running").error;
			^nil
		};

		listArray = Array.fill(200,0.0) ! numChannels;

		# ms, maxBox, minBox, valBox = {
			Array.newClear( numChannels )
		}!4;
		# min,max = { 0 ! numChannels }!2;

		widgets = numChannels.collect{ |i|
			var view;
			var label = StaticText()
			.font_( Font(Font.defaultMonoFace, 34) )
			.stringColor_( Color.grey(0.8) )
			.string_( names.notNil.if({ names[i] }, { i + index }) );

			ms[i] = MultiSliderView()
			.value_(listArray[i])
			.elasticMode_(true)
			.editable_(false)
			// let's make sure values are readable
			.background_(Color.white)
			.xOffset_(2)
			.drawLines_(true)
			.thumbSize_(1)
			.drawRects_(false)
			.resize_(2);

			maxBox[i] = DragSink()
			.font_(Font(Font.defaultMonoFace, 12))
			.mouseDownAction_({ |obj| max[i]=(-1000.0) })
			.string_(" " + 0.asString);

			minBox[i] = DragSink()
			.font_(Font(Font.defaultMonoFace, 12))
			.mouseDownAction_({ |obj| min[i]=(1000.0) })
			.string_(" " + 0.asString);

			valBox[i] = DragSink()
			.font_(Font(Font.defaultMonoFace, 12))
			.string_(" " + 0.asString)
			.stringColor_(Color.green(0.5));

			view = View()
			.background_(Color.grey)
			.minSize_(500@120)
			.layout_(HLayout(
				[StackLayout(label, ms[i]).mode_(1), stretch:2],
				VLayout(maxBox[i], valBox[i], minBox[i])
			).margins_(5));

			[view, shrink:0]
		};


		routine = SkipJack({
			var vals = this.getnSynchronous(this.numChannels).asArray;
			vals.do({ |val, i|
				var aMin, aMax;
				if (val > max[i]) { max[i] = val };
				if (val < min[i]) { min[i] = val };
				minBox[i].string_(min[i].asFloat.asStringPrec(7));
				maxBox[i].string_(max[i].asFloat.asStringPrec(7));
				valBox[i].string_(val.asFloat.asStringPrec(7));
				listArray[i] = listArray[i].copyRange(1, 198) ++ [val];
				ms[i].value_(
					(listArray[i] - min[i]) / (max[i] - min[i])
				);
			})
		},
		dt: 0.1,
		name: "debugScope",
		clock: AppClock
		);

		routine.start;
		CmdPeriod.add(cmdPeriodFunction);

		scroll = ScrollView();
		scroll.canvas = View();
		scroll.canvas.layout = VLayout(*widgets).margins_(0).spacing_(0);

		title = title ? "bus %".format( index );
		Window(
			title,
			510@min(130*widgets.size, Window.availableBounds.height)
		)
		.layout_(VLayout(scroll).margins_(0))
		.onClose_({
			routine.stop;
			CmdPeriod.remove(cmdPeriodFunction);
		})
		.front();
	}
}

+NodeProxy {
	debugScope { |title,names|
		this.bus.debugScope(title,names);
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment