Skip to content
This repository has been archived by the owner on Aug 26, 2020. It is now read-only.

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
3vi1 committed Sep 17, 2017
2 parents 73752dc + 055db1b commit 3c0348a
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 126 deletions.
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
You will need the following dependencies (Ubuntu, Debian):

sudo apt-get update -qq
sudo apt-get install -y build-essential g++ qt5-default qt5-qmake qtmultimedia5-dev libqt5xmlpatterns5-dev libqt5svg5-dev qttools5-dev-tools
sudo apt-get install -y build-essential g++ qt5-default qt5-qmake qtmultimedia5-dev libqt5xmlpatterns5-dev libqt5svg5-dev qttools5-dev-tools libsfml-dev

# Compiling on Linux

Expand Down
9 changes: 9 additions & 0 deletions docs/RELEASES
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.9.7 - Switched to SFML/OpenAL for the audio engine. WAV,
OGG/Vorbis and FLAC sounds are currently supported. MP3
is not yet supported due to licensing issues with the
underlying library, but I expect it to be implemented in
the near future now that the patents have expired.



0.9.6 - Fixes following for users of the German-language client.

Fix KOS check bug for some corps where there are partial
Expand Down Expand Up @@ -397,3 +405,4 @@ Coming soon:
- Don't cache every potential sound.
- Add queue-play option to queue sounds.
- Reload internal list when rules updated.
- Doublecheck windows file update hook
172 changes: 99 additions & 73 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "audio.h"
#include "abstract_os.h"

//#include <QAudio>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
Expand All @@ -30,117 +29,144 @@

ImpAudio::ImpAudio(QObject *parent) : QObject(parent)
{
cacheSounds();
}

void ImpAudio::cacheSounds()
bool ImpAudio::cacheEffect(const QString& fileName)
{
QString path = appFilesPath() + "/audio/";

QDir audioDir(path);
audioDir.setFilter(QDir::Files);

// Load up style combo
foreach(QFileInfo fileInfo, audioDir.entryInfoList())
if(!buffers.contains(fileName))
{
if(fileInfo.fileName().endsWith(".dll"))
continue;
QString fullPath = appFilesPath() + "/audio/" + fileName;

QSoundEffect* effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(fileInfo.absoluteFilePath()));
qDebug() << " Sound not in buffer, caching" << fullPath;

if(!effects.contains(fileInfo.fileName()))
effects.insert(fileInfo.fileName(), effect);
if(!buffers[fileName].loadFromFile(fullPath.toStdString()))
return false;
}

return true;
}

void ImpAudio::playLocalFile(const QString& fileName)
QVector<sf::Sound>::iterator ImpAudio::allocateSound(const QString& fileName)
{
if(!effects.contains(fileName))
QVector<sf::Sound>::iterator i = sounds.end();
if(sounds.count() > 0)
{
QString path = appFilesPath() + "/audio/" + fileName;
QSoundEffect* effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(path));
effects.insert(fileName, effect);
for(i = sounds.begin(); i < sounds.end(); i++)
{
// Reuse a sound if a previous one is free
if((*i).getStatus() != sf::Sound::Playing)
{
qDebug() << " Reusing existing sf::Sound.";
(*i).setBuffer(buffers[fileName]);
break;
}
}
}

effects[fileName]->setVolume(m_volume);
effects[fileName]->play();
if(i == sounds.end())
{
// No free sound in the set, add a new one.
qDebug() << " Adding new sound to set.";
sounds.append(sf::Sound(buffers[fileName]));

// Reinitialize iterator to point to last item in set.
i = sounds.end();
--i;
}

return i;
}

void ImpAudio::changeAudio(AudioEngine ae)
{
engine = ae;
qDebug() << "ImpAudio::changeAudio(" << ae << ")";
}

AudioEngine ImpAudio::getEngine()
{
return engine;
}

void ImpAudio::playLocalFile(const QString& fileName, float volume)
{
if(!effects.contains(fileName))
switch(engine)
{
QString path = appFilesPath() + "/audio/" + fileName;
QSoundEffect* effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(path));
effects.insert(fileName, effect);
case AudioEngine::AE_Qt:
playLocalFileQt(fileName, volume);
break;
default: // case AudioEngine::AE_SFML:
playLocalFileSFML(fileName, volume);
}

