kwave  18.07.70
Kwave::NewSignalDialog Class Reference

#include <NewSignalDialog.h>

Inheritance diagram for Kwave::NewSignalDialog:
Inheritance graph
Collaboration diagram for Kwave::NewSignalDialog:
Collaboration graph

Public Member Functions

 NewSignalDialog (QWidget *parent, sample_index_t samples, unsigned int rate, unsigned int bits, unsigned int tracks, bool by_time)
 
virtual ~NewSignalDialog ()
 
sample_index_t samples ()
 
double rate ()
 
unsigned int bitsPerSample ()
 
unsigned int tracks ()
 
bool byTime ()
 

Private Slots

void checkNewSampleEdit ()
 
void checkTimeAndLengthInfo (int)
 
void rbTimeToggled (bool)
 
void timeChanged (int)
 
void sampleRateChanged (const QString &)
 
void tracksChanged (int)
 
void samplesChanged (int)
 
void updateFileSize ()
 
void setLengthPercentage (int percent)
 
void invokeHelp ()
 

Private Member Functions

sample_index_t maxSamples ()
 
void setHMS (sample_index_t &samples)
 

Private Attributes

QTimer m_timer
 
bool m_recursive
 

Detailed Description

Definition at line 35 of file NewSignalDialog.h.

Constructor & Destructor Documentation

◆ NewSignalDialog()

Kwave::NewSignalDialog::NewSignalDialog ( QWidget *  parent,
sample_index_t  samples,
unsigned int  rate,
unsigned int  bits,
unsigned int  tracks,
bool  by_time 
)

Constructor.

Parameters
parentthe parent widget the dialog belongs to
samplesdefault resolution in bits per sample
ratedefault sample rate
bitsdefault resolution
tracksdefault tracks
by_timeif true: select by time, if false: select by samples

Definition at line 43 of file NewSignalDialog.cpp.

References checkNewSampleEdit(), checkTimeAndLengthInfo(), Kwave::connect(), invokeHelp(), m_timer, rbTimeToggled(), sampleRateChanged(), samplesChanged(), setHMS(), setLengthPercentage(), timeChanged(), Kwave::toInt(), and tracksChanged().

46  :QDialog(parent), Ui::NewSigDlg(), m_timer(this), m_recursive(false)
47 {
48 
49  setupUi(this);
50  setModal(true);
51 
52  edSamples->setRange(0, INT_MAX);
53  edSamples->setSingleStep(1);
54 
55  // connect the timer for the sample edit
56  connect(&m_timer, SIGNAL(timeout()), this, SLOT(checkNewSampleEdit()));
57  connect(rbTime, SIGNAL(toggled(bool)),
58  this, SLOT(rbTimeToggled(bool)));
59 
60  // connect the file format controls
61  connect(cbSampleRate, SIGNAL(editTextChanged(QString)),
62  this, SLOT(sampleRateChanged(QString)));
63  connect(sbChannels, SIGNAL(valueChanged(int)),
64  this, SLOT(tracksChanged(int)));
65  connect(sbResolution, SIGNAL(valueChanged(int)),
66  this, SLOT(checkTimeAndLengthInfo(int)));
67 
68  // connect the time controls
69  connect(sbSeconds, SIGNAL(valueChanged(int)),
70  this, SLOT(timeChanged(int)));
71  connect(sbMinutes, SIGNAL(valueChanged(int)),
72  this, SLOT(timeChanged(int)));
73  connect(sbHours, SIGNAL(valueChanged(int)),
74  this, SLOT(timeChanged(int)));
75 
76  // selection by number of samples
77  connect(slideLength,SIGNAL(valueChanged(int)),
78  this, SLOT(setLengthPercentage(int)));
79 
80  // selection by percentage of maximum possible length
81  connect(edSamples, SIGNAL(valueChanged(int)),
82  this, SLOT(samplesChanged(int)));
83 
84  // help button
85  connect(buttonBox->button(QDialogButtonBox::Help), SIGNAL(clicked()),
86  this, SLOT(invokeHelp()));
87 
88  // pre-initialize the size
89  setMaximumHeight(sizeHint().height());
90  setMaximumWidth(sizeHint().width());
91 
92  // initialize the controls
93  cbSampleRate->setEditText(QString::number(rate));
94  sbResolution->setValue(bits);
95  sbChannels->setValue(tracks);
96  if (by_time) {
97  rbSamples->setChecked(false);
98  rbTime->setChecked(true);
99  setHMS(samples);
100  edSamples->setEnabled(false);
101  sbHours->setEnabled(true);
102  sbMinutes->setEnabled(true);
103  sbSeconds->setEnabled(true);
104  } else {
105  // by samples
106  rbTime->setChecked(false);
107  rbSamples->setChecked(true);
108  edSamples->setValue(Kwave::toInt(samples));
109  edSamples->setEnabled(true);
110  sbHours->setEnabled(false);
111  sbMinutes->setEnabled(false);
112  sbSeconds->setEnabled(false);
113  }
114 
115  tracksChanged(0);
117 
118  // that dialog is big enough, limit it to it's optimal size
119  setFixedHeight(sizeHint().height());
120  setFixedWidth(sizeHint().width());
121 
122  // set the focus onto the "OK" button
123  buttonBox->button(QDialogButtonBox::Ok)->setFocus();
124 }
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
void setHMS(sample_index_t &samples)
void setLengthPercentage(int percent)
int toInt(T x)
Definition: Utils.h:127
void sampleRateChanged(const QString &)
sample_index_t samples()
Here is the call graph for this function:

