File source plugin: added seek bar to move the current pointer in the file

pull/6/head v1.1.2
f4exb 2016-02-25 14:07:39 +01:00
rodzic a8fc503366
commit 5ecf7ea00c
6 zmienionych plików z 77 dodań i 31 usunięć

Wyświetl plik

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

Wyświetl plik

@ -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();
};

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

@ -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);
}
*/

Wyświetl plik

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