Skip to content

Commit

Permalink
New Envelope UI (!) and support for more keyboard device names on RPI
Browse files Browse the repository at this point in the history
  • Loading branch information
topisani committed Aug 14, 2018
1 parent 7613405 commit 59f482b
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 203 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ install_manifest.txt
deploy_key
/external/src/gl3w.c
/external/include/GL
/external/include/KHR
/testdir

imgui.ini
Expand Down
2 changes: 2 additions & 0 deletions boards/desktop/src/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "services/audio.hpp"
#include "services/ui.hpp"

#include "services/logger.hpp"

namespace otto::board::ui {

void handle_keyevent(Action action, Modifiers mods, Key key)
Expand Down
12 changes: 10 additions & 2 deletions boards/parts/ui/egl/src/egl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ namespace otto::service::ui {
egl.init();
#if OTTO_USE_FBCP
auto fbcp = RpiFBCP{egl.eglData};
fbcp.init();
bool use_fbcp = true;
try {
fbcp.init();
} catch (util::exception& e) {
LOGW("Error starting FBCP: {}", e.what());
LOGI("If you are using an HDMI screen you probably meant to compile with OTTO_USE_FBCP=OFF");
LOGI("FBCP has been disabled. /dev/fb0 will not be copied to /dev/fb1");
use_fbcp = false;
}
#endif

NVGcontext* nvg =
Expand Down Expand Up @@ -91,7 +99,7 @@ namespace otto::service::ui {
egl.endFrame();

#if OTTO_USE_FBCP
fbcp.copy();
if (use_fbcp) fbcp.copy();
#endif

lastFrameTime = clock::now() - t0;
Expand Down
11 changes: 9 additions & 2 deletions boards/parts/ui/egl/src/rpi_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ namespace otto::board::ui {

void read_encoders() {
auto file = fopen("/dev/ttyACM0", "r");
if (file == nullptr) return;
if (file == nullptr) {
LOGW("Encoder device not found (expected /dev/ttyACM0). Continuing without it");
return;
}

char *line = nullptr;
std::size_t len;
Expand Down Expand Up @@ -144,7 +147,11 @@ namespace otto::board::ui {
{
static Modifiers left;
static Modifiers right;
static int keyboard = open_device("0-event-kbd");
static int keyboard = [] {
int dev = open_device("0-event-kbd");
if (dev < 0) dev = open_device("event-kbd");
return dev;
}();
static std::thread encoder_thread = std::thread{[] { read_encoders(); }};

if (keyboard == -1) {
Expand Down
230 changes: 38 additions & 192 deletions src/core/audio/voice_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,214 +73,60 @@ namespace otto::core::audio {
}

static void draw_bg(Canvas& ctx);
static void draw_x_arrow(Canvas& ctx, Colour c, float pos);
static void draw_y_arrow(Canvas& ctx, Colour c, float pos);

void EnvelopeScreen::draw(Canvas& ctx)
{
const float a = props.attack.normalize() / 4.f;
const float d = props.decay.normalize() / 4.f + a;
const float s = props.sustain.normalize();
const float r = (props.release.normalize() + 3.f) / 4.f;
draw_bg(ctx);
draw_x_arrow(ctx, Colours::Blue, a);
draw_x_arrow(ctx, Colours::Green, d);
draw_y_arrow(ctx, Colours::Yellow, s);
draw_x_arrow(ctx, Colours::Red, r);

ctx.beginPath();
ctx.moveTo(45.9, 188.7);
ctx.lineTo(45.9 + a * 240.f, 188.7 - 137.f);
ctx.lineTo(45.9 + d * 240.f, 188.7 - s * 137.f);
ctx.lineTo(45.9 + (3.f / 4.f) * 240.f, 188.7 - s * 137.f);
ctx.lineTo(45.9 + r * 240.f, 188.7);
ctx.lineWidth(2.f);
ctx.stroke(Colours::White);
}

static void draw_x_arrow(Canvas& ctx, Colour c, float pos)
{
ctx.save();
ctx.translate(pos * 240.f, 0.f);
ctx.beginPath();
ctx.moveTo(49.9, 206.6);
ctx.lineTo(45.9, 199.7);
ctx.lineTo(41.9, 206.6);
ctx.lineTo(44.9, 206.6);
ctx.lineTo(44.9, 211.2);
ctx.bezierCurveTo(44.9, 211.8, 45.4, 212.2, 45.9, 212.2);
ctx.bezierCurveTo(46.5, 212.2, 46.9, 211.8, 46.9, 211.2);
ctx.lineTo(46.9, 206.6);
ctx.lineTo(49.9, 206.6);
ctx.closePath();
ctx.fill(c);
ctx.restore();
}

static void draw_y_arrow(Canvas& ctx, Colour c, float pos)
{
ctx.save();
ctx.translate(0.f, -pos * 137.f);
ctx.beginPath();
ctx.moveTo(36.3, 188.7);
ctx.lineTo(29.4, 184.7);
ctx.lineTo(29.4, 187.7);
ctx.lineTo(23.8, 187.7);
ctx.bezierCurveTo(23.3, 187.7, 22.8, 188.2, 22.8, 188.7);
ctx.bezierCurveTo(22.8, 189.3, 23.3, 189.7, 23.8, 189.7);
ctx.lineTo(29.4, 189.7);
ctx.lineTo(29.4, 192.7);
ctx.lineTo(36.3, 188.7);
ctx.closePath();
ctx.fill(c);
ctx.restore();
}

static void draw_bg(Canvas& ctx)
{
// Laag1/linegroup2/end
ctx.save();
ctx.beginPath();
ctx.moveTo(48.8, 51.7);
ctx.lineTo(42.3, 51.7);
ctx.lineWidth(2.0);
ctx.strokeStyle(Colour::bytes(61, 63, 65));
ctx.lineCap(Canvas::LineCap::ROUND);
ctx.lineJoin(Canvas::LineJoin::ROUND);
ctx.stroke();

// Laag1/linegroup2/6
ctx.beginPath();
ctx.moveTo(45.8, 71.7);
ctx.lineTo(42.3, 71.7);
ctx.stroke();

// Laag1/linegroup2/5
ctx.beginPath();
ctx.moveTo(45.8, 92.1);
ctx.lineTo(42.3, 92.1);
ctx.stroke();

// Laag1/linegroup2/4
ctx.beginPath();
ctx.moveTo(45.8, 111.7);
ctx.lineTo(42.3, 111.7);
ctx.stroke();
constexpr auto b = vg::Box{ 30.f, 60.f, 260.f, 110.f };
const float spacing = 10.f;
const float max_width = (b.width - 3 * spacing) / 3.f;
const float aw = max_width * props.attack.normalize();
const float dw = max_width * props.decay.normalize();
const float sh = b.height * props.sustain.normalize();
const float rw = max_width * props.release.normalize();

// Laag1/linegroup2/3
ctx.beginPath();
ctx.moveTo(45.8, 131.7);
ctx.lineTo(42.3, 131.7);
ctx.stroke();
ctx.lineWidth(6.f);

// Laag1/linegroup2/2
ctx.beginPath();
ctx.moveTo(45.8, 151.7);
ctx.lineTo(42.3, 151.7);
ctx.stroke();
const float arc_size = 0.9;

// Laag1/linegroup2/1
ctx.beginPath();
ctx.moveTo(45.8, 171.7);
ctx.lineTo(42.3, 171.7);
ctx.stroke();

// Laag1/linegroup
ctx.restore();

// Laag1/linegroup/end
ctx.save();
ctx.beginPath();
ctx.moveTo(285.5, 193.7);
ctx.lineTo(285.5, 184.2);
ctx.lineWidth(2.0);
ctx.strokeStyle(Colour::bytes(61, 63, 65));
ctx.lineCap(Canvas::LineCap::ROUND);
ctx.lineJoin(Canvas::LineJoin::ROUND);
ctx.stroke();

// Laag1/linegroup/11
ctx.beginPath();
ctx.moveTo(265.5, 193.7);
ctx.lineTo(265.5, 189.2);
ctx.stroke();

// Laag1/linegroup/10
ctx.beginPath();
ctx.moveTo(245.5, 193.7);
ctx.lineTo(245.5, 189.2);
ctx.stroke();

// Laag1/linegroup/9
ctx.beginPath();
ctx.moveTo(225.5, 193.7);
ctx.lineTo(225.5, 189.2);
ctx.stroke();

// Laag1/linegroup/8
ctx.beginPath();
ctx.moveTo(205.5, 193.7);
ctx.lineTo(205.5, 189.2);
ctx.stroke();

// Laag1/linegroup/7
ctx.beginPath();
ctx.moveTo(185.5, 193.7);
ctx.lineTo(185.5, 189.2);
ctx.stroke();

// Laag1/linegroup/6
ctx.beginPath();
ctx.moveTo(165.5, 193.7);
ctx.lineTo(165.5, 189.2);
ctx.stroke();

// Laag1/linegroup/5
ctx.beginPath();
ctx.moveTo(145.5, 193.7);
ctx.lineTo(145.5, 189.2);
ctx.stroke();

// Laag1/linegroup/4
ctx.beginPath();
ctx.moveTo(125.5, 193.7);
ctx.lineTo(125.5, 189.2);
ctx.stroke();
ctx.moveTo(b.x, b.y + b.height + 14);
ctx.lineTo(b.x + b.width, b.y + b.height + spacing);
ctx.stroke(Colours::White);

// Laag1/linegroup/3
ctx.beginPath();
ctx.moveTo(105.5, 193.7);
ctx.lineTo(105.5, 189.2);
ctx.stroke();
ctx.moveTo(b.x, b.y + b.height);
ctx.quadraticCurveTo({b.x + aw * arc_size, b.y + b.height * arc_size}, {b.x + aw, b.y}); // curve
ctx.lineTo(b.x + aw, b.y + b.height);
ctx.closePath();
ctx.stroke(Colours::Blue);
ctx.fill(Colours::Blue);

// Laag1/linegroup/2
ctx.beginPath();
ctx.moveTo(85.5, 193.7);
ctx.lineTo(85.5, 189.2);
ctx.stroke();
ctx.moveTo(b.x + aw + spacing, b.y + b.height);
ctx.lineTo(b.x + aw + spacing, b.y);
ctx.quadraticCurveTo({b.x + aw + spacing + dw * (1 - arc_size), b.y + (b.height - sh) * arc_size}, {b.x + aw + spacing + dw, b.y + b.height - sh}); // curve
ctx.lineTo(b.x + aw + spacing + dw, b.y + b.height);
ctx.closePath();
ctx.stroke(Colours::Green);
ctx.fill(Colours::Green);

// Laag1/linegroup/1
ctx.beginPath();
ctx.moveTo(65.5, 193.7);
ctx.lineTo(65.5, 189.2);
ctx.stroke();
ctx.moveTo(b.x + aw + spacing + dw + spacing, b.y + b.height - sh);
ctx.lineTo(b.x + b.width - spacing - rw, b.y + b.height - sh);
ctx.lineTo(b.x + b.width - spacing - rw, b.y + b.height);
ctx.lineTo(b.x + aw + spacing + dw + spacing, b.y + b.height);
ctx.closePath();
ctx.stroke(Colours::Yellow);
ctx.fill(Colours::Yellow);

// Laag1/horizontalline
ctx.restore();
ctx.beginPath();
ctx.moveTo(45.9, 188.7);
ctx.lineTo(285.5, 188.7);
ctx.lineWidth(2.0);
ctx.strokeStyle(Colour::bytes(61, 63, 65));
ctx.lineCap(Canvas::LineCap::ROUND);
ctx.lineJoin(Canvas::LineJoin::ROUND);
ctx.stroke();

// Laag1/verticalline
ctx.beginPath();
ctx.moveTo(45.9, 51.7);
ctx.lineTo(45.9, 188.7);
ctx.stroke();
ctx.moveTo(b.x + b.width - rw, b.y + b.height);
ctx.lineTo(b.x + b.width - rw, b.y + b.height - sh);
ctx.quadraticCurveTo({b.x + b.width - rw * arc_size, b.y + b.height - sh * (1 - arc_size)}, {b.x + b.width, b.y + b.height});
ctx.closePath();
ctx.stroke(Colours::Red);
ctx.fill(Colours::Red);
}

// SETTINGS SCREEN //////////////////////////////////////////////////////////
Expand Down
18 changes: 12 additions & 6 deletions src/core/ui/canvas.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,28 @@ namespace otto::core::ui::vg {

/// A positioned box
struct Box {
Point p1 {0, 0};
Point p2 {0, 0};
float x = 0;
float y = 0;
float width = 0;
float height = 0;

constexpr Box() = default;

constexpr Box(Point p1, Point p2) //
: p1 (p1), p2 (p2)
constexpr Box(float x, float y, float width, float height) //
: x(x), y(y), width(width), height(height)
{}

constexpr Box(Point p, Size s) //
: p1 (p), p2 (p - s.vec())
: x (p.x), y (p.y), width (s.w), height(s.h)
{}

constexpr Box(Point p1, Point p2) //
: Box(p1, Size(p2 - p1))
{}

constexpr Size size() const
{
return Size{p2 - p1}.abs();
return {width, height};
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/services/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace otto::service::ui {

using namespace core::ui;

static constexpr const char* initial_engine = "TapeDeck";
static constexpr const char* initial_engine = "Synth";

// Local vars
namespace {
Expand Down

0 comments on commit 59f482b

Please sign in to comment.