refactored sound

This commit is contained in:
David Skoland 2017-02-14 21:00:02 +01:00
parent 267fe47c5f
commit 7c20ad7292
12 changed files with 55 additions and 23 deletions

View File

@ -10,7 +10,7 @@ AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app)
ao_app = p_ao_app; ao_app = p_ao_app;
} }
void AOBlipPlayer::set_blips(QString p_sfx, int p_volume) void AOBlipPlayer::set_blips(QString p_sfx)
{ {
QString f_path = ao_app->get_sounds_path() + p_sfx; QString f_path = ao_app->get_sounds_path() + p_sfx;
@ -21,7 +21,7 @@ void AOBlipPlayer::set_blips(QString p_sfx, int p_volume)
m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.toStdString().c_str(), 0, 0, 0); m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.toStdString().c_str(), 0, 0, 0);
} }
set_volume(p_volume); set_volume(m_volume);
} }
void AOBlipPlayer::blip_tick() void AOBlipPlayer::blip_tick()
@ -38,6 +38,8 @@ void AOBlipPlayer::blip_tick()
void AOBlipPlayer::set_volume(int p_value) void AOBlipPlayer::set_volume(int p_value)
{ {
m_volume = p_value;
float volume = p_value / 100.0f; float volume = p_value / 100.0f;
for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) for (int n_stream = 0 ; n_stream < 5 ; ++n_stream)

View File

@ -11,7 +11,7 @@ class AOBlipPlayer
public: public:
AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app); AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app);
void set_blips(QString p_sfx, int p_volume); void set_blips(QString p_sfx);
void blip_tick(); void blip_tick();
void set_volume(int p_volume); void set_volume(int p_volume);
@ -21,6 +21,7 @@ private:
QWidget *m_parent; QWidget *m_parent;
AOApplication *ao_app; AOApplication *ao_app;
int m_volume;
HSTREAM m_stream_list[5]; HSTREAM m_stream_list[5];
}; };

View File

@ -25,3 +25,8 @@ void AOEvidenceButton::set_image(QString p_image)
this->setStyleSheet(""); this->setStyleSheet("");
} }
} }
void AOEvidenceButton::on_clicked()
{
evidence_clicked(m_id);
}

View File

@ -20,6 +20,12 @@ private:
AOApplication *ao_app; AOApplication *ao_app;
int m_id; int m_id;
signals:
void evidence_clicked(int p_id);
private slots:
void on_clicked();
}; };
#endif // AOEVIDENCEBUTTON_H #endif // AOEVIDENCEBUTTON_H

View File

@ -15,7 +15,7 @@ AOMusicPlayer::~AOMusicPlayer()
BASS_ChannelStop(m_stream); BASS_ChannelStop(m_stream);
} }
void AOMusicPlayer::play(QString p_song, int p_volume) void AOMusicPlayer::play(QString p_song)
{ {
BASS_ChannelStop(m_stream); BASS_ChannelStop(m_stream);
@ -23,14 +23,16 @@ void AOMusicPlayer::play(QString p_song, int p_volume)
m_stream = BASS_StreamCreateFile(FALSE, f_path.toStdString().c_str(), 0, 0, BASS_STREAM_AUTOFREE); m_stream = BASS_StreamCreateFile(FALSE, f_path.toStdString().c_str(), 0, 0, BASS_STREAM_AUTOFREE);
this->set_volume(p_volume); this->set_volume(m_volume);
BASS_ChannelPlay(m_stream, false); BASS_ChannelPlay(m_stream, false);
} }
void AOMusicPlayer::set_volume(int p_value) void AOMusicPlayer::set_volume(int p_value)
{ {
float volume = p_value / 100.0f; m_volume = p_value;
float volume = m_volume / 100.0f;
BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume);

View File

@ -12,13 +12,14 @@ public:
AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app); AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app);
~AOMusicPlayer(); ~AOMusicPlayer();
void play(QString p_song, int p_volume); void play(QString p_song);
void set_volume(int p_value); void set_volume(int p_value);
private: private:
QWidget *m_parent; QWidget *m_parent;
AOApplication *ao_app; AOApplication *ao_app;
int m_volume = 0;
HSTREAM m_stream; HSTREAM m_stream;
}; };

View File