◆ ~NewSignalDialog()

virtual Kwave::NewSignalDialog::~NewSignalDialog ( )
inlinevirtual

Member Function Documentation

◆ bitsPerSample()

unsigned int Kwave::NewSignalDialog::bitsPerSample ( )

Returns the selected resolution [bits per sample]

Definition at line 158 of file NewSignalDialog.cpp.

Referenced by maxSamples(), Kwave::NewSignalPlugin::setup(), timeChanged(), updateFileSize(), and ~NewSignalDialog().

159 {
160  int res = sbResolution->value();
161  if (res < 8) res = 8;
162  return res;
163 }
Here is the caller graph for this function:

◆ byTime()

bool Kwave::NewSignalDialog::byTime ( )

Returns true if the selection was made by time

Definition at line 166 of file NewSignalDialog.cpp.

Referenced by Kwave::NewSignalPlugin::setup(), and ~NewSignalDialog().

167 {
168  return rbTime->isChecked();
169 }
Here is the caller graph for this function:

◆ checkNewSampleEdit

void Kwave::NewSignalDialog::checkNewSampleEdit ( )
privateslot

Checks for modifications of the sample number edit. That stupid QSpinBox doesn't notify us about changes :-[

Definition at line 142 of file NewSignalDialog.cpp.

References samplesChanged().

Referenced by NewSignalDialog(), and ~NewSignalDialog().

