Save / Load session working
This commit is contained in:
parent
2c5eb4f946
commit
f454c34245
109
src/AppFrame.cpp
109
src/AppFrame.cpp
|
@ -33,7 +33,7 @@ EVT_IDLE(AppFrame::OnIdle)
|
|||
wxEND_EVENT_TABLE()
|
||||
|
||||
AppFrame::AppFrame() :
|
||||
wxFrame(NULL, wxID_ANY, wxT("CubicSDR " CUBICSDR_VERSION " by Charles J. Cliffe (@ccliffe)")), activeDemodulator(NULL) {
|
||||
wxFrame(NULL, wxID_ANY, wxT("CubicSDR " CUBICSDR_VERSION " by Charles J. Cliffe (@ccliffe)")), activeDemodulator(NULL) {
|
||||
|
||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer *demodOpts = new wxBoxSizer(wxVERTICAL);
|
||||
|
@ -42,11 +42,11 @@ AppFrame::AppFrame() :
|
|||
wxBoxSizer *demodScopeTray = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
demodModeSelector = new ModeSelectorCanvas(this, NULL);
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_FM,"FM");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_AM,"AM");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_LSB,"LSB");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_USB,"USB");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_DSB,"DSB");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_FM, "FM");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_AM, "AM");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_LSB, "LSB");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_USB, "USB");
|
||||
demodModeSelector->addChoice(DEMOD_TYPE_DSB, "DSB");
|
||||
demodTray->Add(demodModeSelector, 2, wxEXPAND | wxALL, 0);
|
||||
|
||||
// demodTray->AddSpacer(2);
|
||||
|
@ -115,6 +115,7 @@ AppFrame::AppFrame() :
|
|||
menu->Append(wxID_SAVE, "&Save Session");
|
||||
menu->Append(wxID_SAVEAS, "Save Session &As..");
|
||||
menu->AppendSeparator();
|
||||
menu->Append(wxID_RESET, "&Reset Session");
|
||||
menu->Append(wxID_CLOSE);
|
||||
|
||||
menuBar->Append(menu, wxT("&File"));
|
||||
|
@ -159,6 +160,14 @@ AppFrame::AppFrame() :
|
|||
|
||||
GetStatusBar()->SetStatusText(wxString::Format(wxT("Set center frequency: %i"), DEFAULT_FREQ));
|
||||
|
||||
wxAcceleratorEntry entries[3];
|
||||
entries[0].Set(wxACCEL_CTRL, (int) 'O', wxID_OPEN);
|
||||
entries[1].Set(wxACCEL_CTRL, (int) 'S', wxID_SAVE);
|
||||
entries[2].Set(wxACCEL_CTRL, (int) 'A', wxID_SAVEAS);
|
||||
|
||||
wxAcceleratorTable accel(3, entries);
|
||||
SetAcceleratorTable(accel);
|
||||
|
||||
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
||||
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
|
||||
// ShowFullScreen(true);
|
||||
|
@ -181,18 +190,31 @@ void AppFrame::OnMenu(wxCommandEvent& event) {
|
|||
wxGetApp().setOffset(ofs);
|
||||
}
|
||||
} else if (event.GetId() == wxID_SAVE) {
|
||||
wxFileDialog saveFileDialog(this, _("Save XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
|
||||
if (saveFileDialog.ShowModal() == wxID_CANCEL) {
|
||||
return;
|
||||
}
|
||||
saveSession(saveFileDialog.GetPath().ToStdString());
|
||||
if (!currentSessionFile.empty()) {
|
||||
saveSession(currentSessionFile);
|
||||
} else {
|
||||
wxFileDialog saveFileDialog(this, _("Save XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||
if (saveFileDialog.ShowModal() == wxID_CANCEL) {
|
||||
return;
|
||||
}
|
||||
saveSession(saveFileDialog.GetPath().ToStdString());
|
||||
}
|
||||
} else if (event.GetId() == wxID_OPEN) {
|
||||
wxFileDialog openFileDialog(this, _("Open XML Session file"), "", "","XML files (*.xml)|*.xml", wxFD_OPEN|wxFD_FILE_MUST_EXIST);
|
||||
if (openFileDialog.ShowModal() == wxID_CANCEL) {
|
||||
return;
|
||||
}
|
||||
loadSession(openFileDialog.GetPath().ToStdString());
|
||||
wxFileDialog openFileDialog(this, _("Open XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
if (openFileDialog.ShowModal() == wxID_CANCEL) {
|
||||
return;
|
||||
}
|
||||
loadSession(openFileDialog.GetPath().ToStdString());
|
||||
} else if (event.GetId() == wxID_SAVEAS) {
|
||||
wxFileDialog saveFileDialog(this, _("Save XML Session file"), "", "", "XML files (*.xml)|*.xml", wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||
if (saveFileDialog.ShowModal() == wxID_CANCEL) {
|
||||
return;
|
||||
}
|
||||
saveSession(saveFileDialog.GetPath().ToStdString());
|
||||
} else if (event.GetId() == wxID_RESET) {
|
||||
wxGetApp().getDemodMgr().terminateAll();
|
||||
wxGetApp().setFrequency(DEFAULT_FREQ);
|
||||
wxGetApp().setOffset(0);
|
||||
} else if (event.GetId() == wxID_EXIT) {
|
||||
Close(false);
|
||||
}
|
||||
|
@ -319,8 +341,8 @@ void AppFrame::saveSession(std::string fileName) {
|
|||
*demod->newChild("frequency") = (*instance_i)->getFrequency();
|
||||
*demod->newChild("type") = (*instance_i)->getDemodulatorType();
|
||||
*demod->newChild("squelch_level") = (*instance_i)->getSquelchLevel();
|
||||
*demod->newChild("squelch_enabled") = (*instance_i)->isSquelchEnabled()?1:0;
|
||||
*demod->newChild("stereo") = (*instance_i)->isStereo()?1:0;
|
||||
*demod->newChild("squelch_enabled") = (*instance_i)->isSquelchEnabled() ? 1 : 0;
|
||||
*demod->newChild("stereo") = (*instance_i)->isStereo() ? 1 : 0;
|
||||
*demod->newChild("output_device") = outputDevices[(*instance_i)->getOutputDevice()].name;
|
||||
}
|
||||
|
||||
|
@ -333,7 +355,7 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// wxGetApp().getDemodMgr().terminateAll();
|
||||
wxGetApp().getDemodMgr().terminateAll();
|
||||
|
||||
try {
|
||||
DataNode *header = l.rootNode()->getNext("header");
|
||||
|
@ -346,6 +368,8 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||
std::cout << "\tCenter Frequency: " << center_freq << std::endl;
|
||||
std::cout << "\tOffset: " << offset << std::endl;
|
||||
|
||||
wxGetApp().setOffset(offset);
|
||||
wxGetApp().setFrequency(center_freq);
|
||||
|
||||
DataNode *demodulators = l.rootNode()->getNext("demodulators");
|
||||
|
||||
|
@ -358,17 +382,47 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||
|
||||
long bandwidth = *demod->getNext("bandwidth");
|
||||
long long freq = *demod->getNext("frequency");
|
||||
int type = demod->hasAnother("type")?*demod->getNext("type"):DEMOD_TYPE_FM;
|
||||
float squelch_level = demod->hasAnother("squelch_level")?(float)*demod->getNext("squelch_level"):0;
|
||||
int squelch_enabled = demod->hasAnother("squelch_enabled")?(int)*demod->getNext("squelch_enabled"):0;
|
||||
int stereo = demod->hasAnother("stereo")?(int)*demod->getNext("stereo"):0;
|
||||
std::string output_device = demod->hasAnother("output_device")?string(*(demod->getNext("output_device"))):"";
|
||||
int type = demod->hasAnother("type") ? *demod->getNext("type") : DEMOD_TYPE_FM;
|
||||
float squelch_level = demod->hasAnother("squelch_level") ? (float) *demod->getNext("squelch_level") : 0;
|
||||
int squelch_enabled = demod->hasAnother("squelch_enabled") ? (int) *demod->getNext("squelch_enabled") : 0;
|
||||
int stereo = demod->hasAnother("stereo") ? (int) *demod->getNext("stereo") : 0;
|
||||
std::string output_device = demod->hasAnother("output_device") ? string(*(demod->getNext("output_device"))) : "";
|
||||
|
||||
std::cout << "\tFound demodulator at frequency " << freq << " type " << type << std::endl;
|
||||
DemodulatorInstance *newDemod = wxGetApp().getDemodMgr().newThread();
|
||||
newDemod->setDemodulatorType(type);
|
||||
newDemod->setBandwidth(bandwidth);
|
||||
newDemod->setFrequency(freq);
|
||||
newDemod->updateLabel(freq);
|
||||
if (squelch_enabled) {
|
||||
newDemod->setSquelchEnabled(true);
|
||||
newDemod->setSquelchLevel(squelch_level);
|
||||
}
|
||||
if (stereo) {
|
||||
newDemod->setStereo(true);
|
||||
}
|
||||
|
||||
bool found_device = false;
|
||||
std::map<int, RtAudio::DeviceInfo>::iterator i;
|
||||
for (i = outputDevices.begin(); i != outputDevices.end(); i++) {
|
||||
if (i->second.name == output_device) {
|
||||
newDemod->setOutputDevice(i->first);
|
||||
found_device = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_device) {
|
||||
std::cout << "\tWarning: named output device '" << output_device << "' was not found. Using default output.";
|
||||
}
|
||||
|
||||
newDemod->run();
|
||||
|
||||
wxGetApp().bindDemodulator(newDemod);
|
||||
|
||||
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
|
||||
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
|
||||
std::cout << "\t\tSquelch Level: " << squelch_level << std::endl;
|
||||
std::cout << "\t\tSquelch Enabled: " << (squelch_enabled?"true":"false") << std::endl;
|
||||
std::cout << "\t\tStereo: " << (stereo?"true":"false") << std::endl;
|
||||
std::cout << "\t\tSquelch Enabled: " << (squelch_enabled ? "true" : "false") << std::endl;
|
||||
std::cout << "\t\tStereo: " << (stereo ? "true" : "false") << std::endl;
|
||||
std::cout << "\t\tOutput Device: " << output_device << std::endl;
|
||||
|
||||
}
|
||||
|
@ -381,4 +435,5 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||
return false;
|
||||
}
|
||||
|
||||
currentSessionFile = fileName;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#define wxID_RT_AUDIO_DEVICE 1000
|
||||
#define wxID_SET_FREQ_OFFSET 2001
|
||||
#define wxID_RESET 2002
|
||||
|
||||
// Define a new frame type
|
||||
class AppFrame: public wxFrame {
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
#endif
|
||||
#define DEFAULT_FFT_SIZE 2048
|
||||
|
||||
//#define DEFAULT_FREQ 98900000
|
||||
#define DEFAULT_FREQ 132000000
|
||||
#define DEFAULT_FREQ 100000000
|
||||
#define AUDIO_FREQUENCY 44100
|
||||
|
||||
#include <mutex>
|
||||
|
|
|
@ -213,7 +213,9 @@ float DemodulatorInstance::getSquelchLevel() {
|
|||
}
|
||||
|
||||
void DemodulatorInstance::setOutputDevice(int device_id) {
|
||||
if (audioThread) {
|
||||
if (!active) {
|
||||
audioThread->setInitOutputDevice(device_id);
|
||||
} else if (audioThread) {
|
||||
AudioThreadCommand command;
|
||||
command.cmd = AudioThreadCommand::AUDIO_THREAD_CMD_SET_DEVICE;
|
||||
command.int_value = device_id;
|
||||
|
@ -232,7 +234,12 @@ void DemodulatorInstance::checkBandwidth() {
|
|||
}
|
||||
|
||||
void DemodulatorInstance::setDemodulatorType(int demod_type_in) {
|
||||
if (demodulatorThread && threadQueueControl) {
|
||||
if (!active) {
|
||||
currentDemodType = demod_type_in;
|
||||
checkBandwidth();
|
||||
demodulatorPreThread->getParams().demodType = currentDemodType;
|
||||
demodulatorThread->setDemodulatorType(currentDemodType);
|
||||
} else if (demodulatorThread && threadQueueControl) {
|
||||
DemodulatorThreadControlCommand command;
|
||||
command.cmd = DemodulatorThreadControlCommand::DEMOD_THREAD_CMD_CTL_TYPE;
|
||||
currentDemodType = demod_type_in;
|
||||
|
@ -247,7 +254,11 @@ int DemodulatorInstance::getDemodulatorType() {
|
|||
}
|
||||
|
||||
void DemodulatorInstance::setBandwidth(int bw) {
|
||||
if (demodulatorPreThread && threadQueueCommand) {
|
||||
if (!active) {
|
||||
currentBandwidth = bw;
|
||||
checkBandwidth();
|
||||
demodulatorPreThread->getParams().bandwidth = currentBandwidth;
|
||||
} else if (demodulatorPreThread && threadQueueCommand) {
|
||||
DemodulatorThreadCommand command;
|
||||
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_BANDWIDTH;
|
||||
currentBandwidth = bw;
|
||||
|
@ -255,7 +266,6 @@ void DemodulatorInstance::setBandwidth(int bw) {
|
|||
command.llong_value = currentBandwidth;
|
||||
threadQueueCommand->push(command);
|
||||
}
|
||||
demodulatorPreThread->getParams().bandwidth;
|
||||
}
|
||||
|
||||
int DemodulatorInstance::getBandwidth() {
|
||||
|
@ -266,17 +276,20 @@ int DemodulatorInstance::getBandwidth() {
|
|||
}
|
||||
|
||||
void DemodulatorInstance::setFrequency(long long freq) {
|
||||
if ((freq - getBandwidth()/2) <= 0) {
|
||||
freq = getBandwidth()/2;
|
||||
if ((freq - getBandwidth() / 2) <= 0) {
|
||||
freq = getBandwidth() / 2;
|
||||
}
|
||||
if (demodulatorPreThread && threadQueueCommand) {
|
||||
DemodulatorThreadCommand command;
|
||||
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY;
|
||||
currentFrequency = freq;
|
||||
command.llong_value = freq;
|
||||
threadQueueCommand->push(command);
|
||||
}
|
||||
demodulatorPreThread->getParams().bandwidth;
|
||||
if (!active) {
|
||||
currentFrequency = freq;
|
||||
demodulatorPreThread->getParams().frequency = currentFrequency;
|
||||
} else if (demodulatorPreThread && threadQueueCommand) {
|
||||
DemodulatorThreadCommand command;
|
||||
command.cmd = DemodulatorThreadCommand::DEMOD_THREAD_CMD_SET_FREQUENCY;
|
||||
currentFrequency = freq;
|
||||
command.llong_value = freq;
|
||||
threadQueueCommand->push(command);
|
||||
}
|
||||
demodulatorPreThread->getParams().bandwidth;
|
||||
}
|
||||
|
||||
long long DemodulatorInstance::getFrequency() {
|
||||
|
|
|
@ -29,6 +29,7 @@ DemodulatorInstance *DemodulatorMgr::newThread() {
|
|||
void DemodulatorMgr::terminateAll() {
|
||||
while (demods.size()) {
|
||||
DemodulatorInstance *d = demods.back();
|
||||
wxGetApp().removeDemodulator(d);
|
||||
deleteThread(d);
|
||||
}
|
||||
}
|
||||
|
@ -54,8 +55,8 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
|||
|
||||
if (i != demods.end()) {
|
||||
demods.erase(i);
|
||||
demod->terminate();
|
||||
}
|
||||
demod->terminate();
|
||||
|
||||
demods_deleted.push_back(demod);
|
||||
|
||||
|
|
|
@ -130,9 +130,8 @@ void SDRPostThread::threadMain() {
|
|||
std::vector<DemodulatorInstance *>::iterator i;
|
||||
for (i = demodulators.begin(); i != demodulators.end(); i++) {
|
||||
DemodulatorInstance *demod = *i;
|
||||
|
||||
if (demod->getParams().frequency != data_in->frequency
|
||||
&& abs(data_in->frequency - demod->getParams().frequency) > (SRATE / 2)) {
|
||||
if (demod->getFrequency() != data_in->frequency
|
||||
&& abs(data_in->frequency - demod->getFrequency()) > (SRATE / 2)) {
|
||||
continue;
|
||||
}
|
||||
activeDemods++;
|
||||
|
@ -165,8 +164,8 @@ void SDRPostThread::threadMain() {
|
|||
DemodulatorInstance *demod = *i;
|
||||
DemodulatorThreadInputQueue *demodQueue = demod->threadQueueDemod;
|
||||
|
||||
if (demod->getParams().frequency != data_in->frequency
|
||||
&& abs(data_in->frequency - demod->getParams().frequency) > (SRATE / 2)) {
|
||||
if (demod->getFrequency() != data_in->frequency
|
||||
&& abs(data_in->frequency - demod->getFrequency()) > (SRATE / 2)) {
|
||||
if (demod->isActive()) {
|
||||
demod->setActive(false);
|
||||
DemodulatorThreadIQData *dummyDataOut = new DemodulatorThreadIQData;
|
||||
|
|
Loading…
Reference in New Issue