Can now drag and resize demodulator on waterfall

Pretty typical style of center = drag frequency, edge handles =
bandwidth
This commit is contained in:
Charles J. Cliffe 2014-11-30 21:14:17 -05:00
parent 0d8991eb67
commit 023002f009
2 changed files with 88 additions and 48 deletions

View File

@ -29,7 +29,8 @@ 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), hoveredDemod(-1) { wxFULL_REPAINT_ON_RESIZE), parent(parent), frameTimer(0), activeDemodulatorBandwidth(0), activeDemodulator(NULL), dragState(
WF_DRAG_NONE), nextDragState(WF_DRAG_NONE) {
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;
@ -45,8 +46,6 @@ WaterfallCanvas::WaterfallCanvas(wxWindow *parent, int *attribList) :
timer.start(); timer.start();
mTracker.setTarget(this); mTracker.setTarget(this);
mTracker.setVertDragLock(true);
mTracker.setHorizDragLock(true);
SetCursor(wxCURSOR_CROSS); SetCursor(wxCURSOR_CROSS);
} }
@ -76,16 +75,15 @@ void WaterfallCanvas::OnPaint(wxPaintEvent& WXUNUSED(event)) {
if (mTracker.mouseInView()) { if (mTracker.mouseInView()) {
if (hoveredDemod == -1) { if (activeDemodulator == NULL) {
glContext->DrawFreqSelector(mTracker.getMouseX(), 0, 1, 0); glContext->DrawFreqSelector(mTracker.getMouseX(), 0, 1, 0);
} else { } else {
glContext->DrawDemod(demods[hoveredDemod],1,1,0); glContext->DrawDemod(activeDemodulator, 1, 1, 0);
} }
} }
for (int i = 0, iMax = demods.size(); i < iMax; i++) { for (int i = 0, iMax = demods.size(); i < iMax; i++) {
if (hoveredDemod == i) { if (activeDemodulator == demods[i]) {
continue; continue;
} }
glContext->DrawDemod(demods[i]); glContext->DrawDemod(demods[i]);
@ -210,64 +208,93 @@ void WaterfallCanvas::mouseMoved(wxMouseEvent& event) {
DemodulatorInstance *demod = wxGetApp().getDemodTest(); DemodulatorInstance *demod = wxGetApp().getDemodTest();
if (mTracker.mouseDown()) { if (mTracker.mouseDown()) {
if (demod && mTracker.getDeltaMouseY()) { if (dragState == WF_DRAG_BANDWIDTH_LEFT || dragState == WF_DRAG_BANDWIDTH_RIGHT) {
int bwDiff = (int) (mTracker.getDeltaMouseY() * 100000.0);
if (!demodBW) { int bwDiff = (int) (mTracker.getDeltaMouseX() * (float)SRATE) * 2;
demodBW = demod->getParams().bandwidth;
if (dragState == WF_DRAG_BANDWIDTH_LEFT) {
bwDiff = -bwDiff;
}
if (!activeDemodulatorBandwidth) {
activeDemodulatorBandwidth = demod->getParams().bandwidth;
} }
DemodulatorThreadCommand command; DemodulatorThreadCommand command;
command.cmd = DemodulatorThreadCommand::SDR_THREAD_CMD_SET_BANDWIDTH; command.cmd = DemodulatorThreadCommand::SDR_THREAD_CMD_SET_BANDWIDTH;
demodBW = demodBW - bwDiff; activeDemodulatorBandwidth = activeDemodulatorBandwidth + bwDiff;
if (demodBW < 1000) { if (activeDemodulatorBandwidth < 1000) {
demodBW = 1000; activeDemodulatorBandwidth = 1000;
} }
if (demodBW > SRATE) { if (activeDemodulatorBandwidth > SRATE) {
demodBW = SRATE; activeDemodulatorBandwidth = SRATE;
} }
command.int_value = demodBW; command.int_value = activeDemodulatorBandwidth;
demod->getCommandQueue()->push(command); demod->getCommandQueue()->push(command);
bwChange = true;
} }
// int freqChange = mTracker.getDeltaMouseX() * SRATE; if (dragState == WF_DRAG_FREQUENCY) {
// int bwDiff = (int) (mTracker.getDeltaMouseX() * (float)SRATE);
// if (freqChange != 0) {
// int freq = wxGetApp().getFrequency(); if (!activeDemodulatorFrequency) {
// freq -= freqChange; activeDemodulatorFrequency = demod->getParams().frequency;
// wxGetApp().setFrequency(freq); }
//
// ((wxFrame*) parent)->GetStatusBar()->SetStatusText( DemodulatorThreadCommand command;
// wxString::Format(wxT("Set center frequency: %s"), command.cmd = DemodulatorThreadCommand::SDR_THREAD_CMD_SET_FREQUENCY;
// wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep))); activeDemodulatorFrequency = activeDemodulatorFrequency + bwDiff;
// }
command.int_value = activeDemodulatorFrequency;
demod->getCommandQueue()->push(command);
}
} else { } else {
int hovered = -1;
int nearest = -1;
int near_dist = SRATE;
int freqPos = GetFrequencyAt(mTracker.getMouseX()); int freqPos = GetFrequencyAt(mTracker.getMouseX());
activeDemodulator = NULL;
std::vector<DemodulatorInstance *> *demodsHover = wxGetApp().getDemodMgr().getDemodulatorsAt(freqPos, 15000); std::vector<DemodulatorInstance *> *demodsHover = wxGetApp().getDemodMgr().getDemodulatorsAt(freqPos, 15000);
if (demodsHover->size()) { if (demodsHover->size()) {
for (int i = 0, iMax = demodsHover->size(); i < iMax; i++) { int hovered = -1;
DemodulatorInstance *hoverDemod = (*demodsHover)[i]; int near_dist = SRATE;
int dist = abs(hoverDemod->getParams().frequency-freqPos); for (int i = 0, iMax = demodsHover->size(); i < iMax; i++) {
DemodulatorInstance *demod = (*demodsHover)[i];
int dist = abs((int)demod->getParams().frequency - freqPos);
if (dist < near_dist) { if (dist < near_dist) {
nearest = i; activeDemodulator = demod;
near_dist = dist;
} }
} }
hovered = nearest; int freqDiff = ((int)activeDemodulator->getParams().frequency - freqPos);
}
hoveredDemod = hovered; if (near_dist > (activeDemodulator->getParams().bandwidth / 3)) {
SetCursor(wxCURSOR_SIZEWE);
if (freqDiff > 0) {
nextDragState = WF_DRAG_BANDWIDTH_LEFT;
} else {
nextDragState = WF_DRAG_BANDWIDTH_RIGHT;
}
mTracker.setVertDragLock(true);
mTracker.setHorizDragLock(false);
} else {
SetCursor(wxCURSOR_SIZING);
nextDragState = WF_DRAG_FREQUENCY;
mTracker.setVertDragLock(true);
mTracker.setHorizDragLock(false);
}
} else {
SetCursor(wxCURSOR_CROSS);
nextDragState = WF_DRAG_NONE;
}
delete demodsHover; delete demodsHover;
} }
@ -275,8 +302,10 @@ void WaterfallCanvas::mouseMoved(wxMouseEvent& event) {
void WaterfallCanvas::mouseDown(wxMouseEvent& event) { void WaterfallCanvas::mouseDown(wxMouseEvent& event) {
mTracker.OnMouseDown(event); mTracker.OnMouseDown(event);
SetCursor(wxCURSOR_SIZENS);
bwChange = false; dragState = nextDragState;
activeDemodulatorBandwidth = 0;
activeDemodulatorFrequency = 0;
} }
void WaterfallCanvas::mouseWheelMoved(wxMouseEvent& event) { void WaterfallCanvas::mouseWheelMoved(wxMouseEvent& event) {
@ -287,7 +316,7 @@ void WaterfallCanvas::mouseWheelMoved(wxMouseEvent& event) {
void WaterfallCanvas::mouseReleased(wxMouseEvent& event) { void WaterfallCanvas::mouseReleased(wxMouseEvent& event) {
mTracker.OnMouseReleased(event); mTracker.OnMouseReleased(event);
if (mTracker.getOriginDeltaMouseX() == 0 && mTracker.getOriginDeltaMouseY() == 0 && !bwChange) { if (mTracker.getOriginDeltaMouseX() == 0 && mTracker.getOriginDeltaMouseY() == 0 && dragState == WF_DRAG_NONE) {
float pos = mTracker.getMouseX(); float pos = mTracker.getMouseX();
@ -308,13 +337,18 @@ void WaterfallCanvas::mouseReleased(wxMouseEvent& event) {
wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep))); wxNumberFormatter::ToString((long) freq, wxNumberFormatter::Style_WithThousandsSep)));
} }
dragState = WF_DRAG_NONE;
mTracker.setVertDragLock(true);
mTracker.setHorizDragLock(true);
SetCursor(wxCURSOR_CROSS); SetCursor(wxCURSOR_CROSS);
} }
void WaterfallCanvas::mouseLeftWindow(wxMouseEvent& event) { void WaterfallCanvas::mouseLeftWindow(wxMouseEvent& event) {
mTracker.OnMouseLeftWindow(event); mTracker.OnMouseLeftWindow(event);
SetCursor(wxCURSOR_CROSS); SetCursor(wxCURSOR_CROSS);
hoveredDemod = -1; activeDemodulator = NULL;
} }
void WaterfallCanvas::mouseEnterWindow(wxMouseEvent& event) { void WaterfallCanvas::mouseEnterWindow(wxMouseEvent& event) {

View File

@ -14,6 +14,8 @@
class WaterfallCanvas: public wxGLCanvas { class WaterfallCanvas: public wxGLCanvas {
public: public:
enum DragState { WF_DRAG_NONE, WF_DRAG_BANDWIDTH_LEFT, WF_DRAG_BANDWIDTH_RIGHT, WF_DRAG_FREQUENCY };
WaterfallCanvas(wxWindow *parent, int *attribList = NULL); WaterfallCanvas(wxWindow *parent, int *attribList = NULL);
~WaterfallCanvas(); ~WaterfallCanvas();
@ -50,9 +52,13 @@ private:
Timer timer; Timer timer;
float frameTimer; float frameTimer;
MouseTracker mTracker; MouseTracker mTracker;
bool bwChange;
int demodBW; int activeDemodulatorBandwidth;
int hoveredDemod; int activeDemodulatorFrequency;
DemodulatorInstance *activeDemodulator;
DragState dragState;
DragState nextDragState;
// event table // event table
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();