@ -10,7 +10,7 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app)
ao_app = p_ao_app; ao_app = p_ao_app;
} }
void AOSfxPlayer::play(QString p_sfx, int p_volume, QString p_char) void AOSfxPlayer::play(QString p_sfx, QString p_char)
{ {
BASS_ChannelStop(m_stream); BASS_ChannelStop(m_stream);
@ -23,13 +23,15 @@ void AOSfxPlayer::play(QString p_sfx, int p_volume, QString p_char)
m_stream = BASS_StreamCreateFile(FALSE, f_path.toStdString().c_str(), 0, 0, BASS_STREAM_AUTOFREE); m_stream = BASS_StreamCreateFile(FALSE, f_path.toStdString().c_str(), 0, 0, BASS_STREAM_AUTOFREE);
set_volume(p_volume); set_volume(m_volume);
BASS_ChannelPlay(m_stream, false); BASS_ChannelPlay(m_stream, false);
} }
void AOSfxPlayer::set_volume(int p_value) void AOSfxPlayer::set_volume(int p_value)
{ {
m_volume = p_value;
float volume = p_value / 100.0f; float volume = p_value / 100.0f;
BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume);

View File

@ -11,13 +11,14 @@ class AOSfxPlayer
public: public:
AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app); AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app);
void play(QString p_sfx, int p_volume, QString p_char = ""); void play(QString p_sfx, QString p_char = "");
void set_volume(int p_volume); void set_volume(int p_volume);
private: private:
QWidget *m_parent; QWidget *m_parent;
AOApplication *ao_app; AOApplication *ao_app;
int m_volume = 0;
HSTREAM m_stream; HSTREAM m_stream;
}; };

View File

