10000 Update envtool GUI by klknn · Pull Request #19 · klknn/kdr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update envtool GUI #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into master from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/kdr/envtool/client.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class EnvToolClient : Client {
}

override IGraphics createGraphics() {
if (!_gui) _gui = mallocNew!EnvToolGUI(params[Params.envelope .. $]);
if (!_gui) _gui = mallocNew!EnvToolGUI(params);
return _gui;
}

Expand All @@ -49,7 +49,7 @@ class EnvToolClient : Client {
override void processAudio(
const(float*)[] inputs, float*[] outputs, int frames, TimeInfo info) {
const Envelope env = buildEnvelope(params[Params.envelope .. $]);
const double beatScale = beatScaleValues[readParam!int(Params.beatScale)] * 4;
const double beatScale = rateValues[readParam!int(Params.rate)] * 4;
const float depth = readParam!float(Params.depth);
const double beatPerSample = info.tempo / 60 / _sampleRate;
foreach (c; 0 .. inputs.length) {
Expand Down
114 changes: 100 additions & 14 deletions source/kdr/envtool/gui.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dplug.gui : Click, flagRaw, flagAnimated, makeSizeConstraintsFixed,
import dplug.graphics : cropImageRef, ImageRef, RGBA;
import dplug.canvas : Canvas;
import dplug.flatwidgets : UIWindowResizer;
import dplug.pbrwidgets : PBRBackgroundGUI;
import dplug.pbrwidgets; // : PBRBackgroundGUI;

import kdr.envelope : Envelope;
import kdr.envtool.params;
Expand All @@ -21,6 +21,17 @@ private enum png1 = "114.png"; // "gray.png"; // "black.png"
private enum png2 = "black.png";
private enum png3 = "black.png";

enum RGBA lineColor = RGBA(0, 255, 255, 96);
enum RGBA gradColor = RGBA(0, 32, 32, 96);
enum RGBA gridColor = RGBA(100, 200, 200, 32);
// enum RGBA gridColor = RGBA(64, 64, 64, 64);
enum RGBA darkColor = RGBA(128, 128, 128, 128);
enum RGBA lightColor = RGBA(100, 200, 200, 200);
enum RGBA textColor = RGBA(155, 255, 255, 0);
enum RGBA knobColor = RGBA(96, 96, 96, 96);
enum RGBA litColor = RGBA(155, 255, 255, 0);
enum RGBA unlitColor = RGBA(0, 32, 32, 0);

/// UI for displaying/tweaking kdr.envelope.Envelope.
class EnvelopeUI : UIElement, IParameterListener {
public:
Expand Down Expand Up @@ -132,7 +143,6 @@ class EnvelopeUI : UIElement, IParameterListener {
if (prev < px && px < srcx) prev = px;
if (srcx < px && px < next) next = px;
}
logDebug("newp.x %f, prev %f next %f", newp.x, prev, next);
newp.x = clamp(newp.x, prev, next);

point.x.beginParamEdit();
Expand All @@ -156,20 +166,14 @@ class EnvelopeUI : UIElement, IParameterListener {
}

override void onDrawRaw(ImageRef!RGBA rawMap, box2i[] dirtyRects) {
enum RGBA lineColor = RGBA(0, 255, 255, 96);
enum RGBA gradColor = RGBA(0, 32, 32, 96);
enum RGBA gridColor = RGBA(96, 96, 96, 96);
enum RGBA darkColor = RGBA(128, 128, 128, 128);
enum RGBA lightColor = RGBA(100, 200, 200, 200);

Envelope env = buildEnvelope(_params);
foreach (ref rect; dirtyRects) {
ImageRef!RGBA cropped = cropImageRef(rawMap, rect);
_canvas.initialize(cropped);
_canvas.translate(-rect.min.x, -rect.min.y);

// Draw grid.
enum float gridWidth = 0.002;
enum float gridWidth = 0.0015;
int numGrid = 8;
foreach (float i; 0 .. numGrid + 1) {
_canvas.fillStyle = gridColor;
Expand Down Expand Up @@ -266,28 +270,110 @@ unittest {
class EnvToolGUI : PBRBackgroundGUI!(png1, png2, png3, png3, png3, "") {
public:
@nogc nothrow:
this(Parameter[] envParams) {
this(Parameter[] params) {
logDebug("Initialize %s", __FUNCTION__.ptr);

static immutable float[] ratios = [1.0f, 1.25f, 1.5f, 1.75f, 2.0f];
super(makeSizeConstraintsDiscrete(400, 300, ratios));
super(makeSizeConstraintsDiscrete(500, 300, ratios));

_params = params;
_font = mallocNew!Font(cast(ubyte[]) import("FORCED SQUARE.ttf"));

_title = buildLabel("kdr envtool");
_date = buildLabel("build: " ~ __DATE__ ~ "");

addChild(_resizer = mallocNew!UIWindowResizer(context()));
addChild(_envui = mallocNew!EnvelopeUI(context(), envParams));
addChild(_envui = mallocNew!EnvelopeUI(
context(), params[Params.envelope .. $]));

_rateKnob = buildKnob(Params.rate);
_rateLabel = buildLabel("rate");

_depthKnob = buildKnob(Params.depth);
_depthLabel = buildLabel("depth");

_stereoOffsetKnob = buildKnob(Params.stereoOffset);
_stereoOffsetLabel = buildLabel("offset");
}

override void reflow() {
super.reflow();
const int W = position.width;
const int H = position.height;

enum hintSize = 10;
// Main.
_envui.position = rectangle(0, 0, cast(int) (W * 0.8), cast(int) (H * 0.9));

_title.position = rectangle(0, _envui.position.max.y, _envui.position.width / 2,
cast(int) (H * 0.1));
_title.textSize = _title.position.height;

_date.position = rectangle(_title.position.max.x,
_title.position.min.y + _title.position.height / 2,
_envui.position.width - _title.position.width,
_title.position.height / 2);
_date.textSize = _title.textSize / 2;

// Knobs.
int knobSize = cast(int) (W * 0.15);
int knobX = cast(int) (W * 0.825);
int labelSize = knobSize / 4;
int labelMargin = labelSize / 4;

_rateKnob.position = rectangle(
knobX, cast(int) (H * 0.025), knobSize, knobSize);
_rateLabel.textSize = labelSize;
_rateLabel.position = rectangle(
knobX, _rateKnob.position.max.y, knobSize, labelSize);

_depthKnob.position = rectangle(
knobX, _rateLabel.position.max.y, knobSize, knobSize);
_depthLabel.textSize = labelSize;
_depthLabel.position = rectangle(
knobX, _depthKnob.position.max.y, knobSize, labelSize);

_stereoOffsetKnob.position = rectangle(
knobX, _depthLabel.position.max.y, knobSize, knobSize);
_stereoOffsetLabel.textSize = labelSize;
_stereoOffsetLabel.position = rectangle(
knobX, _stereoOffsetKnob.position.max.y, knobSize, labelSize);

int hintSize = 10;
_resizer.position = rectangle(W - hintSize, H - hintSize,
hintSize, hintSize);
_envui.position = rectangle(0, 0, W - hintSize, H - hintSize);
}

private:
UIKnob buildKnob(Params pid) {
UIKnob knob;
addChild(knob = mallocNew!UIKnob(this.context, _params[pid]));
knob.knobRadius = 0.65f;
knob.knobDiffuse = knobColor;
// NOTE: material [R(smooth), G(metal), B(shiny), A(phisycal)]
knob.knobMaterial = RGBA(255, 0, 0, 0);
knob.numLEDs = 0;
knob.litTrailDiffuse = litColor;
knob.unlitTrailDiffuse = unlitColor;
knob.trailRadiusMin = 0.1;
knob.trailRadiusMax = 0.8;
return knob;
}

UILabel buildLabel(string text) {
UILabel label;
addChild(label = mallocNew!UILabel(this.context, _font, text));
label.textColor = textColor;
return label;
}

Font _font;
UILabel _title, _date;
Parameter[] _params;
UIWindowResizer _resizer;
EnvelopeUI _envui;
UIKnob _rateKnob, _depthKnob, _stereoOffsetKnob;
UILabel _rateLabel, _depthLabel, _stereoOffsetLabel;

enum litTrailDiffuse = RGBA(151, 119, 255, 100);
enum unlitTrailDiffuse = RGBA(81, 54, 108, 0);
}
14 changes: 7 additions & 7 deletions source/kdr/envtool/params.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kdr.envelope;

/// Parameter for EnvToolClient.
enum Params {
beatScale,
rate,
depth,
stereoOffset,
// volumeMod,
Expand All @@ -19,11 +19,11 @@ enum Params {
envelope,
}

/// Used by the "beatScale" param.
immutable string[] beatScaleLabels = ["1/64", "1/48", "1/32", "1/24", "1/16", "1/12", "1/8", "1/6", "1/4", "1/3", "1/2", "1/1", "2/1", "4/1", "8/1"];
/// Used by the "rate" param.
immutable string[] rateLabels = ["1/64", "1/48", "1/32", "1/24", "1/16", "1/12", "1/8", "1/6", "1/4", "1/3", "1/2", "1/1", "2/1", "4/1", "8/1"];
/// ditto.
immutable double[] beatScaleValues = [1./64, 1./48, 1./32, 1./24, 1./16, 1./12, 1./8, 1./6, 1./4, 1./3., 1./2, 1., 2., 4., 8.];
static assert(beatScaleLabels.length == beatScaleValues.length);
immutable double[] rateValues = [1./64, 1./48, 1./32, 1./24, 1./16, 1./12, 1./8, 1./6, 1./4, 1./3., 1./2, 1., 2., 4., 8.];
static assert(rateLabels.length == rateValues.length);

/// Returns:
/// Envelope parameters.
Expand All @@ -33,9 +33,9 @@ Parameter[] buildEnvelopeParameters() {

int n = 0;
// General config.
params.pushBack(mallocNew!EnumParameter(n++, "beatScale", beatScaleLabels, 8));
params.pushBack(mallocNew!EnumParameter(n++, "rate", rateLabels, 8));
params.pushBack(mallocNew!LinearFloatParameter(n++, "depth", "", 0.0, 1.0, 1.0));
params.pushBack(mallocNew!LinearFloatParameter(n++, "stereoOffset", "", 0.0, 0.5, 0.0));
params.pushBack(mallocNew!LinearFloatParameter(n++, "stereoOffset", "", -1, 1, 0.0));

// Envelope config.
params.pushBack(mallocNew!LinearFloatParameter(n++, "bias", "", 0, 1, 0));
Expand Down
0