added music playing, not properly tested

This commit is contained in:
David Skoland 2017-02-11 11:18:57 +01:00
parent 0fb38b5573
commit a97f223390
8 changed files with 138 additions and 7 deletions

View File

@ -38,7 +38,8 @@ SOURCES += main.cpp\
aocharmovie.cpp \ aocharmovie.cpp \
aoemotebutton.cpp \ aoemotebutton.cpp \
emotes.cpp \ emotes.cpp \
aosfxplayer.cpp aosfxplayer.cpp \
aomusicplayer.cpp
HEADERS += lobby.h \ HEADERS += lobby.h \
aoimage.h \ aoimage.h \
@ -60,6 +61,7 @@ HEADERS += lobby.h \
aocharmovie.h \ aocharmovie.h \
aoemotebutton.h \ aoemotebutton.h \
bass.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

52
aomusicplayer.cpp Normal file
View File

@ -0,0 +1,52 @@
#include "aomusicplayer.h"
#include <string.h>
#include <QDebug>
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());
}

23
aomusicplayer.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef AOMUSICPLAYER_H
#define AOMUSICPLAYER_H
#include "bass.h"
#include "aoapplication.h"
#include <QWidget>
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

View File

@ -2,12 +2,51 @@
#include <string.h> #include <string.h>
#include <QDebug>
AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app)
{ {
m_parent = parent; m_parent = parent;
ao_app = p_ao_app; ao_app = p_ao_app;
std::basic_string<char> 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());
} }

View File

@ -11,6 +11,8 @@ class AOSfxPlayer
public: public:
AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app); AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app);
void play(QString p_path);
private: private:
QWidget *m_parent; QWidget *m_parent;
AOApplication *ao_app; AOApplication *ao_app;

View File

@ -31,6 +31,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow()
char_button_mapper = new QSignalMapper(this); char_button_mapper = new QSignalMapper(this);
sfx_player = new QSoundEffect(this); sfx_player = new QSoundEffect(this);
music_player = new AOMusicPlayer(this, ao_app);
ui_background = new AOImage(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) if (f_contents.size() < 2)
return; return;
//T0D0: add audio implementation music_player->play(f_contents.at(0));
int n_char = f_contents.at(1).toInt(); int n_char = f_contents.at(1).toInt();

View File

@ -9,6 +9,7 @@
#include "aoscene.h" #include "aoscene.h"
#include "aomovie.h" #include "aomovie.h"
#include "aocharmovie.h" #include "aocharmovie.h"
#include "aomusicplayer.h"
#include "datatypes.h" #include "datatypes.h"
#include <QMainWindow> #include <QMainWindow>
@ -160,6 +161,7 @@ private:
QString current_background = "gs4"; QString current_background = "gs4";
QSoundEffect *sfx_player; QSoundEffect *sfx_player;
AOMusicPlayer *music_player;
AOImage *ui_background; AOImage *ui_background;

View File

@ -3,6 +3,7 @@
#include "debug_functions.h" #include "debug_functions.h"
#include "aoapplication.h" #include "aoapplication.h"
#include "networkmanager.h" #include "networkmanager.h"
#include "aosfxplayer.h"
#include <QDebug> #include <QDebug>
#include <QScrollBar> #include <QScrollBar>
@ -205,13 +206,22 @@ void Lobby::on_add_to_fav_pressed()
void Lobby::on_add_to_fav_released() 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 //you cant add favorites from favorites m8
if (!public_servers_selected) if (!public_servers_selected)
return; return;
ao_app->add_favorite_server(ui_server_list->currentRow()); ao_app->add_favorite_server(ui_server_list->currentRow());
*/
} }
void Lobby::on_connect_pressed() void Lobby::on_connect_pressed()