diff --git a/plugins/samplesource/filesource/filesourcegui.cpp b/plugins/samplesource/filesource/filesourcegui.cpp index 5554a44cf..688856ae5 100644 --- a/plugins/samplesource/filesource/filesourcegui.cpp +++ b/plugins/samplesource/filesource/filesourcegui.cpp @@ -41,7 +41,8 @@ FileSourceGui::FileSourceGui(PluginAPI* pluginAPI, QWidget* parent) : m_recordLength(0), m_startingTimeStamp(0), m_samplesCount(0), - m_tickCount(0) + m_tickCount(0), + m_enableNavTime(false) { ui->setupUi(this); ui->centerFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); @@ -180,6 +181,23 @@ void FileSourceGui::on_play_toggled(bool checked) { FileSourceInput::MsgConfigureFileSourceWork* message = FileSourceInput::MsgConfigureFileSourceWork::create(checked); m_sampleSource->getInputMessageQueue()->push(message); + ui->navTimeSlider->setEnabled(!checked); + m_enableNavTime = !checked; +} + +void FileSourceGui::on_navTimeSlider_valueChanged(int value) +{ + if (m_enableNavTime && ((value >= 0) && (value <= 100))) + { + int t_sec = (m_recordLength * value) / 100; + QTime t(0, 0, 0, 0); + t = t.addSecs(t_sec); + QString s_time = t.toString("hh:mm:ss"); + ui->navTimeText->setText(s_time); + + FileSourceInput::MsgConfigureFileSourceSeek* message = FileSourceInput::MsgConfigureFileSourceSeek::create(value); + m_sampleSource->getInputMessageQueue()->push(message); + } } void FileSourceGui::on_showFileDialog_clicked(bool checked) @@ -245,9 +263,13 @@ void FileSourceGui::updateWithStreamTime() dt = dt.addMSecs(t_msec); QString s_date = dt.toString("yyyy-MM-dd hh:mm:ss.zzz"); ui->absTimeText->setText(s_date); - float posRatio = (float) t_sec / (float) m_recordLength; - ui->navTimeSlider->setValue((int) (posRatio * 100.0)); - ui->navTimeText->setText(s_time); + + if (!m_enableNavTime) + { + float posRatio = (float) t_sec / (float) m_recordLength; + ui->navTimeSlider->setValue((int) (posRatio * 100.0)); + ui->navTimeText->setText(s_time); + } } void FileSourceGui::tick() diff --git a/plugins/samplesource/filesource/filesourcegui.h b/plugins/samplesource/filesource/filesourcegui.h index d481dc1d4..920c8b090 100644 --- a/plugins/samplesource/filesource/filesourcegui.h +++ b/plugins/samplesource/filesource/filesourcegui.h @@ -62,6 +62,7 @@ private: std::time_t m_startingTimeStamp; int m_samplesCount; std::size_t m_tickCount; + bool m_enableNavTime; void displaySettings(); void displayTime(); @@ -76,6 +77,7 @@ private slots: void handleSourceMessages(); void on_playLoop_toggled(bool checked); void on_play_toggled(bool checked); + void on_navTimeSlider_valueChanged(int value); void on_showFileDialog_clicked(bool checked); void tick(); }; diff --git a/plugins/samplesource/filesource/filesourceinput.cpp b/plugins/samplesource/filesource/filesourceinput.cpp index 4f5de24a0..52ded1400 100644 --- a/plugins/samplesource/filesource/filesourceinput.cpp +++ b/plugins/samplesource/filesource/filesourceinput.cpp @@ -30,6 +30,7 @@ MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSource, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceName, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceWork, Message) +MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceSeek, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgConfigureFileSourceStreamTiming, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceAcquisition, Message) MESSAGE_CLASS_DEFINITION(FileSourceInput::MsgReportFileSourceStreamData, Message) @@ -124,6 +125,20 @@ void FileSourceInput::openFileStream() getOutputMessageQueueToGUI()->push(report); } +void FileSourceInput::seekFileStream(int seekPercentage) +{ + QMutexLocker mutexLocker(&m_mutex); + + if ((m_ifstream.is_open()) && !m_fileSourceThread->isRunning()) + { + int seekPoint = ((m_recordLength * seekPercentage) / 100) * m_sampleRate; + m_fileSourceThread->setSamplesCount(seekPoint); + seekPoint *= 4; // + sizeof(FileSink::Header) + m_ifstream.clear(); + m_ifstream.seekg(seekPoint, std::ios::beg); + } +} + bool FileSourceInput::init(const Message& message) { return false; @@ -224,9 +239,10 @@ bool FileSourceInput::handleMessage(const Message& message) if (working) { m_fileSourceThread->startWork(); + /* MsgReportFileSourceStreamTiming *report = MsgReportFileSourceStreamTiming::create(m_fileSourceThread->getSamplesCount()); - getOutputMessageQueueToGUI()->push(report); + getOutputMessageQueueToGUI()->push(report);*/ } else { @@ -236,6 +252,14 @@ bool FileSourceInput::handleMessage(const Message& message) return true; } + else if (MsgConfigureFileSourceSeek::match(message)) + { + MsgConfigureFileSourceSeek& conf = (MsgConfigureFileSourceSeek&) message; + int seekPercentage = conf.getPercentage(); + seekFileStream(seekPercentage); + + return true; + } else if (MsgConfigureFileSourceStreamTiming::match(message)) { MsgReportFileSourceStreamTiming *report; diff --git a/plugins/samplesource/filesource/filesourceinput.h b/plugins/samplesource/filesource/filesourceinput.h index 5360b2644..eb624f936 100644 --- a/plugins/samplesource/filesource/filesourceinput.h +++ b/plugins/samplesource/filesource/filesourceinput.h @@ -114,6 +114,26 @@ public: { } }; + class MsgConfigureFileSourceSeek : public Message { + MESSAGE_CLASS_DECLARATION + + public: + int getPercentage() const { return m_seekPercentage; } + + static MsgConfigureFileSourceSeek* create(int seekPercentage) + { + return new MsgConfigureFileSourceSeek(seekPercentage); + } + + protected: + int m_seekPercentage; //!< percentage of seek position from the beginning 0..100 + + MsgConfigureFileSourceSeek(int seekPercentage) : + Message(), + m_seekPercentage(seekPercentage) + { } + }; + class MsgReportFileSourceAcquisition : public Message { MESSAGE_CLASS_DECLARATION @@ -217,6 +237,7 @@ private: const QTimer& m_masterTimer; void openFileStream(); + void seekFileStream(int seekPercentage); }; #endif // INCLUDE_FILESOURCEINPUT_H diff --git a/plugins/samplesource/filesource/filesourcethread.cpp b/plugins/samplesource/filesource/filesourcethread.cpp index ee7901fe2..18c82e749 100644 --- a/plugins/samplesource/filesource/filesourcethread.cpp +++ b/plugins/samplesource/filesource/filesourcethread.cpp @@ -55,7 +55,7 @@ void FileSourceThread::startWork() if (m_ifstream->is_open()) { - qDebug() << " - file stream open, starting..."; + qDebug() << "FileSourceThread::startWork: file stream open, starting..."; m_startWaitMutex.lock(); start(); while(!m_running) @@ -64,7 +64,7 @@ void FileSourceThread::startWork() } else { - qDebug() << " - file stream closed, not starting."; + qDebug() << "FileSourceThread::startWork: file stream closed, not starting."; } } @@ -151,27 +151,3 @@ void FileSourceThread::tick() } } } - - -/* -void FileSourceThread::decimate1(SampleVector::iterator* it, const qint16* buf, qint32 len) -{ - qint16 xreal, yimag; - - for (int pos = 0; pos < len; pos += 2) { - xreal = buf[pos+0]; - yimag = buf[pos+1]; - Sample s( xreal * 16, yimag * 16 ); // shift by 4 bit positions (signed) - **it = s; - (*it)++; - } -} - -// Decimate according to specified log2 (ex: log2=4 => decim=16) -void FileSourceThread::callback(const qint16* buf, qint32 len) -{ - SampleVector::iterator it = m_convertBuffer.begin(); - decimate1(&it, buf, len); - m_sampleFifo->write(m_convertBuffer.begin(), it); -} -*/ diff --git a/plugins/samplesource/filesource/filesourcethread.h b/plugins/samplesource/filesource/filesourcethread.h index d4dc92298..522f04c21 100644 --- a/plugins/samplesource/filesource/filesourcethread.h +++ b/plugins/samplesource/filesource/filesourcethread.h @@ -41,6 +41,7 @@ public: void setSamplerate(int samplerate); bool isRunning() const { return m_running; } std::size_t getSamplesCount() const { return m_samplesCount; } + void setSamplesCount(int samplesCount) { m_samplesCount = samplesCount; } void connectTimer(const QTimer& timer);