author | ar <ar> | 2004-05-12 20:25:15 (UTC) |
---|---|---|
committer | ar <ar> | 2004-05-12 20:25:15 (UTC) |
commit | 4b9dcabe79d0d3e73d638981ea045c4969bf21fc (patch) (side-by-side diff) | |
tree | a29198fb88fee4fbdceba3acec7457fdc31668f8 | |
parent | 00efb6af5ff15e43913f91fcc5c33805233c7e91 (diff) | |
download | opie-4b9dcabe79d0d3e73d638981ea045c4969bf21fc.zip opie-4b9dcabe79d0d3e73d638981ea045c4969bf21fc.tar.gz opie-4b9dcabe79d0d3e73d638981ea045c4969bf21fc.tar.bz2 |
- convert qDebug to odebug
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageinfoui.cpp | 2 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.cpp | 2 | ||||
-rw-r--r-- | noncore/multimedia/opieplayer2/audiowidget.cpp | 2 | ||||
-rw-r--r-- | noncore/multimedia/opierec/qtrec.cpp | 18 | ||||
-rw-r--r-- | noncore/multimedia/opierec/wavFile.cpp | 14 |
5 files changed, 19 insertions, 19 deletions
diff --git a/noncore/graphics/opie-eye/gui/imageinfoui.cpp b/noncore/graphics/opie-eye/gui/imageinfoui.cpp index 27a67a6..e70d6a6 100644 --- a/noncore/graphics/opie-eye/gui/imageinfoui.cpp +++ b/noncore/graphics/opie-eye/gui/imageinfoui.cpp @@ -1,205 +1,205 @@ #include "imageinfoui.h" #include <qframe.h> #include <qlabel.h> #include <qpushbutton.h> #include <qtextview.h> #include <qlayout.h> #include <qvariant.h> #include <qtooltip.h> #include <qwhatsthis.h> #include <qimage.h> #include <qpixmap.h> #include <qstring.h> #include <qfileinfo.h> #include "lib/slavemaster.h" #include "lib/imagecache.h" #include <opie2/oconfig.h> #include <opie2/okeyconfigwidget.h> #include <opie2/odebug.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/resource.h> static const int THUMBSIZE = 128; using namespace Opie::Core; imageinfo::imageinfo(Opie::Core::OConfig *cfg,QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ) { m_viewManager = 0; m_cfg = cfg; init(name); initKeys(); } imageinfo::imageinfo(const QString&_path, QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ),currentFile(_path) { m_viewManager = 0; m_cfg = 0; init(name); initKeys(); slotChangeName(_path); } Opie::Core::OKeyConfigManager* imageinfo::manager() { if (!m_viewManager) { initKeys(); } return m_viewManager; } void imageinfo::initKeys() { odebug << "init imageinfo keys" << oendl; #if 0 if (!m_cfg) { m_cfg = new Opie::Core::OConfig("phunkview"); m_cfg->setGroup("imageinfo_keys" ); } #endif Opie::Core::OKeyPair::List lst; lst.append( Opie::Core::OKeyPair::upArrowKey() ); lst.append( Opie::Core::OKeyPair::downArrowKey() ); lst.append( Opie::Core::OKeyPair::leftArrowKey() ); lst.append( Opie::Core::OKeyPair::rightArrowKey() ); lst.append( Opie::Core::OKeyPair::returnKey() ); m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "imageinfo_keys", lst, false,this, "keyconfig name" ); m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Full Image"), "infoview", Resource::loadPixmap("1to1"), ViewItem, Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), this, SLOT(slotShowImage()))); m_viewManager->load(); m_viewManager->handleWidget( this ); m_viewManager->handleWidget( TextView1 ); } void imageinfo::slotShowImage() { emit dispImage(currentFile); } void imageinfo::init(const char* name) { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); } if ( !name ) setName( "imageinfo" ); resize( 289, 335 ); setCaption( tr( "Image info" ) ); imageinfoLayout = new QVBoxLayout( this ); imageinfoLayout->setSpacing(2); imageinfoLayout->setMargin(4); PixmapLabel1 = new QLabel( this, "PixmapLabel1" ); PixmapLabel1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)5, PixmapLabel1->sizePolicy().hasHeightForWidth() ) ); QWhatsThis::add( PixmapLabel1, tr("Displays an thumbnail of the image") ); imageinfoLayout->addWidget( PixmapLabel1 ); Line1 = new QFrame( this, "Line1" ); Line1->setFrameStyle( QFrame::HLine | QFrame::Sunken ); imageinfoLayout->addWidget( Line1 ); fnameLabel = new QLabel( this, "FnameLabel" ); imageinfoLayout->addWidget( fnameLabel); TextView1 = new QTextView( this, "TextView1" ); TextView1->setFrameShadow( QTextView::Sunken ); TextView1->setResizePolicy( QTextView::AutoOneFit ); TextView1->setBackgroundOrigin( QTextView::ParentOrigin ); TextView1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, TextView1->sizePolicy().hasHeightForWidth() ) ); // TextView1->setVScrollBarMode(QScrollView::AlwaysOn); QWhatsThis::add( TextView1, tr("Displays info of selected image") ); imageinfoLayout->addWidget( TextView1 ); SlaveMaster* master = SlaveMaster::self(); connect( master, SIGNAL(sig_fullInfo(const QString&, const QString&)), this, SLOT(slot_fullInfo(const QString&, const QString&)) ); connect(master, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), this, SLOT(slotThumbNail(const QString&, const QPixmap&))); } void imageinfo::slotChangeName(const QString&_path) { currentFile=_path; QFileInfo fi(_path); fnameLabel->setText("<qt><center><b>"+fi.fileName()+"</b></center></qt>"); SlaveMaster::self()->imageInfo( currentFile ); QPixmap*m_pix = PPixmapCache::self()->cachedImage( _path, THUMBSIZE,THUMBSIZE ); if (!m_pix) { PixmapLabel1->setPixmap(QPixmap( Resource::loadPixmap( "UnknownDocument" ))); SlaveMaster::self()->thumbNail(currentFile,THUMBSIZE,THUMBSIZE); } else { PixmapLabel1->setPixmap(*m_pix); } } imageinfo::~imageinfo() { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); } if (m_viewManager) { delete m_viewManager; } } void imageinfo::slot_fullInfo(const QString&_path, const QString&_t) { if (_path == currentFile) { - qDebug(_t); + odebug << _t << oendl; QString t = _t; t.replace(QRegExp("\n"),"<br>"); TextView1->setText(t); } } void imageinfo::slotThumbNail(const QString&_path, const QPixmap&_pix) { if (_path == currentFile) { if (_pix.width()>0) { PPixmapCache::self()->insertImage( _path, _pix, THUMBSIZE, THUMBSIZE ); PixmapLabel1->setPixmap( _pix ); PixmapLabel1->resize(QSize(_pix.width(),_pix.height())); } } } void imageinfo::setPath( const QString& str ) { slotChangeName( str ); } void imageinfo::setDestructiveClose() { WFlags fl = getWFlags(); /* clear it just in case */ fl &= ~WDestructiveClose; fl |= WDestructiveClose; setWFlags( fl ); } /* for testing */ infoDlg::infoDlg(const QString&fname,QWidget * parent, const char * name) :QDialog(parent,name,true,WStyle_ContextHelp) { QVBoxLayout*dlglayout = new QVBoxLayout(this); dlglayout->setSpacing(2); dlglayout->setMargin(1); imageinfo*inf = new imageinfo(fname,this); dlglayout->addWidget(inf); } infoDlg::~infoDlg() { } diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp index 274a22a..6fff5ab 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.cpp +++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp @@ -1,237 +1,237 @@ /* * GPLv2 zecke@handhelds.org * No WArranty... */ #include "mainwindow.h" #include "imageview.h" #include "iconview.h" #include "filesystem.h" #include "imageinfoui.h" #include "viewmodebutton.h" #include <iface/ifaceinfo.h> #include <iface/dirview.h> #include <opie2/odebug.h> #include <opie2/owidgetstack.h> #include <opie2/oapplicationfactory.h> #include <opie2/otabwidget.h> #include <opie2/okeyconfigwidget.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpe/ir.h> #include <qpe/applnk.h> #include <qtoolbar.h> #include <qtoolbutton.h> #include <qlayout.h> #include <qdialog.h> #include <qmap.h> #include <qtimer.h> #include <qframe.h> //OPIE_EXPORT_APP_V2( Opie::Core::OApplicationFactory<PMainWindow>,"Opie Eye" ) OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<PMainWindow>) PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) : QMainWindow( wid, name, style ), m_info( 0 ), m_disp( 0 ) { setCaption( QObject::tr("Opie Eye Caramba" ) ); m_cfg = new Opie::Core::OConfig("phunkview"); m_cfg->setGroup("Zecke_view" ); -// qDebug( "Process-wide OApplication object @ %0x", oApp ); +// odebug << "Process-wide OApplication object @ " << oApp << oendl; /* * Initialize ToolBar and IconView * And Connect Them */ QToolBar *bar = new QToolBar( this ); bar->setHorizontalStretchable( true ); setToolBarsMovable( false ); m_stack = new Opie::Ui::OWidgetStack( this ); setCentralWidget( m_stack ); m_view = new PIconView( m_stack, m_cfg ); m_stack->addWidget( m_view, IconView ); m_stack->raiseWidget( IconView ); connect(m_view, SIGNAL(sig_display(const QString&)), this, SLOT(slotDisplay(const QString&))); connect(m_view, SIGNAL(sig_showInfo(const QString&)), this, SLOT(slotShowInfo(const QString&)) ); m_stack->forceMode(Opie::Ui::OWidgetStack::NoForce); upButton = new QToolButton( bar ); upButton->setIconSet( Resource::loadIconSet( "up" ) ); connect( upButton, SIGNAL(clicked()), m_view, SLOT(slotDirUp()) ); fsButton = new PFileSystem( bar ); connect( fsButton, SIGNAL( changeDir( const QString& ) ), m_view, SLOT(slotChangeDir( const QString& ) ) ); QToolButton*btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "edit" ) ); connect( btn, SIGNAL(clicked()), m_view, SLOT(slotRename()) ); if ( Ir::supported() ) { btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "beam" ) ); connect( btn, SIGNAL(clicked()), m_view, SLOT(slotBeam()) ); } btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "trash" ) ); connect( btn, SIGNAL(clicked() ), m_view, SLOT(slotTrash() ) ); int mode = m_cfg->readNumEntry("ListViewMode", 1); if (mode < 1 || mode>3) mode = 1; viewModeButton = new ViewModeButton( bar,mode ); connect( viewModeButton, SIGNAL(changeMode(int)), m_view, SLOT(slotChangeMode(int))); btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) ); connect( btn, SIGNAL(clicked() ), this, SLOT(slotConfig() ) ); prevButton = new QToolButton(bar); prevButton->setIconSet( Resource::loadIconSet( "back" ) ); connect(prevButton,SIGNAL(clicked()),m_view,SLOT(slotShowPrev())); nextButton = new QToolButton(bar); nextButton->setIconSet( Resource::loadIconSet( "forward" ) ); connect(nextButton,SIGNAL(clicked()),m_view,SLOT(slotShowNext())); rotateButton = new QToolButton(bar); rotateButton->setIconSet( Resource::loadIconSet( "rotate" ) ); rotateButton->setToggleButton(true); if (m_stack->mode() == Opie::Ui::OWidgetStack::SmallScreen) { rotateButton->setOn(true); autoRotate = true; prevButton->hide(); nextButton->hide(); } else { rotateButton->setOn(false); autoRotate = false; } connect(rotateButton,SIGNAL(toggled(bool)),this,SLOT(slotRotateToggled(bool))); scaleButton = new QToolButton(bar); scaleButton->setIconSet( Resource::loadIconSet( "1to1" ) ); scaleButton->setToggleButton(true); scaleButton->setOn(false); connect(scaleButton,SIGNAL(toggled(bool)),this,SLOT(slotScaleToggled(bool))); autoScale = true; zoomButton = new QToolButton(bar); zoomButton->setIconSet( Resource::loadIconSet( "mag" ) ); zoomButton->setToggleButton(true); zoomButton->setOn(true); connect(zoomButton,SIGNAL(toggled(bool)),this,SLOT(slotZoomerToggled(bool))); zoomerOn = true; } PMainWindow::~PMainWindow() { } void PMainWindow::slotToggleZoomer() { if (!m_disp) return; bool cur = zoomButton->isOn(); zoomButton->setOn(!cur); } void PMainWindow::slotZoomerToggled(bool how) { zoomerOn = how; if (m_disp) { m_disp->setShowZoomer(zoomerOn); } } void PMainWindow::slotToggleAutorotate() { if (!m_disp) return; if (!rotateButton->isEnabled()) return; bool cur = rotateButton->isOn(); rotateButton->setOn(!cur); } void PMainWindow::slotToggleAutoscale() { if (!m_disp) return; bool cur = scaleButton->isOn(); scaleButton->setOn(!cur); } void PMainWindow::slotRotateToggled(bool how) { autoRotate = how; if (m_disp) { m_disp->setAutoRotate(how); } } void PMainWindow::slotScaleToggled(bool how) { autoScale = !how; if (!how) { autoRotate = how; } if (m_disp) { m_disp->setAutoScaleRotate(autoScale,autoRotate); } if (!autoScale) { rotateButton->setOn(false); } rotateButton->setEnabled(!how); } void PMainWindow::slotConfig() { /* * have a tab with the possible views * a tab for globals image cache size.. scaled loading * and one tab for the KeyConfigs */ QDialog dlg(this, 0, true); dlg.setCaption( tr("Phunk View - Config" ) ); QHBoxLayout *lay = new QHBoxLayout(&dlg); Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg ); lay->addWidget( wid ); ViewMap *vM = viewMap(); ViewMap::Iterator _it = vM->begin(); QMap<PDirView*, QWidget*> lst; for( ; _it != vM->end(); ++_it ) { PDirView *view = (_it.data())(*m_cfg); PInterfaceInfo *inf = view->interfaceInfo(); QWidget *_wid = inf->configWidget( *m_cfg ); if (!_wid) continue; _wid->reparent(wid, QPoint() ); lst.insert( view, _wid ); wid->addTab( _wid, "fileopen", inf->name() ); } /* * Add the KeyConfigWidget */ Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" ); keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue ); keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() ); if ( !m_info ) { initInfo(); } diff --git a/noncore/multimedia/opieplayer2/audiowidget.cpp b/noncore/multimedia/opieplayer2/audiowidget.cpp index 95a0f45..1c08b41 100644 --- a/noncore/multimedia/opieplayer2/audiowidget.cpp +++ b/noncore/multimedia/opieplayer2/audiowidget.cpp @@ -31,298 +31,298 @@ */ #include "audiowidget.h" /* OPIE */ #include <opie2/odebug.h> #include <qpe/qpeapplication.h> using namespace Opie::Core; using namespace Opie::Ui; namespace { const int xo = -2; // movable x offset const int yo = 22; // movable y offset const MediaWidget::SkinButtonInfo skinInfo[] = { { MediaWidget::Play, "play", MediaWidget::ToggleButton }, { MediaWidget::Stop, "stop", MediaWidget::NormalButton }, { MediaWidget::Next, "next", MediaWidget::NormalButton }, { MediaWidget::Previous, "prev", MediaWidget::NormalButton }, { MediaWidget::VolumeUp, "up", MediaWidget::NormalButton }, { MediaWidget::VolumeDown, "down", MediaWidget::NormalButton }, { MediaWidget::Loop, "loop", MediaWidget::ToggleButton }, { MediaWidget::PlayList, "playlist", MediaWidget::NormalButton }, { MediaWidget::Forward, "forward", MediaWidget::NormalButton }, { MediaWidget::Back, "back", MediaWidget::NormalButton } }; const uint buttonCount = sizeof( skinInfo ) / sizeof( skinInfo[ 0 ] ); void changeTextColor( QWidget * w) { QPalette p = w->palette(); p.setBrush( QColorGroup::Background, QColor( 167, 212, 167 ) ); p.setBrush( QColorGroup::Base, QColor( 167, 212, 167 ) ); w->setPalette( p ); } } AudioWidget::AudioWidget( PlayListWidget &playList, MediaPlayerState &mediaPlayerState, QWidget* parent, const char* name) : MediaWidget( playList, mediaPlayerState, parent, name ), songInfo( this ), slider( Qt::Horizontal, this ), time( this ), audioSliderBeingMoved( false ) { setCaption( tr("OpiePlayer") ); loadSkin(); connect( &mediaPlayerState, SIGNAL( loopingToggled(bool) ), this, SLOT( setLooping(bool) ) ); connect( &mediaPlayerState, SIGNAL( isSeekableToggled(bool) ), this, SLOT( setSeekable(bool) ) ); connect( this, SIGNAL( forwardClicked() ), this, SLOT( skipFor() ) ); connect( this, SIGNAL( backClicked() ), this, SLOT( skipBack() ) ); connect( this, SIGNAL( forwardReleased() ), this, SLOT( stopSkip() ) ); connect( this, SIGNAL( backReleased() ), this, SLOT( stopSkip() ) ); // Intialise state setLength( mediaPlayerState.length() ); setPosition( mediaPlayerState.position() ); setLooping( mediaPlayerState.isFullscreen() ); // setPaused( mediaPlayerState->paused() ); setPlaying( mediaPlayerState.isPlaying() ); } AudioWidget::~AudioWidget() { // mediaPlayerState->setPlaying(false); } MediaWidget::GUIInfo AudioWidget::guiInfo() { return GUIInfo( QString::null /* infix */, ::skinInfo, ::buttonCount ); } void AudioWidget::resizeEvent( QResizeEvent *e ) { int h = height(); int w = width(); songInfo.setGeometry( QRect( 2, 2, w - 4, 20 ) ); slider.setFixedWidth( w - 110 ); slider.setGeometry( QRect( 15, h - 22, w - 90, 20 ) ); slider.setBackgroundOrigin( QWidget::ParentOrigin ); time.setGeometry( QRect( w - 85, h - 30, 70, 20 ) ); upperLeftOfButtonMask.rx() = ( w - buttonUpImage.width() ) / 2; upperLeftOfButtonMask.ry() = (( h - buttonUpImage.height() ) / 2) - 10; MediaWidget::resizeEvent( e ); } void AudioWidget::sliderPressed() { audioSliderBeingMoved = TRUE; } void AudioWidget::sliderReleased() { audioSliderBeingMoved = FALSE; if ( slider.width() == 0 ) return; long val = long((double)slider.value() * mediaPlayerState.length() / slider.width()); mediaPlayerState.setPosition( val ); } void AudioWidget::setPosition( long i ) { // odebug << "<<<<<<<<<<<<<<<<<<<<<<<<set position " << i << "" << oendl; updateSlider( i, mediaPlayerState.length() ); } void AudioWidget::setLength( long max ) { updateSlider( mediaPlayerState.position(), max ); } void AudioWidget::setDisplayType( MediaPlayerState::DisplayType mediaType ) { if ( mediaType == MediaPlayerState::Audio ) { // startTimer( 150 ); QPEApplication::showWidget( this ); return; } killTimers(); hide(); } void AudioWidget::loadSkin() { loadDefaultSkin( guiInfo() ); songInfo.setFocusPolicy( QWidget::NoFocus ); // changeTextColor( &songInfo ); // songInfo.setBackgroundColor( QColor( 167, 212, 167 )); // songInfo.setFrameStyle( QFrame::NoFrame); songInfo.setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); // songInfo.setForegroundColor(Qt::white); slider.setFixedHeight( 20 ); slider.setMinValue( 0 ); slider.setMaxValue( 1 ); slider.setFocusPolicy( QWidget::NoFocus ); slider.setBackgroundPixmap( backgroundPixmap ); // Config cofg("qpe"); // cofg.setGroup("Appearance"); // QColor backgroundcolor = QColor( cofg.readEntry( "Background", "#E5E1D5" ) ); time.setFocusPolicy( QWidget::NoFocus ); time.setAlignment( Qt::AlignCenter ); // time.setFrame(FALSE); // changeTextColor( &time ); resizeEvent( 0 ); } void AudioWidget::setSeekable( bool isSeekable ) { if ( !isSeekable ) { odebug << "<<<<<<<<<<<<<<file is STREAMING>>>>>>>>>>>>>>>>>>>" << oendl; if( !slider.isHidden()) { slider.hide(); } disconnect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); disconnect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); disconnect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); disconnect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); } else { // this stops the slider from being moved, thus // does not stop stream when it reaches the end slider.show(); odebug << " CONNECT SET POSTION " << oendl; connect( &mediaPlayerState, SIGNAL( positionChanged(long) ),this, SLOT( setPosition(long) ) ); connect( &mediaPlayerState, SIGNAL( positionUpdated(long) ),this, SLOT( setPosition(long) ) ); connect( &slider, SIGNAL( sliderPressed() ), this, SLOT( sliderPressed() ) ); connect( &slider, SIGNAL( sliderReleased() ), this, SLOT( sliderReleased() ) ); } } static QString timeAsString( long length ) { int minutes = length / 60; int seconds = length % 60; return QString("%1:%2%3").arg( minutes ).arg( seconds / 10 ).arg( seconds % 10 ); } void AudioWidget::updateSlider( long i, long max ) { time.setText( timeAsString( i ) + " / " + timeAsString( max ) ); -// qDebug( timeAsString( i ) + " / " + timeAsString( max ) ) ; +// odebug << timeAsString( i ) << " / " << timeAsString( max ) << oendl; if ( max == 0 ) { return; } // Will flicker too much if we don't do this // Scale to something reasonable int width = slider.width(); int val = int((double)i * width / max); if ( !audioSliderBeingMoved ) { if ( slider.value() != val ) { slider.setValue( val ); } if ( slider.maxValue() != width ) { slider.setMaxValue( width ); } } } void AudioWidget::skipFor() { skipDirection = +1; startTimer( 50 ); mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); } void AudioWidget::skipBack() { skipDirection = -1; startTimer( 50 ); mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); } void AudioWidget::stopSkip() { killTimers(); } void AudioWidget::timerEvent( QTimerEvent * ) { if ( skipDirection == +1 ) { mediaPlayerState.setPosition( mediaPlayerState.position() + 2 ); } else if ( skipDirection == -1 ) { mediaPlayerState.setPosition( mediaPlayerState.position() - 2 ); } } void AudioWidget::keyReleaseEvent( QKeyEvent *e) { switch ( e->key() ) { ////////////////////////////// Zaurus keys case Key_Home: break; case Key_F9: //activity hide(); // odebug << "Audio F9" << oendl; e->accept(); break; case Key_F10: //contacts break; case Key_F11: //menu mediaPlayerState.toggleBlank(); e->accept(); break; case Key_F12: //home break; case Key_F13: //mail mediaPlayerState.toggleBlank(); e->accept(); break; case Key_Space: { e->accept(); mediaPlayerState.togglePaused(); } break; case Key_Down: // toggleButton(6); emit lessClicked(); emit lessReleased(); // toggleButton(6); e->accept(); break; case Key_Up: // toggleButton(5); emit moreClicked(); emit moreReleased(); // toggleButton(5); e->accept(); break; case Key_Right: // toggleButton(3); mediaPlayerState.setNext(); // toggleButton(3); e->accept(); break; case Key_Left: // toggleButton(4); mediaPlayerState.setPrev(); // toggleButton(4); e->accept(); break; case Key_Escape: { } break; }; } diff --git a/noncore/multimedia/opierec/qtrec.cpp b/noncore/multimedia/opierec/qtrec.cpp index 6eb6524..3b8cb0d 100644 --- a/noncore/multimedia/opierec/qtrec.cpp +++ b/noncore/multimedia/opierec/qtrec.cpp @@ -1,319 +1,318 @@ /**************************************************************************** // qtrec.cpp Created: Thu Jan 17 11:19:58 2002 copyright 2002 by L.J. Potter <ljp@llornkcor.com> ****************************************************************************/ #define DEV_VERSION #include "pixmaps.h" #include "qtrec.h" #include "waveform.h" extern "C" { #include "adpcm.h" } /* OPIE */ #include <opie2/odebug.h> #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/storage.h> using namespace Opie::Core; /* QT */ #include <qcheckbox.h> #include <qcombobox.h> #include <qdir.h> #include <qgroupbox.h> #include <qlabel.h> #include <qlayout.h> #include <qlistview.h> #include <qmessagebox.h> #include <qpopupmenu.h> #include <qpushbutton.h> #include <qslider.h> #include <qtabwidget.h> #include <qtimer.h> /* STD */ #include <errno.h> #include <fcntl.h> #include <math.h> #include <mntent.h> #include <stdio.h> #include <stdlib.h> #include <sys/ioctl.h> #include <sys/soundcard.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/types.h> #include <sys/vfs.h> #include <unistd.h> #include <sys/wait.h> #include <sys/signal.h> #include <pthread.h> #ifdef PDAUDIO //ALSA #include <alsa/asoundlib.h> static int deviceSampleRates[8] = { 32000, 44100, 48000, 88200, 96000, 176400, 192000, -1 }; static int deviceBitRates[] = { 8, 16, 24, 32, -1 }; #else //OSS static int deviceSampleRates[6] = { 11025, 16000, 22050, 32000, 44100, -1 }; static int deviceBitRates[] = { 8, 16, -1 }; #endif #if defined(QT_QWS_SL5XXX) ///#if defined(QT_QWS_EBX) #define DSPSTROUT "/dev/dsp" #define DSPSTRIN "/dev/dsp1" #define DSPSTRMIXEROUT "/dev/mixer" #define DSPSTRMIXERIN "/dev/mixer1" #else #define DSPSTROUT "/dev/dsp" #define DSPSTRIN "/dev/dsp" #define DSPSTRMIXERIN "/dev/mixer" #define DSPSTRMIXEROUT "/dev/mixer" #endif //#define ZAURUS 0 struct adpcm_state encoder_state; struct adpcm_state decoder_state; typedef struct { int sampleRate; /* int fragSize; */ /* int blockSize; */ int resolution; //bitrate int channels; //number of channels int fd; //file descriptor int sd; //sound device descriptor int numberSamples; //total number of samples int SecondsToRecord; // number of seconds that should be recorded float numberOfRecordedSeconds; //total number of samples recorded int samplesToRecord; //number of samples to be recorded int inVol; //input volume int outVol; //output volume int format; //wavfile format PCM.. ADPCM const char *fileName; //name of fiel to be played/recorded } fileParameters; fileParameters filePara; bool monitoring, recording, playing; bool stopped; QLabel *timeLabel; QSlider *timeSlider; int sd; Waveform* waveform; Device *soundDevice; #ifdef THREADED void quickRec() #else void QtRec::quickRec() #endif { - qDebug("%d", - filePara.numberSamples/filePara.sampleRate * filePara.channels); - qDebug("samples %d, rate %d, channels %d", - filePara.numberSamples, filePara.sampleRate, filePara.channels); + odebug << ( filePara.numberSamples/filePara.sampleRate * filePara.channels ) << oendl; + odebug << "samples " << filePara.numberSamples << ", rate " << filePara.sampleRate + << ", channels " << filePara.channels << oendl; int total = 0; // Total number of bytes read in so far. int bytesWritten, number; bytesWritten = 0; number = 0; QString num; int level = 0; int threshold = 0; // int bits = filePara.resolution; // odebug << "bits " << bits << "" << oendl; if( filePara.resolution == 16 ) { //AFMT_S16_LE) // odebug << "AFMT_S16_LE size " << filePara.SecondsToRecord << "" << oendl; // odebug << "samples to record " << filePara.samplesToRecord << "" << oendl; // odebug << "" << filePara.sd << "" << oendl; level = 7; threshold = 0; if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { // odebug << "start recording WAVE_FORMAT_DVI_ADPCM" << oendl; // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> char abuf[ BUFSIZE/2 ]; short sbuf[ BUFSIZE ]; short sbuf2[ BUFSIZE ]; memset( abuf, 0, BUFSIZE/2); memset( sbuf, 0, BUFSIZE); memset( sbuf2, 0, BUFSIZE); for(;;) { if ( stopped) { // odebug << "quickRec:: stopped" << oendl; break; } // number=::read( filePara.sd, sbuf, BUFSIZE); number = soundDevice ->devRead( filePara.sd, sbuf, BUFSIZE); if(number <= 0) { perror("recording error "); odebug << "" << filePara.fileName << " " << number << "" << oendl; stopped = true; return; } //if(stereo == 2) { // adpcm_coder( sbuf2, abuf, number/2, &encoder_state); adpcm_coder( sbuf, abuf, number/2, &encoder_state); bytesWritten = ::write( filePara.fd , (short *)abuf, number/4); waveform->newSamples( sbuf, number ); total += bytesWritten; filePara.numberSamples = total; timeSlider->setValue( total); filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate * (float)2 / filePara.channels; qApp->processEvents(); if( total >= filePara.samplesToRecord) { stopped = true; break; } } } else { // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_PCM >>>>>>>>>>>>>>>>>>>>>> odebug << "start recording WAVE_FORMAT_PCM" << oendl; short inbuffer[ BUFSIZE ], outbuffer[ BUFSIZE ]; memset( inbuffer, 0, BUFSIZE); memset( outbuffer, 0, BUFSIZE); for(;;) { if ( stopped) { odebug << "quickRec:: stopped" << oendl; stopped = true; break; // stop if playing was set to false return; } number = soundDevice->devRead( filePara.sd, (short *)inbuffer, BUFSIZE); if( number <= 0) { perror( "recording error "); odebug << filePara.fileName << oendl; stopped = true; return; } bytesWritten = ::write( filePara.fd , inbuffer, number); waveform->newSamples( inbuffer, number ); if( bytesWritten < 0) { perror("File writing error "); stopped = true; return; } total += bytesWritten; filePara.numberSamples = total; if( filePara.SecondsToRecord != 0) timeSlider->setValue( total); // printf("Writing number %d, bytes %d,total %d\r",number, bytesWritten , total); // fflush(stdout); filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate / (float)2/filePara.channels; qApp->processEvents(); if( total >= filePara.samplesToRecord) { stopped = true; break; } } } //end main loop } else { // <<<<<<<<<<<<<<<<<<<<<<< format = AFMT_U8; unsigned char unsigned_inbuffer[ BUFSIZE ], unsigned_outbuffer[ BUFSIZE ]; memset( unsigned_inbuffer, 0, BUFSIZE); memset( unsigned_outbuffer, 0, BUFSIZE); for(;;) { if ( stopped) { odebug << "quickRec:: stopped" << oendl; break; // stop if playing was set to false } number = ::read( filePara.sd, unsigned_inbuffer, BUFSIZE); bytesWritten = ::write( filePara.fd , unsigned_inbuffer, number); waveform->newSamples( (const short *) unsigned_inbuffer, number ); if(bytesWritten < 0) { stopped = true; QMessageBox::message("Note","<p>There was a problem writing to the file</p>"); perror("File writing error "); return; } total += bytesWritten; filePara.numberSamples = total; // printf("\nWriting number %d, bytes %d,total %d \r",number, bytesWritten , total); // fflush(stdout); if( filePara.SecondsToRecord !=0) timeSlider->setValue( total); filePara.numberOfRecordedSeconds = (float)total / (float)filePara.sampleRate; qApp->processEvents(); if( total >= filePara.samplesToRecord) { stopped = true; break; } } //end main loop } } /// END quickRec() #ifdef THREADED void playIt() #else void QtRec::playIt() #endif { int bytesWritten = 0; int number = 0; int total = 0; // Total number of bytes read in so far. if( filePara.resolution == 16 ) { //AFMT_S16_LE) { if( filePara.format == WAVE_FORMAT_DVI_ADPCM) { char abuf[ BUFSIZE / 2 ]; short sbuf[ BUFSIZE ]; short sbuf2[ BUFSIZE * 2 ]; memset( abuf, 0, BUFSIZE / 2); memset( sbuf, 0, BUFSIZE); memset( sbuf2, 0, BUFSIZE * 2); // <<<<<<<<<<<<<<<<<<<<<<<<<<< WAVE_FORMAT_DVI_ADPCM >>>>>>>>>>>>>>>>>>>>>> for(;;) { // play loop if ( stopped) { break; return; }// stop if playing was set to false number = ::read( filePara.fd, abuf, BUFSIZE / 2); adpcm_decoder( abuf, sbuf, number * 2, &decoder_state); // for (int i=0;i< number * 2; 2 * i++) { //2*i is left channel // sbuf2[i+1]=sbuf2[i]=sbuf[i]; // } bytesWritten = write ( filePara.sd, sbuf, number * 4); waveform->newSamples( (const short *)sbuf, number *4); @@ -730,411 +729,410 @@ void QtRec::initIconView() { temp.sprintf( "%d",i); temp = cfg.readEntry( temp,""); //reads currentFile filePath = cfg.readEntry( temp,""); //currentFileName QFileInfo info(filePath); fileDate = info.lastModified().toString(); fileS = cfg.readEntry( filePath, "0" );// file length in seconds mediaLocation = getStorage( filePath); if( info.exists()) { item = new QListViewItem( ListView1, temp, fileS, mediaLocation, fileDate); item->setPixmap( 0, image0); if( currentFileName == filePath) ListView1->setSelected( item, true); } } } void QtRec::initConnections() { connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); connect( toBeginningButton, SIGNAL( pressed()), this, SLOT( rewindPressed() )); connect( toBeginningButton, SIGNAL( released()), this, SLOT( rewindReleased() )); connect( toEndButton, SIGNAL( pressed()), this, SLOT( FastforwardPressed() )); connect( toEndButton, SIGNAL( released()), this, SLOT( FastforwardReleased() )); connect( deleteSoundButton, SIGNAL(released()), this, SLOT( deleteSound() )); connect( Stop_PushButton, SIGNAL(released()), this, SLOT( doPlayBtn() )); connect( Rec_PushButton, SIGNAL(released()), this, SLOT( newSound() ) ); connect( TabWidget, SIGNAL( currentChanged(QWidget*)), this, SLOT(thisTab(QWidget*) )); connect( OutputSlider, SIGNAL(sliderReleased()), this, SLOT( changedOutVolume()) ); connect( InputSlider, SIGNAL(sliderReleased()), this, SLOT( changedInVolume()) ); connect( sampleRateComboBox, SIGNAL(activated(int)), this, SLOT( changesamplerateCombo(int)) ); connect( bitRateComboBox, SIGNAL(activated(int)), this, SLOT( changebitrateCombo(int)) ); connect( directoryComboBox, SIGNAL(activated(int)), this, SLOT( changeDirCombo(int)) ); connect( sizeLimitCombo, SIGNAL(activated(int)), this, SLOT( changeSizeLimitCombo(int)) ); connect( stereoCheckBox, SIGNAL(toggled(bool)), this, SLOT( changeStereoCheck(bool)) ); connect( outMuteCheckBox, SIGNAL(toggled(bool)), this, SLOT( doVolMuting(bool)) ); connect( inMuteCheckBox , SIGNAL(toggled(bool)), this, SLOT( doMicMuting(bool)) ); connect( ListView1,SIGNAL(doubleClicked(QListViewItem*)), this,SLOT( itClick(QListViewItem*))); connect( ListView1, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int)), this,SLOT( listPressed(int,QListViewItem*,const QPoint&,int)) ); connect( timeSlider, SIGNAL( sliderMoved(int)), this, SLOT( changeTimeSlider(int) )); connect( timeSlider, SIGNAL( sliderPressed()), this, SLOT( timeSliderPressed() )); connect( timeSlider, SIGNAL( sliderReleased()), this, SLOT( timeSliderReleased() )); connect( compressionCheckBox, SIGNAL( toggled(bool)), this, SLOT( compressionSelected(bool))); connect( autoMuteCheckBox, SIGNAL( toggled(bool)), this, SLOT( slotAutoMute(bool))); } void QtRec::initConfig() { int index, fred, i; Config cfg("OpieRec"); cfg.setGroup("Settings"); index = cfg.readNumEntry("samplerate",22050); bool ok; for(int ws=0;ws<sampleRateComboBox->count();ws++) { fred = sampleRateComboBox->text(ws).toInt(&ok, 10); if( index == fred) { filePara.sampleRate = fred; sampleRateComboBox->setCurrentItem(ws); } } i = cfg.readNumEntry("bitrate",16); if(i == 16) bitRateComboBox->setCurrentItem( 1); else if(i == 24) bitRateComboBox->setCurrentItem( 2); else if(i == 32) bitRateComboBox->setCurrentItem( 3); else bitRateComboBox->setCurrentItem( 0); filePara.resolution = i; i = cfg.readNumEntry("sizeLimit", 5 ); QString temp; sizeLimitCombo->setCurrentItem((i/5)); stereoCheckBox->setChecked( cfg.readBoolEntry("stereo", 1)); if( stereoCheckBox->isChecked()) { filePara.channels = 2; } else { filePara.channels = 1; } compressionCheckBox->setChecked( cfg.readBoolEntry("wavCompression",1)); if( compressionCheckBox->isChecked()) { bitRateComboBox->setEnabled(false); bitRateComboBox->setCurrentItem(0); filePara.resolution=16; } autoMuteCheckBox->setChecked( cfg.readBoolEntry("useAutoMute",0)); if( autoMuteCheckBox->isChecked()) slotAutoMute(true); else slotAutoMute(false); Config cofg( "qpe"); cofg.setGroup( "Volume"); outMuteCheckBox->setChecked( cofg.readBoolEntry( "Mute",0)); inMuteCheckBox->setChecked( cofg.readBoolEntry( "MicMute",0)); } void QtRec::stop() { owarn << "STOP" << oendl; setRecordButton(false); if( !recording) endPlaying(); else endRecording(); timeSlider->setValue(0); } void QtRec::doPlayBtn() { if(!stopped) { playLabel2->setText(tr("Play")); stop(); } else { if(ListView1->currentItem() == 0) return; playLabel2->setText(tr("Stop")); currentFile = ListView1->currentItem()->text(0); start(); } } void QtRec::start() { //play if( stopped) { QPixmap image3( ( const char** ) image3_data ); Stop_PushButton->setPixmap( image3 ); Stop_PushButton->setDown( true); stopped = false; paused = false; secCount = 1; if( openPlayFile()) if( setupAudio( false)) //recording is false doPlay(); } } bool QtRec::rec() { //record QString timeString; timeString.sprintf("%.0f", 0.0); timeLabel->setText( timeString+ " seconds"); if(!stopped) { monitoring = true; return false; } else { secCount = 1; playLabel2->setText(tr("Stop")); monitoring = false; setRecordButton( true); if( setupAudio( true)) if(setUpFile()) { int fileSize = 0; Config cfg("OpieRec"); cfg.setGroup("Settings"); -// qDebug( "<<<<<<<Device bits %d, device rate %d, device channels %d", -// soundDevice->getDeviceBits(), -// soundDevice->getDeviceRate(), -// soundDevice->getDeviceChannels()); +// odebug << "<<<<<<<Device bits " << soundDevice->getDeviceBits() +// << ", device rate " << soundDevice->getDeviceRate() +// << ", device channels " << soundDevice->getDeviceChannels() << oendl; //filePara.sampleRate = cfg.readNumEntry("samplerate", 22050); // odebug << "sample rate is " << filePara.sampleRate << "" << oendl; filePara.SecondsToRecord = getCurrentSizeLimit(); // odebug << "size limit " << filePara.SecondsToRecord << " sec" << oendl; int diskSize = checkDiskSpace( (const QString &) wavFile->trackName()); if( filePara.SecondsToRecord == 0) { fileSize = diskSize; } else if( filePara.format == WAVE_FORMAT_PCM) { // odebug << "WAVE_FORMAT_PCM" << oendl; fileSize = (filePara.SecondsToRecord ) * filePara.channels * filePara.sampleRate * ( filePara.resolution / 8) + 1000; } else { // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; fileSize = ((filePara.SecondsToRecord) * filePara.channels * filePara.sampleRate * ( filePara.resolution / 8) ) / 4 + 250; } filePara.samplesToRecord = fileSize; - qDebug("filesize should be %d, bits %d, rate %d", - filePara.samplesToRecord, filePara.resolution, filePara.sampleRate); + odebug << "filesize should be " << filePara.samplesToRecord + << ", bits " << filePara.resolution << ", rate " << filePara.sampleRate; if( paused) { paused = false; } // else { odebug << "Setting timeslider " << filePara.samplesToRecord << "" << oendl; // if(fileSize != 0) timeSlider->setRange(0, filePara.samplesToRecord); // } if( diskSize < fileSize/1024) { QMessageBox::warning(this, tr("Low Disk Space"), tr("You are running low of\nrecording space\n" "or a card isn't being recognized")); stopped = true; //we need to be stopped stop(); } else { QString msg; msg.sprintf("%d, %d, %d", filePara.sampleRate, filePara.channels, filePara.resolution); #ifdef DEV_VERSION setCaption( msg); #endif filePara.fileName=currentFile.latin1(); odebug << "Start recording thread" << oendl; stopped = false; #ifdef THREADED pthread_t thread1; pthread_create( &thread1, NULL, (void * (*)(void *))quickRec, NULL/* &*/); #endif toBeginningButton->setEnabled( false); toEndButton->setEnabled( false); startTimer(1000); #ifndef THREADED quickRec(); #endif } } //end setUpFile } //end setupAudio return true; } /* This happens when a tab is selected*/ void QtRec::thisTab(QWidget* widg) { if(widg != NULL) { int index = TabWidget->currentPageIndex(); if(index == 0) { //file page } if(index == 1) { //control page fillDirectoryCombo(); // soundDevice->getOutVol(); // soundDevice->getInVol(); } if( index==2) { //help page } qApp->processEvents(); update(); } } void QtRec::getOutVol( ) { filePara.outVol = soundDevice->getOutVolume(); // odebug << "out vol " << filePara.outVol << "" << oendl; OutputSlider->setValue( -filePara.outVol); } void QtRec::getInVol() { filePara.inVol = soundDevice->getInVolume(); // odebug << "in vol " << filePara.inVol << "" << oendl; InputSlider->setValue( -filePara.inVol); } void QtRec::changedOutVolume() { soundDevice->changedOutVolume( -OutputSlider->value()); } void QtRec::changedInVolume( ) { soundDevice->changedInVolume( -InputSlider->value()); } bool QtRec::setupAudio( bool b) { bool ok; int sampleformat, stereo, flags; QString dspString, mixerString; filePara.resolution = bitRateComboBox->currentText().toInt( &ok,10); //16 if( !b) { // we want to play #ifdef PDAUDIO //ALSA if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { sampleformat = SND_PCM_FORMAT_S16; filePara.resolution = 16; } else if( filePara.resolution == 24 || compressionCheckBox->isChecked() ) { sampleformat = SND_PCM_FORMAT_S24; filePara.resolution = 24; } else if( filePara.resolution == 32 || compressionCheckBox->isChecked() ) { sampleformat = SND_PCM_FORMAT_S32; filePara.resolution = 32; } else { sampleformat = SND_PCM_FORMAT_U8; filePara.resolution = 8; } #else // we want to play if( filePara.resolution == 16 || compressionCheckBox->isChecked() ) { sampleformat = AFMT_S16_LE; filePara.resolution = 16; } else { sampleformat = AFMT_U8; filePara.resolution = 8; } #endif stereo = filePara.channels; flags = O_WRONLY; Config hwcfg("OpieRec"); hwcfg.setGroup("Hardware"); dspString = hwcfg.readEntry( "Audio", DSPSTROUT); mixerString = hwcfg.readEntry( "Mixer", DSPSTRMIXEROUT); recording = false; } else { // we want to record #ifdef PDAUDIO //ALSA if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") sampleformat = SND_PCM_FORMAT_S16; else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "24") sampleformat = SND_PCM_FORMAT_S24; else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "32") sampleformat = SND_PCM_FORMAT_S32; else sampleformat = SND_PCM_FORMAT_U8; #else if( !bitRateComboBox->isEnabled() || bitRateComboBox->currentText() == "16") sampleformat = AFMT_S16_LE; else sampleformat = AFMT_U8; if( !compressionCheckBox->isChecked()) { filePara.format = WAVE_FORMAT_PCM; // odebug << "WAVE_FORMAT_PCM" << oendl; } else { filePara.format = WAVE_FORMAT_DVI_ADPCM; sampleformat = AFMT_S16_LE; // odebug << "WAVE_FORMAT_DVI_ADPCM" << oendl; } #endif stereo = filePara.channels; // filePara.sampleRate = sampleRateComboBox->currentText().toInt( &ok,10);//44100; flags= O_RDWR; // flags= O_RDONLY; Config hwcfg("OpieRec"); hwcfg.setGroup("Hardware"); dspString = hwcfg.readEntry( "Audio", DSPSTRIN); mixerString = hwcfg.readEntry( "Mixer", DSPSTRMIXERIN); recording = true; } // if(soundDevice) delete soundDevice; odebug << "<<<<<<<<<<<<<<<<<<<open dsp " << filePara.sampleRate << " " << filePara.channels << " " << sampleformat << "" << oendl; owarn << "change waveform settings" << oendl; waveform->changeSettings( filePara.sampleRate, filePara.channels ); soundDevice = new Device( this, dspString, mixerString, b); // soundDevice->openDsp(); soundDevice->reset(); odebug << "device has been made " << soundDevice->sd << "" << oendl; ////////////////// <<<<<<<<<<<<>>>>>>>>>>>> soundDevice->setDeviceFormat( sampleformat); soundDevice->setDeviceChannels( filePara.channels); soundDevice->setDeviceRate( filePara.sampleRate); soundDevice->getDeviceFragSize(); #ifdef QT_QWS_EBX int frag = FRAGSIZE; soundDevice->setFragSize( frag); soundDevice->getDeviceFragSize(); #endif ///////////////// filePara.sd = soundDevice->sd; if ( filePara.sd == -1) { diff --git a/noncore/multimedia/opierec/wavFile.cpp b/noncore/multimedia/opierec/wavFile.cpp index 7e9b50f..fc0130c 100644 --- a/noncore/multimedia/opierec/wavFile.cpp +++ b/noncore/multimedia/opierec/wavFile.cpp @@ -1,314 +1,316 @@ //wavFile.cpp #include "wavFile.h" #include "qtrec.h" /* OPIE */ #include <opie2/odebug.h> #include <qpe/config.h> using namespace Opie::Core; /* QT */ #include <qmessagebox.h> #include <qdir.h> /* STD */ #include <errno.h> #include <sys/time.h> #include <sys/types.h> #include <sys/vfs.h> #include <fcntl.h> #include <math.h> #include <mntent.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> WavFile::WavFile( QObject * parent,const QString &fileName, bool makeNwFile, int sampleRate, int channels, int resolution, int format ) : QObject( parent) { //odebug << "new wave file" << oendl; bool b = makeNwFile; wavSampleRate=sampleRate; wavFormat=format; wavChannels=channels; wavResolution=resolution; useTmpFile=false; if( b) { newFile(); } else { openFile(fileName); } } bool WavFile::newFile() { // odebug << "Set up new file" << oendl; Config cfg("OpieRec"); cfg.setGroup("Settings"); currentFileName=cfg.readEntry("directory",QDir::homeDirPath()); QString date; QDateTime dt = QDateTime::currentDateTime(); date = dt.toString();//TimeString::dateString( QDateTime::currentDateTime(),false,true); date.replace(QRegExp("'"),""); date.replace(QRegExp(" "),"_"); date.replace(QRegExp(":"),"."); date.replace(QRegExp(","),""); QString currentFile=date; if(currentFileName.right(1).find("/",0,true) == -1) currentFileName += "/" + date; else currentFileName += date; currentFileName+=".wav"; // odebug << "set up file for recording: "+currentFileName << oendl; char pointer[] = "/tmp/opierec-XXXXXX"; int fd = 0; if( currentFileName.find("/mnt",0,true) == -1 && currentFileName.find("/tmp",0,true) == -1 ) { // if destination file is most likely in flash (assuming jffs2) // we have to write to a different filesystem first useTmpFile = true; if(( fd = mkstemp( pointer)) < 0 ) { perror("mkstemp failed"); return false; } // odebug << "Opening tmp file " << pointer << "" << oendl; track.setName( pointer); } else { //just use regular file.. no moving useTmpFile = false; track.setName( currentFileName); } if(!track.open( IO_ReadWrite | IO_Truncate)) { QString errorMsg=(QString)strerror(errno); odebug << errorMsg << oendl; QMessageBox::message("Note", "Error opening file.\n" +errorMsg); return false; } else { setWavHeader( track.handle() , &hdr); } return true; } WavFile::~WavFile() { closeFile(); } void WavFile::closeFile() { if(track.isOpen()) track.close(); } int WavFile::openFile(const QString ¤tFileName) { // odebug << "open play file "+currentFileName << oendl; closeFile(); track.setName(currentFileName); if(!track.open(IO_ReadOnly)) { QString errorMsg=(QString)strerror(errno); odebug << "<<<<<<<<<<< "+errorMsg+currentFileName << oendl; QMessageBox::message("Note", "Error opening file.\n" +errorMsg); return -1; } else { parseWavHeader( track.handle()); } return track.handle(); } bool WavFile::setWavHeader(int fd, wavhdr *hdr) { strncpy((*hdr).riffID, "RIFF", 4); // RIFF strncpy((*hdr).wavID, "WAVE", 4); //WAVE strncpy((*hdr).fmtID, "fmt ", 4); // fmt (*hdr).fmtLen = 16; // format length = 16 if( wavFormat == WAVE_FORMAT_PCM) { (*hdr).fmtTag = 1; // PCM // odebug << "set header WAVE_FORMAT_PCM" << oendl; } else { (*hdr).fmtTag = WAVE_FORMAT_DVI_ADPCM; //intel ADPCM // odebug << "set header WAVE_FORMAT_DVI_ADPCM" << oendl; } // (*hdr).nChannels = 1;//filePara.channels;// ? 2 : 1*/; // channels (*hdr).nChannels = wavChannels;// ? 2 : 1*/; // channels (*hdr).sampleRate = wavSampleRate; //samples per second (*hdr).avgBytesPerSec = (wavSampleRate)*( wavChannels*(wavResolution/8)); // bytes per second (*hdr).nBlockAlign = wavChannels*( wavResolution/8); //block align (*hdr).bitsPerSample = wavResolution; //bits per sample 8, or 16 strncpy((*hdr).dataID, "data", 4); write( fd,hdr, sizeof(*hdr)); - qDebug("writing header: bitrate%d, samplerate %d, channels %d", - wavResolution, wavSampleRate, wavChannels); + odebug << "writing header: bitrate " << wavResolution + << ", samplerate " << wavSampleRate + << ", channels " << wavChannels << oendl; return true; } bool WavFile::adjustHeaders(int fd, int total) { lseek(fd, 4, SEEK_SET); int i = total + 36; write( fd, &i, sizeof(i)); lseek( fd, 40, SEEK_SET); write( fd, &total, sizeof(total)); odebug << "adjusting header " << total << "" << oendl; return true; } int WavFile::parseWavHeader(int fd) { odebug << "Parsing wav header" << oendl; char string[4]; int found; short fmt; unsigned short ch, bitrate; unsigned long samplerrate, longdata; if (read(fd, string, 4) < 4) { odebug << " Could not read from sound file.\n" << oendl; return -1; } if (strncmp(string, "RIFF", 4)) { odebug << " not a valid WAV file.\n" << oendl; return -1; } lseek(fd, 4, SEEK_CUR); if (read(fd, string, 4) < 4) { odebug << "Could not read from sound file.\n" << oendl; return -1; } if (strncmp(string, "WAVE", 4)) { odebug << "not a valid WAV file.\n" << oendl; return -1; } found = 0; while (!found) { if (read(fd, string, 4) < 4) { odebug << "Could not read from sound file.\n" << oendl; return -1; } if (strncmp(string, "fmt ", 4)) { if (read(fd, &longdata, 4) < 4) { odebug << "Could not read from sound file.\n" << oendl; return -1; } lseek(fd, longdata, SEEK_CUR); } else { lseek(fd, 4, SEEK_CUR); if (read(fd, &fmt, 2) < 2) { odebug << "Could not read format chunk.\n" << oendl; return -1; } if (fmt != WAVE_FORMAT_PCM && fmt != WAVE_FORMAT_DVI_ADPCM) { - qDebug("Wave file contains unknown format." - " Unable to continue.\n"); + odebug << "Wave file contains unknown format. Unable to continue.\n" << oendl; return -1; } wavFormat = fmt; // compressionFormat=fmt; odebug << "compressionFormat is " << fmt << "" << oendl; if (read(fd, &ch, 2) < 2) { odebug << "Could not read format chunk.\n" << oendl; return -1; } else { wavChannels = ch; odebug << "File has " << ch << " channels" << oendl; } if (read(fd, &samplerrate, 4) < 4) { odebug << "Could not read from format chunk.\n" << oendl; return -1; } else { wavSampleRate = samplerrate; // sampleRate = samplerrate; odebug << "File has samplerate of " << (int) samplerrate << "" << oendl; } lseek(fd, 6, SEEK_CUR); if (read(fd, &bitrate, 2) < 2) { odebug << "Could not read format chunk.\n" << oendl; return -1; } else { wavResolution=bitrate; // resolution = bitrate; odebug << "File has bitrate of " << bitrate << "" << oendl; } found++; } } found = 0; while (!found) { if (read(fd, string, 4) < 4) { odebug << "Could not read from sound file.\n" << oendl; return -1; } if (strncmp(string, "data", 4)) { if (read(fd, &longdata, 4)<4) { odebug << "Could not read from sound file.\n" << oendl; return -1; } lseek(fd, longdata, SEEK_CUR); } else { if (read(fd, &longdata, 4) < 4) { odebug << "Could not read from sound file.\n" << oendl; return -1; } else { wavNumberSamples = longdata; - qDebug("file has length of %d \nlasting %d seconds", (int)longdata, - (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) ); + odebug << "file hase length of " << (int)longdata << "\n" + << "lasting " + << (int)(( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)) + << " seconds" << oendl; // wavSeconds = (( longdata / wavSampleRate) / wavChannels) / ( wavChannels*( wavResolution/8)); return longdata; } } } lseek(fd, 0, SEEK_SET); return 0; } QString WavFile::trackName() { return track.name(); } int WavFile::wavHandle(){ return track.handle(); } int WavFile::getFormat() { return wavFormat; } int WavFile::getResolution() { return wavResolution; } int WavFile::getSampleRate() { return wavSampleRate; } int WavFile::getNumberSamples() { return wavNumberSamples; } bool WavFile::isTempFile() { return useTmpFile; } int WavFile::getChannels() { return wavChannels; } |