Bass.dll functionality-based clientside music looping system by using channel loopable flags (no use of QTimer required)
Implement Goofball's AOV loopable music server message where any value that's not -1 when the length of the handle_message packet is longer than 3 will not loop the music (still confused about this but w/e)
This commit is contained in:
parent
f9b3bd5bb5
commit
1139bf5cd0
@ -17,15 +17,18 @@ class AOMusicPlayer
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app);
|
AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app);
|
||||||
~AOMusicPlayer();
|
virtual ~AOMusicPlayer();
|
||||||
|
|
||||||
void play(QString p_song);
|
void play(QString p_song);
|
||||||
|
void stop();
|
||||||
void set_volume(int p_value);
|
void set_volume(int p_value);
|
||||||
|
void set_looping(bool toggle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *m_parent;
|
QWidget *m_parent;
|
||||||
AOApplication *ao_app;
|
AOApplication *ao_app;
|
||||||
|
|
||||||
|
bool m_looping = true;
|
||||||
int m_volume = 0;
|
int m_volume = 0;
|
||||||
HSTREAM m_stream;
|
HSTREAM m_stream;
|
||||||
};
|
};
|
||||||
|
@ -17,22 +17,42 @@ void AOMusicPlayer::play(QString p_song)
|
|||||||
BASS_ChannelStop(m_stream);
|
BASS_ChannelStop(m_stream);
|
||||||
|
|
||||||
QString f_path = ao_app->get_music_path(p_song);
|
QString f_path = ao_app->get_music_path(p_song);
|
||||||
|
unsigned int flags = BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE;
|
||||||
m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE);
|
m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, flags);
|
||||||
|
|
||||||
this->set_volume(m_volume);
|
this->set_volume(m_volume);
|
||||||
|
this->set_looping(m_looping);
|
||||||
if (ao_app->get_audio_output_device() != "default")
|
if (ao_app->get_audio_output_device() != "default")
|
||||||
BASS_ChannelSetDevice(m_stream, BASS_GetDevice());
|
BASS_ChannelSetDevice(m_stream, BASS_GetDevice());
|
||||||
BASS_ChannelPlay(m_stream, false);
|
BASS_ChannelPlay(m_stream, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOMusicPlayer::stop()
|
||||||
|
{
|
||||||
|
BASS_ChannelStop(m_stream);
|
||||||
|
}
|
||||||
|
|
||||||
void AOMusicPlayer::set_volume(int p_value)
|
void AOMusicPlayer::set_volume(int p_value)
|
||||||
{
|
{
|
||||||
m_volume = p_value;
|
m_volume = p_value;
|
||||||
float volume = m_volume / 100.0f;
|
float volume = m_volume / 100.0f;
|
||||||
BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume);
|
BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AOMusicPlayer::set_looping(bool toggle)
|
||||||
|
{
|
||||||
|
m_looping = toggle;
|
||||||
|
if (BASS_ChannelFlags(m_stream, 0, 0) & BASS_SAMPLE_LOOP)
|
||||||
|
{
|
||||||
|
if (m_looping == false)
|
||||||
|
BASS_ChannelFlags(m_stream, 0, BASS_SAMPLE_LOOP); // remove the LOOP flag
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_looping == true)
|
||||||
|
BASS_ChannelFlags(m_stream, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP); // set the LOOP flag
|
||||||
|
}
|
||||||
|
}
|
||||||
#elif defined(QTAUDIO)
|
#elif defined(QTAUDIO)
|
||||||
AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
|
AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
|
||||||
{
|
{
|
||||||
|
@ -2615,9 +2615,25 @@ void Courtroom::handle_song(QStringList *p_contents)
|
|||||||
QString str_show = char_list.at(n_char).name;
|
QString str_show = char_list.at(n_char).name;
|
||||||
|
|
||||||
if (p_contents->length() > 2)
|
if (p_contents->length() > 2)
|
||||||
|
{
|
||||||
|
if(p_contents->at(2) != "")
|
||||||
{
|
{
|
||||||
str_show = p_contents->at(2);
|
str_show = p_contents->at(2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (p_contents->length() > 3)
|
||||||
|
{
|
||||||
|
//I am really confused why "-1" is "loop this song" and why anything else passes as "don't loop"
|
||||||
|
//(if we even have this length) but alright
|
||||||
|
if(p_contents->at(3) != "-1")
|
||||||
|
{
|
||||||
|
music_player->set_looping(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
music_player->set_looping(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!mute_map.value(n_char))
|
if (!mute_map.value(n_char))
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user