Demodulator finder, hover states for waterfall

This commit is contained in:
Charles J. Cliffe 2014-11-30 18:54:13 -05:00
parent 0bc31eed6c
commit 0d8991eb67
6 changed files with 83 additions and 13 deletions

View File

@ -97,3 +97,23 @@ void DemodulatorMgr::terminateAll() {
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() { std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
return demods; return demods;
} }
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(int freq, int bandwidth) {
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
DemodulatorInstance *testDemod = demods[i];
int freqTest = testDemod->getParams().frequency;
int bandwidthTest = testDemod->getParams().bandwidth;
int halfBandwidthTest = bandwidthTest / 2;
int halfBuffer = bandwidth / 2;
if ((freq <= (freqTest + halfBandwidthTest + halfBuffer)) && (freq >= (freqTest - halfBandwidthTest - halfBuffer))) {
foundDemods->push_back(testDemod);
}
}
return foundDemods;
}

View File

@ -37,6 +37,7 @@ public:
DemodulatorInstance *newThread(); DemodulatorInstance *newThread();
std::vector<DemodulatorInstance *> &getDemodulators(); std::vector<DemodulatorInstance *> &getDemodulators();
std::vector<DemodulatorInstance *> *getDemodulatorsAt(int freq, int bandwidth);
void terminateAll(); void terminateAll();
private: private:

View File

@ -29,7 +29,7 @@ wxEND_EVENT_TABLE()
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) : WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxGLCanvas(parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize,
wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), bwChange(false), demodBW(0) { wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), bwChange(false), demodBW(0), hoveredDemod(-1) {
int in_block_size = BUF_SIZE / 2; int in_block_size = BUF_SIZE / 2;
int out_block_size = FFT_SIZE; int out_block_size = FFT_SIZE;
@ -54,6 +54,14 @@ WaterfallCanvas::~WaterfallCanvas() {
} }
int WaterfallCanvas::GetFrequencyAt(float x) {
int center_freq = wxGetApp().getFrequency();
int freq = center_freq - (int) (0.5 * (float) SRATE) + (int) ((float) x * (float) SRATE);
return freq;
}
void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) { void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
wxPaintDC dc(this); wxPaintDC dc(this);
const wxSize ClientSize = GetClientSize(); const wxSize ClientSize = GetClientSize();
@ -64,15 +72,25 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
glContext->BeginDraw(); glContext->BeginDraw();
glContext->Draw(spectrum_points); glContext->Draw(spectrum_points);
std::vector<DemodulatorInstance *> *demods = &wxGetApp().getDemodMgr().getDemodulators(); std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
for (int i = 0, iMax = demods->size(); i < iMax; i++) {
glContext->DrawDemod((*demods)[i]);
}
if (mTracker.mouseInView()) { if (mTracker.mouseInView()) {
glContext->DrawFreqSelector(mTracker.getMouseX(),0,1,0);
if (hoveredDemod == -1) {
glContext->DrawFreqSelector(mTracker.getMouseX(), 0, 1, 0);
} else {
glContext->DrawDemod(demods[hoveredDemod],1,1,0);
} }
}
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
if (hoveredDemod == i) {
continue;
}
glContext->DrawDemod(demods[i]);
}
glContext->EndDraw(); glContext->EndDraw();
SwapBuffers(); SwapBuffers();
@ -225,6 +243,33 @@ void WaterfallCanvas::mouseMoved(wxMouseEvent& event) {
// wxString::Format(wxT("Set center frequency: %s"), // wxString::Format(wxT("Set center frequency: %s"),
// wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep))); // wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep)));
// } // }
} else {
int hovered = -1;
int nearest = -1;
int near_dist = SRATE;
int freqPos = GetFrequencyAt(mTracker.getMouseX());
std::vector<DemodulatorInstance *> *demodsHover = wxGetApp().getDemodMgr().getDemodulatorsAt(freqPos, 15000);
if (demodsHover->size()) {
for (int i = 0, iMax = demodsHover->size(); i < iMax; i++) {
DemodulatorInstance *hoverDemod = (*demodsHover)[i];
int dist = abs(hoverDemod->getParams().frequency-freqPos);
if (dist < near_dist) {
nearest = i;
}
}
hovered = nearest;
}
hoveredDemod = hovered;
delete demodsHover;
} }
} }
@ -269,6 +314,7 @@ void WaterfallCanvas::mouseReleased(wxMouseEvent& event) {
void WaterfallCanvas::mouseLeftWindow(wxMouseEvent& event) { void WaterfallCanvas::mouseLeftWindow(wxMouseEvent& event) {
mTracker.OnMouseLeftWindow(event); mTracker.OnMouseLeftWindow(event);
SetCursor(wxCURSOR_CROSS); SetCursor(wxCURSOR_CROSS);
hoveredDemod = -1;
} }
void WaterfallCanvas::mouseEnterWindow(wxMouseEvent& event) { void WaterfallCanvas::mouseEnterWindow(wxMouseEvent& event) {

View File

@ -18,6 +18,8 @@ public:
~WaterfallCanvas(); ~WaterfallCanvas();
void setData(std::vector<signed char> *data); void setData(std::vector<signed char> *data);
int GetFrequencyAt(float x);
private: private:
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
void OnKeyDown(wxKeyEvent& event); void OnKeyDown(wxKeyEvent& event);
@ -50,6 +52,7 @@ private:
MouseTracker mTracker; MouseTracker mTracker;
bool bwChange; bool bwChange;
int demodBW; int demodBW;
int hoveredDemod;
// event table // event table
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();

View File

@ -82,7 +82,7 @@ void WaterfallContext::Draw(std::vector<float> &points) {
} }
void WaterfallContext::DrawDemod(DemodulatorInstance *demod) { void WaterfallContext::DrawDemod(DemodulatorInstance *demod, float r, float g, float b) {
if (!demod) { if (!demod) {
return; return;
} }
@ -94,7 +94,7 @@ void WaterfallContext::DrawDemod(DemodulatorInstance *demod) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
glColor4f(1.0, 1.0, 1.0, 0.6); glColor4f(r, g, b, 0.6);
glBegin(GL_LINES); glBegin(GL_LINES);
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
@ -111,7 +111,7 @@ void WaterfallContext::DrawDemod(DemodulatorInstance *demod) {
glEnd(); glEnd();
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR); glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
glColor4f(1.0, 1.0, 1.0, 0.2); glColor4f(r, g, b, 0.2);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0 - ofs, 1.0, 0.0);
glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0); glVertex3f((uxPos - 0.5) * 2.0 - ofs, -1.0, 0.0);
@ -125,7 +125,7 @@ void WaterfallContext::DrawDemod(DemodulatorInstance *demod) {
} }
void WaterfallContext::DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1) { void WaterfallContext::DrawFreqSelector(float uxPos, float r, float g, float b) {
DemodulatorInstance *demod = wxGetApp().getDemodTest(); DemodulatorInstance *demod = wxGetApp().getDemodTest();
if (!demod) { if (!demod) {

View File

@ -14,8 +14,8 @@ public:
void BeginDraw(); void BeginDraw();
void Draw(std::vector<float> &points); void Draw(std::vector<float> &points);
void DrawFreqSelector(float uxPos, float r, float g, float b); void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1);
void DrawDemod(DemodulatorInstance *demod); void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
void EndDraw(); void EndDraw();
private: private: