aboutsummaryrefslogtreecommitdiff
path: root/src/aomusicplayer.cpp
diff options
context:
space:
mode:
authorCrystalwarrior <varsash@gmail.com>2019-09-20 22:11:37 +0300
committerCrystalwarrior <varsash@gmail.com>2019-09-20 22:11:37 +0300
commit842b829bee8b840149c0042bb7adfc3bda6eec9d (patch)
treec6ce50d4cbeb8d83aaf061c8b252bc6fcb942485 /src/aomusicplayer.cpp
parent497901e8c361326770e88e8a01daa7891b6a16e1 (diff)
Tweak the ambience/crosfade layer to fade in regardless of another sample being there
Fix music not being looped sometimes Prevent channel less than 0 from being passed Set up a new music display element with an attached music name, it displays a scrolling text of the currently playing music Fix music packet processing issues Make SFX slider responsible for all music channels besides 0 (actual music) scrolltext.cpp code recipe was taken from https://stackoverflow.com/questions/10651514/text-scrolling-marquee-in-qlabel - thanks to leemes for that one, I only adapted it for newer C++ version and tweaked some stuff.
Diffstat (limited to 'src/aomusicplayer.cpp')
-rw-r--r--src/aomusicplayer.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp
index f6bcb17a..c845948c 100644
--- a/src/aomusicplayer.cpp
+++ b/src/aomusicplayer.cpp
@@ -18,6 +18,8 @@ AOMusicPlayer::~AOMusicPlayer()
void AOMusicPlayer::play(QString p_song, int channel, bool crossfade)
{
channel = channel % m_channelmax;
+ if (channel < 0) //wtf?
+ return;
QString f_path = ao_app->get_music_path(p_song);
// QString d_path = f_path + ".txt";
@@ -39,27 +41,33 @@ void AOMusicPlayer::play(QString p_song, int channel, bool crossfade)
// }
unsigned int flags = BASS_STREAM_PRESCAN | BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE;
+ if (m_looping)
+ flags |= BASS_SAMPLE_LOOP;
DWORD newstream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, flags);
if (ao_app->get_audio_output_device() != "default")
BASS_ChannelSetDevice(m_stream_list[channel], BASS_GetDevice());
- if (BASS_ChannelIsActive(m_stream_list[channel]) == BASS_ACTIVE_PLAYING && crossfade)
+ if (crossfade)
{
DWORD oldstream = m_stream_list[channel];
-
- //Fade out the other sample and stop it
- BASS_ChannelSlideAttribute(oldstream, BASS_ATTRIB_VOL|BASS_SLIDE_LOG, -1, 5000);
- BASS_ChannelLock(oldstream, true);
//Mute the new sample
BASS_ChannelSetAttribute(newstream, BASS_ATTRIB_VOL, 0);
- //Sync it with the new sample
- BASS_ChannelSetPosition(newstream, BASS_ChannelGetPosition(oldstream, BASS_POS_BYTE), BASS_POS_BYTE);
+ //Crossfade time
+ if (BASS_ChannelIsActive(oldstream) == BASS_ACTIVE_PLAYING)
+ {
+ //Fade out the other sample and stop it
+ BASS_ChannelSlideAttribute(oldstream, BASS_ATTRIB_VOL|BASS_SLIDE_LOG, -1, 5000);
+ BASS_ChannelLock(oldstream, true);
+ //Sync it with the new sample
+ BASS_ChannelSetPosition(newstream, BASS_ChannelGetPosition(oldstream, BASS_POS_BYTE), BASS_POS_BYTE);
+ BASS_ChannelLock(oldstream, false);
+ }
//Start it
BASS_ChannelPlay(newstream, false);
//Fade in our sample
BASS_ChannelSlideAttribute(newstream, BASS_ATTRIB_VOL, static_cast<float>(m_volume / 100.0f), 1000);
- BASS_ChannelLock(oldstream, false);
+
m_stream_list[channel] = newstream;
}
else
@@ -67,7 +75,7 @@ void AOMusicPlayer::play(QString p_song, int channel, bool crossfade)
BASS_ChannelStop(m_stream_list[channel]);
m_stream_list[channel] = newstream;
BASS_ChannelPlay(m_stream_list[channel], false);
- this->set_volume(m_volume);
+ this->set_volume(m_volume, channel);
}
this->set_looping(m_looping); //Have to do this here due to any crossfading-related changes, etc.
@@ -82,7 +90,17 @@ void AOMusicPlayer::set_volume(int p_value, int channel)
{
m_volume = p_value;
float volume = m_volume / 100.0f;
- BASS_ChannelSetAttribute(m_stream_list[channel], BASS_ATTRIB_VOL, volume);
+ if (channel < 0)
+ {
+ for (int n_stream = 0 ; n_stream < m_channelmax ; ++n_stream)
+ {
+ BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume);
+ }
+ }
+ else
+ {
+ BASS_ChannelSetAttribute(m_stream_list[channel], BASS_ATTRIB_VOL, volume);
+ }
}
//void CALLBACK loopProc(HSYNC handle, DWORD channel, DWORD data, void *user)