void MediaObject::play() { if (currentGraph()->isLoading()) { m_nextState = Phonon::PlayingState; } else { currentGraph()->play(); } }
void MediaObject::stop() { if (currentGraph()->isLoading()) { m_nextState = Phonon::StoppedState; } else { currentGraph()->stop(); } }
void MediaObject::pause() { if (currentGraph()->isLoading()) { m_nextState = Phonon::PausedState; } else { currentGraph()->pause(); } }
void MediaObject::switchFilters(int index, Filter oldFilter, Filter newFilter) { if (currentGraph()->index() == index) { currentGraph()->switchFilters(oldFilter, newFilter); } else { nextGraph()->switchFilters(oldFilter, newFilter); } }
void MediaObject::updateStopPosition() { if (!m_autoplayTitles && m_currentTitle < _iface_availableTitles() - 1) { //stop position is set to the end of the track currentGraph()->setStopPosition(titleAbsolutePosition(m_currentTitle+1)); } else { //stop position is set to the end currentGraph()->setStopPosition(-1); } }
void MediaObject::setSource(const Phonon::MediaSource &source) { m_nextSourceReadyToStart = false; m_prefinishMarkSent = false; m_aboutToFinishSent = false; m_oldHasVideo = currentGraph()->hasVideo(); setState(Phonon::LoadingState); //After loading we go into stopped state m_nextState = Phonon::StoppedState; catchComError(currentGraph()->loadSource(source)); emit currentSourceChanged(source); }
qint64 MediaObject::totalTime() const { #ifndef QT_NO_PHONON_MEDIACONTROLLER //1st, check if there is more titles after const qint64 ret = (m_currentTitle < _iface_availableTitles() - 1) ? titleAbsolutePosition(m_currentTitle+1) : currentGraph()->absoluteTotalTime(); //this is the duration of the current title return ret - titleAbsolutePosition(m_currentTitle); #else return currentGraph()->absoluteTotalTime(); #endif //QT_NO_PHONON_MEDIACONTROLLER }
void EconomyGraph::draw( Painter& painter ){ Color white; white.parse( "white" ); Rect2D background( 0, 0, getWidth(), getHeight() ); int mgX = border; int mgY = 3*border; int mgW = getConfig()->monthgraphW; int mgH = getConfig()->monthgraphH; painter.setFillColor( white ); painter.fillRectangle( background ); Vector2 labelPos( 2 * border, border-1 ); //Draw HistoryLineGraph painter.drawTexture( labelTextureEconomy, labelPos ); Rect2D currentGraph( mgX, mgY, mgX + mgW, mgY + mgH ); drawHistoryLineGraph( painter, currentGraph ); //Draw Sustainability Bars labelPos.y += 2 * border + mgH; painter.drawTexture( labelTextureSustainability, labelPos ); currentGraph.move( Vector2( 0, 2 * border + mgH ) ); drawSustBarGraph( painter, currentGraph); //Draw FPS-Window labelPos.y += 2 * border + mgH; painter.drawTexture( labelTextureFPS, labelPos ); currentGraph.move( Vector2( 0, 2 * border + mgH ) ); currentGraph.setHeight( mgH/2 ); drawFPSGraph( painter, currentGraph ); }
void MediaObject::ensureStopped() { currentGraph()->ensureStopped(); if (m_state == Phonon::ErrorState) { //we reset the state here m_state = Phonon::StoppedState; } }
void MediaObject::seek(qint64 time) { //we seek into the current title currentGraph()->absoluteSeek(time #ifndef QT_NO_PHONON_MEDIACONTROLLER + titleAbsolutePosition(m_currentTitle) #endif //QT_NO_PHONON_MEDIACONTROLLER ); }
qint64 MediaObject::currentTime() const { //this handles inaccuracy when stopping on a title return currentGraph()->absoluteCurrentTime() #ifndef QT_NO_PHONON_MEDIACONTROLLER - titleAbsolutePosition(m_currentTitle) #endif //QT_NO_PHONON_MEDIACONTROLLER ; }
void MediaObject::switchToNextSource() { m_prefinishMarkSent = false; m_aboutToFinishSent = false; m_nextSourceReadyToStart = false; m_oldHasVideo = currentGraph()->hasVideo(); qSwap(m_graphs[0], m_graphs[1]); //swap the graphs if (m_transitionTime >= 0) m_graphs[1]->stop(); //make sure we stop the previous graph if (currentGraph()->mediaSource().type() != Phonon::MediaSource::Invalid && catchComError(currentGraph()->renderResult())) { setState(Phonon::ErrorState); return; } //we need to play the next media play(); //we tell the video widgets to switch now to the new source #ifndef QT_NO_PHONON_VIDEO for (int i = 0; i < m_videoWidgets.count(); ++i) { m_videoWidgets.at(i)->setCurrentGraph(currentGraph()->index()); } #endif //QT_NO_PHONON_VIDEO emit currentSourceChanged(currentGraph()->mediaSource()); emit metaDataChanged(currentGraph()->metadata()); if (nextGraph()->hasVideo() != currentGraph()->hasVideo()) { emit hasVideoChanged(currentGraph()->hasVideo()); } emit tick(0); emit totalTimeChanged(totalTime()); #ifndef QT_NO_PHONON_MEDIACONTROLLER setTitles(currentGraph()->titles()); #endif //QT_NO_PHONON_MEDIACONTROLLER }
void MediaObject::handleComplete(IGraphBuilder *graph) { if (graph == currentGraph()->graph()) { if (m_transitionTime >= PRELOAD_TIME || m_aboutToFinishSent == false) { emit aboutToFinish(); //give a chance to the frontend to give a next source m_aboutToFinishSent = true; } if (!m_nextSourceReadyToStart) { //this is the last source, we simply finish const qint64 current = currentTime(); const OAFilterState currentState = currentGraph()->syncGetRealState(); emit tick(current); //this ensures that the end of the seek slider is reached emit finished(); if (currentTime() == current && currentGraph()->syncGetRealState() == currentState) { //no seek operation in-between pause(); setState(Phonon::PausedState); //we set it here } } else if (m_transitionTime == 0) { //gapless transition switchToNextSource(); //let's call the function immediately } else if (m_transitionTime > 0) { //management of the transition (if it is >= 0) QTimer::singleShot(m_transitionTime, this, SLOT(switchToNextSource())); } } else { //it is just the end of the previous source (in case of cross-fading) nextGraph()->cleanup(); } for (int i = 0; i < m_audioOutputs.count(); ++i) { m_audioOutputs.at(i)->setCrossFadingProgress( currentGraph()->index(), 1.); //cross-fading is in any case finished } }
void MediaObject::seekingFinished(MediaGraph *mg) { if (mg == currentGraph()) { updateTargetTick(); if (currentTime() < totalTime() - m_prefinishMark) { m_prefinishMarkSent = false; } if (currentTime() < totalTime() - PRELOAD_TIME + m_transitionTime) { m_aboutToFinishSent = false; } //this helps the update of the application (seekslider for example) if (m_state == PausedState || m_state == PlayingState) { emit tick(currentTime()); } } }
void MediaObject::loadingFinished(MediaGraph *mg) { if (mg == currentGraph()) { #ifndef QT_NO_PHONON_MEDIACONTROLLER //Title interface m_currentTitle = 0; setTitles(currentGraph()->titles()); #endif //QT_NO_PHONON_MEDIACONTROLLER HRESULT hr = mg->renderResult(); if (catchComError(hr)) { return; } if (m_oldHasVideo != currentGraph()->hasVideo()) { emit hasVideoChanged(currentGraph()->hasVideo()); } #ifndef QT_NO_PHONON_VIDEO if (currentGraph()->hasVideo()) { updateVideoGeometry(); } #endif //QT_NO_PHONON_VIDEO emit metaDataChanged(currentGraph()->metadata()); emit totalTimeChanged(totalTime()); //let's put the next state switch(m_nextState) { case Phonon::PausedState: pause(); break; case Phonon::PlayingState: play(); break; case Phonon::ErrorState: setState(Phonon::ErrorState); break; case Phonon::StoppedState: default: stop(); break; } } }
void MediaObject::handleEvents(Graph graph, long eventCode, long param1) { QString eventDescription; switch (eventCode) { case EC_BUFFERING_DATA: if (graph == currentGraph()->graph()) { m_buffering = param1; emit stateChanged(state(), m_state); } break; case EC_LENGTH_CHANGED: if (graph == currentGraph()->graph()) { emit totalTimeChanged( totalTime() ); } break; case EC_COMPLETE: handleComplete(graph); break; #ifndef QT_NO_PHONON_VIDEO case EC_VIDEO_SIZE_CHANGED: if (graph == currentGraph()->graph()) { updateVideoGeometry(); } break; #endif //QT_NO_PHONON_VIDEO #ifdef GRAPH_DEBUG case EC_ACTIVATE: qDebug() << "EC_ACTIVATE: A video window is being " << (param1 ? "ACTIVATED" : "DEACTIVATED"); break; case EC_BUILT: qDebug() << "EC_BUILT: Send by the Video Control when a graph has been built. Not forwarded to applications."; break; case EC_CLOCK_CHANGED: qDebug() << "EC_CLOCK_CHANGED"; break; case EC_CLOCK_UNSET: qDebug() << "EC_CLOCK_UNSET: The clock provider was disconnected."; break; case EC_CODECAPI_EVENT: qDebug() << "EC_CODECAPI_EVENT: Sent by an encoder to signal an encoding event."; break; case EC_DEVICE_LOST: qDebug() << "EC_DEVICE_LOST: A Plug and Play device was removed or has become available again."; break; case EC_DISPLAY_CHANGED: qDebug() << "EC_DISPLAY_CHANGED: The display mode has changed."; break; case EC_END_OF_SEGMENT: qDebug() << "EC_END_OF_SEGMENT: The end of a segment has been reached."; break; case EC_ERROR_STILLPLAYING: qDebug() << "EC_ERROR_STILLPLAYING: An asynchronous command to run the graph has failed."; break; case EC_ERRORABORT: qDebug() << "EC_ERRORABORT: An operation was aborted because of an error."; break; case EC_EXTDEVICE_MODE_CHANGE: qDebug() << "EC_EXTDEVICE_MODE_CHANGE: Not supported."; break; case EC_FULLSCREEN_LOST: qDebug() << "EC_FULLSCREEN_LOST: The video renderer is switching out of full-screen mode."; break; case EC_GRAPH_CHANGED: qDebug() << "EC_GRAPH_CHANGED: The filter graph has changed."; break; case EC_NEED_RESTART: qDebug() << "EC_NEED_RESTART: A filter is requesting that the graph be restarted."; break; case EC_NOTIFY_WINDOW: qDebug() << "EC_NOTIFY_WINDOW: Notifies a filter of the video renderer's window."; break; case EC_OLE_EVENT: qDebug() << "EC_OLE_EVENT: A filter is passing a text string to the application."; break; case EC_OPENING_FILE: qDebug() << "EC_OPENING_FILE: The graph is opening a file, or has finished opening a file."; break; case EC_PALETTE_CHANGED: qDebug() << "EC_PALETTE_CHANGED: The video palette has changed."; break; case EC_PAUSED: qDebug() << "EC_PAUSED: A pause request has completed."; break; case EC_PREPROCESS_COMPLETE: qDebug() << "EC_PREPROCESS_COMPLETE: Sent by the WM ASF Writer filter when it completes the pre-processing for multipass encoding."; break; case EC_QUALITY_CHANGE: qDebug() << "EC_QUALITY_CHANGE: The graph is dropping samples, for quality control."; break; case EC_REPAINT: qDebug() << "EC_REPAINT: A video renderer requires a repaint."; break; case EC_SEGMENT_STARTED: qDebug() << "EC_SEGMENT_STARTED: A new segment has started."; break; case EC_SHUTTING_DOWN: qDebug() << "EC_SHUTTING_DOWN: The filter graph is shutting down, prior to being destroyed."; break; case EC_SNDDEV_IN_ERROR: qDebug() << "EC_SNDDEV_IN_ERROR: A device error has occurred in an audio capture filter."; break; case EC_SNDDEV_OUT_ERROR: qDebug() << "EC_SNDDEV_OUT_ERROR: A device error has occurred in an audio renderer filter."; break; case EC_STARVATION: qDebug() << "EC_STARVATION: A filter is not receiving enough data."; break; case EC_STATE_CHANGE: qDebug() << "EC_STATE_CHANGE: The filter graph has changed state."; break; case EC_STEP_COMPLETE: qDebug() << "EC_STEP_COMPLETE: A filter performing frame stepping has stepped the specified number of frames."; break; case EC_STREAM_CONTROL_STARTED: qDebug() << "EC_STREAM_CONTROL_STARTED: A stream-control start command has taken effect."; break; case EC_STREAM_CONTROL_STOPPED: qDebug() << "EC_STREAM_CONTROL_STOPPED: A stream-control stop command has taken effect."; break; case EC_STREAM_ERROR_STILLPLAYING: qDebug() << "EC_STREAM_ERROR_STILLPLAYING: An error has occurred in a stream. The stream is still playing."; break; case EC_STREAM_ERROR_STOPPED: qDebug() << "EC_STREAM_ERROR_STOPPED: A stream has stopped because of an error."; break; case EC_TIMECODE_AVAILABLE: qDebug() << "EC_TIMECODE_AVAILABLE: Not supported."; break; case EC_UNBUILT: qDebug() << "Sent by the Video Control when a graph has been torn down. Not forwarded to applications."; break; case EC_USERABORT: qDebug() << "EC_USERABORT: Send by the Video Control when a graph has been torn down. Not forwarded to applications."; break; case EC_VMR_RECONNECTION_FAILED: qDebug() << "EC_VMR_RECONNECTION_FAILED: Sent by the VMR-7 and the VMR-9 when it was unable to accept a dynamic format change request from the upstream decoder."; break; case EC_VMR_RENDERDEVICE_SET: qDebug() << "EC_VMR_RENDERDEVICE_SET: Sent when the VMR has selected its rendering mechanism."; break; case EC_VMR_SURFACE_FLIPPED: qDebug() << "EC_VMR_SURFACE_FLIPPED: Sent when the VMR-7's allocator presenter has called the DirectDraw Flip method on the surface being presented."; break; case EC_WINDOW_DESTROYED: qDebug() << "EC_WINDOW_DESTROYED: The video renderer was destroyed or removed from the graph"; break; case EC_WMT_EVENT: qDebug() << "EC_WMT_EVENT: Sent by the Windows Media Format SDK when an application uses the ASF Reader filter to play ASF files protected by digital rights management (DRM)."; break; case EC_WMT_INDEX_EVENT: qDebug() << "EC_WMT_INDEX_EVENT: Sent by the Windows Media Format SDK when an application uses the ASF Writer to index Windows Media Video files."; break; //documented by Microsoft but not supported in the Platform SDK // case EC_BANDWIDTHCHANGE : qDebug() << "EC_BANDWIDTHCHANGE: not supported"; break; // case EC_CONTENTPROPERTY_CHANGED: qDebug() << "EC_CONTENTPROPERTY_CHANGED: not supported."; break; // case EC_EOS_SOON: qDebug() << "EC_EOS_SOON: not supported"; break; // case EC_ERRORABORTEX: qDebug() << "EC_ERRORABORTEX: An operation was aborted because of an error."; break; // case EC_FILE_CLOSED: qDebug() << "EC_FILE_CLOSED: The source file was closed because of an unexpected event."; break; // case EC_LOADSTATUS: qDebug() << "EC_LOADSTATUS: Notifies the application of progress when opening a network file."; break; // case EC_MARKER_HIT: qDebug() << "EC_MARKER_HIT: not supported."; break; // case EC_NEW_PIN: qDebug() << "EC_NEW_PIN: not supported."; break; // case EC_PLEASE_REOPEN: qDebug() << "EC_PLEASE_REOPEN: The source file has changed."; break; // case EC_PROCESSING_LATENCY: qDebug() << "EC_PROCESSING_LATENCY: Indicates the amount of time that a component is taking to process each sample."; break; // case EC_RENDER_FINISHED: qDebug() << "EC_RENDER_FINISHED: Not supported."; break; // case EC_SAMPLE_LATENCY: qDebug() << "EC_SAMPLE_LATENCY: Specifies how far behind schedule a component is for processing samples."; break; // case EC_SAMPLE_NEEDED: qDebug() << "EC_SAMPLE_NEEDED: Requests a new input sample from the Enhanced Video Renderer (EVR) filter."; break; // case EC_SCRUB_TIME: qDebug() << "EC_SCRUB_TIME: Specifies the time stamp for the most recent frame step."; break; // case EC_STATUS: qDebug() << "EC_STATUS: Contains two arbitrary status strings."; break; // case EC_VIDEOFRAMEREADY: qDebug() << "EC_VIDEOFRAMEREADY: A video frame is ready for display."; break; default: qDebug() << "Unknown event" << eventCode << "(" << param1 << ")"; break; #else default: break; #endif } }
void MediaObject::slotStateReady(Graph graph, Phonon::State newState) { if (graph == currentGraph()->graph() && !currentGraph()->isLoading()) { setState(newState); } }
Phonon::MediaSource MediaObject::source() const { return currentGraph()->mediaSource(); }
//utility function to save the graph to a file void MediaObject::timerEvent(QTimerEvent *e) { if (e->timerId() == m_tickTimer.timerId()) { const qint64 current = currentTime(); const qint64 total = totalTime(); if ( m_tickInterval != 0 && current > m_targetTick) { updateTargetTick(); emit tick(current); } //check that the title hasn't changed #ifndef QT_NO_PHONON_MEDIACONTROLLER if (m_autoplayTitles && m_currentTitle < _iface_availableTitles() - 1) { if (current >= total) { //we go to the next title _iface_setCurrentTitle(m_currentTitle + 1, false); emit tick(current); } return; } #endif //QT_NO_PHONON_MEDIACONTROLLER if (total) { const qint64 remaining = total - current; if (m_transitionTime < 0 && m_nextSourceReadyToStart) { if (remaining < -m_transitionTime + TIMER_INTERVAL/2) { //we need to switch graphs to run the next source in the queue (with cross-fading) switchToNextSource(); return; } else if (current < -m_transitionTime) { //we are currently crossfading for (int i = 0; i < m_audioOutputs.count(); ++i) { m_audioOutputs.at(i)->setCrossFadingProgress( currentGraph()->index(), qMin( qreal(1.), qreal(current) / qreal(-m_transitionTime))); } } } if (m_prefinishMark > 0 && !m_prefinishMarkSent && remaining < m_prefinishMark + TIMER_INTERVAL/2) { #ifdef GRAPH_DEBUG qDebug() << "DS9: emit prefinishMarkReached" << remaining << QTime::currentTime().toString(); #endif m_prefinishMarkSent = true; emit prefinishMarkReached( remaining ); } if (!m_aboutToFinishSent && remaining < PRELOAD_TIME - m_transitionTime + TIMER_INTERVAL/2) { //let's take a 2 seconds time time to actually load the next file #ifdef GRAPH_DEBUG qDebug() << "DS9: emit aboutToFinish" << remaining << QTime::currentTime().toString(); #endif m_aboutToFinishSent = true; emit aboutToFinish(); } } else { //total is 0: the stream is probably live (endless) } if (m_buffering) { ComPointer<IAMNetworkStatus> status(currentGraph()->realSource(), IID_IAMNetworkStatus); if (status) { long l; status->get_BufferingProgress(&l); emit bufferStatus(l); #ifdef GRAPH_DEBUG qDebug() << "emit bufferStatus(" << l << ")"; #endif } } } }
bool dlgGraphViewer::intializeGraphs(std::string graphEquations[], std::string xAxisLabel,std::string yAxisLabel, double xAxisRangeFrom, double xAxisRangeTo, double yAxisRangeFrom, double yAxisRangeTo) { try { double range = 1440; bool temp = false; QVector<double> x(range), currentGraph(range); for(int j = 0; graphEquations[j] != ""; j++) { GraphsCordinates = ""; std::string formulaInput(graphEquations[j]); std::vector<variableValue*> variableValues; FormulaElement* formula = FormulaElement::parseFormula(formulaInput); formula->getVariableValues(&variableValues); if(variableValues.size() > 1) { QString msg ="Following types of graphs are not possible:\n\t> 3D graphs.\n\t> Log and ln graphs.\n\t> Complex graphs."; QMessageBox::critical(this,"Infinity Calculator", msg, QMessageBox::Ok); return false; } if(!temp) { std::string trig = "sin"; temp = strstr(formulaInput.c_str(), trig.c_str()); if(!temp) { trig = "cos"; temp = strstr(formulaInput.c_str(), trig.c_str()); } trig = "tan"; if(strstr(formulaInput.c_str(), trig.c_str())) { QMessageBox::critical(this,"Infinity Calculator","Trignometric graphs are supported only for Sine and Cosine.", QMessageBox::Ok); return false; } if(temp) { QMessageBox::StandardButton overideInfo = QMessageBox::question(this,"Infinity Calculator","One or more graph contains trignometric functions. Do you need to replace the range values with default values?", QMessageBox::Yes|QMessageBox::No); if(overideInfo == QMessageBox::Yes) { xAxisRangeFrom = -360; xAxisRangeTo = 360; yAxisRangeFrom = -1.2; yAxisRangeTo = 1.2; QMessageBox::information(this,"Infinity Calculator","Default range values will were taken. Non Trignometric grpahs will be out of scale.", QMessageBox::Ok); } else { QMessageBox::information(this,"Infinity Calculator","Trignometric grpahs will be out of scale.", QMessageBox::Ok); } } } double xAxis = xAxisRangeFrom; for (int i=0; i<range; i++) { x[i] = xAxis; if(variableValues.size() == 1) { variableValues[0]->value = xAxis; formula->setVariableValues(&variableValues); } currentGraph[i] = (float)formula->evaluate(); if(x[i] < xAxisRangeTo) { QString x1 = QString::number(xAxis); QString y1 = QString::number(currentGraph[i]); GraphsCordinates += x1 + ", " + y1 + "\n "; } xAxis++; } GraphsData += QString::fromStdString(graphEquations[j]) + "\n\nX,Y\n " + GraphsCordinates + "\n\n"; ui->customPlot->legend->setVisible(true); ui->customPlot->addGraph(); switch(j) { case 0: ui->customPlot->graph(j)->setPen(QPen(Qt::red)); break; case 1: ui->customPlot->graph(j)->setPen(QPen(Qt::green)); break; case 2: ui->customPlot->graph(j)->setPen(QPen(Qt::blue));break; case 3: ui->customPlot->graph(j)->setPen(QPen(Qt::black));break; case 4: ui->customPlot->graph(j)->setPen(QPen(Qt::darkRed));break; case 5: ui->customPlot->graph(j)->setPen(QPen(Qt::darkGreen));break; case 6: ui->customPlot->graph(j)->setPen(QPen(Qt::darkBlue));break; case 7: ui->customPlot->graph(j)->setPen(QPen(Qt::cyan));break; case 8: ui->customPlot->graph(j)->setPen(QPen(Qt::magenta));break; case 9: ui->customPlot->graph(j)->setPen(QPen(Qt::yellow));break; case 10: ui->customPlot->graph(j)->setPen(QPen(Qt::gray));break; case 11: ui->customPlot->graph(j)->setPen(QPen(Qt::darkCyan));break; case 12: ui->customPlot->graph(j)->setPen(QPen(Qt::darkMagenta));break; case 13: ui->customPlot->graph(j)->setPen(QPen(Qt::darkYellow));break; case 14: ui->customPlot->graph(j)->setPen(QPen(Qt::darkGray));break; default: ui->customPlot->graph(j)->setPen(QPen(Qt::lightGray)); } ui->customPlot->graph(j)->setData(x, currentGraph); ui->customPlot->graph(j)->setName(QString::fromStdString(graphEquations[j])); } ui->customPlot->xAxis->setRange(xAxisRangeFrom, xAxisRangeTo); ui->customPlot->yAxis->setRange(yAxisRangeFrom, yAxisRangeTo); ui->customPlot->xAxis->setLabel(QString::fromStdString(xAxisLabel)); ui->customPlot->yAxis->setLabel(QString::fromStdString(yAxisLabel)); ui->customPlot->replot(); return true; } catch(...) { QMessageBox::critical(this,"Infinity Calculator","Unexpected error occurred when plotting the graph.", QMessageBox::Ok); return false; } }
bool MediaObject::hasVideo() const { return currentGraph()->hasVideo(); }
bool MediaObject::isSeekable() const { return currentGraph()->isSeekable(); }