tuning tweaks, zoomed view following fix

This commit is contained in:
Charles J. Cliffe 2015-03-29 20:24:00 -04:00
parent d95925a3c4
commit efa2cd75c9
5 changed files with 81 additions and 68 deletions

View File

@ -38,7 +38,7 @@ EVT_IDLE(AppFrame::OnIdle)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
AppFrame::AppFrame() : AppFrame::AppFrame() :
wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) { wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) {
#ifdef __linux__ #ifdef __linux__
SetIcon(wxICON(cubicsdr)); SetIcon(wxICON(cubicsdr));
@ -50,13 +50,7 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) {
wxBoxSizer *demodTray = new wxBoxSizer(wxHORIZONTAL); wxBoxSizer *demodTray = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *demodScopeTray = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodScopeTray = new wxBoxSizer(wxVERTICAL);
int attribList[] = { int attribList[] = { WX_GL_RGBA, WX_GL_STENCIL_SIZE, 8, WX_GL_BUFFER_SIZE, 24, WX_GL_DOUBLEBUFFER, 0 };
WX_GL_RGBA,
WX_GL_STENCIL_SIZE, 8,
WX_GL_BUFFER_SIZE, 24,
WX_GL_DOUBLEBUFFER,
0
};
demodModeSelector = new ModeSelectorCanvas(this, attribList); demodModeSelector = new ModeSelectorCanvas(this, attribList);
demodModeSelector->addChoice(DEMOD_TYPE_FM, "FM"); demodModeSelector->addChoice(DEMOD_TYPE_FM, "FM");
@ -164,7 +158,6 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) {
i++; i++;
} }
for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) { for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) {
wxMenuItem *itm = menu->AppendRadioItem(wxID_RT_AUDIO_DEVICE + mdevices_i->first, mdevices_i->second.name, wxT("Description?")); wxMenuItem *itm = menu->AppendRadioItem(wxID_RT_AUDIO_DEVICE + mdevices_i->first, mdevices_i->second.name, wxT("Description?"));
itm->SetId(wxID_RT_AUDIO_DEVICE + mdevices_i->first); itm->SetId(wxID_RT_AUDIO_DEVICE + mdevices_i->first);
@ -232,31 +225,30 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) {
menuBar->Append(menu, wxT("Input &Device")); menuBar->Append(menu, wxT("Input &Device"));
} }
menu = new wxMenu; menu = new wxMenu;
#define NUM_RATES_DEFAULT 4
#define NUM_RATES_DEFAULT 4
int desired_rates[NUM_RATES_DEFAULT] = { 48000, 44100, 96000, 192000 }; int desired_rates[NUM_RATES_DEFAULT] = { 48000, 44100, 96000, 192000 };
for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) { for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) {
int desired_rate = 0; int desired_rate = 0;
int desired_rank = NUM_RATES_DEFAULT+1; int desired_rank = NUM_RATES_DEFAULT + 1;
for (std::vector<unsigned int>::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end(); srate++) { for (std::vector<unsigned int>::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end();
for (i = 0; i < NUM_RATES_DEFAULT; i++) { srate++) {
if (desired_rates[i] == (*srate)) { for (i = 0; i < NUM_RATES_DEFAULT; i++) {
if (desired_rank > i) { if (desired_rates[i] == (*srate)) {
desired_rank = i; if (desired_rank > i) {
desired_rate = (*srate); desired_rank = i;
} desired_rate = (*srate);
} }
} }
}
} }
if (desired_rank > NUM_RATES_DEFAULT) { if (desired_rank > NUM_RATES_DEFAULT) {
desired_rate = mdevices_i->second.sampleRates.back(); desired_rate = mdevices_i->second.sampleRates.back();
} }
AudioThread::deviceSampleRate[mdevices_i->first] = desired_rate; AudioThread::deviceSampleRate[mdevices_i->first] = desired_rate;
} }
@ -264,18 +256,19 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) {
new wxMenu; new wxMenu;
int menu_id = wxID_AUDIO_BANDWIDTH_BASE + wxID_AUDIO_DEVICE_MULTIPLIER * mdevices_i->first; int menu_id = wxID_AUDIO_BANDWIDTH_BASE + wxID_AUDIO_DEVICE_MULTIPLIER * mdevices_i->first;
wxMenu *subMenu = new wxMenu; wxMenu *subMenu = new wxMenu;
menu->AppendSubMenu(subMenu,mdevices_i->second.name, wxT("Description?")); menu->AppendSubMenu(subMenu, mdevices_i->second.name, wxT("Description?"));
int j = 0; int j = 0;
for (std::vector<unsigned int>::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end(); srate++) { for (std::vector<unsigned int>::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end();
srate++) {
std::stringstream srateName; std::stringstream srateName;
srateName << ((float)(*srate)/1000.0f) << "kHz"; srateName << ((float) (*srate) / 1000.0f) << "kHz";
wxMenuItem *itm = subMenu->AppendRadioItem(menu_id+j, srateName.str(), wxT("Description?")); wxMenuItem *itm = subMenu->AppendRadioItem(menu_id + j, srateName.str(), wxT("Description?"));
if ((*srate) == AudioThread::deviceSampleRate[mdevices_i->first]) { if ((*srate) == AudioThread::deviceSampleRate[mdevices_i->first]) {
itm->Check(true); itm->Check(true);
} }
audioSampleRateMenuItems[menu_id+j] = itm; audioSampleRateMenuItems[menu_id + j] = itm;
j++; j++;
} }
@ -283,7 +276,6 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) {
menuBar->Append(menu, wxT("Audio &Bandwidth")); menuBar->Append(menu, wxT("Audio &Bandwidth"));
SetMenuBar(menuBar); SetMenuBar(menuBar);
CreateStatusBar(); CreateStatusBar();
@ -291,7 +283,6 @@ wxFrame(NULL, wxID_ANY, CUBICSDR_TITLE), activeDemodulator(NULL) {
Centre(); Centre();
Show(); Show();
#ifdef _WIN32 #ifdef _WIN32
SetIcon(wxICON(frame_icon)); SetIcon(wxICON(frame_icon));
#endif #endif
@ -398,7 +389,6 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
wxGetApp().setDevice(event.GetId() - wxID_DEVICE_ID); wxGetApp().setDevice(event.GetId() - wxID_DEVICE_ID);
} }
if (event.GetId() >= wxID_AUDIO_BANDWIDTH_BASE) { if (event.GetId() >= wxID_AUDIO_BANDWIDTH_BASE) {
int evId = event.GetId(); int evId = event.GetId();
std::vector<RtAudio::DeviceInfo>::iterator devices_i; std::vector<RtAudio::DeviceInfo>::iterator devices_i;
@ -406,21 +396,22 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
int i = 0; int i = 0;
for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) { for (mdevices_i = outputDevices.begin(); mdevices_i != outputDevices.end(); mdevices_i++) {
int menu_id = wxID_AUDIO_BANDWIDTH_BASE + wxID_AUDIO_DEVICE_MULTIPLIER * mdevices_i->first; int menu_id = wxID_AUDIO_BANDWIDTH_BASE + wxID_AUDIO_DEVICE_MULTIPLIER * mdevices_i->first;
int j = 0; int j = 0;
for (std::vector<unsigned int>::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end(); srate++) { for (std::vector<unsigned int>::iterator srate = mdevices_i->second.sampleRates.begin(); srate != mdevices_i->second.sampleRates.end();
srate++) {
if (evId == menu_id + j) { if (evId == menu_id + j) {
//audioSampleRateMenuItems[menu_id+j]; //audioSampleRateMenuItems[menu_id+j];
//std::cout << "Would set audio sample rate on device " << mdevices_i->second.name << " (" << mdevices_i->first << ") to " << (*srate) << "Hz" << std::endl; //std::cout << "Would set audio sample rate on device " << mdevices_i->second.name << " (" << mdevices_i->first << ") to " << (*srate) << "Hz" << std::endl;
AudioThread::setDeviceSampleRate(mdevices_i->first, *srate); AudioThread::setDeviceSampleRate(mdevices_i->first, *srate);
} }
j++; j++;
} }
i++; i++;
} }
} }
} }
@ -463,12 +454,12 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
if (demod->getDemodulatorType() == DEMOD_TYPE_USB) { if (demod->getDemodulatorType() == DEMOD_TYPE_USB) {
demodBw /= 2; demodBw /= 2;
centerFreq += demod->getBandwidth()/4; centerFreq += demod->getBandwidth() / 4;
} }
if (demod->getDemodulatorType() == DEMOD_TYPE_LSB) { if (demod->getDemodulatorType() == DEMOD_TYPE_LSB) {
demodBw /= 2; demodBw /= 2;
centerFreq -= demod->getBandwidth()/4; centerFreq -= demod->getBandwidth() / 4;
} }
if (demodBw > wxGetApp().getSampleRate() / 2) { if (demodBw > wxGetApp().getSampleRate() / 2) {
@ -516,11 +507,11 @@ void AppFrame::OnIdle(wxIdleEvent& event) {
demodGainMeter->setLevel(demodGainMeter->getInputValue()); demodGainMeter->setLevel(demodGainMeter->getInputValue());
} }
if (wxGetApp().getFrequency() != waterfallCanvas->getCenterFrequency()) { if (wxGetApp().getFrequency() != demodWaterfallCanvas->getCenterFrequency()) {
if (!spectrumCanvas->getMouseTracker()->mouseDown()) { if (spectrumCanvas->getViewState() && abs(wxGetApp().getFrequency()-spectrumCanvas->getCenterFrequency()) > (wxGetApp().getSampleRate()/2)) {
spectrumCanvas->setCenterFrequency(wxGetApp().getFrequency()); spectrumCanvas->setCenterFrequency(wxGetApp().getFrequency());
waterfallCanvas->setCenterFrequency(wxGetApp().getFrequency());
} }
waterfallCanvas->setCenterFrequency(wxGetApp().getFrequency());
demodWaterfallCanvas->setCenterFrequency(wxGetApp().getFrequency()); demodWaterfallCanvas->setCenterFrequency(wxGetApp().getFrequency());
demodSpectrumCanvas->setCenterFrequency(wxGetApp().getFrequency()); demodSpectrumCanvas->setCenterFrequency(wxGetApp().getFrequency());
} }

View File

@ -236,9 +236,9 @@ int DemodulatorInstance::getOutputDevice() {
} }
void DemodulatorInstance::checkBandwidth() { void DemodulatorInstance::checkBandwidth() {
if ((currentDemodType == DEMOD_TYPE_USB || currentDemodType == DEMOD_TYPE_LSB) && (getBandwidth() % 2)) { // if ((currentDemodType == DEMOD_TYPE_USB || currentDemodType == DEMOD_TYPE_LSB) && (getBandwidth() % 2)) {
setBandwidth(getBandwidth()+1); // setBandwidth(getBandwidth()+1);
} // }
} }
void DemodulatorInstance::setDemodulatorType(int demod_type_in) { void DemodulatorInstance::setDemodulatorType(int demod_type_in) {

View File

@ -41,6 +41,10 @@ void InteractiveCanvas::disableView() {
lastBandwidth = 0; lastBandwidth = 0;
} }
bool InteractiveCanvas::getViewState() {
return isView;
}
long long InteractiveCanvas::getFrequencyAt(float x) { long long InteractiveCanvas::getFrequencyAt(float x) {
long long iqCenterFreq = getCenterFrequency(); long long iqCenterFreq = getCenterFrequency();
long long iqBandwidth = getBandwidth(); long long iqBandwidth = getBandwidth();

View File

@ -15,6 +15,7 @@ public:
void setView(long long center_freq_in, int bandwidth_in); void setView(long long center_freq_in, int bandwidth_in);
void disableView(); void disableView();
bool getViewState();
void setCenterFrequency(long long center_freq_in); void setCenterFrequency(long long center_freq_in);
long long getCenterFrequency(); long long getCenterFrequency();

View File

@ -223,25 +223,42 @@ void TuningCanvas::OnMouseMoved(wxMouseEvent& event) {
if (index > 0) { if (index > 0) {
hoverIndex = index; hoverIndex = index;
hoverState = TUNING_HOVER_FREQ; hoverState = TUNING_HOVER_FREQ;
return;
} }
index = glContext->GetTunerDigitIndex(mouseTracker.getMouseX(), 7, bwDP, bwW); // bw if (!index) {
if (index > 0) { index = glContext->GetTunerDigitIndex(mouseTracker.getMouseX(), 7, bwDP, bwW); // bw
hoverIndex = index; if (index > 0) {
hoverState = TUNING_HOVER_BW; hoverIndex = index;
return; hoverState = TUNING_HOVER_BW;
}
} }
index = glContext->GetTunerDigitIndex(mouseTracker.getMouseX(), 11, centerDP, centerW); // center if (!index) {
if (index > 0) { index = glContext->GetTunerDigitIndex(mouseTracker.getMouseX(), 11, centerDP, centerW); // center
hoverIndex = index; if (index > 0) {
hoverState = TUNING_HOVER_CENTER; hoverIndex = index;
return; hoverState = TUNING_HOVER_CENTER;
}
} }
hoverIndex = 0; if (!index) {
hoverState = TUNING_HOVER_NONE; hoverIndex = 0;
hoverState = TUNING_HOVER_NONE;
} else {
switch (hoverState) {
case TUNING_HOVER_FREQ:
setStatusText("Click or drag a digit to change frequency. Hold shift to disable carry.");
break;
case TUNING_HOVER_BW:
setStatusText("Click or drag a digit to change bandwidth. Hold shift to disable carry.");
break;
case TUNING_HOVER_CENTER:
setStatusText("Click or drag a digit to change center frequency. Hold shift to disable carry.");
break;
}
}
} }
void TuningCanvas::OnMouseDown(wxMouseEvent& event) { void TuningCanvas::OnMouseDown(wxMouseEvent& event) {
@ -270,7 +287,7 @@ void TuningCanvas::OnMouseReleased(wxMouseEvent& event) {
int hExponent = hoverIndex - 1; int hExponent = hoverIndex - 1;
if (hoverState != TUNING_HOVER_NONE && !dragging) { if (hoverState != TUNING_HOVER_NONE && !dragging && (downState == hoverState) && (downIndex == hoverIndex)) {
StepTuner(hoverState, hExponent, top); StepTuner(hoverState, hExponent, top);
} }