You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
403 lines
13 KiB
403 lines
13 KiB
15 years ago
|
/***************************************************************************
|
||
|
recording-monitor.cpp - description
|
||
|
-------------------
|
||
|
begin : Mo Sep 1 2003
|
||
|
copyright : (C) 2003 by Martin Witte
|
||
|
email : witte@kawo1.rwth-aachen.de
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
|
#include "recording-monitor.h"
|
||
|
#include "recording-datamonitor.h"
|
||
|
#include "../../src/include/aboutwidget.h"
|
||
|
|
||
14 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqpushbutton.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqcheckbox.h>
|
||
15 years ago
|
#include <kcombobox.h>
|
||
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
12 years ago
|
#include <tdeaboutdata.h>
|
||
15 years ago
|
|
||
14 years ago
|
RecordingMonitor::RecordingMonitor(const TQString &name)
|
||
|
: TQWidget(NULL, name.ascii()),
|
||
15 years ago
|
WidgetPluginBase(name, i18n("Recording Monitor")),
|
||
|
m_recording(false),
|
||
14 years ago
|
m_defaultStreamDescription(TQString())
|
||
15 years ago
|
{
|
||
12 years ago
|
setCaption(i18n("TDERadio Recording Monitor"));
|
||
15 years ago
|
|
||
14 years ago
|
TQVBoxLayout *l = new TQVBoxLayout(this, 10, 4);
|
||
|
TQGridLayout *l0 = new TQGridLayout(l, 6, 2);
|
||
15 years ago
|
|
||
14 years ago
|
l0->addWidget( new TQLabel(i18n("SoundStream"), this), 0, 0);
|
||
15 years ago
|
l0->addWidget(m_comboSoundStreamSelector = new KComboBox( this), 0, 1);
|
||
13 years ago
|
l0->addWidget( new TQLabel(i18n("Status"), this), 1, 0);
|
||
13 years ago
|
l0->addWidget(m_labelStatus = new TQLabel(i18n("<undefined>"), this), 1, 1);
|
||
14 years ago
|
l0->addWidget( new TQLabel(i18n("Recording File"), this), 2, 0);
|
||
|
l0->addWidget(m_labelFileName = new TQLabel(i18n("<undefined>"), this), 2, 1);
|
||
|
l0->addWidget( new TQLabel(i18n("File Size"), this), 3, 0);
|
||
|
l0->addWidget(m_labelSize = new TQLabel(i18n("<undefined>"), this), 3, 1);
|
||
|
l0->addWidget( new TQLabel(i18n("Recording Time"), this), 4, 0);
|
||
|
l0->addWidget(m_labelTime = new TQLabel(i18n("<undefined>"), this), 4, 1);
|
||
|
l0->addWidget( new TQLabel(i18n("Sample Rate"), this), 5, 0);
|
||
|
l0->addWidget(m_labelRate = new TQLabel(i18n("<undefined>"), this), 5, 1);
|
||
|
|
||
|
TQPushButton *close = new TQPushButton(i18n("&Close"), this);
|
||
|
m_btnStartStop = new TQPushButton(i18n("&Record"), this);
|
||
|
TQObject::connect(close, TQT_SIGNAL(clicked()), this, TQT_SLOT(hide()));
|
||
|
TQObject::connect(m_btnStartStop, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotStartStopRecording()));
|
||
15 years ago
|
|
||
|
m_dataMonitor = new RecordingDataMonitor(this, NULL);
|
||
|
m_dataMonitor->setEnabled(false);
|
||
|
|
||
14 years ago
|
TQHBoxLayout *hl0 = new TQHBoxLayout(l);
|
||
15 years ago
|
hl0->addWidget(m_dataMonitor);
|
||
|
|
||
14 years ago
|
TQHBoxLayout *hl2 = new TQHBoxLayout(l);
|
||
|
hl2->addItem(new TQSpacerItem(10, 1));
|
||
15 years ago
|
hl2->addWidget(close);
|
||
|
hl2->addWidget(m_btnStartStop);
|
||
14 years ago
|
hl2->addItem(new TQSpacerItem(10, 1));
|
||
15 years ago
|
|
||
|
|
||
|
m_comboSoundStreamSelector->insertItem(i18n("nothing"));
|
||
14 years ago
|
TQObject::connect(m_comboSoundStreamSelector, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotStreamSelected(int)));
|
||
15 years ago
|
|
||
|
updateRecordingButton();
|
||
|
}
|
||
|
|
||
|
|
||
|
RecordingMonitor::~RecordingMonitor()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
// WidgetPluginBase
|
||
|
|
||
12 years ago
|
void RecordingMonitor::saveState (TDEConfig *config) const
|
||
15 years ago
|
{
|
||
14 years ago
|
config->setGroup(TQString("recordingmonitor-") + name());
|
||
15 years ago
|
|
||
|
WidgetPluginBase::saveState(config);
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
void RecordingMonitor::restoreState (TDEConfig *config)
|
||
15 years ago
|
{
|
||
14 years ago
|
config->setGroup(TQString("recordingmonitor-") + name());
|
||
15 years ago
|
|
||
|
WidgetPluginBase::restoreState(config, false);
|
||
|
}
|
||
|
|
||
|
|
||
|
bool RecordingMonitor::connectI(Interface *i)
|
||
|
{
|
||
|
bool a = ISoundStreamClient::connectI(i);
|
||
|
bool b = WidgetPluginBase::connectI(i);
|
||
|
return a || b;
|
||
|
}
|
||
|
|
||
|
bool RecordingMonitor::disconnectI(Interface *i)
|
||
|
{
|
||
|
bool a = ISoundStreamClient::disconnectI(i);
|
||
|
bool b = WidgetPluginBase::disconnectI(i);
|
||
|
if (a) {
|
||
|
m_comboSoundStreamSelector->clear();
|
||
|
m_SoundStreamID2idx.clear();
|
||
|
m_idx2SoundStreamID.clear();
|
||
|
m_comboSoundStreamSelector->insertItem(i18n("nothing"));
|
||
|
}
|
||
|
return a || b;
|
||
|
}
|
||
|
|
||
|
|
||
|
void RecordingMonitor::noticeConnectedI (ISoundStreamServer *s, bool pointer_valid)
|
||
|
{
|
||
|
ISoundStreamClient::noticeConnectedI(s, pointer_valid);
|
||
|
if (s && pointer_valid) {
|
||
|
s->register4_notifySoundStreamCreated(this);
|
||
|
s->register4_notifySoundStreamClosed(this);
|
||
|
s->register4_notifySoundStreamChanged(this);
|
||
|
s->register4_notifySoundStreamData(this);
|
||
|
s->register4_sendStartRecordingWithFormat(this);
|
||
|
s->register4_sendStopRecording(this);
|
||
|
|
||
14 years ago
|
TQMap<TQString, SoundStreamID> tmp;
|
||
15 years ago
|
queryEnumerateSoundStreams(tmp);
|
||
|
|
||
|
m_comboSoundStreamSelector->clear();
|
||
|
m_SoundStreamID2idx.clear();
|
||
|
m_idx2SoundStreamID.clear();
|
||
|
m_comboSoundStreamSelector->insertItem(i18n("nothing"));
|
||
14 years ago
|
TQMapConstIterator<TQString, SoundStreamID> end = tmp.end();
|
||
|
for (TQMapConstIterator<TQString, SoundStreamID> it = tmp.begin(); it != end; ++it) {
|
||
15 years ago
|
int idx = m_comboSoundStreamSelector->count();
|
||
|
m_comboSoundStreamSelector->insertItem(it.key());
|
||
|
m_idx2SoundStreamID[idx] = *it;
|
||
|
m_SoundStreamID2idx[*it] = idx;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
ConfigPageInfo RecordingMonitor::createConfigurationPage()
|
||
|
{
|
||
|
return ConfigPageInfo();
|
||
|
}
|
||
|
|
||
|
AboutPageInfo RecordingMonitor::createAboutPage()
|
||
|
{
|
||
12 years ago
|
/* TDEAboutData aboutData("tderadio",
|
||
15 years ago
|
NULL,
|
||
|
NULL,
|
||
12 years ago
|
I18N_NOOP("Recording Monitor Plugin for TDERadio"),
|
||
12 years ago
|
TDEAboutData::License_GPL,
|
||
15 years ago
|
"(c) 2002-2005 Martin Witte",
|
||
|
0,
|
||
12 years ago
|
"http://sourceforge.net/projects/tderadio",
|
||
15 years ago
|
0);
|
||
|
aboutData.addAuthor("Martin Witte", "", "witte@kawo1.rwth-aachen.de");
|
||
|
|
||
|
return AboutPageInfo(
|
||
12 years ago
|
new TDERadioAboutWidget(aboutData, TDERadioAboutWidget::AbtTabbed),
|
||
15 years ago
|
i18n("Recording Monitor"),
|
||
|
i18n("Recording Monitor Plugin"),
|
||
|
"goto"
|
||
|
);
|
||
|
*/
|
||
|
return AboutPageInfo();
|
||
|
}
|
||
|
|
||
|
|
||
|
void RecordingMonitor::show()
|
||
|
{
|
||
|
WidgetPluginBase::pShow();
|
||
14 years ago
|
TQWidget::show();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
void RecordingMonitor::showOnOrgDesktop()
|
||
|
{
|
||
|
WidgetPluginBase::pShowOnOrgDesktop();
|
||
14 years ago
|
//TQWidget::show();
|
||
15 years ago
|
}
|
||
|
|
||
|
void RecordingMonitor::hide()
|
||
|
{
|
||
|
WidgetPluginBase::pHide();
|
||
14 years ago
|
TQWidget::hide();
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void RecordingMonitor::showEvent(TQShowEvent *e)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQWidget::showEvent(e);
|
||
15 years ago
|
WidgetPluginBase::pShowEvent(e);
|
||
|
//m_comboSoundStreamSelector->setCurrentItem(1);
|
||
|
//slotStreamSelected(1);
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void RecordingMonitor::hideEvent(TQHideEvent *e)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQWidget::hideEvent(e);
|
||
15 years ago
|
WidgetPluginBase::pHideEvent(e);
|
||
|
m_comboSoundStreamSelector->setCurrentItem(0);
|
||
|
slotStreamSelected(0);
|
||
|
}
|
||
|
|
||
|
|
||
|
void RecordingMonitor::slotStartStopRecording()
|
||
|
{
|
||
|
if (m_currentStream.isValid()) {
|
||
|
if (m_recording) {
|
||
|
sendStopRecording(m_currentStream);
|
||
|
} else {
|
||
|
sendStartRecording(m_currentStream);
|
||
|
}
|
||
|
}
|
||
|
updateRecordingButton();
|
||
|
}
|
||
|
|
||
|
|
||
|
bool RecordingMonitor::noticeSoundStreamCreated(SoundStreamID id)
|
||
|
{
|
||
14 years ago
|
TQString tmp = TQString();
|
||
15 years ago
|
querySoundStreamDescription(id, tmp);
|
||
|
|
||
|
int idx = m_comboSoundStreamSelector->count();
|
||
|
m_comboSoundStreamSelector->insertItem(tmp);
|
||
|
m_idx2SoundStreamID[idx] = id;
|
||
|
m_SoundStreamID2idx[id] = idx;
|
||
|
|
||
|
if (tmp == m_defaultStreamDescription) {
|
||
|
m_comboSoundStreamSelector->setCurrentItem(idx);
|
||
|
slotStreamSelected(idx);
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool RecordingMonitor::noticeSoundStreamClosed(SoundStreamID id)
|
||
|
{
|
||
13 years ago
|
if (m_SoundStreamID2idx.contains(id)) {
|
||
15 years ago
|
int idx = m_SoundStreamID2idx[id];
|
||
|
m_idx2SoundStreamID.clear();
|
||
|
m_SoundStreamID2idx.remove(id);
|
||
14 years ago
|
TQMapIterator<SoundStreamID, int> end = m_SoundStreamID2idx.end();
|
||
|
for (TQMapIterator<SoundStreamID, int> it = m_SoundStreamID2idx.begin(); it != end; ++it) {
|
||
15 years ago
|
if (*it > idx) {
|
||
|
(*it)--;
|
||
|
}
|
||
|
m_idx2SoundStreamID[*it] = it.key();
|
||
|
}
|
||
|
m_comboSoundStreamSelector->removeItem(idx);
|
||
|
slotStreamSelected(m_comboSoundStreamSelector->currentItem());
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
bool RecordingMonitor::noticeSoundStreamChanged(SoundStreamID id)
|
||
|
{
|
||
13 years ago
|
if (m_SoundStreamID2idx.contains(id)) {
|
||
15 years ago
|
int idx = m_SoundStreamID2idx[id];
|
||
14 years ago
|
TQString tmp = TQString();
|
||
15 years ago
|
querySoundStreamDescription(id, tmp);
|
||
|
m_comboSoundStreamSelector->changeItem(tmp, idx);
|
||
|
if (idx == m_comboSoundStreamSelector->currentItem()) {
|
||
|
m_defaultStreamDescription = tmp;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool RecordingMonitor::startRecordingWithFormat(SoundStreamID id, const SoundFormat &/*sf*/, SoundFormat &/*real_format*/)
|
||
|
{
|
||
|
if (id == m_currentStream) {
|
||
|
m_recording = true;
|
||
|
updateRecordingButton();
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool RecordingMonitor::stopRecording(SoundStreamID id)
|
||
|
{
|
||
|
if (id == m_currentStream) {
|
||
|
m_recording = false;
|
||
|
updateRecordingButton();
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
bool RecordingMonitor::noticeSoundStreamData(SoundStreamID id,
|
||
|
const SoundFormat &sf, const char *data, size_t size, size_t &consumed_size,
|
||
|
const SoundMetaData &md
|
||
|
)
|
||
|
{
|
||
|
if (m_idx2SoundStreamID[m_comboSoundStreamSelector->currentItem()] == id) {
|
||
|
|
||
|
m_labelFileName->setText(md.url().url());
|
||
|
|
||
|
double B = (double)md.position() + (double)size;
|
||
|
|
||
|
double s = md.relativeTimestamp();
|
||
|
|
||
|
int m = (int)(s / 60); s -= 60 * m;
|
||
|
int h = m / 60; m %= 60;
|
||
|
int d = h / 24; h %= 24;
|
||
14 years ago
|
TQString time;
|
||
15 years ago
|
if (d) {
|
||
|
time.sprintf("%dd - %02d:%02d:%05.2f", d, h, m, s);
|
||
|
} else {
|
||
|
time.sprintf("%02d:%02d:%05.2f", h, m, s);
|
||
|
}
|
||
|
m_labelTime->setText(time);
|
||
|
|
||
|
if (sf.m_Encoding == "raw") {
|
||
|
m_dataMonitor->setEnabled(true);
|
||
|
m_dataMonitor->noticeSoundStreamData(id, sf, data, size, consumed_size, md);
|
||
|
} else {
|
||
|
m_dataMonitor->setEnabled(false);
|
||
|
}
|
||
|
|
||
|
double kB = B / 1024;
|
||
|
double MB = kB / 1024;
|
||
|
double GB = MB / 1024;
|
||
14 years ago
|
TQString str_size;
|
||
12 years ago
|
str_size = i18n("%1 Byte").arg(TDEGlobal::locale()->formatNumber((int)B, 0));
|
||
|
if (kB > 1) str_size = i18n("%1 kB").arg(TDEGlobal::locale()->formatNumber(kB, 3));
|
||
|
if (MB > 1) str_size = i18n("%1 MB").arg(TDEGlobal::locale()->formatNumber(MB, 3));
|
||
|
if (GB > 1) str_size = i18n("%1 GB").arg(TDEGlobal::locale()->formatNumber(GB, 3));
|
||
15 years ago
|
m_labelSize->setText(str_size);
|
||
|
|
||
13 years ago
|
m_labelRate->setText(i18n("%1 Hz").arg(sf.m_SampleRate));
|
||
15 years ago
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
void RecordingMonitor::slotStreamSelected(int idx)
|
||
|
{
|
||
|
SoundStreamID old_id = m_currentStream;
|
||
|
if (old_id.isValid()) {
|
||
|
sendStopCapture(old_id);
|
||
|
}
|
||
|
|
||
13 years ago
|
SoundStreamID id = m_idx2SoundStreamID.contains(idx) ? m_idx2SoundStreamID[idx] : SoundStreamID::InvalidID;
|
||
15 years ago
|
if (id.isValid()) {
|
||
|
|
||
|
m_defaultStreamDescription = m_comboSoundStreamSelector->text(idx);
|
||
|
|
||
|
SoundFormat sf;
|
||
|
sendStartCaptureWithFormat(id, sf, sf);
|
||
|
m_dataMonitor ->setEnabled(true);
|
||
|
m_labelSize ->setEnabled(true);
|
||
|
m_labelSize ->setEnabled(true);
|
||
|
m_labelTime ->setEnabled(true);
|
||
|
m_labelRate ->setEnabled(true);
|
||
|
m_labelFileName ->setEnabled(true);
|
||
13 years ago
|
m_labelStatus ->setEnabled(true);
|
||
15 years ago
|
} else {
|
||
|
m_dataMonitor ->setEnabled(false);
|
||
|
m_labelSize ->setEnabled(false);
|
||
|
m_labelSize ->setEnabled(false);
|
||
|
m_labelTime ->setEnabled(false);
|
||
|
m_labelRate ->setEnabled(false);
|
||
|
m_labelFileName ->setEnabled(false);
|
||
13 years ago
|
m_labelStatus ->setEnabled(false);
|
||
15 years ago
|
}
|
||
|
m_currentStream = id;
|
||
|
m_recording = false;
|
||
|
SoundFormat sf;
|
||
|
queryIsRecordingRunning(m_currentStream, m_recording, sf);
|
||
|
updateRecordingButton();
|
||
|
}
|
||
|
|
||
|
|
||
|
void RecordingMonitor::updateRecordingButton()
|
||
|
{
|
||
|
if (m_currentStream.isValid()) {
|
||
|
m_btnStartStop->setText(!m_recording ? i18n("&Record") : i18n("&Stop Recording"));
|
||
|
m_btnStartStop->setEnabled(true);
|
||
|
} else {
|
||
|
m_btnStartStop->setText(i18n("&Record"));
|
||
|
m_btnStartStop->setEnabled(false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "recording-monitor.moc"
|