Esempio n. 1
0
void WaterfallCanvas::OnMouseReleased(wxMouseEvent& event) {
    InteractiveCanvas::OnMouseReleased(event);
    wxGetApp().getDemodMgr().updateLastState();

    bool isNew = shiftDown || (wxGetApp().getDemodMgr().getLastActiveDemodulator() == NULL)
            || (wxGetApp().getDemodMgr().getLastActiveDemodulator() && !wxGetApp().getDemodMgr().getLastActiveDemodulator()->isActive());

    mouseTracker.setVertDragLock(false);
    mouseTracker.setHorizDragLock(false);

    DemodulatorInstance *demod = isNew?NULL:wxGetApp().getDemodMgr().getLastActiveDemodulator();
    DemodulatorInstance *activeDemod = isNew?NULL:wxGetApp().getDemodMgr().getActiveDemodulator();

    DemodulatorMgr *mgr = &wxGetApp().getDemodMgr();

    if (mouseTracker.getOriginDeltaMouseX() == 0 && mouseTracker.getOriginDeltaMouseY() == 0) {
        float pos = mouseTracker.getMouseX();
        long long input_center_freq = getCenterFrequency();
        long long freqTarget = input_center_freq - (long long) (0.5 * (float) getBandwidth()) + (long long) ((float) pos * (float) getBandwidth());
        long long demodFreq = demod?demod->getFrequency():freqTarget;
        long long bwDiff = freqTarget - demodFreq;
        long long freq = demodFreq;

         int snap = wxGetApp().getFrequencySnap();

         if (snap > 1) {
             if (demod) {
                 bwDiff = roundf((double)bwDiff/(double)snap)*snap;
                 freq += bwDiff;
             } else {
                 freq = roundl((long double)freq/(double)snap)*snap;
             }
         } else {
             freq += bwDiff;
         }


        if (dragState == WF_DRAG_NONE) {
            if (!isNew && wxGetApp().getDemodMgr().getDemodulators().size()) {
                mgr->updateLastState();
                demod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
            } else {
                isNew = true;
                demod = wxGetApp().getDemodMgr().newThread();
                demod->setFrequency(freq);

                demod->setDemodulatorType(mgr->getLastDemodulatorType());
                demod->setBandwidth(mgr->getLastBandwidth());
                demod->setSquelchLevel(mgr->getLastSquelchLevel());
                demod->setSquelchEnabled(mgr->isLastSquelchEnabled());
                demod->setGain(mgr->getLastGain());
                demod->setMuted(mgr->isLastMuted());
                if (mgr->getLastDeltaLock()) {
                    demod->setDeltaLock(true);
                    demod->setDeltaLockOfs(wxGetApp().getFrequency()-freq);
                } else {
                    demod->setDeltaLock(false);
                }
                demod->writeModemSettings(mgr->getLastModemSettings(mgr->getLastDemodulatorType()));
                demod->run();

                wxGetApp().bindDemodulator(demod);
            }

            if (!demod) {
                dragState = WF_DRAG_NONE;
                return;
            }

            demod->updateLabel(freq);
            demod->setFrequency(freq);
            if (demod->isDeltaLock()) {
                demod->setDeltaLockOfs(demod->getFrequency() - wxGetApp().getFrequency());
            }
  
            if (isNew) {
                setStatusText("New demodulator at frequency: %s", freq);
            } else {
                setStatusText("Moved demodulator to frequency: %s", freq);
            }

            wxGetApp().getDemodMgr().setActiveDemodulator(demod, false);
          SetCursor(wxCURSOR_SIZING);
            nextDragState = WF_DRAG_FREQUENCY;
            mouseTracker.setVertDragLock(true);
            mouseTracker.setHorizDragLock(false);
        } else {
            if (activeDemod) {
                wxGetApp().getDemodMgr().setActiveDemodulator(activeDemod, false);
                mgr->updateLastState();
                activeDemod->setTracking(true);
                nextDragState = WF_DRAG_FREQUENCY;
            } else {
                nextDragState = WF_DRAG_NONE;
            }
        }
    } else if (dragState == WF_DRAG_RANGE) {
        float width = mouseTracker.getOriginDeltaMouseX();

        float pos;
        std::string last_type = mgr->getLastDemodulatorType();

        if (last_type == "LSB" || last_type == "USB") {
            float pos1 = mouseTracker.getOriginMouseX();
            float pos2 = mouseTracker.getMouseX();

            if (pos2 < pos1) {
                float tmp = pos1;
                pos1 = pos2;
                pos2 = tmp;
            }

            pos = (last_type == "LSB")?pos2:pos1;
            width *= 2;
        } else {
            pos = mouseTracker.getOriginMouseX() + width / 2.0;
        }

        long long input_center_freq = getCenterFrequency();
        long long freq = input_center_freq - (long long) (0.5 * (float) getBandwidth()) + (long long) ((float) pos * (float) getBandwidth());
        unsigned int bw = (unsigned int) (fabs(width) * (float) getBandwidth());

        if (bw < MIN_BANDWIDTH) {
            bw = MIN_BANDWIDTH;
        }

        if (!bw) {
            dragState = WF_DRAG_NONE;
            return;
        }

        int snap = wxGetApp().getFrequencySnap();

        if (snap > 1) {
            freq = roundl((long double)freq/(double)snap)*snap;
        }


        if (!isNew && wxGetApp().getDemodMgr().getDemodulators().size()) {
            mgr->updateLastState();
            demod = wxGetApp().getDemodMgr().getLastActiveDemodulator();
        } else {
            demod = wxGetApp().getDemodMgr().newThread();
            demod->setFrequency(freq);
            demod->setDemodulatorType(mgr->getLastDemodulatorType());
            demod->setBandwidth(bw);
            demod->setSquelchLevel(mgr->getLastSquelchLevel());
            demod->setSquelchEnabled(mgr->isLastSquelchEnabled());
            demod->setGain(mgr->getLastGain());
            demod->setMuted(mgr->isLastMuted());
            if (mgr->getLastDeltaLock()) {
                demod->setDeltaLock(true);
                demod->setDeltaLockOfs(wxGetApp().getFrequency()-freq);
            } else {
                demod->setDeltaLock(false);
            }
            demod->writeModemSettings(mgr->getLastModemSettings(mgr->getLastDemodulatorType()));

            demod->run();

            wxGetApp().bindDemodulator(demod);
        }

        if (demod == NULL) {
            dragState = WF_DRAG_NONE;
            return;
        }

        setStatusText("New demodulator at frequency: %s", freq);

        demod->updateLabel(freq);
        demod->setFrequency(freq);
        demod->setBandwidth(bw);
        mgr->setActiveDemodulator(demod, false);
        mgr->updateLastState();
    }

    dragState = WF_DRAG_NONE;
}
Esempio n. 2
0
void WaterfallCanvas::OnKeyDown(wxKeyEvent& event) {
    InteractiveCanvas::OnKeyDown(event);

    DemodulatorInstance *activeDemod = wxGetApp().getDemodMgr().getActiveDemodulator();

    long long originalFreq = getCenterFrequency();
    long long freq = originalFreq;

    switch (event.GetKeyCode()) {
    case WXK_UP:
    case WXK_NUMPAD_UP:
            if (!shiftDown) {
                mouseZoom = 1.0;
                zoom = 0.95;
            } else {
                scaleMove = 1.0;
            }
        break;
    case WXK_DOWN:
    case WXK_NUMPAD_DOWN:
            if (!shiftDown) {
                mouseZoom = 1.0;
                zoom = 1.05;
            } else {
                scaleMove = -1.0;
            }
        break;
    case WXK_RIGHT:
    case WXK_NUMPAD_RIGHT:
        if (isView) {
            freqMove = shiftDown?5.0:1.0;
            freqMoving = true;
        } else {
            freq += shiftDown?(getBandwidth() * 10):(getBandwidth() / 2);
        }
        break;
    case WXK_LEFT:
    case WXK_NUMPAD_LEFT:
        if (isView) {
            freqMove = shiftDown?-5.0:-1.0;
            freqMoving = true;
        } else {
            freq -= shiftDown?(getBandwidth() * 10):(getBandwidth() / 2);
        }
        break;
    case 'D':
    case WXK_DELETE:
        if (!activeDemod) {
            break;
        }
        wxGetApp().removeDemodulator(activeDemod);
        wxGetApp().getDemodMgr().deleteThread(activeDemod);
        break;
    case 'M':
        if (!activeDemod) {
            break;
        }
        activeDemod->setMuted(!activeDemod->isMuted());
        break;
    case 'B':
        if (spectrumCanvas) {
            spectrumCanvas->setShowDb(!spectrumCanvas->getShowDb());
        }
        break;
    case WXK_SPACE:
        wxGetApp().showFrequencyInput();
        break;
    case 'C':
        if (wxGetApp().getDemodMgr().getActiveDemodulator()) {
            wxGetApp().setFrequency(wxGetApp().getDemodMgr().getActiveDemodulator()->getFrequency());
        } else if (mouseTracker.mouseInView()) {
            long long freq = getFrequencyAt(mouseTracker.getMouseX());
            
            int snap = wxGetApp().getFrequencySnap();
            
            if (snap > 1) {
                freq = roundf((float)freq/(float)snap)*snap;
            }
            
            wxGetApp().setFrequency(freq);
        }
#ifdef USE_HAMLIB
            if (wxGetApp().rigIsActive() && !wxGetApp().getRigThread()->getControlMode()) {
                wxGetApp().getRigThread()->setFrequency(wxGetApp().getFrequency(),true);
            }
#endif
        break;
    default:
        event.Skip();
        return;
    }

    long long minFreq = bandwidth/2;
    if (freq < minFreq) {
        freq = minFreq;
    }

    if (freq != originalFreq) {
        updateCenterFrequency(freq);
    }

}