mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-11-25 21:28:38 -05:00
Demodulator finder, hover states for waterfall
This commit is contained in:
parent
0bc31eed6c
commit
0d8991eb67
@ -97,3 +97,23 @@ void DemodulatorMgr::terminateAll() {
|
||||
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
||||
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;
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
|
||||
DemodulatorInstance *newThread();
|
||||
std::vector<DemodulatorInstance *> &getDemodulators();
|
||||
std::vector<DemodulatorInstance *> *getDemodulatorsAt(int freq, int bandwidth);
|
||||
|
||||
void terminateAll();
|
||||
private:
|
||||
|
@ -29,7 +29,7 @@ wxEND_EVENT_TABLE()
|
||||
|
||||
WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
|
||||
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 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)) {
|
||||
wxPaintDC dc(this);
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
@ -64,15 +72,25 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
|
||||
glContext->BeginDraw();
|
||||
glContext->Draw(spectrum_points);
|
||||
|
||||
std::vector<DemodulatorInstance *> *demods = &wxGetApp().getDemodMgr().getDemodulators();
|
||||
|
||||
for (int i = 0, iMax = demods->size(); i < iMax; i++) {
|
||||
glContext->DrawDemod((*demods)[i]);
|
||||
}
|
||||
std::vector<DemodulatorInstance *> &demods = wxGetApp().getDemodMgr().getDemodulators();
|
||||
|
||||
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();
|
||||
|
||||
SwapBuffers();
|
||||
@ -225,6 +243,33 @@ void WaterfallCanvas::mouseMoved(wxMouseEvent& event) {
|
||||
// wxString::Format(wxT("Set center frequency: %s"),
|
||||
// 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) {
|
||||
mTracker.OnMouseLeftWindow(event);
|
||||
SetCursor(wxCURSOR_CROSS);
|
||||
hoveredDemod = -1;
|
||||
}
|
||||
|
||||
void WaterfallCanvas::mouseEnterWindow(wxMouseEvent& event) {
|
||||
|
@ -18,6 +18,8 @@ public:
|
||||
~WaterfallCanvas();
|
||||
|
||||
void setData(std::vector<signed char> *data);
|
||||
int GetFrequencyAt(float x);
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void OnKeyDown(wxKeyEvent& event);
|
||||
@ -50,6 +52,7 @@ private:
|
||||
MouseTracker mTracker;
|
||||
bool bwChange;
|
||||
int demodBW;
|
||||
int hoveredDemod;
|
||||
|
||||
// event table
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
|
@ -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) {
|
||||
return;
|
||||
}
|
||||
@ -94,7 +94,7 @@ void WaterfallContext::DrawDemod(DemodulatorInstance *demod) {
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
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);
|
||||
glVertex3f((uxPos - 0.5) * 2.0, 1.0, 0.0);
|
||||
@ -111,7 +111,7 @@ void WaterfallContext::DrawDemod(DemodulatorInstance *demod) {
|
||||
glEnd();
|
||||
|
||||
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);
|
||||
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();
|
||||
|
||||
if (!demod) {
|
||||
|
@ -14,8 +14,8 @@ public:
|
||||
|
||||
void BeginDraw();
|
||||
void Draw(std::vector<float> &points);
|
||||
void DrawFreqSelector(float uxPos, float r, float g, float b);
|
||||
void DrawDemod(DemodulatorInstance *demod);
|
||||
void DrawFreqSelector(float uxPos, float r = 1, float g = 1, float b = 1);
|
||||
void DrawDemod(DemodulatorInstance *demod, float r = 1, float g = 1, float b = 1);
|
||||
void EndDraw();
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user