Make mutable static variables instance variables where necessary

Static storage variables that should  have been class members are made
so. This  ensures that  if they  are used  as initialization  one time
switches   then  they   will  operate   correctly  when   their  class
instantiated more than once. This now happoens for most classes due to
the configurations  switching facility which destroys  all windows and
re-instantiates them.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6661 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville 2016-05-01 00:40:51 +00:00
parent d8350bd35e
commit 080f7ef1a2
14 changed files with 87 additions and 80 deletions

View File

@ -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<TransceiverBase> wrapped
, QString const& server
, bool use_for_ptt

View File

@ -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)

View File

@ -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 ()
{

View File

@ -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;

View File

@ -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

View File

@ -39,7 +39,7 @@ public:
return name == text (0);
}
static int const Type {UserType};
static int constexpr Type {UserType};
};
inline

View File

@ -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

View File

@ -64,7 +64,7 @@ private:
QPointer<QTableWidget> bands_table_;
QBrush coord_background_brush_;
QPointer<QSpinBox> 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

View File

@ -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
}
}

View File

@ -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];

View File

@ -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)

View File

@ -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<NSMAX; i++)
splot[i]=s[i];
} else {
for (int i=0; i<NSMAX; i++)
splot[i] += s[i];
}
n++;
m_n++;
if (n>=m_waterfallAvg) {
if (m_n>=m_waterfallAvg) {
for (int i=0; i<NSMAX; i++)
splot[i] /= n; //Normalize the average
n=0;
splot[i] /= m_n; //Normalize the average
m_n=0;
int i=int(ui->widePlot->startFreq()/df3 + 0.5);
int jz=5000.0/(nbpp*df3);
if(jz>MAX_SCREENSIZE) jz=MAX_SCREENSIZE;

View File

@ -107,6 +107,7 @@ private:
QString m_mode;
QString m_modeTx;
QString m_waterfallPalette;
int m_n;
};
#endif // WIDEGRAPH_H