From 13f1345a66719cadd2695716a04febfca1e04f6a Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 14 Jun 2018 08:23:25 -0400 Subject: [PATCH] Type into MidiCcChoices --- CHANGELOG.md | 2 +- src/Core/MIDICCToCVInterface.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd48f0b5..6505eda9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Added JACK support on Linux - Added velocity mode to MIDI-Trig - Added MIDI multiplexing so multiple MIDI modules can use the same MIDI device on Windows -- Make Module Browser layout more compact +- Made Module Browser layout more compact - Add power meter - Add icons to toolbar - [VCV Bridge](https://vcvrack.com/manual/Bridge.html) 0.6.1 diff --git a/src/Core/MIDICCToCVInterface.cpp b/src/Core/MIDICCToCVInterface.cpp index 2e468f0e..92aaddd9 100644 --- a/src/Core/MIDICCToCVInterface.cpp +++ b/src/Core/MIDICCToCVInterface.cpp @@ -1,6 +1,7 @@ #include "Core.hpp" #include "midi.hpp" #include "dsp/filter.hpp" +#include "window.hpp" struct MIDICCToCVInterface : Module { @@ -106,6 +107,7 @@ struct MIDICCToCVInterface : Module { struct MidiCcChoice : GridChoice { MIDICCToCVInterface *module; int id; + int focusCc; MidiCcChoice() { box.size.y = mm2px(6.666); @@ -118,7 +120,10 @@ struct MidiCcChoice : GridChoice { void step() override { if (module->learningId == id) { - text = "LRN"; + if (0 <= focusCc) + text = stringf("%d", focusCc); + else + text = "LRN"; color.a = 0.5; } else { @@ -132,11 +137,36 @@ struct MidiCcChoice : GridChoice { void onFocus(EventFocus &e) override { e.consumed = true; module->learningId = id; + focusCc = -1; } void onDefocus(EventDefocus &e) override { + if (0 <= focusCc && focusCc < 128) { + module->learnedCcs[id] = focusCc; + } module->learningId = -1; } + + void onText(EventText &e) override { + char c = e.codepoint; + if ('0' <= c && c <= '9') { + if (focusCc < 0) + focusCc = 0; + focusCc = focusCc * 10 + (c - '0'); + } + e.consumed = true; + } + + void onKey(EventKey &e) override { + if (gFocusedWidget == this) { + if (e.key == GLFW_KEY_ENTER || e.key == GLFW_KEY_KP_ENTER) { + EventDefocus eDefocus; + onDefocus(eDefocus); + gFocusedWidget = NULL; + e.consumed = true; + } + } + } };