fix qt sfx player
This commit is contained in:
		
							parent
							
								
									7a7dd25459
								
							
						
					
					
						commit
						e81fac7e07
					
				@ -35,11 +35,12 @@ private:
 | 
				
			|||||||
  bool m_looping = true;
 | 
					  bool m_looping = true;
 | 
				
			||||||
  void set_volume_internal(qreal p_volume);
 | 
					  void set_volume_internal(qreal p_volume);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(BASSAUDIO)
 | 
					 | 
				
			||||||
  const int m_channelmax = 5;
 | 
					  const int m_channelmax = 5;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if defined(BASSAUDIO)
 | 
				
			||||||
  HSTREAM m_stream_list[5];
 | 
					  HSTREAM m_stream_list[5];
 | 
				
			||||||
#elif defined(QTAUDIO)
 | 
					#elif defined(QTAUDIO)
 | 
				
			||||||
  QSoundEffect m_sfx;
 | 
					  QSoundEffect m_stream_list[5];
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -114,9 +114,26 @@ void AOSfxPlayer::set_looping(bool toggle, int channel)
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
#elif defined(QTAUDIO) // Using Qt's QSoundEffect class
 | 
					#elif defined(QTAUDIO) // Using Qt's QSoundEffect class
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout)
 | 
					void AOSfxPlayer::clear()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  m_sfx.stop();
 | 
					  for (int n_stream = 0; n_stream < m_channelmax; ++n_stream) {
 | 
				
			||||||
 | 
					    m_stream_list[n_stream].stop();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  set_volume_internal(m_volume);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOSfxPlayer::loop_clear()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  for (int n_stream = 0; n_stream < m_channelmax; ++n_stream) {
 | 
				
			||||||
 | 
					    m_stream_list[n_stream].stop();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  set_volume_internal(m_volume);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout,
 | 
				
			||||||
 | 
					                       int channel)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  m_stream_list[channel].stop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  QString misc_path = "";
 | 
					  QString misc_path = "";
 | 
				
			||||||
  QString char_path = "";
 | 
					  QString char_path = "";
 | 
				
			||||||
@ -138,15 +155,21 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  if (file_exists(f_path)) // if its missing, it will glitch out
 | 
					  if (file_exists(f_path)) // if its missing, it will glitch out
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    m_sfx.setSource(QUrl::fromLocalFile(f_path));
 | 
					    m_stream_list[channel].setSource(QUrl::fromLocalFile(f_path));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    set_volume_internal(m_volume);
 | 
					    set_volume_internal(m_volume);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_sfx.play();
 | 
					    m_stream_list[channel].play();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AOSfxPlayer::stop() { m_sfx.stop(); }
 | 
					void AOSfxPlayer::stop(int channel)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (channel == -1) {
 | 
				
			||||||
 | 
					    channel = m_channel;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  m_stream_list[channel].stop();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AOSfxPlayer::set_volume(qreal p_value)
 | 
					void AOSfxPlayer::set_volume(qreal p_value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -156,8 +179,19 @@ void AOSfxPlayer::set_volume(qreal p_value)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void AOSfxPlayer::set_volume_internal(qreal p_value)
 | 
					void AOSfxPlayer::set_volume_internal(qreal p_value)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  m_volume = p_value;
 | 
					  float volume = static_cast<float>(p_value);
 | 
				
			||||||
  m_sfx.setVolume(m_volume);
 | 
					  for (int n_stream = 0; n_stream < m_channelmax; ++n_stream) {
 | 
				
			||||||
 | 
					    m_stream_list[n_stream].setVolume(volume);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOSfxPlayer::set_looping(bool toggle, int channel)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (channel == -1) {
 | 
				
			||||||
 | 
					    channel = m_channel;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  m_looping = toggle;
 | 
				
			||||||
 | 
					  // TODO
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
void AOSfxPlayer::clear() {}
 | 
					void AOSfxPlayer::clear() {}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user