diff --git a/FrequencyList.cpp b/FrequencyList.cpp index 764110504..3eb51993b 100644 --- a/FrequencyList.cpp +++ b/FrequencyList.cpp @@ -154,7 +154,7 @@ public: QMimeData * mimeData (QModelIndexList const&) const override; static int constexpr num_cols {3}; - static auto constexpr mime_type ="application/wsjt.Frequencies"; + static auto constexpr mime_type = "application/wsjt.Frequencies"; Bands const * bands_; FrequencyItems frequency_list_; diff --git a/HRDTransceiver.cpp b/HRDTransceiver.cpp index 9d90a5e40..427e7a3c8 100644 --- a/HRDTransceiver.cpp +++ b/HRDTransceiver.cpp @@ -62,13 +62,10 @@ struct HRDMessage qint32 checksum_; // Apparently not used. QChar payload_[0]; // UTF-16 (which is wchar_t on Windows) - static qint32 const magic_1_value_; - static qint32 const magic_2_value_; + static qint32 constexpr magic_1_value_ = 0x1234ABCD; + static qint32 constexpr magic_2_value_ = 0xABCD1234; }; -qint32 const HRDMessage::magic_1_value_ (0x1234ABCD); -qint32 const HRDMessage::magic_2_value_ (0xABCD1234); - HRDTransceiver::HRDTransceiver (std::unique_ptr wrapped , QString const& server , bool use_for_ptt diff --git a/HamlibTransceiver.cpp b/HamlibTransceiver.cpp index e2ac77b00..c755ca1cf 100644 --- a/HamlibTransceiver.cpp +++ b/HamlibTransceiver.cpp @@ -34,7 +34,7 @@ namespace int debug_callback (enum rig_debug_level_e level, rig_ptr_t /* arg */, char const * format, va_list ap) { QString message; - static char const fmt[] = "Hamlib: %s"; + static char constexpr fmt[] = "Hamlib: %s"; message = message.vsprintf (format, ap).trimmed (); switch (level) diff --git a/MessageServer.cpp b/MessageServer.cpp index b6f59bb87..d3c9e51d8 100644 --- a/MessageServer.cpp +++ b/MessageServer.cpp @@ -58,7 +58,7 @@ public: MessageServer * self_; port_type port_; QHostAddress multicast_group_address_; - static BindMode const bind_mode_; + static BindMode constexpr bind_mode_ = ShareAddress | ReuseAddressHint; struct Client { Client () = default; @@ -81,9 +81,9 @@ public: QTimer * clock_; }; -#include "MessageServer.moc" +MessageServer::impl::BindMode constexpr MessageServer::impl::bind_mode_; -MessageServer::impl::BindMode const MessageServer::impl::bind_mode_ = ShareAddress | ReuseAddressHint; +#include "MessageServer.moc" void MessageServer::impl::leave_multicast_group () { diff --git a/Modulator.cpp b/Modulator.cpp index 13ae5eccf..c46f69d36 100644 --- a/Modulator.cpp +++ b/Modulator.cpp @@ -18,12 +18,12 @@ extern float gran(); // Noise generator (for tests only) # define SOFT_KEYING 1 #endif -double const Modulator::m_twoPi = 2.0 * 3.141592653589793238462; +double constexpr Modulator::m_twoPi; // float wpm=20.0; // unsigned m_nspd=1.2*48000.0/wpm; // m_nspd=3072; //18.75 WPM -unsigned const Modulator::m_nspd = 2048 + 512; // 22.5 WPM +unsigned const Modulator::m_nspd; Modulator::Modulator (unsigned frameRate, unsigned periodLengthInSeconds, QObject * parent) @@ -37,6 +37,8 @@ Modulator::Modulator (unsigned frameRate, unsigned periodLengthInSeconds, , m_state {Idle} , m_tuning {false} , m_cwLevel {false} + , m_j0 {-1} + , m_toneFrequency0 {1500.0} { } @@ -127,8 +129,6 @@ void Modulator::close () qint64 Modulator::readData (char * data, qint64 maxSize) { - static int j0=-1; - static double toneFrequency0=1500.0; double toneFrequency=1500.0; if(maxSize==0) return 0; @@ -232,28 +232,28 @@ qint64 Modulator::readData (char * data, qint64 maxSize) if(m_bFastMode) isym=isym%m_symbolsLength; if (isym != m_isym0 || m_frequency != m_frequency0) { if(itone[0]>=100) { - toneFrequency0=itone[0]; + m_toneFrequency0=itone[0]; } else { if(m_toneSpacing==0.0) { - toneFrequency0=m_frequency + itone[isym]*baud; + m_toneFrequency0=m_frequency + itone[isym]*baud; } else { - toneFrequency0=m_frequency + itone[isym]*m_toneSpacing; + m_toneFrequency0=m_frequency + itone[isym]*m_toneSpacing; } } // qDebug() << "B" << m_bFastMode << m_ic << numFrames << isym << itone[isym] -// << toneFrequency0 << m_nsps; - m_dphi = m_twoPi * toneFrequency0 / m_frameRate; +// << m_toneFrequency0 << m_nsps; + m_dphi = m_twoPi * m_toneFrequency0 / m_frameRate; m_isym0 = isym; m_frequency0 = m_frequency; //??? } int j=m_ic/480; - if(m_fSpread>0.0 and j!=j0) { + if(m_fSpread>0.0 and j!=m_j0) { float x1=(float)qrand()/RAND_MAX; float x2=(float)qrand()/RAND_MAX; - toneFrequency = toneFrequency0 + 0.5*m_fSpread*(x1+x2-1.0); + toneFrequency = m_toneFrequency0 + 0.5*m_fSpread*(x1+x2-1.0); m_dphi = m_twoPi * toneFrequency / m_frameRate; - j0=j; + m_j0=j; } m_phi += m_dphi; diff --git a/Modulator.hpp b/Modulator.hpp index cea1eccc6..ff5975205 100644 --- a/Modulator.hpp +++ b/Modulator.hpp @@ -57,8 +57,8 @@ private: unsigned m_symbolsLength; - static double const m_twoPi; - static unsigned const m_nspd; // CW ID WPM factor + static double constexpr m_twoPi = 2.0 * 3.141592653589793238462; + static unsigned constexpr m_nspd = 2048 + 512; // CW ID WPM factor = 22.5 WPM double m_phi; double m_dphi; @@ -86,6 +86,8 @@ private: bool m_cwLevel; unsigned m_ic; unsigned m_isym0; + int m_j0; + double m_toneFrequency0; }; #endif diff --git a/SampleDownloader/DirectoryNode.hpp b/SampleDownloader/DirectoryNode.hpp index 5d26b7207..2de16eac4 100644 --- a/SampleDownloader/DirectoryNode.hpp +++ b/SampleDownloader/DirectoryNode.hpp @@ -39,7 +39,7 @@ public: return name == text (0); } - static int const Type {UserType}; + static int constexpr Type {UserType}; }; inline diff --git a/SampleDownloader/FileNode.hpp b/SampleDownloader/FileNode.hpp index c34519f15..6261a1f27 100644 --- a/SampleDownloader/FileNode.hpp +++ b/SampleDownloader/FileNode.hpp @@ -34,7 +34,7 @@ public: bool sync (bool local); void abort (); - static int const Type {UserType + 1}; + static int constexpr Type {UserType + 1}; // // Clients may use this RAII class to block nested calls to sync diff --git a/WSPRBandHopping.cpp b/WSPRBandHopping.cpp index 1638f5368..0ea3d7632 100644 --- a/WSPRBandHopping.cpp +++ b/WSPRBandHopping.cpp @@ -64,7 +64,7 @@ private: QPointer bands_table_; QBrush coord_background_brush_; QPointer gray_line_width_spin_box_; - static int const band_index_role {Qt::UserRole}; + static int constexpr band_index_role {Qt::UserRole}; }; Dialog::Dialog (QSettings * settings, Configuration const * configuration, BandList const * WSPR_bands diff --git a/mainwindow.cpp b/mainwindow.cpp index 01d91e68f..b136cf298 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -173,6 +173,15 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple, m_uploading {false}, m_tuneup {false}, m_bSimplex {false}, + m_ihsym {0}, + m_nzap {0}, + m_px {0.0}, + m_decodeEarly {false}, + m_iptt0 {0}, + m_btxok0 {false}, + m_nsendingsh {0}, + m_onAirFreq0 {0.0}, + m_first_error {true}, m_appDir {QApplication::applicationDirPath ()}, mem_jt9 {shdmem}, m_msAudioOutputBuffered (0u), @@ -875,12 +884,6 @@ void MainWindow::setDecodedTextFont (QFont const& font) void MainWindow::dataSink(qint64 frames) { static float s[NSMAX]; - static int ihsym=0; - static int nzap=0; - static int trmin; - static int npts8; - static float px=0.0; - static float df3; int k (frames); QString fname {QDir::toNativeSeparators(m_dataDir.absoluteFilePath ("refspec.dat"))}; @@ -902,22 +905,22 @@ void MainWindow::dataSink(qint64 frames) } // Get power, spectrum, and ihsym - trmin=m_TRperiod/60; + int trmin=m_TRperiod/60; // int k (frames - 1); dec_data.params.nfa=m_wideGraph->nStartFreq(); dec_data.params.nfb=m_wideGraph->Fmax(); int nsps=m_nsps; if(m_bFastMode) nsps=6912; int nsmo=m_wideGraph->smoothYellow()-1; - symspec_(&dec_data,&k,&trmin,&nsps,&m_inGain,&nsmo,&px,s,&df3,&ihsym,&npts8); + symspec_(&dec_data,&k,&trmin,&nsps,&m_inGain,&nsmo,&m_px,s,&m_df3,&m_ihsym,&m_npts8); if(m_mode=="WSPR-2") wspr_downsample_(dec_data.d2,&k); - if(ihsym <=0) return; + if(m_ihsym <=0) return; QString t; - m_pctZap=nzap*100.0/m_nsps; - t.sprintf(" Rx noise: %5.1f ",px); - ui->signal_meter_widget->setValue(px); // Update thermometer + m_pctZap=m_nzap*100.0/m_nsps; // TODO: this is currently redundant + t.sprintf(" Rx noise: %5.1f ",m_px); + ui->signal_meter_widget->setValue(m_px); // Update thermometer if(m_monitoring || m_diskData) { - m_wideGraph->dataSink2(s,df3,ihsym,m_diskData); + m_wideGraph->dataSink2(s,m_df3,m_ihsym,m_diskData); } if(m_mode=="WSPR-2") { @@ -931,11 +934,11 @@ void MainWindow::dataSink(qint64 frames) if(m_config.decode_at_52s()) m_hsymStop=179; } - if(ihsym==3*m_hsymStop/4) { + if(m_ihsym==3*m_hsymStop/4) { m_dialFreqRxWSPR=m_freqNominal; } - if(ihsym == m_hsymStop) { + if(m_ihsym == m_hsymStop) { if(m_mode=="Echo") { float snr=0; int nfrit=0; @@ -965,7 +968,7 @@ void MainWindow::dataSink(qint64 frames) } if( m_dialFreqRxWSPR==0) m_dialFreqRxWSPR=m_freqNominal; m_dataAvailable=true; - dec_data.params.npts8=(ihsym*m_nsps)/16; + dec_data.params.npts8=(m_ihsym*m_nsps)/16; dec_data.params.newdat=1; dec_data.params.nagain=0; dec_data.params.nzhsym=m_hsymStop; @@ -1060,8 +1063,6 @@ void MainWindow::save_wave_file (QString const& name, short const * data, int se //-------------------------------------------------------------- fastSink() void MainWindow::fastSink(qint64 frames) { - static float px; - static bool decodeEarly; int k (frames); bool decodeNow=false; @@ -1075,7 +1076,7 @@ void MainWindow::fastSink(qint64 frames) memcpy(fast_s2,fast_s,4*703*64); //Copy fast_s[] into fast_s2[] fast_jh2=fast_jh; if(!m_diskData) memset(dec_data.d2,0,2*30*12000); //Zero the d2[] array - decodeEarly=false; + m_decodeEarly=false; m_bFastDecodeCalled=false; QDateTime t=QDateTime::currentDateTimeUtc(); //.addSecs(2-m_TRperiod); int ihr=t.toString("hh").toInt(); @@ -1090,7 +1091,7 @@ void MainWindow::fastSink(qint64 frames) } hspec_(dec_data.d2, &k, &m_inGain, fast_green, fast_s, &fast_jh); - px=fast_green[fast_jh] - 5.0; + float px = fast_green[fast_jh] - 5.0; QString t; t.sprintf(" Rx noise: %5.1f ",px); ui->signal_meter_widget->setValue(px); // Update thermometer @@ -1112,14 +1113,14 @@ void MainWindow::fastSink(qint64 frames) decode(); } if(!m_diskData and (m_saveAll or m_saveDecoded) and m_fname != "" and - !decodeEarly) { + !m_decodeEarly) { // the following is potential a threading hazard - not a good // idea to pass pointer to be processed in another thread QtConcurrent::run (this, &MainWindow::save_wave_file, m_fname, &dec_data.d2[0], m_TRperiod); m_fileToKill=m_fname; killFileTimer->start (3*1000*m_TRperiod/4); //Kill 3/4 period from now } - decodeEarly=false; + m_decodeEarly=false; } } @@ -2228,12 +2229,8 @@ void MainWindow::decodeBusy(bool b) //decodeBusy() //------------------------------------------------------------- //guiUpdate() void MainWindow::guiUpdate() { - static int iptt0=0; - static bool btxok0=false; static char message[29]; static char msgsent[29]; - static int nsendingsh=0; - static double onAirFreq0=0.0; double txDuration; QString rt; @@ -2310,8 +2307,8 @@ void MainWindow::guiUpdate() m_bTxTime=false; // if (m_tune) stop_tuning (); if (m_auto) auto_tx_mode (false); - if(onAirFreq!=onAirFreq0) { - onAirFreq0=onAirFreq; + if(onAirFreq!=m_onAirFreq0) { + m_onAirFreq0=onAirFreq; QString t="Please choose another Tx frequency.\n"; t+="WSJT-X will not knowingly transmit another\n"; t+="mode in the WSPR sub-band on 30 m."; @@ -2363,7 +2360,7 @@ void MainWindow::guiUpdate() } // Calculate Tx tones when needed - if((g_iptt==1 && iptt0==0) || m_restart) { + if((g_iptt==1 && m_iptt0==0) || m_restart) { //---------------------------------------------------------------------- QByteArray ba; @@ -2525,7 +2522,7 @@ void MainWindow::guiUpdate() } } - if (g_iptt == 1 && iptt0 == 0) + if (g_iptt == 1 && m_iptt0 == 0) { QString t=QString::fromLatin1(msgsent); if(t==m_msgSent0) { @@ -2562,7 +2559,7 @@ void MainWindow::guiUpdate() m_transmitting, m_decoderBusy); } - if(!m_btxok && btxok0 && g_iptt==1) stopTx(); + if(!m_btxok && m_btxok0 && g_iptt==1) stopTx(); if(m_startAnother) { m_startAnother=false; @@ -2592,11 +2589,11 @@ void MainWindow::guiUpdate() if(m_transmitting) { char s[37]; sprintf(s,"Tx: %s",msgsent); - nsendingsh=0; - if(s[4]==64) nsendingsh=1; - if(nsendingsh==1 or m_currentMessageType==7) { + m_nsendingsh=0; + if(s[4]==64) m_nsendingsh=1; + if(m_nsendingsh==1 or m_currentMessageType==7) { tx_status_label->setStyleSheet("QLabel{background-color: #66ffff}"); - } else if(nsendingsh==-1 or m_currentMessageType==6) { + } else if(m_nsendingsh==-1 or m_currentMessageType==6) { tx_status_label->setStyleSheet("QLabel{background-color: #ffccff}"); } else { tx_status_label->setStyleSheet("QLabel{background-color: #ffff33}"); @@ -2630,8 +2627,8 @@ void MainWindow::guiUpdate() m_sec0=nsec; displayDialFrequency (); } - iptt0=g_iptt; - btxok0=m_btxok; + m_iptt0=g_iptt; + m_btxok0=m_btxok; } //End of GUIupdate @@ -4443,12 +4440,11 @@ void MainWindow::handle_transceiver_failure (QString const& reason) void MainWindow::rigFailure (QString const& reason, QString const& detail) { - static bool first_error {true}; - if (first_error) + if (m_first_error) { // one automatic retry QTimer::singleShot (0, this, SLOT (rigOpen ())); - first_error = false; + m_first_error = false; } else { @@ -4470,7 +4466,7 @@ void MainWindow::rigFailure (QString const& reason, QString const& detail) QTimer::singleShot (0, this, SLOT (close ())); break; } - first_error = true; // reset + m_first_error = true; // reset } } diff --git a/mainwindow.h b/mainwindow.h index ffb425fc7..f1907604e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -429,6 +429,17 @@ private: bool m_bRefSpec; bool m_bUseRef; float m_pctZap; + int m_ihsym; + int m_nzap; + int m_npts8; + float m_px; + float m_df3; + bool m_decodeEarly; + int m_iptt0; + bool m_btxok0; + int m_nsendingsh; + double m_onAirFreq0; + bool m_first_error; char m_msg[100][80]; diff --git a/signalmeter.cpp b/signalmeter.cpp index 74025387c..a24d6f605 100644 --- a/signalmeter.cpp +++ b/signalmeter.cpp @@ -59,11 +59,11 @@ protected: } private: - static int const tick_length {4}; - static int const text_indent {2}; - static int const line_spacing {0}; - static int const range {6}; - static int const scale {10}; + static int constexpr tick_length {4}; + static int constexpr text_indent {2}; + static int constexpr line_spacing {0}; + static int constexpr range {6}; + static int constexpr scale {10}; }; SignalMeter::SignalMeter (QWidget * parent) diff --git a/widegraph.cpp b/widegraph.cpp index 3cc7a741b..9c15412bb 100644 --- a/widegraph.cpp +++ b/widegraph.cpp @@ -17,7 +17,8 @@ WideGraph::WideGraph(QSettings * settings, QWidget *parent) : QDialog(parent), ui(new Ui::WideGraph), m_settings (settings), - m_palettes_path {":/Palettes"} + m_palettes_path {":/Palettes"}, + m_n {0} { ui->setupUi(this); @@ -140,22 +141,21 @@ void WideGraph::dataSink2(float s[], float df3, int ihsym, int ndiskdata) //dat { static float splot[NSMAX]; int nbpp = ui->widePlot->binsPerPixel(); - static int n=0; //Average spectra over specified number, m_waterfallAvg - if (n==0) { + if (m_n==0) { for (int i=0; i=m_waterfallAvg) { + if (m_n>=m_waterfallAvg) { for (int i=0; iwidePlot->startFreq()/df3 + 0.5); int jz=5000.0/(nbpp*df3); if(jz>MAX_SCREENSIZE) jz=MAX_SCREENSIZE; diff --git a/widegraph.h b/widegraph.h index 4fdce40ed..1bfaacebf 100644 --- a/widegraph.h +++ b/widegraph.h @@ -107,6 +107,7 @@ private: QString m_mode; QString m_modeTx; QString m_waterfallPalette; + int m_n; }; #endif // WIDEGRAPH_H