143 {
144  static int last_samples = -1;
145  if (edSamples->value() != last_samples) {
146  last_samples = edSamples->value();
147  samplesChanged(last_samples);
148  }
149 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkTimeAndLengthInfo

void Kwave::NewSignalDialog::checkTimeAndLengthInfo ( int  )
privateslot

Checks for changes in the samples or time info

Definition at line 199 of file NewSignalDialog.cpp.

References samplesChanged(), and timeChanged().

Referenced by NewSignalDialog(), sampleRateChanged(), tracksChanged(), and ~NewSignalDialog().

200 {
201  (rbTime->isChecked()) ? timeChanged(0) : samplesChanged(0);
202 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ invokeHelp

void Kwave::NewSignalDialog::invokeHelp ( )
privateslot

invoke the online help

Definition at line 373 of file NewSignalDialog.cpp.

References _.

Referenced by NewSignalDialog(), and ~NewSignalDialog().

374 {
375  KHelpClient::invokeHelp(_("newsignal"));
376 }
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ maxSamples()

sample_index_t Kwave::NewSignalDialog::maxSamples ( )
private

Returns the maximum number of samples per track that can be created with the current settings, based on the maximum file size of a .wav file and the header sizes.

Definition at line 172 of file NewSignalDialog.cpp.

References bitsPerSample(), and tracks().

Referenced by samplesChanged(), setHMS(), setLengthPercentage(), timeChanged(), and ~NewSignalDialog().

173 {
174  unsigned int bytes_per_sample = bitsPerSample() >> 3;
175 
176  /*
177  * NOTE: this limitation to INT_MAX instead of UINT_MAX is
178  * only needed because some gui elements like
179  * QSpinBox cannot handle more :-(
180  */
181  const sample_index_t max_file_size = INT_MAX;
182 
183  return (max_file_size / tracks() / bytes_per_sample);
184 }
unsigned int bitsPerSample()
quint64 sample_index_t
Definition: Sample.h:28
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rate()

double Kwave::NewSignalDialog::rate ( )

Returns the selected sample rate [samples/second]

Definition at line 133 of file NewSignalDialog.cpp.

Referenced by setHMS(), setLengthPercentage(), Kwave::NewSignalPlugin::setup(), timeChanged(), and ~NewSignalDialog().

134 {
135  bool ok;
136  double r = cbSampleRate->currentText().toDouble(&ok);
137  if (!ok) r = 0;
138  return r;
139 }
Here is the caller graph for this function:

◆ rbTimeToggled

void Kwave::NewSignalDialog::rbTimeToggled ( bool  )
privateslot

starts/stops the sample edit's timer if rbTime has been toggled

Definition at line 187 of file NewSignalDialog.cpp.

References m_timer.

Referenced by NewSignalDialog(), and ~NewSignalDialog().

188 {
189  if (rbTime->isChecked()) {
190  m_timer.stop();
191  } else {
192  // activate the sample edit timer
193  m_timer.setSingleShot(false);
194  m_timer.start(100);
195  }
196 }
Here is the caller graph for this function:

◆ sampleRateChanged

void Kwave::NewSignalDialog::sampleRateChanged ( const QString &  )
privateslot

called when the sample rate has been edited or changed

Definition at line 290 of file NewSignalDialog.cpp.

References checkTimeAndLengthInfo().

Referenced by NewSignalDialog(), and ~NewSignalDialog().

291 {
293 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ samples()

sample_index_t Kwave::NewSignalDialog::samples ( )

Returns the number of samples

Definition at line 127 of file NewSignalDialog.cpp.

Referenced by samplesChanged(), setLengthPercentage(), Kwave::NewSignalPlugin::setup(), timeChanged(), updateFileSize(), and ~NewSignalDialog().

128 {
129  return static_cast<sample_index_t>(edSamples->value());
130 }
quint64 sample_index_t
Definition: Sample.h:28
Here is the caller graph for this function:

◆ samplesChanged

void Kwave::NewSignalDialog::samplesChanged ( int  )
privateslot

number of samples changed

Definition at line 266 of file NewSignalDialog.cpp.

References m_recursive, maxSamples(), samples(), setHMS(), Kwave::toInt(), and updateFileSize().

Referenced by checkNewSampleEdit(), checkTimeAndLengthInfo(), NewSignalDialog(), and ~NewSignalDialog().

267 {
268  if (m_recursive) return; // don't do recursive processing
269  if (!rbSamples->isChecked()) return;
270  m_recursive = true;
271 
272  sample_index_t samples = edSamples->value();
273  sample_index_t max_samples = maxSamples();
274 
275  if (samples > max_samples) {
276  samples = max_samples;
277  edSamples->setValue(Kwave::toInt(samples));
278  }
279 
280  // update the other controls
281  setHMS(samples);
282  slideLength->setValue(Kwave::toInt(100.0 * samples / max_samples));
283  updateFileSize();
284  buttonBox->button(QDialogButtonBox::Ok)->setEnabled(samples > 0.0);
285 
286  m_recursive = false;
287 }
sample_index_t maxSamples()
quint64 sample_index_t
Definition: Sample.h:28
void setHMS(sample_index_t &samples)
int toInt(T x)
Definition: Utils.h:127
sample_index_t samples()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setHMS()

void Kwave::NewSignalDialog::setHMS ( sample_index_t samples)
private

Sets hours, minutes and seconds according to a given number of samples.

Definition at line 354 of file NewSignalDialog.cpp.

References maxSamples(), rate(), and Kwave::toInt().

Referenced by NewSignalDialog(), samplesChanged(), setLengthPercentage(), timeChanged(), and ~NewSignalDialog().

355 {
356  double rate = this->rate();
357  if (rate <= 0.0) return;
358 
359  // TODO: support for 64 bit
360  if (samples > maxSamples()) samples = maxSamples();
361 
362  int total_sec = Kwave::toInt(ceil(samples / rate));
363  int hours = total_sec / (60*60);
364  int minutes = (total_sec / 60) % 60;
365  int seconds = total_sec % 60;
366 
367  sbHours->setValue(hours);
368  sbMinutes->setValue(minutes);
369  sbSeconds->setValue(seconds);
370 }
sample_index_t maxSamples()
int toInt(T x)
Definition: Utils.h:127
sample_index_t samples()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLengthPercentage

void Kwave::NewSignalDialog::setLengthPercentage ( int  percent)
privateslot

called if the slider for the length has been moved

Definition at line 335 of file NewSignalDialog.cpp.

References m_recursive, maxSamples(), rate(), samples(), setHMS(), Kwave::toInt(), and updateFileSize().

Referenced by NewSignalDialog(), and ~NewSignalDialog().

336 {
337  if (m_recursive) return; // don't do recursive processing
338  if (rate() <= 0) return;
339  m_recursive = true;
340 
342  static_cast<double>(percent) / 100.0);
343 
344  // update the other controls
345  setHMS(samples);
346  edSamples->setValue(Kwave::toInt(samples));
347  updateFileSize();
348  buttonBox->button(QDialogButtonBox::Ok)->setEnabled(samples > 0);
349 
350  m_recursive = false;
351 }
sample_index_t maxSamples()
quint64 sample_index_t
Definition: Sample.h:28
void setHMS(sample_index_t &samples)
int toInt(T x)
Definition: Utils.h:127
sample_index_t samples()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeChanged

void Kwave::NewSignalDialog::timeChanged ( int  )
privateslot

updates the number of samples if the time changed

Definition at line 205 of file NewSignalDialog.cpp.

References bitsPerSample(), m_recursive, maxSamples(), rate(), samples(), setHMS(), Kwave::toInt(), tracks(), and updateFileSize().

Referenced by checkTimeAndLengthInfo(), NewSignalDialog(), and ~NewSignalDialog().

206 {
207  if (m_recursive) return; // don't do recursive processing
208  if (!rbTime->isChecked()) return;
209  if ((rate() <= 0) || !tracks() || (bitsPerSample() < 8)) return;
210  m_recursive = true;
211 
212  // get current time and correct wrap-overs
213  int seconds = sbSeconds->value();
214  int minutes = sbMinutes->value();
215  int hours = sbHours->value();
216  if ((seconds < 0) && ((minutes > 0) || (hours > 0)) ) {
217  sbSeconds->setValue(59);
218  sbMinutes->stepDown();
219  minutes--;
220  } else if (seconds < 0) {
221  sbSeconds->setValue(0);
222  } else if (seconds > 59) {
223  sbSeconds->setValue(0);
224  sbMinutes->stepUp();
225  minutes++;
226  }
227 
228  if ((minutes < 0) && (hours > 0)) {
229  sbMinutes->setValue(59);
230  sbHours->stepDown();
231  hours--;
232  } else if (minutes < 0) {
233  sbMinutes->setValue(0);
234  } else if (minutes > 59) {
235  sbMinutes->setValue(0);
236  sbHours->stepUp();
237  hours++;
238  }
239  seconds = sbSeconds->value();
240  minutes = sbMinutes->value();
241  hours = sbHours->value();
242  minutes += 60 * hours;
243  seconds += 60 * minutes;
244 
245  // limit the current number of samples
246  sample_index_t max_samples = maxSamples();
247  sample_index_t samples = static_cast<sample_index_t>(ceil(
248  static_cast<double>(seconds) * rate()));
249 
250  if (samples > max_samples) {
251  // wrap down to the maximum allowed number of samples
252  samples = max_samples;
253  setHMS(samples);
254  }
255 
256  // update the other controls
257  edSamples->setValue(Kwave::toInt(samples));
258  slideLength->setValue(Kwave::toInt(100.0 * samples / max_samples));
259  updateFileSize();
260  buttonBox->button(QDialogButtonBox::Ok)->setEnabled(samples > 0.0);
261 
262  m_recursive = false;
263 }
unsigned int bitsPerSample()
sample_index_t maxSamples()
quint64 sample_index_t
Definition: Sample.h:28
void setHMS(sample_index_t &samples)
int toInt(T x)
Definition: Utils.h:127
sample_index_t samples()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tracks()

unsigned int Kwave::NewSignalDialog::tracks ( )

Returns the selected number of tracks

Definition at line 152 of file NewSignalDialog.cpp.

Referenced by maxSamples(), Kwave::NewSignalPlugin::setup(), timeChanged(), tracksChanged(), updateFileSize(), and ~NewSignalDialog().

153 {
154  return sbChannels->value();
155 }
Here is the caller graph for this function:

◆ tracksChanged

void Kwave::NewSignalDialog::tracksChanged ( int  )
privateslot

called when the sample rate has been changed

Definition at line 296 of file NewSignalDialog.cpp.

References _, checkTimeAndLengthInfo(), and tracks().

Referenced by NewSignalDialog(), and ~NewSignalDialog().

297 {
298  switch (tracks()) {
299  case 1:
300  lblTracksVerbose->setText(i18n("(Mono)"));
301  break;
302  case 2:
303  lblTracksVerbose->setText(i18n("(Stereo)"));
304  break;
305  case 4:
306  lblTracksVerbose->setText(i18n("(Quadro)"));
307  break;
308  default:
309  lblTracksVerbose->setText(_(""));
310  break;
311  }
313 }
#define _(m)
Definition: memcpy.c:66
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateFileSize

void Kwave::NewSignalDialog::updateFileSize ( )
privateslot

updates the file size

Definition at line 316 of file NewSignalDialog.cpp.

References bitsPerSample(), samples(), and tracks().

Referenced by samplesChanged(), setLengthPercentage(), timeChanged(), and ~NewSignalDialog().

317 {
318  double samples = static_cast<double>(edSamples->value());
319  double mbytes = samples * static_cast<double>(tracks()) *
320  static_cast<double>(bitsPerSample() >> 3);
321  mbytes /= 1024.0; // to kilobytes
322  mbytes /= 1024.0; // to megabytes
323 
324  QString str_bytes;
325  if (mbytes >= 10.0) {
326  str_bytes.sprintf("%0.1f", mbytes);
327  } else {
328  str_bytes.sprintf("%0.3f", mbytes);
329  }
330 
331  lblFileSize->setText(i18n("(Resulting file size: %1 MB)", str_bytes));
332 }
unsigned int bitsPerSample()
sample_index_t samples()
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_recursive

bool Kwave::NewSignalDialog::m_recursive
private

flag to avoid recursion

Definition at line 127 of file NewSignalDialog.h.

Referenced by samplesChanged(), setLengthPercentage(), and timeChanged().

◆ m_timer

QTimer Kwave::NewSignalDialog::m_timer
private

Timer that checks for changes in the sample edit field

Definition at line 124 of file NewSignalDialog.h.

Referenced by NewSignalDialog(), and rbTimeToggled().


The documentation for this class was generated from the following files: