Esempio n. 1
0
CWaveFile *CSound::loadSound(const CString &name) {
	checkSounds();

	// Check whether an entry for the given name is already active
	for (CSoundItemList::iterator i = _sounds.begin(); i != _sounds.end(); ++i) {
		CSoundItem *soundItem = *i;
		if (soundItem->_name == name) {
			// Found it, so move it to the front of the list and return
			_sounds.remove(soundItem);
			_sounds.push_front(soundItem);
			return soundItem->_waveFile;
		}
	}

	// Create new sound item
	CSoundItem *soundItem = new CSoundItem(name);
	soundItem->_waveFile = _soundManager.loadSound(name);

	if (!soundItem->_waveFile) {
		// Couldn't load sound, so destroy new item and return
		delete soundItem;
		return 0;
	}

	// Add the item to the list of sounds
	_sounds.push_front(soundItem);

	// If there are more than 10 sounds loaded, remove the last one,
	// which is the least recently used of all of them
	if (_sounds.size() > 10)
		removeOldest();

	return soundItem->_waveFile;
}
Esempio n. 2
0
CWaveFile *CSound::loadSpeech(CDialogueFile *dialogueFile, int speechId) {
	checkSounds();

	// Check whether an entry for the given name is already active
	for (CSoundItemList::iterator i = _sounds.begin(); i != _sounds.end(); ++i) {
		CSoundItem *soundItem = *i;
		if (soundItem->_dialogueFileHandle == dialogueFile->getFile()
				&& soundItem->_speechId == speechId) {
			// Found it, so move it to the front of the list and return
			_sounds.remove(soundItem);
			_sounds.push_front(soundItem);
			return soundItem->_waveFile;
		}
	}

	// Create new sound item
	CSoundItem *soundItem = new CSoundItem(dialogueFile->getFile(), speechId);
	soundItem->_waveFile = _soundManager.loadSpeech(dialogueFile, speechId);

	if (!soundItem->_waveFile) {
		// Couldn't load speech, so destroy new item and return
		delete soundItem;
		return 0;
	}

	// Add the item to the list of sounds
	_sounds.push_front(soundItem);

	// If there are more than 10 sounds loaded, remove the last one,
	// which is the least recently used of all of them
	if (_sounds.size() > 10)
		removeOldest();

	return soundItem->_waveFile;
}
Esempio n. 3
0
void FMCSounds::slotCheckSoundsTimer()
{
    if (!m_flightstatus->isValid() || m_flightstatus->paused || m_flightstatus->slew)
    {
        if (m_sound_map.contains(CFG_SOUNDS_ALT_ALERT_CONT) &&
            m_sound_map[CFG_SOUNDS_ALT_ALERT_CONT]->hasPlayed())
            m_sound_map[CFG_SOUNDS_ALT_ALERT_CONT]->stop();

        if (m_sound_map.contains(CFG_SOUNDS_STALL) &&
            m_sound_map[CFG_SOUNDS_STALL]->hasPlayed())
            m_sound_map[CFG_SOUNDS_STALL]->stop();

        if (m_sound_map.contains(CFG_SOUNDS_OVERSPEED) &&
            m_sound_map[CFG_SOUNDS_OVERSPEED]->hasPlayed())
            m_sound_map[CFG_SOUNDS_OVERSPEED]->stop();

        if (m_flightstatus->paused || m_flightstatus->slew) return;
    }

    if (m_refresh_timer.elapsed() < m_sounds_cfg->getIntValue(CFG_SOUNDS_REFRESH_PERIOD_MS)) return;
    m_refresh_timer.start();

    // check for sounds to play

    checkBaseSounds();
    checkSounds();

    // check sound queue

    int index = FMCSoundBase::SOUND_SOURCE_UNKNOWN;
    for (; index <= FMCSoundBase::SOUND_SOURCE_OTHER_PILOT; ++index)
    {
        FMCSoundBase::SOUND_SOURCE sound_source_index = (FMCSoundBase::SOUND_SOURCE)index;

        while(!m_sound_queue_map[sound_source_index].isEmpty())
        {
            QString sound_name = m_sound_queue_map[sound_source_index][0];

            if (!m_sound_map[sound_name]->hasPlayed())
            {
                //Logger::log(QString("FMCSounds:slotCheckSoundsTimer: playing (%1) from queue").
                //arg(sound_name));
                
                m_sound_map[sound_name]->play();
                break;
            }
            else
            {
                if (!m_sound_map[sound_name]->isFinished()) break;
                
                //Logger::log(QString("FMCSounds:slotCheckSoundsTimer: removing (%1) from queue").
                //arg(sound_name));
                
                m_sound_map[sound_name]->stop();
                m_sound_queue_map[sound_source_index].removeFirst();

                if (m_sound_map[sound_name]->doDeleteSoundAfterPlayed())
                {
                    delete m_sound_map[sound_name];
                    m_sound_map.remove(sound_name);
                }
            }
        }
    }

    // set history values

    m_prev_flaps_notch = m_flightstatus->current_flap_lever_notch;
    m_prev_alt_ft = m_flightstatus->smoothedAltimeterReadout();
}