QT_BEGIN_NAMESPACE /*! \class QAudioOutput \brief The QAudioOutput class provides an interface for sending audio data to an audio output device. \inmodule QtMultimedia \ingroup multimedia \since 4.6 You can construct an audio output with the system's \l{QAudioDeviceInfo::defaultOutputDevice()}{default audio output device}. It is also possible to create QAudioOutput with a specific QAudioDeviceInfo. When you create the audio output, you should also send in the QAudioFormat to be used for the playback (see the QAudioFormat class description for details). To play a file: Starting to play an audio stream is simply a matter of calling start() with a QIODevice. QAudioOutput will then fetch the data it needs from the io device. So playing back an audio file is as simple as: \snippet doc/src/snippets/audio/main.cpp 9 \dots 4 \snippet doc/src/snippets/audio/main.cpp 4 The file will start playing assuming that the audio system and output device support it. If you run out of luck, check what's up with the error() function. After the file has finished playing, we need to stop the device: \snippet doc/src/snippets/audio/main.cpp 5 At any given time, the QAudioOutput will be in one of four states: active, suspended, stopped, or idle. These states are described by the QAudio::State enum. State changes are reported through the stateChanged() signal. You can use this signal to, for instance, update the GUI of the application; the mundane example here being changing the state of a \c { play/pause } button. You request a state change directly with suspend(), stop(), reset(), resume(), and start(). While the stream is playing, you can set a notify interval in milliseconds with setNotifyInterval(). This interval specifies the time between two emissions of the notify() signal. This is relative to the position in the stream, i.e., if the QAudioOutput is in the SuspendedState or the IdleState, the notify() signal is not emitted. A typical use-case would be to update a \l{QSlider}{slider} that allows seeking in the stream. If you want the time since playback started regardless of which states the audio output has been in, elapsedUSecs() is the function for you. If an error occurs, you can fetch the \l{QAudio::Error}{error type} with the error() function. Please see the QAudio::Error enum for a description of the possible errors that are reported. When an error is encountered, the state changes to QAudio::StoppedState. You can check for errors by connecting to the stateChanged() signal: \snippet doc/src/snippets/audio/main.cpp 8 \sa QAudioInput, QAudioDeviceInfo */ /*! Construct a new audio output and attach it to \a parent. The default audio output device is used with the output \a format parameters. */ QAudioOutput::QAudioOutput(const QAudioFormat &format, QObject *parent): QObject(parent) { d = QAudioDeviceFactory::createDefaultOutputDevice(format); connect(d, SIGNAL(notify()), SIGNAL(notify())); connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State))); }
void ToggleButton::setState(bool _state) { state = _state; emit stateChanged(); update(); }
bool QAudioOutputPrivate::deviceReady() { if(pullMode) { int l = 0; int chunks = bytesAvailable/period_size; if(chunks==0) { bytesAvailable = bytesFree(); return false; } #ifdef DEBUG_AUDIO qDebug()<<"deviceReady() avail="<<bytesAvailable<<" bytes, period size="<<period_size<<" bytes"; qDebug()<<"deviceReady() no. of chunks that can fit ="<<chunks<<", chunks in bytes ="<<period_size*chunks; #endif int input = period_frames*chunks; if(input > (int)buffer_frames) input = buffer_frames; l = audioSource->read(audioBuffer,snd_pcm_frames_to_bytes(handle, input)); if(l > 0) { // Got some data to output if(deviceState != QAudio::ActiveState) return true; qint64 bytesWritten = write(audioBuffer,l); if (bytesWritten != l) audioSource->seek(audioSource->pos()-(l-bytesWritten)); bytesAvailable = bytesFree(); } else if(l == 0) { // Did not get any data to output bytesAvailable = bytesFree(); if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) { // Underrun if (deviceState != QAudio::IdleState) { errorState = QAudio::UnderrunError; deviceState = QAudio::IdleState; emit stateChanged(deviceState); } } } else if(l < 0) { close(); deviceState = QAudio::StoppedState; errorState = QAudio::IOError; emit stateChanged(deviceState); } } else { bytesAvailable = bytesFree(); if(bytesAvailable > snd_pcm_frames_to_bytes(handle, buffer_frames-period_frames)) { // Underrun if (deviceState != QAudio::IdleState) { errorState = QAudio::UnderrunError; deviceState = QAudio::IdleState; emit stateChanged(deviceState); } } } if(deviceState != QAudio::ActiveState) return true; if(intervalTime && (timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) { emit notify(); elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime; timeStamp.restart(); } return true; }
void QtScrollerFilter::remove(QObject *target) { disconnect(QtScroller::scroller(target), SIGNAL(stateChanged(QtScroller::State)), this, SLOT(stateChanged(QtScroller::State))); target->removeEventFilter(this); }
FindDocWidget::FindDocWidget(LiteApi::IApplication *app, QWidget *parent) : QWidget(parent), m_liteApp(app) { m_findEdit = new SearchEdit; m_findEdit->setPlaceholderText(tr("Search")); m_chaseWidget = new ChaseWidget; m_chaseWidget->setMinimumSize(QSize(16,16)); m_chaseWidget->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); QToolButton *findBtn = new QToolButton; findBtn->setPopupMode(QToolButton::InstantPopup); findBtn->setText(tr("Find")); QHBoxLayout *findLayout = new QHBoxLayout; findLayout->setMargin(2); findLayout->addWidget(m_findEdit); findLayout->addWidget(findBtn); findLayout->addWidget(m_chaseWidget); m_browser = m_liteApp->htmlWidgetManager()->createByName(this,"QTextBrowser"); QStringList paths; paths << m_liteApp->resourcePath()+"/packages/go/godoc"; m_browser->setSearchPaths(paths); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setMargin(1); mainLayout->setSpacing(1); mainLayout->addLayout(findLayout); mainLayout->addWidget(m_browser->widget()); QAction *findAll = new QAction(tr("Find All"),this); QAction *findConst = new QAction(tr("Find const"),this); findConst->setData("const"); QAction *findFunc = new QAction(tr("Find func"),this); findFunc->setData("func"); QAction *findInterface = new QAction(tr("Find interface"),this); findInterface->setData("interface"); QAction *findPkg = new QAction(tr("Find pkg"),this); findPkg->setData("pkg"); QAction *findStruct = new QAction(tr("Find struct"),this); findStruct->setData("struct"); QAction *findType = new QAction(tr("Find type"),this); findType->setData("type"); QAction *findVar = new QAction(tr("Find var"),this); findVar->setData("var"); m_useRegexpCheckAct = new QAction(tr("Use Regexp"),this); m_useRegexpCheckAct->setCheckable(true); m_matchCaseCheckAct = new QAction(tr("Match Case"),this); m_matchCaseCheckAct->setCheckable(true); m_matchWordCheckAct = new QAction(tr("Match Word"),this); m_matchWordCheckAct->setCheckable(true); m_useRegexpCheckAct->setChecked(m_liteApp->settings()->value(GODOCFIND_USEREGEXP,false).toBool()); m_matchCaseCheckAct->setChecked(m_liteApp->settings()->value(GODOCFIND_MATCHCASE,true).toBool()); m_matchWordCheckAct->setChecked(m_liteApp->settings()->value(GODOCFIND_MATCHWORD,false).toBool()); QMenu *menu = new QMenu(findBtn); menu->addActions(QList<QAction*>() << findAll //<< findPkg ); menu->addSeparator(); menu->addActions(QList<QAction*>() << findInterface << findStruct << findType << findFunc << findConst << findVar ); menu->addSeparator(); menu->addAction(m_matchWordCheckAct); menu->addAction(m_matchCaseCheckAct); menu->addAction(m_useRegexpCheckAct); findBtn->setMenu(menu); QAction *helpAct = new QAction(tr("Help"),this); menu->addSeparator(); menu->addAction(helpAct); connect(helpAct,SIGNAL(triggered()),this,SLOT(showHelp())); this->setLayout(mainLayout); connect(findAll,SIGNAL(triggered()),this,SLOT(findDoc())); connect(findConst,SIGNAL(triggered()),this,SLOT(findDoc())); connect(findFunc,SIGNAL(triggered()),this,SLOT(findDoc())); connect(findInterface,SIGNAL(triggered()),this,SLOT(findDoc())); connect(findPkg,SIGNAL(triggered()),this,SLOT(findDoc())); connect(findStruct,SIGNAL(triggered()),this,SLOT(findDoc())); connect(findType,SIGNAL(triggered()),this,SLOT(findDoc())); connect(findVar,SIGNAL(triggered()),this,SLOT(findDoc())); m_process = new ProcessEx(this); connect(m_process,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState))); connect(m_process,SIGNAL(extOutput(QByteArray,bool)),this,SLOT(extOutput(QByteArray,bool))); connect(m_process,SIGNAL(extFinish(bool,int,QString)),this,SLOT(extFinish(bool,int,QString))); connect(m_findEdit,SIGNAL(returnPressed()),findAll,SIGNAL(triggered())); connect(m_findEdit,SIGNAL(rightButtonClicked()),this,SLOT(abortFind())); connect(m_browser,SIGNAL(linkClicked(QUrl)),this,SLOT(openUrl(QUrl))); QString path = m_liteApp->resourcePath()+"/packages/go/godoc/finddoc.html"; QFile file(path); if (file.open(QIODevice::ReadOnly)) { m_templateData = file.readAll(); file.close(); } //QFont font = m_browser->widget()->font(); //font.setPointSize(12); //m_browser->widget()->setFont(font); showHelp(); }
// for playing a valid audio file given by the slot // if this function is called by a slot for the first time, audio will be played // if a slot called this function twice in sequence, the currently played // audio will be stopped void Player::play(Slot *givenSlot) { QString filepath = givenSlot->getPath(); QFile audioFile(filepath); // in order to stop playback for the audio file given by the // same slot after calling this function in sequence DURING playback if(givenSlot == lastSlot) stop(); else { stop(); lastSlot = givenSlot; // some basic checks: // 1. check audio file (*.wav ending AND subsistence) if(!filepath.endsWith(".wav", Qt::CaseInsensitive)) { // if the given file is not valid, you don't have to call this // function twice in order to play a (new set) valid file if(lastSlot != NULL) lastSlot = NULL; throw QString("The given audio file is no *.wav!"); } if(!audioFile.exists()) throw QString("The given audio file does not exist!"); // 2. check if format is supported by the audio device if(!device.isFormatSupported(format)) throw QString("Raw audio format not supported by back-end, cannot play audio."); // if audio is currently playing - stop it stop(); // prepare audio playback player = new QAudioOutput(device, format); player->setNotifyInterval(500); connect(player, SIGNAL(stateChanged(QAudio::State)), this, SLOT(handleStateChanged(QAudio::State))); //connect(player, SIGNAL(notify()), this, SLOT(displayCurrentDuration())); // read audio data if(audioFile.open(QIODevice::ReadOnly)) { // read out wav info // ######### IMPLEMENTATION ######### audioFile.seek(44); // skip wav header audioData = audioFile.readAll(); audioFile.close(); audioBuffer.setBuffer(&audioData); audioBuffer.open(QIODevice::ReadOnly); // prepare/open buffer for playback lastSlot->setStatus(SlotStatus::PLAYING); // start playback thread player->start(&audioBuffer); qDebug() << ">> Audio has been started."; } } }
// qtopiamedia signal handling void MediaObject::mediaError(QString const& errorString) { d->errorString = errorString; emit stateChanged(Phonon::ErrorState, qtopiaStateToPhononState(d->state)); }
void Server::setStarting() { this->state = this->STARTING; this->setIcon(QIcon(":/images/start.png")); emit stateChanged(this->state); }
void Server::setShutingDown() { this->state = this->SHUTING_DOWN; this->setIcon(QIcon(":/images/stop.png")); emit stateChanged(this->state); }
void Server::setOff() { this->state = this->OFF; this->setIcon(QIcon(":/images/network-offline.png")); emit stateChanged(this->state); }
void Server::setOn() { this->state = this->ON; this->setIcon(QIcon(":/images/network-transmit-receive.png")); emit stateChanged(this->state); }
void MainWindow::welcomeScreen() { stateChanged("playing", KXMLGUIClient::StateReverse); }
void MainWindow::startingGame() { stateChanged("playing"); }
void DialerControl::callStateChanged( const QPhoneCall& call ) { // Set value space appropriately // XXX Optimize for redundancy! if(hasIncomingCall()) { QPhoneCall icall = incomingCall(); QString number = icall.number(); QString name; QUniqueId contact = icall.contact(); QContactModel *m = ServerContactModel::instance(); if(!contact.isNull()) { QContact cnt = m->contact(contact); if (!cnt.uid().isNull()) name = cnt.label(); } else if(!number.isEmpty()) { QContact cnt = m->matchPhoneNumber(number); if (!cnt.uid().isNull()) name = cnt.label(); } else { number = tr("Unknown", "Unknown caller"); } phoneValueSpace.setAttribute("Incoming/Number", QVariant(number.trimmed())); phoneValueSpace.setAttribute("Incoming/Name", QVariant(name)); if(!aaTid && mProfiles->activeProfile().autoAnswer()) aaTid = startTimer(auto_answer_gap); } else { if(aaTid) killTimer(aaTid); phoneValueSpace.removeAttribute("Incoming"); } // emit useful signals if( call.state() == QPhoneCall::Connected ) { emit callConnected( call ); // update cached call info. updateCachedCall( call ); } else if( call.state() == QPhoneCall::Hold ) { emit callPutOnHold( call ); } else if( call.dialing() ) { emit callDialing( call ); } else if( call.incoming() ) { // Turn off screen saver so the incoming call will be visible. QtopiaPowerManager::setActive(false); emit callIncoming( call ); } else if ( call.dropped() ) { emit callDropped( call ); } doActiveCalls(); // Disable screen saver if in a call if (hasIncomingCall() || hasActiveCalls() || hasCallsOnHold()) QtopiaApplication::setPowerConstraint(QtopiaApplication::DisableLightOff); else QtopiaApplication::setPowerConstraint(QtopiaApplication::Enable); emit stateChanged(); }
SecLabels::SecLabels(QWidget *parent) : _QWidget(parent) { useSecLabel = new QCheckBox("Use Security Label", this); typeLabel = new QLabel("Type:", this); type = new QComboBox(this); type->addItems(QStringList()<<"None"<<"Dynamic"<<"Static"); typeLayout = new QHBoxLayout(this); typeLayout->addWidget(typeLabel); typeLayout->addWidget(type); typeWdg = new QWidget(this); typeWdg->setLayout(typeLayout); modelLabel = new QLabel("Model:", this); model = new QComboBox(this); model->addItems(QStringList()<<"SELinux"<<"AppArmor"<<"DAC"); labelTypeLabel = new QComboBox(this); labelTypeLabel->addItems(QStringList()<<"Label"<<"BaseLabel"<<"ImageLabel"); label = new QLineEdit(this); relabelLabel = new QLabel("Relabel:", this); relabel = new QComboBox(this); relabel->addItems(QStringList()<<"Default"<<"Yes"<<"No"); baseLayout = new QGridLayout(); baseLayout->addWidget(modelLabel, 0, 0); baseLayout->addWidget(model, 0, 1); baseLayout->addWidget(labelTypeLabel, 1, 0); baseLayout->addWidget(label, 1, 1); baseLayout->addWidget(relabelLabel, 2, 0); baseLayout->addWidget(relabel, 2, 1); baseWdg = new QWidget(this); baseWdg->setLayout(baseLayout); baseWdg->setVisible(false); add = new QPushButton(QIcon::fromTheme("list-add"), "", this); del = new QPushButton(QIcon::fromTheme("list-remove"), "", this); list = new QListWidget(this); listLayout = new QGridLayout(); listLayout->addWidget(add, 0, 0); listLayout->addWidget(del, 0, 3); listLayout->addWidget(list, 1, 0, 2, 4); listWdg = new QWidget(this); listWdg->setLayout(listLayout); usedStateChanged(false); commonLayout = new QVBoxLayout(this); commonLayout->addWidget(useSecLabel); commonLayout->addWidget(typeWdg); commonLayout->addWidget(baseWdg); commonLayout->addWidget(listWdg); commonLayout->addStretch(-1); setLayout(commonLayout); connect(useSecLabel, SIGNAL(toggled(bool)), this, SLOT(usedStateChanged(bool))); connect(type, SIGNAL(currentIndexChanged(QString)), this, SLOT(securityTypeChanged(QString))); connect(model, SIGNAL(currentIndexChanged(QString)), this, SLOT(modelTypeChanged(QString))); connect(add, SIGNAL(clicked()), this, SLOT(addSecLabel())); connect(del, SIGNAL(clicked()), this, SLOT(delSecLabel())); // dataChanged connections connect(model, SIGNAL(currentIndexChanged(int)), this, SLOT(stateChanged())); connect(label, SIGNAL(textEdited(QString)), this, SLOT(stateChanged())); connect(labelTypeLabel, SIGNAL(currentIndexChanged(int)), this, SLOT(stateChanged())); connect(relabel, SIGNAL(currentIndexChanged(int)), this, SLOT(stateChanged())); connect(type, SIGNAL(currentIndexChanged(int)), this, SLOT(stateChanged())); connect(useSecLabel, SIGNAL(toggled(bool)), this, SLOT(stateChanged())); }
void Server::setRebooting() { this->state = this->REBOOTING; this->setIcon(QIcon(":/images/restart.png")); emit stateChanged(this->state); }
void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) { GstMessage* gm = message.rawMessage(); if (gm == 0) { // Null message, query current position quint32 newPos = position(); if (newPos/1000 != m_lastPosition) { m_lastPosition = newPos/1000; emit positionChanged(newPos); } } else { //tag message comes from elements inside playbin, not from playbin itself if (GST_MESSAGE_TYPE(gm) == GST_MESSAGE_TAG) { //qDebug() << "tag message"; GstTagList *tag_list; gst_message_parse_tag(gm, &tag_list); gst_tag_list_foreach(tag_list, addTagToMap, &m_tags); //qDebug() << m_tags; emit tagsChanged(); } if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_playbin)) { switch (GST_MESSAGE_TYPE(gm)) { case GST_MESSAGE_STATE_CHANGED: { GstState oldState; GstState newState; GstState pending; gst_message_parse_state_changed(gm, &oldState, &newState, &pending); #ifdef DEBUG_PLAYBIN_STATES QStringList states; states << "GST_STATE_VOID_PENDING" << "GST_STATE_NULL" << "GST_STATE_READY" << "GST_STATE_PAUSED" << "GST_STATE_PLAYING"; qDebug() << QString("state changed: old: %1 new: %2 pending: %3") \ .arg(states[oldState]) \ .arg(states[newState]) \ .arg(states[pending]); #endif switch (newState) { case GST_STATE_VOID_PENDING: case GST_STATE_NULL: setSeekable(false); if (m_state != QMediaPlayer::StoppedState) emit stateChanged(m_state = QMediaPlayer::StoppedState); break; case GST_STATE_READY: setSeekable(false); if (m_state != QMediaPlayer::StoppedState) emit stateChanged(m_state = QMediaPlayer::StoppedState); break; case GST_STATE_PAUSED: if (m_state != QMediaPlayer::PausedState) emit stateChanged(m_state = QMediaPlayer::PausedState); //check for seekable if (oldState == GST_STATE_READY) { /* //gst_element_seek_simple doesn't work reliably here, have to find a better solution GstFormat format = GST_FORMAT_TIME; gint64 position = 0; bool seekable = false; if (gst_element_query_position(m_playbin, &format, &position)) { seekable = gst_element_seek_simple(m_playbin, format, GST_SEEK_FLAG_NONE, position); } setSeekable(seekable); */ setSeekable(true); if (!qFuzzyCompare(m_playbackRate, qreal(1.0))) { qreal rate = m_playbackRate; m_playbackRate = 1.0; setPlaybackRate(rate); } if (m_renderer) m_renderer->precessNewStream(); } break; case GST_STATE_PLAYING: if (oldState == GST_STATE_PAUSED) getStreamsInfo(); if (m_state != QMediaPlayer::PlayingState) emit stateChanged(m_state = QMediaPlayer::PlayingState); break; } } break; case GST_MESSAGE_EOS: emit playbackFinished(); break; case GST_MESSAGE_TAG: case GST_MESSAGE_STREAM_STATUS: case GST_MESSAGE_UNKNOWN: break; case GST_MESSAGE_ERROR: { GError *err; gchar *debug; gst_message_parse_error (gm, &err, &debug); emit error(int(QMediaPlayer::ResourceError), QString::fromUtf8(err->message)); qWarning() << "Error:" << QString::fromUtf8(err->message); g_error_free (err); g_free (debug); } break; case GST_MESSAGE_WARNING: case GST_MESSAGE_INFO: break; case GST_MESSAGE_BUFFERING: { int progress = 0; gst_message_parse_buffering(gm, &progress); emit bufferingProgressChanged(progress); } break; case GST_MESSAGE_STATE_DIRTY: case GST_MESSAGE_STEP_DONE: case GST_MESSAGE_CLOCK_PROVIDE: case GST_MESSAGE_CLOCK_LOST: case GST_MESSAGE_NEW_CLOCK: case GST_MESSAGE_STRUCTURE_CHANGE: case GST_MESSAGE_APPLICATION: case GST_MESSAGE_ELEMENT: break; case GST_MESSAGE_SEGMENT_START: { const GstStructure *structure = gst_message_get_structure(gm); qint64 position = g_value_get_int64(gst_structure_get_value(structure, "position")); position /= 1000000; m_lastPosition = position; emit positionChanged(position); } break; case GST_MESSAGE_SEGMENT_DONE: break; case GST_MESSAGE_DURATION: { GstFormat format = GST_FORMAT_TIME; gint64 duration = 0; if (gst_element_query_duration(m_playbin, &format, &duration)) { int newDuration = duration / 1000000; if (m_duration != newDuration) { m_duration = newDuration; emit durationChanged(m_duration); } } } break; case GST_MESSAGE_LATENCY: #if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 13) case GST_MESSAGE_ASYNC_START: case GST_MESSAGE_ASYNC_DONE: #if GST_VERSION_MICRO >= 23 case GST_MESSAGE_REQUEST_STATE: #endif #endif case GST_MESSAGE_ANY: break; } } } }
void PhononAudioOutput::slotStateChanged(Phonon::State newstate) { if (newstate == Phonon::ErrorState) qDebug() << "Phonon error:" << mediaObject_->errorType() << mediaObject_->errorString(); emit stateChanged(audioState(newstate)); }
void TransferJob::handleStateChanged (QXmppTransferJob::State state) { emit stateChanged (static_cast<TransferState> (state)); }
void SipPhoneProxy::localStatusUpdate( void ) { QString subject; //QIcon icon; SipCallIterator it( _pSipClient->getCallList() ); if( _pSipRegister == 0 ) { return; } if( _setSubscribeOffline && _pSipRegister->getRegisterState() == SipRegister::Connected ) { _setSubscribeOffline = false; _isOnline = false; //QIcon icon; //icon.setPixmap(SHARE_DIR "/icons/offline.png", QIcon::Automatic ); ////buttonOffOnline->setIconSet( icon ); ////buttonUpdate->setEnabled( false ); ////buttonOffOnline->setEnabled( false ); SipCall* current = NULL; it.toFront(); while(it.hasNext()) { current = it.next(); if( current->getCallType() == SipCall::outSubscribeCall ) { if( current->getCallStatus() == SipCall::callInProgress ) { SipCallMemberIterator mIt = current->getMemberList(); mIt.toFront(); SipCallMember *member = mIt.next(); if( member ) { member->requestClearSubscribe(); } } } } } else { if( _pSipRegister->getRegisterState() == SipRegister::NotConnected ) { _isOnline = false; //QIcon icon1; //icon1.setPixmap(SHARE_DIR "/icons/offline.png", QIcon::Automatic ); //buttonOffOnline->setIconSet( icon1 ); //buttonUpdate->setEnabled( false ); //buttonOffOnline->setEnabled( false ); } else if( _pSipRegister->getRegisterState() == SipRegister::Connected ) { if( _buttonSetOffline ) { //buttonOffOnline->setEnabled( true ); } else { _isOnline = true; //QIcon icon2; //icon2.setPixmap(SHARE_DIR "/icons/online.png", QIcon::Automatic ); //buttonOffOnline->setIconSet( icon2 ); //buttonUpdate->setEnabled( true ); //buttonOffOnline->setEnabled( true ); SipCall* current = NULL; it.toFront(); while(it.hasNext()) { current = it.next(); if( current->getCallType() == SipCall::outSubscribeCall ) { if( current->getCallStatus() != SipCall::callDead ) { SipCallMemberIterator mIt = current->getMemberList(); mIt.toFront(); SipCallMember *member = mIt.next(); if( member ) { member->requestSubscribe( _subscribeExpiresTime ); } } } } } } } emit ( stateChanged() ); }
void Activity::activityStateChanged(KActivities::Info::State state) { Q_UNUSED(state) emit stateChanged(); }
Player::Player(QWidget *parent) : QWidget(parent) , videoWidget(0) , coverLabel(0) , slider(0) , colorDialog(0) { //! [create-objs] player = new QMediaPlayer; playlist = new QMediaPlaylist(player); //! [create-objs] connect(player, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64))); connect(player, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64))); connect(player, SIGNAL(metaDataChanged()), SLOT(metaDataChanged())); connect(playlist, SIGNAL(playlistPositionChanged(int)), SLOT(playlistPositionChanged(int))); connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(statusChanged(QMediaPlayer::MediaStatus))); connect(player, SIGNAL(bufferStatusChanged(int)), this, SLOT(bufferingProgress(int))); videoWidget = new VideoWidget(player); playlistModel = new PlaylistModel(this); playlistModel->setPlaylist(playlist); playlistView = new QListView; playlistView->setModel(playlistModel); playlistView->setCurrentIndex(playlistModel->index(playlist->currentPosition(), 0)); connect(playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(jump(QModelIndex))); slider = new QSlider(Qt::Horizontal); slider->setRange(0, player->duration() / 1000); connect(slider, SIGNAL(sliderMoved(int)), this, SLOT(seek(int))); QPushButton *openButton = new QPushButton(tr("Open")); connect(openButton, SIGNAL(clicked()), this, SLOT(open())); PlayerControls *controls = new PlayerControls; controls->setState(player->state()); controls->setVolume(player->volume()); controls->setMuted(controls->isMuted()); connect(controls, SIGNAL(play()), player, SLOT(play())); connect(controls, SIGNAL(pause()), player, SLOT(pause())); connect(controls, SIGNAL(stop()), player, SLOT(stop())); connect(controls, SIGNAL(next()), playlist, SLOT(next())); connect(controls, SIGNAL(previous()), playlist, SLOT(previous())); connect(controls, SIGNAL(changeVolume(int)), player, SLOT(setVolume(int))); connect(controls, SIGNAL(changeMuting(bool)), player, SLOT(setMuted(bool))); connect(controls, SIGNAL(changeRate(qreal)), player, SLOT(setPlaybackRate(qreal))); connect(player, SIGNAL(stateChanged(QMediaPlayer::State)), controls, SLOT(setState(QMediaPlayer::State))); connect(player, SIGNAL(volumeChanged(int)), controls, SLOT(setVolume(int))); connect(player, SIGNAL(mutingChanged(bool)), controls, SLOT(setMuted(bool))); QPushButton *fullScreenButton = new QPushButton(tr("FullScreen")); fullScreenButton->setCheckable(true); if (videoWidget != 0) { connect(fullScreenButton, SIGNAL(clicked(bool)), videoWidget, SLOT(setFullScreen(bool))); connect(videoWidget, SIGNAL(fullScreenChanged(bool)), fullScreenButton, SLOT(setChecked(bool))); } else { fullScreenButton->setEnabled(false); } QPushButton *colorButton = new QPushButton(tr("Color Options...")); if (videoWidget) connect(colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); else colorButton->setEnabled(false); QBoxLayout *displayLayout = new QHBoxLayout; if (videoWidget) displayLayout->addWidget(videoWidget, 2); else displayLayout->addWidget(coverLabel, 2); displayLayout->addWidget(playlistView); QBoxLayout *controlLayout = new QHBoxLayout; controlLayout->setMargin(0); controlLayout->addWidget(openButton); controlLayout->addStretch(1); controlLayout->addWidget(controls); controlLayout->addStretch(1); controlLayout->addWidget(fullScreenButton); controlLayout->addWidget(colorButton); QBoxLayout *layout = new QVBoxLayout; layout->addLayout(displayLayout); layout->addWidget(slider); layout->addLayout(controlLayout); setLayout(layout); metaDataChanged(); }
void QPhoneHandler::setState(const QString &state) { m_state = state; emit stateChanged(); }
//-------------------------------------------------------------------------------------- // Mwars::Mwars() // the Constructor //-------------------------------------------------------------------------------------- Mwars::Mwars(QWidget *parent) : QMainWindow(parent), ui(new Ui::mwarsForm) { ui->setupUi(this); // Ui:mwarsForm ui //*********** two timers QTimer *keepServerAliveTimer = new QTimer(this); // instantiate timer QTimer *testTimer = new QTimer(this); // a. TCP stream to scanner server // clientSocket: client socket sends stream to scanner. clientSocket already exists // Q_SIGNALS signals emitted by socket unimplemented: void hostFound() void connected() connect( &clientSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(clientSocketError(QAbstractSocket::SocketError)) ); connect( &clientSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(clientSocketState(QAbstractSocket::SocketState)) ); connect( &clientSocket, SIGNAL(readyRead()),this, SLOT(OnReadyRead()) ); connect( &clientSocket, SIGNAL(disconnected()), this, SLOT(disconnectedz()) ); // b. UDP stream from opencv / camera listenSocket = new QUdpSocket ( this ); listenSocket->bind(9988 ); connect( listenSocket, SIGNAL(readyRead()),this, SLOT(OnReadyRead()) ); //signals from within code connect( this, SIGNAL(connectScanner()), this, SLOT(connectToScanner())); // Constructor connect( keepServerAliveTimer, SIGNAL(timeout()), this, SLOT(keepServerAlive())); // connect( testTimer, SIGNAL(timeout()), this, SLOT(testSignal())); // signals from ui connect( ui->xSlider, SIGNAL(valueChanged(int)), this, SLOT(sendScanCmd())); connect( ui->ySlider, SIGNAL(valueChanged(int)), this, SLOT(sendScanCmd())); connect( ui->spinboxXCamTrim, SIGNAL(valueChanged(int)), this, SLOT(sendScanCmd())); connect( ui->spinboxYCamTrim, SIGNAL(valueChanged(int)), this, SLOT(sendScanCmd())); //connect( ui->pbLaserToggle, SIGNAL(clicked()), this, SLOT(laserToggle())); connect( ui->pushButtonLaserDisableToggle, SIGNAL(clicked()), this, SLOT(laserDisableToggle())); connect( ui->pushButtonScannerToggle, SIGNAL(clicked()), this, SLOT(scannerToggle())); connect( ui->pushButtonConnect, SIGNAL(clicked()), this, SLOT(connectToScanner())); connect( ui->radioButtonVerboseOn, SIGNAL(clicked()), this, SLOT(verboseOn())); connect( ui->radioButtonVerboseOff, SIGNAL(clicked()), this, SLOT(verboseOff())); connect( ui->pushButtonResetScanner, SIGNAL(clicked()), this, SLOT(resetScanner())); connect( ui->pushButtonCameraDataToggle, SIGNAL(clicked()), this, SLOT(cameraDataToggle())); connect( ui->pushButtonTestDataToggle, SIGNAL(clicked()), this, SLOT(testDataToggle())); //connect( ui->pbAlignBS, SIGNAL(clicked()), this, SLOT(alignBoresight())); connect( ui->pbCalibrateToggle, SIGNAL(clicked()), this, SLOT(calibrateToggle())); connect( ui->pbCalSetULHC, SIGNAL(clicked()), this, SLOT(calSetULHC())); connect( ui->pbCalSetLRHC, SIGNAL(clicked()), this, SLOT(calSetLRHC())); connect( ui->pbCalFullFrame, SIGNAL(clicked()), this, SLOT(calFullFrame())); connect( ui->pbCalHalfFrame, SIGNAL(clicked()), this, SLOT(calHalfFrame())); connect( ui->spinboxXCamTrim, SIGNAL(valueChanged(int)), this, SLOT(xCamTrim())); connect( ui->spinboxYCamTrim, SIGNAL(valueChanged(int)), this, SLOT(yCamTrim())); connect( ui->pbCamTrimOffset, SIGNAL(clicked()), this, SLOT(camTrimOffset())); connect( ui->sbXCamOffset, SIGNAL(valueChanged(int)), this, SLOT(xCamOffset())); connect( ui->sbYCamOffset, SIGNAL(valueChanged(int)), this, SLOT(yCamOffset())); connect( ui->pbCamOffset, SIGNAL(clicked()), this, SLOT(camScanOffset())); connect( ui->pbCalLaserBsight, SIGNAL(clicked()), this, SLOT(alignBoresight())); //connect( this, SIGNAL (testSignal()), this, SLOT (testSignal())); // temporary stuff to test parallax offset g_xLenWallFOV_mm = (1310 * 2); // measured width, x axis, of FOV at target distance = range (mm) g_yLenWallFOV_mm = (975 * 2); g_xSF_pixelTomm = (float)g_xLenWallFOV_mm / CAMERA_X_PIXELS; g_ySF_pixelTomm = (float)g_yLenWallFOV_mm / CAMERA_Y_PIXELS; range_mm = 2750; // measured range cam to target (mm) //overwritten when cam file is read g_xScanFOVOrigin_su = DAC_X_MIN; // scanner origin corresponding to x_camFOVOrigin (scan units) g_xScanFOVMax_su = DAC_X_MAX; // scanner max x corresponding to x_camFOVMax (scan units) // read camera to scanner calibration file. This reads the calibration parameters // and sets main slider and spin box values readXMLFile(); ui->spinboxXCamTrim->setRange(-5000, +5000); ui->spinboxYCamTrim->setRange(-5000, +5000); ui->radioButtonVerboseOff->setChecked(true); clearStateWidets(); // clear Server State widget text #ifdef FORCE_ENABLE_WIDGETS enableWidgets(); #else disableWidgets(); // control widgets get enabled when connected #endif verbose = false; // verbose OFF laserOnFlag = false; testDataEnableFlag = false; // set by TestData button to turn on test data stream cameraDataEnableFlag = false; // set by Camera Data button to turn on OpenCVcamera data stream laserDisableFlag = false; // set by Laser On/Off button scannerOnFlag = false; // set by Scanner On/Off button tcpConnected = false; // tcp connected serverReady = false; calibrateFlag = false; setWindowTitle(tr("MWARS SCANNER CONSOLE")); // =================== start scannerserver comms =============================== // a) UDP stream of co-ords and laser command from OpenCV Project mwars // b) TCP connection to server in the scanner unit // 1. connect to the TCP server in the laser scanner unit emit connectScanner(); //runs connectToScanner // ==================== timers ================================== // start the keep alivetimer. Used to get response to update Console keepServerAliveTimer->start(1000); //1000 = 1 sec //start the test signal timer for testSignal() // 1000 = 1 sec, 1 = 1mS //testTimer->start(100); // 5 Hz //testTimer->start(10); // 50 Hz //testTimer->start(20); // 25 Hz // testTimer->start(60); // 8 Hz // testTimer->start(50); // 10 Hz sendScanCmd(); // init scanner, slew to slider values rectangleIsRunning = false; }
void EspeakTTSWorker::run() { // int freq = cst_wave_sample_rate(w); int freq = espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, buflength, NULL, 0); // espeak_EVENT_TYPE freq = espeak_EVENT_TYPE-> espeakEVENT_SAMPLERATE = 8 // internal use, set sample rate // int numchannels = cst_wave_num_channels(w); // can not find alternative in espeak int numchannels = 1; //mono setting //int samplesize_bytes = sizeof(typeof(*(w->samples))); // search in struct . sample (short * sample ) int samplesize_bytes = sizeof(typeof(sounddata)); int samplesize = samplesize_bytes * 8; //size in bits //short* buf = (short*)(cst_wave_samples(w)); // sounddata // short* buf = (short*)(sounddata); short* buf = waves; // int numsamples = cst_wave_num_samples(w); qDebug() <<"Number of Samples :"<<counter<<endl; // numsamples: is the number of entries in wav. SynthCallback(short *wav, int numsamples, espeak_EVENT *events); //Qt Functions need to change the passed parameter to be from Espeak m_format.setFrequency(freq); //done m_format.setChannels(numchannels); m_format.setSampleSize(samplesize); //bits per sample //not changed m_format.setCodec("audio/pcm"); m_format.setByteOrder(QAudioFormat::LittleEndian); m_format.setSampleType(QAudioFormat::SignedInt); if (!info->isFormatSupported(m_format)) { std::cerr << "Default format not supported - trying to use nearest"; m_format = info->nearestFormat(m_format); } QAudioOutput m_audioOutput(m_format, 0); // connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(finishedPlaying(QAudio::State))); int sizeinbytes = counter * samplesize_bytes; b.open(QIODevice::ReadWrite); // b for Qbuffer b.write((char*)buf, sizeinbytes); b.seek(0); m_audioOutput.start(&b); //hold until sound is done QEventLoop loop; QObject::connect(&m_audioOutput, SIGNAL(stateChanged(QAudio::State)), &loop, SLOT(quit())); do { loop.exec(); } while(m_audioOutput.state() == QAudio::ActiveState); }
void QLocalSocket::connectToServer(const QString &name, OpenMode openMode) { Q_D(QLocalSocket); if (state() == ConnectedState || state() == ConnectingState) { setErrorString(tr("Trying to connect while connection is in progress")); emit error(QLocalSocket::OperationError); return; } d->error = QLocalSocket::UnknownSocketError; d->errorString = QString(); d->state = ConnectingState; emit stateChanged(d->state); if (name.isEmpty()) { d->error = QLocalSocket::ServerNotFoundError; setErrorString(QLocalSocket::tr("%1: Invalid name").arg(QLatin1String("QLocalSocket::connectToServer"))); d->state = UnconnectedState; emit error(d->error); emit stateChanged(d->state); return; } QString pipePath = QLatin1String("\\\\.\\pipe\\"); if (name.startsWith(pipePath)) d->fullServerName = name; else d->fullServerName = pipePath + name; // Try to open a named pipe HANDLE localSocket; forever { DWORD permissions = (openMode & QIODevice::ReadOnly) ? GENERIC_READ : 0; permissions |= (openMode & QIODevice::WriteOnly) ? GENERIC_WRITE : 0; localSocket = CreateFile((const wchar_t *)d->fullServerName.utf16(), // pipe name permissions, 0, // no sharing NULL, // default security attributes OPEN_EXISTING, // opens existing pipe FILE_FLAG_OVERLAPPED, NULL); // no template file if (localSocket != INVALID_HANDLE_VALUE) break; DWORD error = GetLastError(); // It is really an error only if it is not ERROR_PIPE_BUSY if (ERROR_PIPE_BUSY != error) { break; } // All pipe instances are busy, so wait until connected or up to 5 seconds. if (!WaitNamedPipe((const wchar_t *)d->fullServerName.utf16(), 5000)) break; } if (localSocket == INVALID_HANDLE_VALUE) { d->setErrorString(QLatin1String("QLocalSocket::connectToServer")); d->fullServerName = QString(); return; } // we have a valid handle d->serverName = name; if (setSocketDescriptor((qintptr)localSocket, ConnectedState, openMode)) { d->handle = localSocket; emit connected(); } }
void MainWindow::slot_recording_finished( TrackRecorder::TmpFilePtr tmp_file, quint64 start_offset, quint64 end_offset ) { // Show TrackSettings window, set file to edit // QAudio output ... std::cout << "Recording ended (" << tmp_file->fileName().toStdString() << ")." << std::endl; std::cout << "Start: " << start_offset << " End: " << end_offset << std::endl; FILE *tmp = tmpfile(); FILE *fp = fopen( tmp_file->fileName().toStdString().c_str(), "rb" ); fseek( fp, start_offset, SEEK_CUR ); unsigned short int sample; while( !feof( fp ) ) { fread( &sample, sizeof( unsigned short int ), 1, fp ); fwrite( &sample, sizeof( unsigned short int ), 1, tmp ); if( ftell(fp) != -1 && (unsigned int)ftell( fp ) == end_offset ) { break; } } fclose( fp ); remove( tmp_file->fileName().toStdString().c_str() ); rewind( tmp ); fp = fopen( tmp_file->fileName().toStdString().c_str(), "wb" ); while( !feof( tmp ) ) { fread( &sample, sizeof( unsigned short int ), 1, tmp ); fwrite( &sample, sizeof( unsigned short int ), 1, fp ); } fclose( fp ); fclose( tmp ); f.setFileName( tmp_file->fileName() ); f.open( QIODevice::ReadOnly ); QAudioFormat format; // Set up the format, eg. format.setSampleRate( 44100 ); format.setChannelCount( 1 ); format.setSampleSize( 16 ); format.setCodec( "audio/pcm" ); format.setByteOrder( QAudioFormat::LittleEndian ); format.setSampleType( QAudioFormat::UnSignedInt ); QAudioDeviceInfo info( QAudioDeviceInfo::defaultOutputDevice() ); if( !info.isFormatSupported(format) ) { std::cout << "Raw audio format not supported by backend, cannot play audio." << std::endl; return; } audio = new QAudioOutput( format, this ); connect( audio, SIGNAL( stateChanged(QAudio::State) ), this, SLOT( slot_handle_audio_state(QAudio::State) ) ); audio->start( &f ); }
void QDeclarativeBluetoothSocket::socket_state(QBluetoothSocket::SocketState state) { d->m_state = static_cast<QDeclarativeBluetoothSocket::SocketState>(state); emit stateChanged(); }
/*------------------------------------------------------------------------------ | OpenMAXILPlayerControl::onStateChanged +-----------------------------------------------------------------------------*/ void OpenMAXILPlayerControl::onStateChanged(OMX_MediaProcessor::OMX_MediaProcessorState state) { LOG_DEBUG(LOG_TAG, "State changed..."); emit stateChanged(convertState(state)); }
qint64 QAudioInputPrivate::read(char* data, qint64 len) { // Read in some audio data and write it to QIODevice, pull mode if ( !handle ) return 0; int bytesRead = 0; int bytesInRingbufferBeforeRead = ringBuffer.bytesOfDataInBuffer(); if (ringBuffer.bytesOfDataInBuffer() < len) { // bytesAvaiable is saved as a side effect of checkBytesReady(). int bytesToRead = checkBytesReady(); if (bytesToRead < 0) { // bytesAvailable as negative is error code, try to recover from it. xrun_recovery(bytesToRead); bytesToRead = checkBytesReady(); if (bytesToRead < 0) { // recovery failed must stop and set error. close(); errorState = QAudio::IOError; deviceState = QAudio::StoppedState; emit stateChanged(deviceState); return 0; } } bytesToRead = qMin<qint64>(len, bytesToRead); bytesToRead = qMin<qint64>(ringBuffer.freeBytes(), bytesToRead); bytesToRead -= bytesToRead % period_size; int count=0; int err = 0; while(count < 5 && bytesToRead > 0) { char buffer[bytesToRead]; int chunks = bytesToRead / period_size; int frames = chunks * period_frames; if (frames > (int)buffer_frames) frames = buffer_frames; int readFrames = snd_pcm_readi(handle, buffer, frames); if (readFrames >= 0) { bytesRead = snd_pcm_frames_to_bytes(handle, readFrames); ringBuffer.write(buffer, bytesRead); #ifdef DEBUG_AUDIO qDebug() << QString::fromLatin1("read in bytes = %1 (frames=%2)").arg(bytesRead).arg(readFrames).toLatin1().constData(); #endif break; } else if((readFrames == -EAGAIN) || (readFrames == -EINTR)) { errorState = QAudio::IOError; err = 0; break; } else { if(readFrames == -EPIPE) { errorState = QAudio::UnderrunError; err = snd_pcm_prepare(handle); } else if(readFrames == -ESTRPIPE) { err = snd_pcm_prepare(handle); } if(err != 0) break; } count++; } } bytesRead += bytesInRingbufferBeforeRead; if (bytesRead > 0) { // got some send it onward #ifdef DEBUG_AUDIO qDebug() << "frames to write to QIODevice = " << snd_pcm_bytes_to_frames( handle, (int)bytesRead ) << " (" << bytesRead << ") bytes"; #endif if (deviceState != QAudio::ActiveState && deviceState != QAudio::IdleState) return 0; if (pullMode) { qint64 l = 0; qint64 bytesWritten = 0; while (ringBuffer.bytesOfDataInBuffer() > 0) { l = audioSource->write(ringBuffer.availableData(), ringBuffer.availableDataBlockSize()); if (l > 0) { ringBuffer.readBytes(l); bytesWritten += l; } else { break; } } if (l < 0) { close(); errorState = QAudio::IOError; deviceState = QAudio::StoppedState; emit stateChanged(deviceState); } else if (l == 0 && bytesWritten == 0) { if (deviceState != QAudio::IdleState) { errorState = QAudio::NoError; deviceState = QAudio::IdleState; emit stateChanged(deviceState); } } else { bytesAvailable -= bytesWritten; totalTimeValue += bytesWritten; resuming = false; if (deviceState != QAudio::ActiveState) { errorState = QAudio::NoError; deviceState = QAudio::ActiveState; emit stateChanged(deviceState); } } return bytesWritten; } else { while (ringBuffer.bytesOfDataInBuffer() > 0) { int size = ringBuffer.availableDataBlockSize(); memcpy(data, ringBuffer.availableData(), size); data += size; ringBuffer.readBytes(size); } bytesAvailable -= bytesRead; totalTimeValue += bytesRead; resuming = false; if (deviceState != QAudio::ActiveState) { errorState = QAudio::NoError; deviceState = QAudio::ActiveState; emit stateChanged(deviceState); } return bytesRead; } } return 0; }