示例#1
0
void Engine::audioNotify()
{
    switch (m_mode) {
    case QAudio::AudioInput: {
            const qint64 recordPosition = qMin(m_bufferLength, audioLength(m_format, m_audioInput->processedUSecs()));
            setRecordPosition(recordPosition);
            const qint64 levelPosition = m_dataLength - m_levelBufferLength;
            if (levelPosition >= 0)
                calculateLevel(levelPosition, m_levelBufferLength);
            if (m_dataLength >= m_spectrumBufferLength) {
                const qint64 spectrumPosition = m_dataLength - m_spectrumBufferLength;
                calculateSpectrum(spectrumPosition);
            }
            emit bufferChanged(0, m_dataLength, m_buffer);
        }
        break;
    case QAudio::AudioOutput: {
            const qint64 playPosition = audioLength(m_format, m_audioOutput->processedUSecs());
            setPlayPosition(qMin(bufferLength(), playPosition));
            const qint64 levelPosition = playPosition - m_levelBufferLength;
            const qint64 spectrumPosition = playPosition - m_spectrumBufferLength;
            if (m_file) {
                if (levelPosition > m_bufferPosition ||
                    spectrumPosition > m_bufferPosition ||
                    qMax(m_levelBufferLength, m_spectrumBufferLength) > m_dataLength) {
                    m_bufferPosition = 0;
                    m_dataLength = 0;
                    // Data needs to be read into m_buffer in order to be analysed
                    const qint64 readPos = qMax(qint64(0), qMin(levelPosition, spectrumPosition));
                    const qint64 readEnd = qMin(m_analysisFile->size(), qMax(levelPosition + m_levelBufferLength, spectrumPosition + m_spectrumBufferLength));
                    const qint64 readLen = readEnd - readPos + audioLength(m_format, WaveformWindowDuration);
                    qDebug() << "Engine::audioNotify [1]"
                             << "analysisFileSize" << m_analysisFile->size()
                             << "readPos" << readPos
                             << "readLen" << readLen;
                    if (m_analysisFile->seek(readPos + m_analysisFile->headerLength())) {
                        m_buffer.resize(readLen);
                        m_bufferPosition = readPos;
                        m_dataLength = m_analysisFile->read(m_buffer.data(), readLen);
                        qDebug() << "Engine::audioNotify [2]" << "bufferPosition" << m_bufferPosition << "dataLength" << m_dataLength;
                    } else {
                        qDebug() << "Engine::audioNotify [2]" << "file seek error";
                    }
                    emit bufferChanged(m_bufferPosition, m_dataLength, m_buffer);
                }
            } else {
                if (playPosition >= m_dataLength)
                    stopPlayback();
            }
            if (levelPosition >= 0 && levelPosition + m_levelBufferLength < m_bufferPosition + m_dataLength)
                calculateLevel(levelPosition, m_levelBufferLength);
            if (spectrumPosition >= 0 && spectrumPosition + m_spectrumBufferLength < m_bufferPosition + m_dataLength)
                calculateSpectrum(spectrumPosition);
        }
        break;
    }
}
示例#2
0
void calculateLevel(AbstractAchievementItem::ItemType type,
                    int lastValue,
                    int currentValue,
                    int& levelFrom,
                    int& levelTo)
{
  levelFrom = calculateLevel(type, lastValue);
  levelTo = calculateLevel(type, currentValue);
}
示例#3
0
bool PlayerMonsterBook::addCard(int32_t cardid, uint8_t level, bool initialload) {
	if (m_cards.find(cardid) == m_cards.end()) {
		if (GameLogicUtilities::isSpecialCard(cardid)) {
			m_specialcount++;
		}
		else {
			m_normalcount++;
		}
	}

	if (initialload) {
		MonsterCard card = MonsterCard(cardid, level);
		m_cards[cardid] = card;
	}
	else {
		MonsterCard card = (m_cards.find(cardid) != m_cards.end() ? m_cards[cardid] : MonsterCard(cardid, 0));
		if (isFull(cardid)) {
			return true;
		}
		card.level++;
		m_cards[cardid] = card;
		if (card.level == 1) {
			calculateLevel();
		}
		return false;
	}
	return false;
}
示例#4
0
void Hero::addExperience(const int increaseBy)
{
	if (level < LEVEL_CAP)
	{
		experience = +increaseBy;
		calculateLevel();
	}
}
示例#5
0
void PlayerMonsterBook::load() {
	mysqlpp::Query query = Database::getCharDB().query();
	query << "SELECT cardid, level FROM monsterbook WHERE charid = " << m_player->getId() << " ORDER BY cardid ASC";
	mysqlpp::StoreQueryResult res = query.store();

	for (size_t i = 0; i < res.num_rows(); ++i) {
		addCard(res[i][0], (uint8_t) res[i][1], true);
	}

	calculateLevel();
}
示例#6
0
void SublevelNode::spectrumChanged(const FrequencySpectrum &spectrum)
{
    m_spectrum = spectrum;
    if (isActive()) {
        calculateLevel();
        // levelChanged signal is connected to the appropriate slot
        // in any subrangemeter widgets in SublevelNodeItem ctor
        float out;
        getValue("out", out);
        emit levelChanged(out);
    }
}
示例#7
0
void Achievements::statisticChanged(Statistic::StatisticType type,
                                    int lastValue,
                                    int currentValue)
{
  int levelFrom;
  int levelTo;
  AbstractAchievementItem::ItemType itemType = typeConvert(type);
  calculateLevel(itemType, lastValue, currentValue, levelFrom, levelTo);
  if (levelTo > levelFrom)
  {
    AbstractAchievementItem *item = getAchievementItem(itemType);
    if (item != NULL)
    {
      item->setPos(QPointF(MAX_X, -MAX_Y));
      items.push_back(item);
    }
  }
}
示例#8
0
int Achievements::getAchievementLevel(AbstractAchievementItem::ItemType type,
                                      int value)
{
  if (value == -1)
  {
    switch (type)
    {
    case AbstractAchievementItem::FlameGet:
      value = statistic.getStatistic(Statistic::FlameGetCount);
      break;
    case AbstractAchievementItem::StarGet:
      value = statistic.getStatistic(Statistic::StarGetCount);
      break;
    case AbstractAchievementItem::RotateClassic:
      value = statistic.getStatistic(Statistic::RotateClassicPoint);
      break;
    case AbstractAchievementItem::Timing:
      value = qMax(statistic.getStatistic(Statistic::SwapTimingPoint),
                   statistic.getStatistic(Statistic::RotateTimingPoint));
      break;
    case AbstractAchievementItem::RotatePuzzle:
      if (statistic.getStatistic(Statistic::RotatePuzzleFinished) == 0)
        value = 0;
      else if (statistic.getStatistic(Statistic::RotatePuzzleFinished) ==
               statistic.getStatistic(Statistic::RotatePuzzleTotal))
        value = 2;
      else
        value = 1;
      break;
    default:
      return 0;
      break;
    }
  }
  return calculateLevel(type, value);
}