void QDeclarativeAudio::pause()
{
    if (!m_complete)
        return;

    setPlaybackState(QMediaPlayer::PausedState);
}
void QDeclarativeAudio::stop()
{
    if (!m_complete)
        return;

    setPlaybackState(QMediaPlayer::StoppedState);
}
예제 #3
0
void AudioScheduledSourceHandler::finishWithoutOnEnded() {
  if (playbackState() != FINISHED_STATE) {
    // Let the context dereference this AudioNode.
    context()->notifySourceNodeFinishedProcessing(this);
    setPlaybackState(FINISHED_STATE);
  }
}
void QDeclarativeAudio::play()
{
    if (!m_complete)
        return;

    setPlaybackState(QMediaPlayer::PlayingState);
}
예제 #5
0
void AudioScheduledSourceHandler::start(double when,
                                        ExceptionState& exceptionState) {
  DCHECK(isMainThread());

  context()->maybeRecordStartAttempt();

  if (playbackState() != UNSCHEDULED_STATE) {
    exceptionState.throwDOMException(InvalidStateError,
                                     "cannot call start more than once.");
    return;
  }

  if (when < 0) {
    exceptionState.throwDOMException(
        InvalidAccessError,
        ExceptionMessages::indexExceedsMinimumBound("start time", when, 0.0));
    return;
  }

  // The node is started. Add a reference to keep us alive so that audio will
  // eventually get played even if Javascript should drop all references to this
  // node. The reference will get dropped when the source has finished playing.
  context()->notifySourceNodeStartedProcessing(node());

  // This synchronizes with process(). updateSchedulingInfo will read some of
  // the variables being set here.
  MutexLocker processLocker(m_processLock);

  // If |when| < currentTime, the source must start now according to the spec.
  // So just set startTime to currentTime in this case to start the source now.
  m_startTime = std::max(when, context()->currentTime());

  setPlaybackState(SCHEDULED_STATE);
}
예제 #6
0
APlayer::APlayer()
{
	old = 0;

	m_fsModel = new QFileSystemModel(this);
	m_fsModel->setRootPath("/");
	m_fsModel->setFilter(QDir::Dirs | QDir::Drives | QDir::NoDotAndDotDot);

	w_fileSystemTree = new QTreeView();
	w_fileSystemTree->setModel(m_fsModel);
	w_fileSystemTree->setSelectionMode(QAbstractItemView::SingleSelection);

	w_folderContents = new QTreeWidget();
	w_folderContents->setHeaderLabels(QStringList() << "Artist" << "Title" << "Album" << "Year");

	w_splitter = new QSplitter();
	w_splitter->setOrientation(Qt::Horizontal);
	w_splitter->addWidget(w_fileSystemTree);
	w_splitter->addWidget(w_folderContents);
	w_splitter->setStretchFactor(0, 40);
	w_splitter->setStretchFactor(1, 60);

	w_playPause = new QPushButton(QIcon::fromTheme("media-playback-start"), tr(""));
	w_stop = new QPushButton(QIcon::fromTheme("media-playback-stop"), tr(""));
	w_sound = new QPushButton(QIcon::fromTheme("player-volume"), tr(""));

	w_progress = new QSlider(Qt::Horizontal);

	m_media = Phonon::createPlayer(Phonon::MusicCategory);
	m_media->setTickInterval(1000);

	la_playerButtons = new QHBoxLayout();
	la_playerButtons->addWidget(w_playPause);
	la_playerButtons->addWidget(w_stop);
	la_playerButtons->addWidget(w_sound);
	la_playerButtons->addWidget(w_progress);

	la_mainWindow = new QVBoxLayout();
	la_mainWindow->addWidget(w_splitter);
	la_mainWindow->addLayout(la_playerButtons);

	QWidget *w = new QWidget();
	w->setLayout(la_mainWindow);
	setCentralWidget(w);


	connect(w_fileSystemTree, SIGNAL(clicked(QModelIndex)), this, SLOT(treeItemClicked(QModelIndex)));

	connect(w_playPause, SIGNAL(clicked()), this, SLOT(playPause()));
	connect(w_stop, SIGNAL(clicked()), this, SLOT(stop()));

	connect(w_fileSystemTree, SIGNAL(collapsed(QModelIndex)), this, SLOT(treeChanged()));
	connect(w_fileSystemTree, SIGNAL(expanded(QModelIndex)), this, SLOT(treeChanged()));

	connect(m_media, SIGNAL(tick(qint64)), this, SLOT(setPlaybackState(qint64)));
	connect(m_media, SIGNAL(totalTimeChanged(qint64)), this, SLOT(setPlaybackMax(qint64)));

	connect(w_folderContents, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(fileDoubleClicked(QTreeWidgetItem*,int)));
}
void AudioBufferSourceHandler::startSource(double when, double grainOffset, double grainDuration, bool isDurationGiven, ExceptionState& exceptionState)
{
    ASSERT(isMainThread());

    context()->recordUserGestureState();

    if (playbackState() != UNSCHEDULED_STATE) {
        exceptionState.throwDOMException(
            InvalidStateError,
            "cannot call start more than once.");
        return;
    }

    if (when < 0) {
        exceptionState.throwDOMException(
            InvalidStateError,
            ExceptionMessages::indexExceedsMinimumBound(
                "start time",
                when,
                0.0));
        return;
    }

    if (grainOffset < 0) {
        exceptionState.throwDOMException(
            InvalidStateError,
            ExceptionMessages::indexExceedsMinimumBound(
                "offset",
                grainOffset,
                0.0));
        return;
    }

    if (grainDuration < 0) {
        exceptionState.throwDOMException(
            InvalidStateError,
            ExceptionMessages::indexExceedsMinimumBound(
                "duration",
                grainDuration,
                0.0));
        return;
    }

    // The node is started. Add a reference to keep us alive so that audio
    // will eventually get played even if Javascript should drop all references
    // to this node. The reference will get dropped when the source has finished
    // playing.
    context()->notifySourceNodeStartedProcessing(node());

    // This synchronizes with process(). updateSchedulingInfo will read some of the variables being
    // set here.
    MutexLocker processLocker(m_processLock);

    m_isDurationGiven = isDurationGiven;
    m_isGrain = true;
    m_grainOffset = grainOffset;
    m_grainDuration = grainDuration;

    // If |when| < currentTime, the source must start now according to the spec.
    // So just set startTime to currentTime in this case to start the source now.
    m_startTime = std::max(when, context()->currentTime());

    if (buffer())
        clampGrainParameters(buffer());

    setPlaybackState(SCHEDULED_STATE);
}
예제 #8
0
void AudioScheduledSourceHandler::updateSchedulingInfo(
    size_t quantumFrameSize,
    AudioBus* outputBus,
    size_t& quantumFrameOffset,
    size_t& nonSilentFramesToProcess) {
  DCHECK(outputBus);
  if (!outputBus)
    return;

  DCHECK_EQ(quantumFrameSize,
            static_cast<size_t>(AudioUtilities::kRenderQuantumFrames));
  if (quantumFrameSize != AudioUtilities::kRenderQuantumFrames)
    return;

  double sampleRate = this->sampleRate();

  // quantumStartFrame     : Start frame of the current time quantum.
  // quantumEndFrame       : End frame of the current time quantum.
  // startFrame            : Start frame for this source.
  // endFrame              : End frame for this source.
  size_t quantumStartFrame = context()->currentSampleFrame();
  size_t quantumEndFrame = quantumStartFrame + quantumFrameSize;
  size_t startFrame =
      AudioUtilities::timeToSampleFrame(m_startTime, sampleRate);
  size_t endFrame =
      m_endTime == UnknownTime ? 0 : AudioUtilities::timeToSampleFrame(
                                         m_endTime, sampleRate);

  // If we know the end time and it's already passed, then don't bother doing
  // any more rendering this cycle.
  if (m_endTime != UnknownTime && endFrame <= quantumStartFrame)
    finish();

  PlaybackState state = playbackState();

  if (state == UNSCHEDULED_STATE || state == FINISHED_STATE ||
      startFrame >= quantumEndFrame) {
    // Output silence.
    outputBus->zero();
    nonSilentFramesToProcess = 0;
    return;
  }

  // Check if it's time to start playing.
  if (state == SCHEDULED_STATE) {
    // Increment the active source count only if we're transitioning from
    // SCHEDULED_STATE to PLAYING_STATE.
    setPlaybackState(PLAYING_STATE);
  }

  quantumFrameOffset =
      startFrame > quantumStartFrame ? startFrame - quantumStartFrame : 0;
  quantumFrameOffset =
      std::min(quantumFrameOffset, quantumFrameSize);  // clamp to valid range
  nonSilentFramesToProcess = quantumFrameSize - quantumFrameOffset;

  if (!nonSilentFramesToProcess) {
    // Output silence.
    outputBus->zero();
    return;
  }

  // Handle silence before we start playing.
  // Zero any initial frames representing silence leading up to a rendering
  // start time in the middle of the quantum.
  if (quantumFrameOffset) {
    for (unsigned i = 0; i < outputBus->numberOfChannels(); ++i)
      memset(outputBus->channel(i)->mutableData(), 0,
             sizeof(float) * quantumFrameOffset);
  }

  // Handle silence after we're done playing.
  // If the end time is somewhere in the middle of this time quantum, then zero
  // out the frames from the end time to the very end of the quantum.
  if (m_endTime != UnknownTime && endFrame >= quantumStartFrame &&
      endFrame < quantumEndFrame) {
    size_t zeroStartFrame = endFrame - quantumStartFrame;
    size_t framesToZero = quantumFrameSize - zeroStartFrame;

    bool isSafe = zeroStartFrame < quantumFrameSize &&
                  framesToZero <= quantumFrameSize &&
                  zeroStartFrame + framesToZero <= quantumFrameSize;
    DCHECK(isSafe);

    if (isSafe) {
      if (framesToZero > nonSilentFramesToProcess)
        nonSilentFramesToProcess = 0;
      else
        nonSilentFramesToProcess -= framesToZero;

      for (unsigned i = 0; i < outputBus->numberOfChannels(); ++i)
        memset(outputBus->channel(i)->mutableData() + zeroStartFrame, 0,
               sizeof(float) * framesToZero);
    }

    finish();
  }

  return;
}
예제 #9
0
// default constructor
Keypad::Keypad()
{
	sInstance = this;
	// use 'stopped' state by default
	setPlaybackState(false);
} //Keypad