void LLAudioSource::update()
{
	if(mCorrupted)
	{
		return ; //no need to update
	}

	//if (!getCurrentBuffer()) // Same as !adp->getBuffer()
	{
		LLAudioData *adp = getCurrentData();
		if (adp && !adp->getBuffer())
		{
			// Hack - try and load the sound.  Will do this as a callback
			// on decode later.
			if (adp->load())
			{
				play(adp->getID());
			}
			else if (adp->hasCompletedDecode())		// Only mark corrupted after decode is done
			{
				LL_WARNS("AudioEngine") << "Marking LLAudioSource corrupted for " << adp->getID() << llendl;
				mCorrupted = true ;
			}
		}
	}
}
Exemplo n.º 2
0
void LLAudioSource::update()
{
	if(mCorrupted)
	{
		return ; //no need to update
	}

	if (!getCurrentBuffer())
	{
		if (getCurrentData())
		{
			// Hack - try and load the sound.  Will do this as a callback
			// on decode later.
			if (getCurrentData()->load() && getCurrentData()->getBuffer())
			{
				play(getCurrentData()->getID());
			}
			else
			{
				mCorrupted = true ;
			}
		}
	}
}
Exemplo n.º 3
0
int SpeedPlotView::maxYValue()
{
    boost::circular_buffer<PointData> &queue = getCurrentData();

    int maxYValue = 0;
    for (int id = UP; id < NB_GRAPHS; ++id) {

        if (!m_properties[static_cast<GraphID>(id)].enable)
            continue;

        for (int i = int(queue.size()) - 1, j = 0; i >= 0 && j <= m_viewablePointsCount; --i, ++j)
            if (queue[i].y[id] > maxYValue)
                maxYValue = queue[i].y[id];
    }

    return maxYValue;
}
Exemplo n.º 4
0
void LLAudioSource::update()
{
	if(mCorrupted)
	{
		return ; //no need to update
	}

	// If data is queued up and we aren't playing it, shuffle it to current and try to load it.
	if(isQueueSounds() && mPlayedOnce && mQueuedDatap && !mChannelp)	
	{
		mCurrentDatap = mQueuedDatap;
		mQueuedDatap = NULL;

		//Make sure this source looks like its brand new again to prevent removal.
		mPlayedOnce = false;
		mAgeTimer.reset();	
	}

	LLAudioData *adp = getCurrentData();
	if (adp && !adp->getBuffer())
	{
		if(adp->getLoadState() == LLAudioData::STATE_LOAD_ERROR)
		{
			LL_WARNS("AudioEngine") << "Marking LLAudioSource corrupted for " << adp->getID() << LL_ENDL;
			mCorrupted = true ;
		}
		else if(adp->getLoadState() == LLAudioData::STATE_LOAD_READY)
		{
			// Update the audio buffer first - load a sound if we have it.
			// Note that this could potentially cause us to waste time updating buffers
			// for sounds that actually aren't playing, although this should be mitigated
			// by the fact that we limit the number of buffers, and we flush buffers based
			// on priority.
			adp->load();	//If it fails, just try again next update.
		}
		else
		{
			//The sound wasn't preloaded yet... so we must kick off the process.
			adp->updateLoadState();
		}
	}
}
Exemplo n.º 5
0
bool LLAudioSource::setupChannel()
{
	LLAudioData *adp = getCurrentData();

	if (!adp->getBuffer())
	{
		// We're not ready to play back the sound yet, so don't try and allocate a channel for it.
		//LL_WARNS() << "Aborting, no buffer" << LL_ENDL;
		return false;
	}

	if (!gAudiop)
	{
		LL_WARNS("AudioEngine") << "LLAudioEngine instance doesn't exist!" << LL_ENDL;
		return false;
	}

	if (!mChannelp)
	{
		// Update the priority, in case we need to push out another channel.
		updatePriority();

		setChannel(gAudiop->getFreeChannel(getPriority()));
	}

	if (!mChannelp)
	{
		// Ugh, we don't have any free channels.
		// Now we have to reprioritize.
		// For now, just don't play the sound.
		//LL_WARNS() << "Aborting, no free channels" << LL_ENDL;
		return false;
	}

	mChannelp->setSource(this);
	return true;
}
Exemplo n.º 6
0
void SpeedPlotView::paintEvent(QPaintEvent *)
{
    QPainter painter(viewport());

    QRect fullRect = viewport()->rect();
    QRect rect = viewport()->rect();
    QFontMetrics fontMetrics = painter.fontMetrics();

    rect.adjust(4, 4, 0, -4); // Add padding

    int maxY = maxYValue();

    rect.adjust(0, fontMetrics.height(), 0, 0); // Add top padding for top speed text

    // draw Y axis speed labels
    QVector<QString> speedLabels = {
        Utils::Misc::friendlyUnit(maxY, true),
        Utils::Misc::friendlyUnit(0.75 * maxY, true),
        Utils::Misc::friendlyUnit(0.5 * maxY, true),
        Utils::Misc::friendlyUnit(0.25 * maxY, true),
        Utils::Misc::friendlyUnit(0, true)
    };

    int yAxeWidth = 0;
    for (const QString &label : speedLabels)
        if (fontMetrics.width(label) > yAxeWidth)
            yAxeWidth = fontMetrics.width(label);

    int i = 0;
    for (const QString &label : speedLabels) {
        QRectF labelRect(rect.topLeft() + QPointF(-yAxeWidth, (i++) * 0.25 * rect.height() - fontMetrics.height()),
                         QSizeF(2 * yAxeWidth, fontMetrics.height()));
        painter.drawText(labelRect, label, Qt::AlignRight | Qt::AlignTop);
    }

    // draw grid lines
    rect.adjust(yAxeWidth + 4, 0, 0, 0);

    QPen gridPen;
    gridPen.setStyle(Qt::DashLine);
    gridPen.setWidthF(1);
    gridPen.setColor(QColor(128, 128, 128, 128));
    painter.setPen(gridPen);

    painter.drawLine(fullRect.left(), rect.top(), rect.right(), rect.top());
    painter.drawLine(fullRect.left(), rect.top() + 0.25 * rect.height(), rect.right(), rect.top() + 0.25 * rect.height());
    painter.drawLine(fullRect.left(), rect.top() + 0.50 * rect.height(), rect.right(), rect.top() + 0.50 * rect.height());
    painter.drawLine(fullRect.left(), rect.top() + 0.75 * rect.height(), rect.right(), rect.top() + 0.75 * rect.height());
    painter.drawLine(fullRect.left(), rect.bottom(), rect.right(), rect.bottom());

    painter.drawLine(rect.left(), fullRect.top(), rect.left(), fullRect.bottom());
    painter.drawLine(rect.left() + 0.2 * rect.width(), fullRect.top(), rect.left() + 0.2 * rect.width(), fullRect.bottom());
    painter.drawLine(rect.left() + 0.4 * rect.width(), fullRect.top(), rect.left() + 0.4 * rect.width(), fullRect.bottom());
    painter.drawLine(rect.left() + 0.6 * rect.width(), fullRect.top(), rect.left() + 0.6 * rect.width(), fullRect.bottom());
    painter.drawLine(rect.left() + 0.8 * rect.width(), fullRect.top(), rect.left() + 0.8 * rect.width(), fullRect.bottom());

    // Set antialiasing for graphs
    painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing);

    // draw graphs
    rect.adjust(3, 0, 0, 0); // Need, else graphs cross left gridline

    double yMultiplier = (maxY == 0) ? 0.0 : static_cast<double>(rect.height()) / maxY;
    double xTickSize = static_cast<double>(rect.width()) / m_viewablePointsCount;

    boost::circular_buffer<PointData> &queue = getCurrentData();

    for (int id = UP; id < NB_GRAPHS; ++id) {

        if (!m_properties[static_cast<GraphID>(id)].enable)
            continue;

        QVector<QPoint> points;

        for (int i = int(queue.size()) - 1, j = 0; i >= 0 && j <= m_viewablePointsCount; --i, ++j) {

            int new_x = rect.right() - j * xTickSize;
            int new_y = rect.bottom() - queue[i].y[id] * yMultiplier;

            points.push_back(QPoint(new_x, new_y));
        }

        painter.setPen(m_properties[static_cast<GraphID>(id)].pen);
        painter.drawPolyline(points.data(), points.size());
    }

    // draw legend
    QPoint legendTopLeft(rect.left() + 4, fullRect.top() + 4);

    double legendHeight = 0;
    int legendWidth = 0;
    for (const auto &property : m_properties) {

        if (!property.enable)
            continue;

        if (fontMetrics.width(property.name) > legendWidth)
            legendWidth =  fontMetrics.width(property.name);
        legendHeight += 1.5 * fontMetrics.height();
    }

    QRectF legendBackgroundRect(QPoint(legendTopLeft.x() - 4, legendTopLeft.y() - 4), QSizeF(legendWidth + 8, legendHeight + 8));
    QColor legendBackgroundColor = QWidget::palette().color(QWidget::backgroundRole());
    legendBackgroundColor.setAlpha(128);  // 50% transparent
    painter.fillRect(legendBackgroundRect, legendBackgroundColor);

    i = 0;
    for (const auto &property : m_properties) {

        if (!property.enable)
            continue;

        int nameSize = fontMetrics.width(property.name);
        double indent = 1.5 * (i++) * fontMetrics.height();

        painter.setPen(property.pen);
        painter.drawLine(legendTopLeft + QPointF(0, indent + fontMetrics.height()),
                         legendTopLeft + QPointF(nameSize, indent + fontMetrics.height()));
        painter.drawText(QRectF(legendTopLeft + QPointF(0, indent), QSizeF(2 * nameSize, fontMetrics.height())),
                         property.name, QTextOption(Qt::AlignVCenter));
    }
}