effects[fileName]->setVolume(volume);
effects[fileName]->play();
}

/*
QSoundEffect* ImpAudio::oldPlayLocalFile(const QString& fileName)
void ImpAudio::playLocalFileSFML(const QString& fileName, float volume)
{
QString path = appFilesPath() + "/audio/" + fileName;
qDebug() << "ImpAudio::playLocalFile - Playing " << path;
qDebug() << "ImpAudio::playLocalFileSFML(" << fileName << "," << volume << ")";
if(!cacheEffect(fileName))
{
qDebug() << " Caching failed for " << fileName;
return;
}

QSoundEffect* effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(path));
qDebug() << " Setting buffer and playing.";
QVector<sf::Sound>::iterator i = allocateSound(fileName);
(*i).setVolume(volume * 100);
(*i).play();
}

qDebug() << "ImpAudio::playLocalFile - Setting volume on effect to " << QString::number(volume, 'g', 2);
effect->setVolume(volume);
connect(effect, &QSoundEffect::playingChanged, this, &ImpAudio::playingChanged);
effect->play();

qDebug() << "ImpAudio::playLocalFile - played " << &effect;
return effect;
}
*/
void ImpAudio::playingChanged()
void ImpAudio::playLocalFileQt(const QString& fileName, float volume)
{
QSoundEffect *s = qobject_cast<QSoundEffect *> (sender());
if (!s->isPlaying())
qDebug() << "ImpAudio::playLocalFileQt(" << fileName << "," << volume << ")";
if(!effects.contains(fileName))
{
qDebug() << "ImpAudio::playingChanged - cleaning up " << &s;
s->deleteLater();
QString path = appFilesPath() + "/audio/" + fileName;
QSoundEffect* effect = new QSoundEffect(this);
effect->setSource(QUrl::fromLocalFile(path));
effects.insert(fileName, effect);
}
}

void ImpAudio::setVolume(int i)
{
// Docs said Qt supports logarithmic volume scale...
// but doesn't appear implemented.

/* volume = QAudio::convertVolume(i / qreal(100.0),
QAudio::LogarithmicVolumeScale,
QAudio::LinearVolumeScale);
*/
m_volume = i / qreal(100.0);
qDebug() << "Volume changed to " << QString::number(m_volume, 'g', 2);
effects[fileName]->setVolume(volume);
effects[fileName]->play();
}

void ImpAudio::playLocalMedia(const QString& fileName)
void ImpAudio::playLocalMedia(const QString& fileName, float volume)
{
QString path = appFilesPath() + "/audio/" + fileName;

qDebug() << "Playing " << path;

player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile(path));
player->setVolume(50);
player->play();
switch(engine) {
case AudioEngine::AE_Qt:
player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile(path));
player->setVolume(50);
player->play();
break;

default:
if (!music.openFromFile(path.toStdString()))
return; // error

music.setVolume(volume*100);
music.play();
break;
}
}

