From a97f2233903951caf187178195ef875a853f9709 Mon Sep 17 00:00:00 2001 From: David Skoland Date: Sat, 11 Feb 2017 11:18:57 +0100 Subject: [PATCH] added music playing, not properly tested --- Attorney_Online_remake.pro | 8 +++--- aomusicplayer.cpp | 52 ++++++++++++++++++++++++++++++++++++++ aomusicplayer.h | 23 +++++++++++++++++ aosfxplayer.cpp | 43 +++++++++++++++++++++++++++++-- aosfxplayer.h | 2 ++ courtroom.cpp | 3 ++- courtroom.h | 2 ++ lobby.cpp | 12 ++++++++- 8 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 aomusicplayer.cpp create mode 100644 aomusicplayer.h diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 1bde5d3..4c3f116 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -38,7 +38,8 @@ SOURCES += main.cpp\ aocharmovie.cpp \ aoemotebutton.cpp \ emotes.cpp \ - aosfxplayer.cpp + aosfxplayer.cpp \ + aomusicplayer.cpp HEADERS += lobby.h \ aoimage.h \ @@ -60,6 +61,7 @@ HEADERS += lobby.h \ aocharmovie.h \ aoemotebutton.h \ bass.h \ - aosfxplayer.h + aosfxplayer.h \ + aomusicplayer.h -unix:LIBS += -L/home/omnitroid/lib/bass_linux -lbass +unix:LIBS += -L/home/omnitroid/Project/Attorney_Online_2/src -lbass diff --git a/aomusicplayer.cpp b/aomusicplayer.cpp new file mode 100644 index 0000000..3881829 --- /dev/null +++ b/aomusicplayer.cpp @@ -0,0 +1,52 @@ +#include "aomusicplayer.h" + +#include + +#include + +AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app) +{ + m_parent = parent; + ao_app = p_ao_app; + + + BASS_Init(-1, 44100, BASS_DEVICE_LATENCY, 0, NULL); + + +} + +void AOMusicPlayer::play(QString p_song) +{ + + BASS_ChannelStop(m_stream); + + QString f_path = ao_app->get_music_path(p_song); + + m_stream = BASS_StreamCreateFile(FALSE, f_path.toStdString().c_str(), 0, 0, BASS_STREAM_PRESCAN); + + /* + if ((BASS_StreamPutFileData( + m_stream, + p_path.toStdString().c_str(), + BASS_FILEDATA_END + ) == -1)) + { + qDebug() << "BASS_StreamPutFileData failllled!"; + qDebug() << "Error: " << QString::number(BASS_ErrorGetCode()); + } + + if (m_stream == 0) + { + qDebug() << "OHSHIT something broke. error code: " << QString::number(BASS_ErrorGetCode()); + } + */ + + //m_stream = BASS_StreamCreateFileUser(STREAMFILE_BUFFERPUSH, BASS_STREAM_AUTOFREE, nullptr, p_path.toStdString().c_str()); + + if (BASS_ChannelPlay(m_stream, true)) + qDebug() <<"success."; + else + qDebug() <<"error"; + + qDebug() << QString::number(BASS_ErrorGetCode()); +} diff --git a/aomusicplayer.h b/aomusicplayer.h new file mode 100644 index 0000000..c3ce715 --- /dev/null +++ b/aomusicplayer.h @@ -0,0 +1,23 @@ +#ifndef AOMUSICPLAYER_H +#define AOMUSICPLAYER_H + +#include "bass.h" +#include "aoapplication.h" + +#include + +class AOMusicPlayer +{ +public: + AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app); + + void play(QString p_song); + +private: + QWidget *m_parent; + AOApplication *ao_app; + + HSTREAM m_stream; +}; + +#endif // AOMUSICPLAYER_H diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index 132b0bf..511a9a2 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -2,12 +2,51 @@ #include +#include + AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; - std::basic_string path = ao_app->get_sounds_path().toStdString() + "sfx-squee.wav"; - m_stream = BASS_StreamCreateFile(FALSE, path.c_str(), 0, 0, 0); + BASS_Init(-1, 44100, BASS_DEVICE_LATENCY, 0, NULL); + + +} + +void AOSfxPlayer::play(QString p_path) +{ + + BASS_Stop(); + + m_stream = BASS_StreamCreateFile(FALSE, p_path.toStdString().c_str(), 0, 0, BASS_STREAM_PRESCAN); + + /* + if ((BASS_StreamPutFileData( + m_stream, + p_path.toStdString().c_str(), + BASS_FILEDATA_END + ) == -1)) + { + qDebug() << "BASS_StreamPutFileData failllled!"; + qDebug() << "Error: " << QString::number(BASS_ErrorGetCode()); + } + + if (m_stream == 0) + { + qDebug() << "OHSHIT something broke. error code: " << QString::number(BASS_ErrorGetCode()); + } + */ + + //m_stream = BASS_StreamCreateFileUser(STREAMFILE_BUFFERPUSH, BASS_STREAM_AUTOFREE, nullptr, p_path.toStdString().c_str()); + + if (BASS_ChannelPlay(m_stream, true)) + qDebug() <<"success."; + else + qDebug() <<"error"; + + BASS_Start(); + + qDebug() << QString::number(BASS_ErrorGetCode()); } diff --git a/aosfxplayer.h b/aosfxplayer.h index 8e3a021..c704878 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -11,6 +11,8 @@ class AOSfxPlayer public: AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app); + void play(QString p_path); + private: QWidget *m_parent; AOApplication *ao_app; diff --git a/courtroom.cpp b/courtroom.cpp index d7f6ea7..d2a0599 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -31,6 +31,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() char_button_mapper = new QSignalMapper(this); sfx_player = new QSoundEffect(this); + music_player = new AOMusicPlayer(this, ao_app); ui_background = new AOImage(this, ao_app); @@ -1271,7 +1272,7 @@ void Courtroom::handle_song(QStringList *p_contents) if (f_contents.size() < 2) return; - //T0D0: add audio implementation + music_player->play(f_contents.at(0)); int n_char = f_contents.at(1).toInt(); diff --git a/courtroom.h b/courtroom.h index 6dc58d2..ea8c295 100644 --- a/courtroom.h +++ b/courtroom.h @@ -9,6 +9,7 @@ #include "aoscene.h" #include "aomovie.h" #include "aocharmovie.h" +#include "aomusicplayer.h" #include "datatypes.h" #include @@ -160,6 +161,7 @@ private: QString current_background = "gs4"; QSoundEffect *sfx_player; + AOMusicPlayer *music_player; AOImage *ui_background; diff --git a/lobby.cpp b/lobby.cpp index e73345c..e9ee7b3 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -3,6 +3,7 @@ #include "debug_functions.h" #include "aoapplication.h" #include "networkmanager.h" +#include "aosfxplayer.h" #include #include @@ -205,13 +206,22 @@ void Lobby::on_add_to_fav_pressed() void Lobby::on_add_to_fav_released() { - ui_add_to_fav->set_image("addtofav.png"); + AOSfxPlayer *sfx = new AOSfxPlayer(this, ao_app); + QString path = ao_app->get_music_path("Mystery Skulls - Money.mp3"); + + qDebug() << "path: " << path; + + sfx->play(path); + + ui_add_to_fav->set_image("addtofav.png"); + /* //you cant add favorites from favorites m8 if (!public_servers_selected) return; ao_app->add_favorite_server(ui_server_list->currentRow()); + */ } void Lobby::on_connect_pressed()