Skip to content

Commit

Permalink
File source plugin: added seek bar to move the current pointer in the…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
f4exb committed Feb 25, 2016
1 parent a8fc503 commit 5ecf7ea
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 31 deletions.
30 changes: 26 additions & 4 deletions plugins/samplesource/filesource/filesourcegui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions plugins/samplesource/filesource/filesourcegui.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class FileSourceGui : public QWidget, public PluginGUI {
std::time_t m_startingTimeStamp;
int m_samplesCount;
std::size_t m_tickCount;
bool m_enableNavTime;

void displaySettings();
void displayTime();
Expand All @@ -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();
};
Expand Down
26 changes: 25 additions & 1 deletion plugins/samplesource/filesource/filesourceinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions plugins/samplesource/filesource/filesourceinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,26 @@ class FileSourceInput : public SampleSource {
{ }
};

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

Expand Down Expand Up @@ -217,6 +237,7 @@ class FileSourceInput : public SampleSource {
const QTimer& m_masterTimer;

void openFileStream();
void seekFileStream(int seekPercentage);
};

#endif // INCLUDE_FILESOURCEINPUT_H
28 changes: 2 additions & 26 deletions plugins/samplesource/filesource/filesourcethread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -64,7 +64,7 @@ void FileSourceThread::startWork()
}
else
{
qDebug() << " - file stream closed, not starting.";
qDebug() << "FileSourceThread::startWork: file stream closed, not starting.";
}
}

Expand Down Expand Up @@ -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);
}
*/
1 change: 1 addition & 0 deletions plugins/samplesource/filesource/filesourcethread.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FileSourceThread : public QThread {
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);

Expand Down

0 comments on commit 5ecf7ea

Please sign in to comment.