void ImpAudio::stopMusic()
{
if(player != NULL && player->state() == player->PlayingState)
{
player->stop();
switch(engine) {
case AudioEngine::AE_Qt:
if(player != NULL && player->state() == player->PlayingState)
{
player->stop();
}
break;

case AudioEngine::AE_SFML:
music.stop();
break;
}
}
36 changes: 26 additions & 10 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,54 @@
#define IMPAUDIO_H

#include <QFile>
#include <QMap>
#include <QObject>
#include <QMediaPlayer>
#include <QSoundEffect>
#include <QVector>
#include <QMediaPlayer> // Qt engine
#include <QSoundEffect> // Qt engine
#include <SFML/Audio.hpp> // SFML engine

enum AudioEngine { AE_SFML, AE_Qt };
Q_DECLARE_METATYPE(AudioEngine)

class ImpAudio : public QObject
{
Q_OBJECT
public:
explicit ImpAudio(QObject *parent = 0);

void playLocalFile(const QString& fileName);
void playLocalFile(const QString& fileName, float volume);

//QSoundEffect* oldPlayLocalFile(const QString& fileName);
AudioEngine getEngine();

void playLocalMedia(const QString& fileName);
void playLocalMedia(const QString& fileName, float volume = 1.0);
void stopMusic();

void setVolume(int i);

void cacheSounds();

signals:

public slots:
void playingChanged();
//void playingChanged();
void playLocalFile(const QString& fileName, float volume = 1.0);
void changeAudio(AudioEngine);

private:
void playLocalFileSFML(const QString& fileName, float volume);
void playLocalFileQt(const QString& fileName, float volume);

QVector<sf::Sound>::iterator allocateSound(const QString& fileName);
bool cacheEffect(const QString& fileName);

AudioEngine engine = AudioEngine::AE_SFML;
qreal m_volume = 1.0f;

QMediaPlayer* player;
QMap<QString, QSoundEffect*> effects;

// SFML sound structures
QMap<QString, sf::SoundBuffer> buffers;
QVector<sf::Sound> sounds;

sf::Music music;
};

#endif // AUDIO_H
20 changes: 18 additions & 2 deletions src/imp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
#
#-------------------------------------------------

QT += core gui multimedia #opengl
QT += core gui #opengl
QT += multimedia # Qt audio engine
QT += xml xmlpatterns svg widgets

#greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = imp
TEMPLATE = app

VERSION = 0.9.6
VERSION = 0.9.6.1
QMAKE_TARGET_COMPANY = EternalDusk
QMAKE_TARGET_DESCRIPTION = Eve Online Intelligence Management Program
QMAKE_TARGET_COPYRIGHT = (c) Copyright 2016-2017 Jesse Litton
Expand All @@ -22,6 +23,21 @@ DEFINES += VERSION=\\\"$VERSION\\\"

include(../ThirdParty/QSimpleUpdater/QSimpleUpdater.pri)

win32 {
LIBS += -LC:/SFML/lib

CONFIG(release, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-main -lsfml-network -lsfml-window -lsfml-system
CONFIG(debug, debug|release): LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-main-d -lsfml-network-d -lsfml-window-d -lsfml-system-d

INCLUDEPATH += C:/SFML/include
DEPENDPATH += C:/SFML/include
}
unix {
CONFIG(release, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-window -lsfml-system
CONFIG(debug, debug|release): LIBS += -lsfml-audio -lsfml-graphics -lsfml-network -lsfml-window -lsfml-system
#CONFIG(debug, debug|release): LIBS += -lsfml-audio-d -lsfml-graphics-d -lsfml-network-d -lsfml-window-d -lsfml-system-d
}

SOURCES += \
main.cpp\
mainwindow.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ void Info::reject()
void Info::startMusic(ImpAudio *audio)
{
m_audio = audio;
audio->playLocalMedia("info/1 dont kn0w.m4a");
audio->playLocalMedia("info/1 dont kn0w.ogg", 0.6);
}
2 changes: 1 addition & 1 deletion src/info.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private slots:
private:
Ui::Info *ui;

QSoundEffect* music;
//QSoundEffect* music;
ImpAudio* m_audio = NULL;
};

Expand Down
3 changes: 1 addition & 2 deletions src/logcatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void LogCatcher::setLogDir(QString logDir)
lastSizes = new QMap<QString, qint64>;

fallbackPollTimer = new QTimer(this);
fallbackPollTimer->setInterval(1000);
fallbackPollTimer->setInterval(pollerInterval);
connect(fallbackPollTimer, &QTimer::timeout,
this, &LogCatcher::fallbackPoller);
fallbackPollTimer->start();
Expand Down Expand Up @@ -132,7 +132,6 @@ void LogCatcher::findCurrentLogs(const QString& dirName)
// are in them.

QString channelName = logNameRegEx.cap(1);
//if(m_options->getIntelChannels().contains(channelName))
if(!localChannels.contains(channelName))
{
QMutableListIterator<QFileInfo> i(infoList);
Expand Down
Loading

0 comments on commit 3c0348a

Please sign in to comment.