gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

commit 73e8e51cbf54ec17e7ac693d1e9d223c0d7fcffa
parent 70c1cf13d18db2a63972eacf1a470b383f404120
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date:   Fri,  2 Aug 2024 00:19:37 +0200

begin LCD implementation

Diffstat:
Msource/nord/n2x/n2xJucePlugin/n2xLcd.cpp | 100++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msource/nord/n2x/n2xJucePlugin/n2xLcd.h | 35++++++++++++++++++++++++++++++++---
2 files changed, 131 insertions(+), 4 deletions(-)

diff --git a/source/nord/n2x/n2xJucePlugin/n2xLcd.cpp b/source/nord/n2x/n2xJucePlugin/n2xLcd.cpp @@ -1,8 +1,106 @@ #include "n2xLcd.h" +#include "n2xEditor.h" + namespace n2xJucePlugin { - Lcd::Lcd(Editor& _editor): m_editor(_editor) + constexpr char space = 0x21; // unit separator, i.e. full width space + + constexpr uint32_t g_animDelayStart = 1000; + constexpr uint32_t g_animDelayScroll = 500; + constexpr uint32_t g_animDelayEnd = 1000; + + Lcd::Lcd(Editor& _editor) : m_editor(_editor) + { + m_label = _editor.findComponentT<juce::Label>("PatchName"); + setText("Hello World"); + } + + void Lcd::setText(const std::string& _text) + { + if(m_text == _text) + return; + m_text = _text; + onTextChanged(); + } + + void Lcd::timerCallback() + { + stopTimer(); + + switch(m_animState) + { + case AnimState::Start: + if(updateClippedText(m_text, ++m_currentOffset)) + { + m_animState = AnimState::Scroll; + startTimer(g_animDelayScroll); + } + break; + case AnimState::Scroll: + if(!updateClippedText(m_text, ++m_currentOffset)) + { + m_animState = AnimState::End; + startTimer(g_animDelayEnd); + } + else + { + startTimer(g_animDelayScroll); + } + break; + case AnimState::End: + m_animState = AnimState::Start; + m_currentOffset = 0; + updateClippedText(m_text, m_currentOffset); + startTimer(g_animDelayStart); + break; + } + } + + void Lcd::setClippedText(const std::string& _text) { + if(m_clippedText == _text) + return; + m_clippedText = _text; + + auto t = _text; + + for (char& c : t) + { + if(c == ' ') + c = space; + } + + m_label->setText(t, juce::dontSendNotification); + } + + bool Lcd::updateClippedText(const std::string& _text, const uint32_t _offset) + { + const auto str = _text.substr(_offset, 3); + if(str.size() < 3) + return false; + setClippedText(str); + return true; + } + + void Lcd::startAnim() + { + m_currentOffset = 0; + m_animState = AnimState::Start; + startTimer(g_animDelayStart); + } + + void Lcd::onTextChanged() + { + updateClippedText(m_text, 0); + + if(m_clippedText != m_text) + { + startAnim(); + } + else + { + stopTimer(); + } } } diff --git a/source/nord/n2x/n2xJucePlugin/n2xLcd.h b/source/nord/n2x/n2xJucePlugin/n2xLcd.h @@ -1,15 +1,45 @@ #pragma once +#include <string> + +#include "juce_events/juce_events.h" + +namespace juce +{ + class Label; +} + namespace n2xJucePlugin { class Editor; - class Lcd + class Lcd : juce::Timer { public: + enum class AnimState + { + Start, + Scroll, + End + }; + explicit Lcd(Editor& _editor); + void setText(const std::string& _key); + + void timerCallback() override; + private: + void setClippedText(const std::string& _text); + bool updateClippedText(const std::string& _text, uint32_t _offset); + void startAnim(); + void onTextChanged(); + Editor& m_editor; + juce::Label* m_label; + std::string m_text; + std::string m_clippedText; + uint32_t m_currentOffset = 0; + AnimState m_animState = AnimState::Start; }; -} -\ No newline at end of file +}