SC OSC trackpad

Thought some of you might find this useful. It’s a GUI interface for sending OSC signals via trackpad. Works similar to a Pitch bend wheel, in that it always snaps back to center.

Written by alberto.decampo@gmail.com

// here in 2D with explanatory comments
// - happy to share this on the tidal list of course!

(
////// 2D-Bend wheel for Tidal, written by adc, 3/2019
m = NetAddr("127.0.0.1", 6010);
w = Window("XY Bender", Rect(1920, 1080, 235, 150)).front.alwaysOnTop_(true);

~benddx = 0; ~benddy = 0;
~bendxval = 0; ~bendyval = 0;
u = UserView(w, w.view.bounds);
u.background_(Color.green);
u.resize_(5);

// change where x and y bendvals are sent:
~sendFunc = {
        m.sendMsg(*["/ctrl sf", "k1", ~bendxval].postln);
        m.sendMsg(*["/ctrl sf", "k2", ~bendyval].postln);
};

u.drawFunc = { |uv|
        var bounds = uv.bounds;
        var height = bounds.height;
        var width = bounds.width;
        var xpos = ~bendxval.linlin(-1.0, 1.0, 0, width - 3);
        var ypos = ~bendyval.linlin(-1.0, 1.0, 0, height - 3);
        Pen.stringCenteredIn("click and drag\nhere for 2D bend", bounds, Font.default.size_(20));
        Pen.width = 3;
        Pen.line(xpos@0, xpos@height).stroke;
        Pen.line(0@ypos, width@ypos).stroke;
};

u.mouseDownAction = { |u, x, y|
        // just init, dont send
        ~bendx0 = x; ~bendy0 = x;
};

u.mouseMoveAction = { |u, x, y|
        // calc relative movement and send
        ~benddx = x - ~bendx0;
        ~benddy = y - ~bendy0;
        ~bendxval = (~benddx / 200).clip2(1);
        ~bendyval = (~benddy / 200).clip2(1);
        ~sendFunc.value;
        u.refresh;
};
u.mouseUpAction = { |u, x, y|
        // reset to center and send
        ~bendxval = 0;
        ~bendyval = 0;
        ~sendFunc.value;
        u.refresh;
};
)
4 Likes