From 00e241a784917534512ed75d3d626d2f3c9a518d Mon Sep 17 00:00:00 2001 From: vsonnier Date: Sat, 11 Jun 2016 07:46:07 +0200 Subject: [PATCH] LABEL: first attempt, is read from session XML, apparently also saved. --- src/AppFrame.cpp | 15 +++++++++++++ src/demod/DemodulatorInstance.cpp | 24 ++++++++++++-------- src/demod/DemodulatorInstance.h | 14 +++++++----- src/util/GLFont.h | 2 +- src/visual/PrimaryGLContext.cpp | 37 +++++++++++++++++++++++-------- src/visual/PrimaryGLContext.h | 2 ++ 6 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index 902e258..4afd065 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -1561,6 +1561,7 @@ void AppFrame::saveSession(std::string fileName) { *demod->newChild("bandwidth") = (*instance_i)->getBandwidth(); *demod->newChild("frequency") = (*instance_i)->getFrequency(); *demod->newChild("type") = (*instance_i)->getDemodulatorType(); + *demod->newChild("user_label") = (*instance_i)->getDemodulatorUserLabel(); *demod->newChild("squelch_level") = (*instance_i)->getSquelchLevel(); *demod->newChild("squelch_enabled") = (*instance_i)->isSquelchEnabled() ? 1 : 0; *demod->newChild("output_device") = outputDevices[(*instance_i)->getOutputDevice()].name; @@ -1659,6 +1660,7 @@ bool AppFrame::loadSession(std::string fileName) { float gain = demod->hasAnother("gain") ? (float) *demod->getNext("gain") : 1.0; std::string type = "FM"; + DataNode *demodTypeNode = demod->hasAnother("type")?demod->getNext("type"):nullptr; @@ -1688,6 +1690,16 @@ bool AppFrame::loadSession(std::string fileName) { demodTypeNode->element()->get(type); } + //read the user label associated with the demodulator + //manage other languages than English if you please... + std::string user_label = ""; + + DataNode *demodUserLabel = demod->hasAnother("user_label") ? demod->getNext("user_label") : nullptr; + + if (demodUserLabel && demodUserLabel->element()->getDataType() == DATA_STRING) { + demodUserLabel->element()->get(user_label); + } + ModemSettings mSettings; if (demod->hasAnother("settings")) { @@ -1702,6 +1714,8 @@ bool AppFrame::loadSession(std::string fileName) { } } } + + newDemod = wxGetApp().getDemodMgr().newThread(); @@ -1711,6 +1725,7 @@ bool AppFrame::loadSession(std::string fileName) { numDemodulators++; newDemod->setDemodulatorType(type); + newDemod->setDemodulatorUserLabel(user_label); newDemod->writeModemSettings(mSettings); newDemod->setBandwidth(bandwidth); newDemod->setFrequency(freq); diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index e1e6860..f2f7382 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -30,8 +30,7 @@ void DemodVisualCue::step() { } } -DemodulatorInstance::DemodulatorInstance() : - t_PreDemod(nullptr), t_Demod(nullptr), t_Audio(nullptr) { +DemodulatorInstance::DemodulatorInstance() { #if ENABLE_DIGITAL_LAB activeOutput = nullptr; @@ -50,7 +49,9 @@ DemodulatorInstance::DemodulatorInstance() : follow.store(false); tracking.store(false); - label = new std::string("Unnamed"); + label.store(new std::string("Unnamed")); + user_label.store(new std::string()); + pipeIQInputData = new DemodulatorThreadInputQueue; pipeIQDemodData = new DemodulatorThreadPostInputQueue; pipeDemodNotify = new DemodulatorThreadCommandQueue; @@ -149,12 +150,8 @@ std::string DemodulatorInstance::getLabel() { } void DemodulatorInstance::setLabel(std::string labelStr) { - std::string *newLabel = new std::string; - newLabel->append(labelStr); - std::string *oldLabel; - oldLabel = label; - label = newLabel; - delete oldLabel; + + delete label.exchange(new std::string(labelStr)); } bool DemodulatorInstance::isTerminated() { @@ -330,6 +327,15 @@ std::string DemodulatorInstance::getDemodulatorType() { return demodulatorPreThread->getDemodType(); } +std::string DemodulatorInstance::getDemodulatorUserLabel() { + return *(user_label.load()); +} + +void DemodulatorInstance::setDemodulatorUserLabel(const std::string& demod_user_label) { + + delete user_label.exchange(new std::string(demod_user_label)); +} + void DemodulatorInstance::setDemodulatorLock(bool demod_lock_in) { Modem *cModem = demodulatorPreThread->getModem(); if (cModem && cModem->getType() == "digital") { diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index b5532ae..076c6de 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -35,12 +35,12 @@ public: pthread_t t_PreDemod; pthread_t t_Demod; #else - std::thread *t_PreDemod; - std::thread *t_Demod; + std::thread *t_PreDemod = nullptr; + std::thread *t_Demod = nullptr; #endif - AudioThread *audioThread; - std::thread *t_Audio; + AudioThread *audioThread = nullptr; + std::thread *t_Audio = nullptr; DemodulatorInstance(); ~DemodulatorInstance(); @@ -73,7 +73,10 @@ public: void setDemodulatorType(std::string demod_type_in); std::string getDemodulatorType(); - + + std::string getDemodulatorUserLabel(); + void setDemodulatorUserLabel(const std::string& demod_user_label); + void setDemodulatorLock(bool demod_lock_in); int getDemodulatorLock(); @@ -136,6 +139,7 @@ protected: private: std::atomic label; // + std::atomic user_label; // std::atomic_bool terminated; // std::atomic_bool demodTerminated; // std::atomic_bool audioTerminated; // diff --git a/src/util/GLFont.h b/src/util/GLFont.h index 041fc49..dc86cc7 100644 --- a/src/util/GLFont.h +++ b/src/util/GLFont.h @@ -91,7 +91,7 @@ public: void doCacheGC(); private: std::map stringCache; - + std::string nextParam(std::istringstream &str); std::string getParamKey(std::string param_str); std::string getParamValue(std::string param_str); diff --git a/src/visual/PrimaryGLContext.cpp b/src/visual/PrimaryGLContext.cpp index 75abef3..4e44017 100644 --- a/src/visual/PrimaryGLContext.cpp +++ b/src/visual/PrimaryGLContext.cpp @@ -351,10 +351,9 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, RGBA4f color, long glEnable(GL_BLEND); - std::string demodStr = ""; GLFont::Align demodAlign = GLFont::GLFONT_ALIGN_CENTER; - demodStr = demod->getDemodulatorType(); + std::string demodStr = demod->getDemodulatorType(); demodAlign = GLFont::GLFONT_ALIGN_CENTER; @@ -373,22 +372,42 @@ void PrimaryGLContext::DrawDemod(DemodulatorInstance *demod, RGBA4f color, long // add lock to string if we have an lock if(demod->getDemodulatorLock()) { - demodStr = demodStr + " Lock"; - } + demodStr += " Lock"; + } + // else { // demodStr = demodStr + " UnLock"; // } - glColor3f(0, 0, 0); - GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5) + xOfs, -1.0 + hPos - yOfs, 16, demodAlign, - GLFont::GLFONT_ALIGN_CENTER, 0, 0, true); - glColor3f(1, 1, 1); - GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5), -1.0 + hPos, 16, demodAlign, GLFont::GLFONT_ALIGN_CENTER, 0, 0, true); + //demodulator user label if present: type is displayed above the label, which is at the bottom of the screen. + if (!demod->getDemodulatorUserLabel().empty()) { + hPos += 2 * labelHeight; + } + + drawSingleDemodLabel(demodStr, uxPos, hPos, xOfs, yOfs, GLFont::GLFONT_ALIGN_CENTER); + + //revert... + if (!demod->getDemodulatorUserLabel().empty()) { + hPos -= 2 * labelHeight; + drawSingleDemodLabel(demod->getDemodulatorUserLabel(), uxPos, hPos, xOfs, yOfs, GLFont::GLFONT_ALIGN_CENTER); + } glDisable(GL_BLEND); } +void PrimaryGLContext::drawSingleDemodLabel(std::string demodStr, float uxPos, float hPos, float xOfs, float yOfs, GLFont::Align demodAlign) { + + glColor3f(0, 0, 0); + GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5) + xOfs, + -1.0 + hPos - yOfs, 16, demodAlign, + GLFont::GLFONT_ALIGN_CENTER, 0, 0, true); + glColor3f(1, 1, 1); + GLFont::getFont(GLFont::GLFONT_SIZE16).drawString(demodStr, 2.0 * (uxPos - 0.5), + -1.0 + hPos, 16, demodAlign, + GLFont::GLFONT_ALIGN_CENTER, 0, 0, true); +} + void PrimaryGLContext::DrawFreqSelector(float uxPos, RGBA4f color, float w, long long /* center_freq */, long long srate) { DemodulatorInstance *demod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); diff --git a/src/visual/PrimaryGLContext.h b/src/visual/PrimaryGLContext.h index 5cbda79..303f2c4 100644 --- a/src/visual/PrimaryGLContext.h +++ b/src/visual/PrimaryGLContext.h @@ -24,6 +24,7 @@ public: void DrawFreqSelector(float uxPos, RGBA4f color, float w = 0, long long center_freq = -1, long long srate = 0); void DrawRangeSelector(float uxPos1, float uxPos2, RGBA4f color); void DrawDemod(DemodulatorInstance *demod, RGBA4f color, long long center_freq = -1, long long srate = 0); + void DrawDemodInfo(DemodulatorInstance *demod, RGBA4f color, long long center_freq = -1, long long srate = 0, bool centerline = false); void DrawFreqBwInfo(long long freq, int bw, RGBA4f color, long long center_freq = - 1, long long srate = 0, bool stack = false, bool centerline = false); @@ -31,4 +32,5 @@ public: private: float hoverAlpha; + void drawSingleDemodLabel(std::string demodStr, float uxPos, float hPos, float xOfs, float yOfs, GLFont::Align demodAlign); };