@ -599,6 +599,10 @@ void Courtroom::done_received()
{ {
m_cid = -1; m_cid = -1;
music_player->set_volume(0);
sfx_player->set_volume(0);
blip_player->set_volume(0);
set_char_select_page(); set_char_select_page();
set_mute_list(); set_mute_list();
@ -971,20 +975,20 @@ void Courtroom::handle_chatmessage(QStringList *p_contents)
{ {
case 1: case 1:
ui_vp_objection->play("holdit"); ui_vp_objection->play("holdit");
sfx_player->play("holdit.wav", ui_sfx_slider->value(), m_chatmessage[CHAR_NAME]); sfx_player->play("holdit.wav", m_chatmessage[CHAR_NAME]);
break; break;
case 2: case 2:
ui_vp_objection->play("objection"); ui_vp_objection->play("objection");
sfx_player->play("objection.wav", ui_sfx_slider->value(), m_chatmessage[CHAR_NAME]); sfx_player->play("objection.wav", m_chatmessage[CHAR_NAME]);
break; break;
case 3: case 3:
ui_vp_objection->play("takethat"); ui_vp_objection->play("takethat");
sfx_player->play("takethat.wav", ui_sfx_slider->value(), m_chatmessage[CHAR_NAME]); sfx_player->play("takethat.wav", m_chatmessage[CHAR_NAME]);
break; break;
//case 4 is AO2 only //case 4 is AO2 only
case 4: case 4:
ui_vp_objection->play("custom", m_chatmessage[CHAR_NAME]); ui_vp_objection->play("custom", m_chatmessage[CHAR_NAME]);
sfx_player->play("custom.wav", ui_sfx_slider->value(), m_chatmessage[CHAR_NAME]); sfx_player->play("custom.wav", m_chatmessage[CHAR_NAME]);
break; break;
default: default:
qDebug() << "W: Logic error in objection switch statement!"; qDebug() << "W: Logic error in objection switch statement!";
@ -1102,7 +1106,7 @@ void Courtroom::handle_chatmessage_3()
{ {
realization_timer->start(60); realization_timer->start(60);
ui_vp_realization->show(); ui_vp_realization->show();
sfx_player->play("sfx-realization.wav", ui_sfx_slider->value()); sfx_player->play("sfx-realization.wav");
} }
} }
@ -1179,7 +1183,7 @@ void Courtroom::start_chat_ticking()
QString f_gender = ao_app->get_gender(m_chatmessage[CHAR_NAME]); QString f_gender = ao_app->get_gender(m_chatmessage[CHAR_NAME]);
blip_player->set_blips("sfx-blip" + f_gender + ".wav", ui_blip_slider->value()); blip_player->set_blips("sfx-blip" + f_gender + ".wav");
//means text is currently ticking //means text is currently ticking
text_state = 1; text_state = 1;
@ -1246,7 +1250,7 @@ void Courtroom::play_sfx()
if (sfx_name == "1") if (sfx_name == "1")
return; return;
sfx_player->play(sfx_name + ".wav", ui_sfx_slider->value()); sfx_player->play(sfx_name + ".wav");
//T0D0: add audio implementation //T0D0: add audio implementation
//QString sfx_name = m_chatmessage[SFX_NAME]; //QString sfx_name = m_chatmessage[SFX_NAME];
@ -1399,7 +1403,7 @@ void Courtroom::handle_song(QStringList *p_contents)
if (f_contents.size() < 2) if (f_contents.size() < 2)
return; return;
music_player->play(f_contents.at(0), ui_music_slider->value()); music_player->play(f_contents.at(0));
int n_char = f_contents.at(1).toInt(); int n_char = f_contents.at(1).toInt();
@ -1412,7 +1416,7 @@ void Courtroom::handle_wtce(QString p_wtce)
//witness testimony //witness testimony
if (p_wtce == "testimony1") if (p_wtce == "testimony1")
{ {
sfx_player->play("sfx-testimony2.wav", ui_sfx_slider->value()); sfx_player->play("sfx-testimony2.wav");
ui_vp_wtce->play("witnesstestimony"); ui_vp_wtce->play("witnesstestimony");
testimony_in_progress = true; testimony_in_progress = true;
show_testimony(); show_testimony();
@ -1420,7 +1424,7 @@ void Courtroom::handle_wtce(QString p_wtce)
//cross examination //cross examination
else if (p_wtce == "testimony2") else if (p_wtce == "testimony2")
{ {
sfx_player->play("sfx-testimony.wav", ui_sfx_slider->value()); sfx_player->play("sfx-testimony.wav");
ui_vp_wtce->play("crossexamination"); ui_vp_wtce->play("crossexamination");
testimony_in_progress = false; testimony_in_progress = false;
} }
@ -1447,7 +1451,7 @@ void Courtroom::mod_called(QString p_ip)
{ {
ui_server_chatlog->appendPlainText(p_ip); ui_server_chatlog->appendPlainText(p_ip);
if (ui_guard->isChecked()) if (ui_guard->isChecked())
modcall_player->play("sfx-gallery.wav", 50); modcall_player->play("sfx-gallery.wav");
} }
void Courtroom::on_ooc_return_pressed() void Courtroom::on_ooc_return_pressed()

View File

@ -326,6 +326,7 @@ private slots:
void on_music_list_double_clicked(QModelIndex p_model); void on_music_list_double_clicked(QModelIndex p_model);
void on_emote_clicked(int p_id); void on_emote_clicked(int p_id);
void on_evidence_clicked(int p_id);
void on_emote_left_clicked(); void on_emote_left_clicked();
void on_emote_right_clicked(); void on_emote_right_clicked();

View File

@ -37,7 +37,7 @@ void Courtroom::construct_emotes()
++x_mod_count; ++x_mod_count;
//if emote number is divisible by columns with rest columns -1 then the next emote button should start on a new line //if emote number is divisible by columns with rest columns -1 then the next emote button should start on a new line
if ((n % emote_columns) == (emote_columns - 1) && (n != 0)) if (x_mod_count == emote_columns)
{ {
++y_mod_count; ++y_mod_count;
x_mod_count = 0; x_mod_count = 0;

View File

@ -34,7 +34,7 @@ void Courtroom::construct_evidence()
f_evidence->set_id(n); f_evidence->set_id(n);
//connect(f_evidence, SIGNAL(evidence_clicked(int)), this, SLOT(on_evidence_clicked(int))); connect(f_evidence, SIGNAL(evidence_clicked(int)), this, SLOT(on_evidence_clicked(int)));
++x_mod_count; ++x_mod_count;
@ -45,3 +45,10 @@ void Courtroom::construct_evidence()
} }
} }
} }
void Courtroom::on_evidence_clicked(int p_id)
{
}