From 3af564037ca465a0b8b68d8b3656d8d15dbdd8c8 Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Thu, 26 Mar 2015 22:45:52 -0400 Subject: [PATCH] New tuning bar now functional --- src/demod/DemodulatorInstance.cpp | 8 ++ src/demod/DemodulatorInstance.h | 3 + src/demod/DemodulatorPreThread.cpp | 10 +- src/sdr/SDRPostThread.cpp | 12 +- src/visual/ColorTheme.cpp | 12 ++ src/visual/ScopeContext.cpp | 13 +++ src/visual/TuningCanvas.cpp | 173 +++++++++++++++++++---------- src/visual/TuningCanvas.h | 4 + src/visual/TuningContext.cpp | 5 +- 9 files changed, 171 insertions(+), 69 deletions(-) diff --git a/src/demod/DemodulatorInstance.cpp b/src/demod/DemodulatorInstance.cpp index 12a27fb..e27a913 100644 --- a/src/demod/DemodulatorInstance.cpp +++ b/src/demod/DemodulatorInstance.cpp @@ -335,3 +335,11 @@ void DemodulatorInstance::setGain(float gain_in) { float DemodulatorInstance::getGain() { return audioThread->getGain(); } + +bool DemodulatorInstance::isFollow() { + return follow; +} + +void DemodulatorInstance::setFollow(bool follow) { + this->follow = follow; +} diff --git a/src/demod/DemodulatorInstance.h b/src/demod/DemodulatorInstance.h index 15743b6..5f53a38 100644 --- a/src/demod/DemodulatorInstance.h +++ b/src/demod/DemodulatorInstance.h @@ -77,6 +77,8 @@ public: void setAudioSampleRate(int sampleRate); int getAudioSampleRate(); + bool isFollow(); + void setFollow(bool follow); private: @@ -96,4 +98,5 @@ private: int currentDemodType; int currentOutputDevice; int currentAudioSampleRate; + bool follow; }; diff --git a/src/demod/DemodulatorPreThread.cpp b/src/demod/DemodulatorPreThread.cpp index 3d5345d..1dad193 100644 --- a/src/demod/DemodulatorPreThread.cpp +++ b/src/demod/DemodulatorPreThread.cpp @@ -151,12 +151,10 @@ void DemodulatorPreThread::threadMain() { } // Requested frequency is not center, shift it into the center! - if (inp->frequency != params.frequency) { - if ((params.frequency - inp->frequency) != shiftFrequency || rateChanged) { - shiftFrequency = params.frequency - inp->frequency; - if (abs(shiftFrequency) <= (int) ((double) (wxGetApp().getSampleRate() / 2) * 1.5)) { - nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) wxGetApp().getSampleRate()))); - } + if ((params.frequency - inp->frequency) != shiftFrequency || rateChanged) { + shiftFrequency = params.frequency - inp->frequency; + if (abs(shiftFrequency) <= (int) ((double) (wxGetApp().getSampleRate() / 2) * 1.5)) { + nco_crcf_set_frequency(freqShifter, (2.0 * M_PI) * (((double) abs(shiftFrequency)) / ((double) wxGetApp().getSampleRate()))); } } diff --git a/src/sdr/SDRPostThread.cpp b/src/sdr/SDRPostThread.cpp index 34b8942..f07b2b2 100644 --- a/src/sdr/SDRPostThread.cpp +++ b/src/sdr/SDRPostThread.cpp @@ -185,15 +185,18 @@ void SDRPostThread::threadMain() { DemodulatorInstance *demod = *i; DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod; - if (demod->getFrequency() != data_in->frequency - && abs(data_in->frequency - demod->getFrequency()) > (wxGetApp().getSampleRate() / 2)) { - if (demod->isActive()) { + if (abs(data_in->frequency - demod->getFrequency()) > (wxGetApp().getSampleRate() / 2)) { + if (demod->isActive() && !demod->isFollow()) { demod->setActive(false); DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData; dummyDataOut->frequency = data_in->frequency; dummyDataOut->sampleRate = data_in->sampleRate; demodQueue->push(dummyDataOut); } + + if (demod->isFollow() && wxGetApp().getFrequency() != demod->getFrequency()) { + wxGetApp().setFrequency(demod->getFrequency()); + } } else if (!demod->isActive()) { demod->setActive(true); if (wxGetApp().getDemodMgr().getLastActiveDemodulator() == NULL) { @@ -204,6 +207,9 @@ void SDRPostThread::threadMain() { if (!demod->isActive()) { continue; } + if (demod->isFollow()) { + demod->setFollow(false); + } demodQueue->push(demodDataOut); pushedData = true; diff --git a/src/visual/ColorTheme.cpp b/src/visual/ColorTheme.cpp index 4278876..038461f 100644 --- a/src/visual/ColorTheme.cpp +++ b/src/visual/ColorTheme.cpp @@ -79,6 +79,8 @@ RadarColorTheme::RadarColorTheme() { fftHighlight = RGBColor(1, 1, 1); scopeLine = RGBColor(0.8, 1.0, 0.8); tuningBar = RGBColor(0.2, 0.9, 0.2); + tuningBarUp = RGBColor(1.0, 139.0/255.0, 96.0/255.0); + tuningBarDown = RGBColor(148.0/255.0, 148.0/255.0, 1.0); meterLevel = RGBColor(0, 0.5, 0); meterValue = RGBColor(0, 0.5, 0); text = RGBColor(0.8, 1.0, 0.8); @@ -105,6 +107,8 @@ BlackAndWhiteColorTheme::BlackAndWhiteColorTheme() { fftHighlight = RGBColor(1, 1, 0.9); scopeLine = RGBColor(0.9, 0.9, 0.9); tuningBar = RGBColor(0.4, 0.4, 0.4); + tuningBarUp = RGBColor(1.0, 139.0/255.0, 96.0/255.0); + tuningBarDown = RGBColor(148.0/255.0, 148.0/255.0, 1.0); meterLevel = RGBColor(0.5, 0.5, 0.5); meterValue = RGBColor(0.5, 0.5, 0.5); text = RGBColor(1, 1, 1); @@ -140,6 +144,8 @@ SharpColorTheme::SharpColorTheme() { fftHighlight = RGBColor(0.9, 0.9, 1.0); scopeLine = RGBColor(0.85, 0.85, 1.0); tuningBar = RGBColor(0.2, 0.2, 0.9); + tuningBarUp = RGBColor(1.0, 139.0/255.0, 96.0/255.0); + tuningBarDown = RGBColor(148.0/255.0, 148.0/255.0, 1.0); meterLevel = RGBColor(28.0 / 255.0, 106.0 / 255.0, 179.0 / 255.0); meterValue = RGBColor(190.0 / 255.0, 190.0 / 255.0, 60.0 / 255.0); text = RGBColor(0.9, 0.9, 1); @@ -168,6 +174,8 @@ RadColorTheme::RadColorTheme() { fftHighlight = RGBColor(1, 1, 1); scopeLine = RGBColor(1.0, 0.9, 0.9); tuningBar = RGBColor(0.2, 0.2, 0.9); + tuningBarUp = RGBColor(1.0, 139.0/255.0, 96.0/255.0); + tuningBarDown = RGBColor(148.0/255.0, 148.0/255.0, 1.0); meterLevel = RGBColor(0, 0.5, 0); meterValue = RGBColor(0.5, 0, 0); text = RGBColor(1, 1, 1); @@ -199,6 +207,8 @@ TouchColorTheme::TouchColorTheme() { fftHighlight = RGBColor(1.0, 1.0, 1.0); scopeLine = RGBColor(234.0 / 255.0, 232.0 / 255.0, 247.0 / 255.0); tuningBar = RGBColor(61.0 / 255.0, 57.0 / 255.0, 88.0 / 255.0); + tuningBarUp = RGBColor(1.0, 139.0/255.0, 96.0/255.0); + tuningBarDown = RGBColor(148.0/255.0, 148.0/255.0, 1.0); meterLevel = RGBColor(61.0 / 255.0, 57.0 / 255.0, 88.0 / 255.0); meterValue = RGBColor(61.0 / 255.0, 57.0 / 255.0, 88.0 / 255.0); text = RGBColor(1, 1, 1); @@ -231,6 +241,8 @@ HDColorTheme::HDColorTheme() { fftHighlight = RGBColor(1, 1, 1); scopeLine = RGBColor(0.9, 0.9, 0.9); tuningBar = RGBColor(0, 0.7, 0.7); + tuningBarUp = RGBColor(1.0, 139.0/255.0, 96.0/255.0); + tuningBarDown = RGBColor(148.0/255.0, 148.0/255.0, 1.0); meterLevel = RGBColor(0, 0.5, 0); meterValue = RGBColor(0.0, 0.0, 1.0); text = RGBColor(1, 1, 1); diff --git a/src/visual/ScopeContext.cpp b/src/visual/ScopeContext.cpp index 9c5bf2e..6b72c4a 100644 --- a/src/visual/ScopeContext.cpp +++ b/src/visual/ScopeContext.cpp @@ -73,6 +73,19 @@ void ScopeContext::Plot(std::vector &points, bool stereo) { } glLineWidth(1.0); + + GLint vp[4]; + glGetIntegerv(GL_VIEWPORT, vp); + float viewHeight = (float) vp[3]; + float hPos = (float) (13) / viewHeight; + + glColor3f(0.65, 0.65, 0.65); + + getFont(PrimaryGLContext::GLFONT_SIZE12).drawString("Frequency", -0.66, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER); + getFont(PrimaryGLContext::GLFONT_SIZE12).drawString("Bandwidth", 0.0, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER); + getFont(PrimaryGLContext::GLFONT_SIZE12).drawString("Center Frequency", 0.66, -1.0+hPos, 12, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER); + + if (stereo) { glColor3f(ThemeMgr::mgr.currentTheme->scopeLine.r, ThemeMgr::mgr.currentTheme->scopeLine.g, ThemeMgr::mgr.currentTheme->scopeLine.b); glBegin (GL_LINES); diff --git a/src/visual/TuningCanvas.cpp b/src/visual/TuningCanvas.cpp index 152bfef..5b8ae67 100644 --- a/src/visual/TuningCanvas.cpp +++ b/src/visual/TuningCanvas.cpp @@ -25,7 +25,7 @@ EVT_ENTER_WINDOW(TuningCanvas::OnMouseEnterWindow) wxEND_EVENT_TABLE() TuningCanvas::TuningCanvas(wxWindow *parent, int *attribList) : - InteractiveCanvas(parent, attribList), dragAccum(0) { + InteractiveCanvas(parent, attribList), dragAccum(0), top(false), bottom(false), uxDown(0) { glContext = new TuningContext(this, &wxGetApp().GetContext(this)); @@ -73,31 +73,32 @@ void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { 0.6, mouseTracker.getOriginMouseX(), mouseTracker.getMouseX()); } - bool top = mouseTracker.getMouseY() >= 0.5; - bool bottom = mouseTracker.getMouseY() <= 0.5; - RGBColor clr = top ? ThemeMgr::mgr.currentTheme->tuningBarUp : ThemeMgr::mgr.currentTheme->tuningBarDown; RGBColor clrDark = ThemeMgr::mgr.currentTheme->tuningBar; RGBColor clrMid = ThemeMgr::mgr.currentTheme->tuningBar; RGBColor clrLight = ThemeMgr::mgr.currentTheme->tuningBar; - clrDark.r*=0.5;clrDark.g*=0.5;clrDark.b*=0.5; - clrLight.r*=2.0;clrLight.g*=2.0;clrLight.b*=2.0; + clrDark.r *= 0.5; + clrDark.g *= 0.5; + clrDark.b *= 0.5; + clrLight.r *= 2.0; + clrLight.g *= 2.0; + clrLight.b *= 2.0; - glContext->DrawTunerBarIndexed(1, 3, 11, freqDP, freqW, clrDark, 0.25, true, true); // freq - glContext->DrawTunerBarIndexed(4, 6, 11, freqDP, freqW, clrMid, 0.25, true, true); - glContext->DrawTunerBarIndexed(7, 9, 11, freqDP, freqW, clrDark, 0.25, true, true); - glContext->DrawTunerBarIndexed(10, 11, 11, freqDP, freqW, clrMid, 0.25, true, true); + glContext->DrawTunerBarIndexed(1, 3, 11, freqDP, freqW, clrMid, 0.25, true, true); // freq + glContext->DrawTunerBarIndexed(4, 6, 11, freqDP, freqW, clrDark, 0.25, true, true); + glContext->DrawTunerBarIndexed(7, 9, 11, freqDP, freqW, clrMid, 0.25, true, true); + glContext->DrawTunerBarIndexed(10, 11, 11, freqDP, freqW, clrDark, 0.25, true, true); - glContext->DrawTunerBarIndexed(1, 3, 7, bwDP, bwW, clrDark, 0.25, true, true); // bw - glContext->DrawTunerBarIndexed(4, 6, 7, bwDP, bwW, clrMid, 0.25, true, true); - glContext->DrawTunerBarIndexed(7, 7, 7, bwDP, bwW, clrDark, 0.25, true, true); + glContext->DrawTunerBarIndexed(1, 3, 7, bwDP, bwW, clrMid, 0.25, true, true); // bw + glContext->DrawTunerBarIndexed(4, 6, 7, bwDP, bwW, clrDark, 0.25, true, true); + glContext->DrawTunerBarIndexed(7, 7, 7, bwDP, bwW, clrMid, 0.25, true, true); - glContext->DrawTunerBarIndexed(1, 3, 11, centerDP, centerW, clrDark, 0.25, true, true); // freq - glContext->DrawTunerBarIndexed(4, 6, 11, centerDP, centerW, clrMid, 0.25, true, true); - glContext->DrawTunerBarIndexed(7, 9, 11, centerDP, centerW, clrDark, 0.25, true, true); - glContext->DrawTunerBarIndexed(10, 11, 11, centerDP, centerW, clrMid, 0.25, true, true); + glContext->DrawTunerBarIndexed(1, 3, 11, centerDP, centerW, clrMid, 0.25, true, true); // freq + glContext->DrawTunerBarIndexed(4, 6, 11, centerDP, centerW, clrDark, 0.25, true, true); + glContext->DrawTunerBarIndexed(7, 9, 11, centerDP, centerW, clrMid, 0.25, true, true); + glContext->DrawTunerBarIndexed(10, 11, 11, centerDP, centerW, clrDark, 0.25, true, true); if (hoverIndex > 0) { switch (hoverState) { @@ -126,44 +127,44 @@ void TuningCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { } void TuningCanvas::OnIdle(wxIdleEvent &event) { - if (mouseTracker.mouseDown()) { - DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); - - float dragDelta = mouseTracker.getMouseX() - mouseTracker.getOriginMouseX(); - - dragAccum += dragDelta; - - float moveVal = dragAccum * 10.0; - - if (uxDown > 0.275) { - wxGetApp().setFrequency( - wxGetApp().getFrequency() - + (int) (dragAccum * fabs(dragAccum * 10.0) * fabs(dragAccum * 10.0) * (float) wxGetApp().getSampleRate())); - } else if (fabs(moveVal) >= 1.0) { - if (uxDown < -0.275) { - if (activeDemod != NULL) { - long long freq = activeDemod->getFrequency() + (int) (moveVal * fabs(moveVal) * fabs(moveVal) * fabs(moveVal)); - activeDemod->setFrequency(freq); - activeDemod->updateLabel(freq); - } - } else { - int amt = (int) (moveVal * fabs(moveVal) * fabs(moveVal) * fabs(moveVal)); - if (activeDemod != NULL) { - activeDemod->setBandwidth(activeDemod->getBandwidth() + amt); - } else { - wxGetApp().getDemodMgr().setLastBandwidth(wxGetApp().getDemodMgr().getLastBandwidth() + amt); - } - } - } - - while (fabs(dragAccum * 10.0) >= 1.0) { - if (dragAccum > 0) { - dragAccum -= 1.0 / 10.0; - } else { - dragAccum += 1.0 / 10.0; - } - } - } +// if (mouseTracker.mouseDown()) { +// DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); +// +// float dragDelta = mouseTracker.getMouseX() - mouseTracker.getOriginMouseX(); +// +// dragAccum += dragDelta; +// +// float moveVal = dragAccum * 10.0; +// +// if (uxDown > 0.275) { +// wxGetApp().setFrequency( +// wxGetApp().getFrequency() +// + (int) (dragAccum * fabs(dragAccum * 10.0) * fabs(dragAccum * 10.0) * (float) wxGetApp().getSampleRate())); +// } else if (fabs(moveVal) >= 1.0) { +// if (uxDown < -0.275) { +// if (activeDemod != NULL) { +// long long freq = activeDemod->getFrequency() + (int) (moveVal * fabs(moveVal) * fabs(moveVal) * fabs(moveVal)); +// activeDemod->setFrequency(freq); +// activeDemod->updateLabel(freq); +// } +// } else { +// int amt = (int) (moveVal * fabs(moveVal) * fabs(moveVal) * fabs(moveVal)); +// if (activeDemod != NULL) { +// activeDemod->setBandwidth(activeDemod->getBandwidth() + amt); +// } else { +// wxGetApp().getDemodMgr().setLastBandwidth(wxGetApp().getDemodMgr().getLastBandwidth() + amt); +// } +// } +// } +// +// while (fabs(dragAccum * 10.0) >= 1.0) { +// if (dragAccum > 0) { +// dragAccum -= 1.0 / 10.0; +// } else { +// dragAccum += 1.0 / 10.0; +// } +// } +// } Refresh(false); } @@ -173,6 +174,9 @@ void TuningCanvas::OnMouseMoved(wxMouseEvent& event) { int index = 0; + top = mouseTracker.getMouseY() >= 0.5; + bottom = mouseTracker.getMouseY() <= 0.5; + index = glContext->GetTunerDigitIndex(mouseTracker.getMouseX(), 11, freqDP, freqW); // freq if (index > 0) { hoverIndex = index; @@ -200,12 +204,9 @@ void TuningCanvas::OnMouseMoved(wxMouseEvent& event) { void TuningCanvas::OnMouseDown(wxMouseEvent& event) { InteractiveCanvas::OnMouseDown(event); - mouseTracker.setVertDragLock(true); uxDown = 2.0 * (mouseTracker.getMouseX() - 0.5); - dragAccum = 0; - SetCursor(wxCURSOR_IBEAM); } void TuningCanvas::OnMouseWheelMoved(wxMouseEvent& event) { @@ -213,8 +214,62 @@ void TuningCanvas::OnMouseWheelMoved(wxMouseEvent& event) { } void TuningCanvas::OnMouseReleased(wxMouseEvent& event) { + GLint vp[4]; + glGetIntegerv( GL_VIEWPORT, vp); + + float viewHeight = (float) vp[3]; + float viewWidth = (float) vp[2]; + InteractiveCanvas::OnMouseReleased(event); - mouseTracker.setVertDragLock(false); + + DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getLastActiveDemodulator(); + + int hExponent = hoverIndex - 1; + + if (hoverState == TUNING_HOVER_FREQ && activeDemod) { + long long freq = activeDemod->getFrequency(); + if (top) { + freq += pow(10, hExponent); + } else { + freq -= pow(10, hExponent); + } + + long long diff = abs(wxGetApp().getFrequency() - freq); + + if (wxGetApp().getSampleRate() / 2 < diff) { + wxGetApp().setFrequency(freq); + } + + activeDemod->setFrequency(freq); + activeDemod->updateLabel(freq); + } + + if (hoverState == TUNING_HOVER_BW) { + long bw = wxGetApp().getDemodMgr().getLastBandwidth(); + if (bw > wxGetApp().getSampleRate()) { + bw = wxGetApp().getSampleRate(); + } + if (top) { + bw += pow(10, hExponent); + } else { + bw -= pow(10, hExponent); + } + + wxGetApp().getDemodMgr().setLastBandwidth(bw); + + if (activeDemod) { + activeDemod->setBandwidth(wxGetApp().getDemodMgr().getLastBandwidth()); + } + } + + if (hoverState == TUNING_HOVER_CENTER) { + if (top) { + wxGetApp().setFrequency(wxGetApp().getFrequency() + pow(10, hExponent)); + } else { + wxGetApp().setFrequency(wxGetApp().getFrequency() - pow(10, hExponent)); + } + } + SetCursor(wxCURSOR_ARROW); } diff --git a/src/visual/TuningCanvas.h b/src/visual/TuningCanvas.h index 2f2db8a..53bc2c3 100644 --- a/src/visual/TuningCanvas.h +++ b/src/visual/TuningCanvas.h @@ -50,6 +50,10 @@ private: float centerDP; float centerW; + + bool top; + bool bottom; + // wxDECLARE_EVENT_TABLE(); }; diff --git a/src/visual/TuningContext.cpp b/src/visual/TuningContext.cpp index ac1d72b..d5c0115 100644 --- a/src/visual/TuningContext.cpp +++ b/src/visual/TuningContext.cpp @@ -99,7 +99,9 @@ void TuningContext::DrawTuner(long long freq, int count, float displayPos, float getFont(fontSize).drawString(freqStr.str().substr(i - ofs, 1), xpos, 0, fontHeight, GLFont::GLFONT_ALIGN_CENTER, GLFont::GLFONT_ALIGN_CENTER); } - glColor3f(0.65, 0.65, 0.65); + glColor4f(0.65, 0.65, 0.65, 0.25); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_LINES); for (int i = count; i >= 0; i--) { float xpos = displayPos + (displayWidth / (float) count) * (float) i; @@ -107,6 +109,7 @@ void TuningContext::DrawTuner(long long freq, int count, float displayPos, float glVertex2f(xpos, 1.0); } glEnd(); + glDisable(GL_BLEND); } int TuningContext::GetTunerDigitIndex(float mPos, int count, float displayPos, float displayWidth) {