limpieza código no usado e includes

This commit is contained in:
snt 2024-04-25 16:29:33 +02:00
parent 3613d8fa51
commit 66c2850e06
19 changed files with 83 additions and 338 deletions

View file

@ -12,8 +12,6 @@ HEADERS += src/libremediaserver-audio.h \
src/audiowidget.h \
src/defines.h \
src/settings.h \
src/settingsdialog.h \
src/layersettingswidget.h \
src/slidergroup.h
SOURCES += src/main.cpp \
src/dmxwidget.cpp \
@ -25,12 +23,8 @@ SOURCES += src/main.cpp \
src/audiolayerwidget.cpp \
src/audiowidget.cpp \
src/settings.cpp \
src/settingsdialog.cpp \
src/layersettingswidget.cpp \
src/slidergroup.cpp
FORMS += src/libremediaserver-audio.ui \
src/settingsdialog.ui \
src/layersettingswidget.ui
FORMS += src/libremediaserver-audio.ui
CCFLAG += -msse2 -mavx2 #-fsanitize=address -g -O0
QMAKE_CXXFLAGS += $$(CXXFLAG)
#QMAKE_CXXFLAGS += -fsanitize=address -g -O0

View file

@ -1,20 +1,9 @@
#ifndef AUDIOLAYERWIDGET_H
#define AUDIOLAYERWIDGET_H
#include <iostream>
#include <QDebug>
#include <QTime>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QSlider>
#include <QTimer>
#include <QTimeEdit>
#include <QGroupBox>
#include <QCheckBox>
#include <QSpinBox>
#include <QLabel>
#include "defines.h"
#include "slidergroup.h"

View file

@ -1,22 +1,15 @@
#ifndef AUDIOWIDGET_H
#define AUDIOWIDGET_H
#include <QObject>
#include <QWidget>
#include <QDialog>
#include <QTimer>
#include "dmxwidget.h"
#include "audiolayerwidget.h"
#include "settings.h"
#include "miniaudioengine.h"
#include "defines.h"
#include "defines.h" // MAX_LAYERS
class AudioWidget : public QWidget
{
friend class libreMediaServerAudio;
friend class AudioLayerWidget;
Q_OBJECT
public:
@ -24,8 +17,6 @@ public:
bool startEngine();
bool startEngine(int id);
void stopEngine();
protected:
void mediaLoaded(int layer, QString media );
void volChanged(int layer, float vol);
void panChanged(int layer, int pan);

View file

@ -1,13 +1,10 @@
#ifndef DEFINES_H
#define DEFINES_H
#include <QString>
#include <QList>
#include <QtGlobal>
#define VERSION "LibreMediaServerAudio 0.2.0 Antigona Release"
#define COPYRIGHT "(C) 2014-2024 Santi Norena lms@criptomart.net"
#define LICENSE "GPL 3 License. See LICENSE.txt and credits.txt for details"
//#define VERSION "LibreMediaServerAudio 0.2.0 Antigona Release"
#define VERSION "Kike Substitutor - No AI required - v0.2.0"
#define COPYRIGHT "(C) 2014-2024 Santi Noreña <lms@criptomart.net>"
#define LICENSE "GPL 3 Licensed. See LICENSE.txt.\nSound guys are not allowed to use this software."
#define DEFAULT_FILE "lms-audio.xlm"
#define MAX_LAYERS 16
#define UI_REFRESH_TIME 200
@ -15,26 +12,10 @@
// struct where save the DMX settings for each layer
struct dmxSetting {
int address;
quint8 universe;
bool updated;
unsigned int universe;
int layer;
};
// Media Information for MELIn packages. v1.0
struct MediaFile {
quint8 Number; // 0-based contiguous index of the media.
QString MediaName;// Media name.
quint32 MediaLength;// Media length (in frames).
};
// Media Library for ELin packages v1.0
struct MediaFolder {
quint8 m_Id; // Library id.
QString m_Name;// Library name.
quint8 m_ElementCount;// Number of elements in the library.
QList<MediaFile> m_MediaInformation; // Pointer to the Medias Information List of this Library
};
enum Status
{
Stopped,
@ -49,7 +30,7 @@ static const char* StatusStr[] =
"Pause",
"Playing One",
"Playing Loop",
NULL
0x0
};
enum Slider

View file

@ -7,7 +7,7 @@ dmxWidget::dmxWidget(QWidget *parent) :
{
this->setFocusPolicy(Qt::FocusPolicy::NoFocus);
QVBoxLayout *vbox = new QVBoxLayout;
m_receiveDMX->setText("DMX signal");
m_receiveDMX->setText("DMX Signal");
vbox->addWidget(m_receiveDMX);
this->setLayout(vbox);
connect(m_watchDMX, SIGNAL(timeout()),

View file

@ -1,13 +1,10 @@
#ifndef DMXWIDGET_H
#define DMXWIDGET_H
#include <QtGui>
#include <QLabel>
#include <QSlider>
#include <QCheckBox>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QWidget>
#include <QTimer>
class dmxWidget : public QGroupBox
{

View file

@ -25,73 +25,40 @@ libreMediaServerAudio::libreMediaServerAudio(QStringList args, QWidget *parent)
: QMainWindow(parent)
{
Q_UNUSED(args);
qDebug() << VERSION;
qDebug() << COPYRIGHT;
qDebug() << LICENSE;
ui.setupUi(this);
this->setWindowTitle(VERSION);
Settings *set = Settings::getInstance();
set->readFile();
connect(set, SIGNAL(audioDeviceChanged(int)), this, SLOT(audioDeviceChanged(int)));
this->setWindowTitle(VERSION);
qDebug() << VERSION;
qDebug() << COPYRIGHT;
qDebug() << LICENSE;
MediaLibrary::getInstance()->initMediaLibrary();
aw = new AudioWidget;
setCentralWidget(aw);
m_mediaLibrary = new MediaLibrary;
m_mediaLibrary->initMediaLibrary();
m_aw = new AudioWidget;
setCentralWidget(m_aw);
m_dmxWidget = new dmxWidget(this);
QDockWidget *topWidget = new QDockWidget(tr("Master"), this);
topWidget->setAllowedAreas(Qt::TopDockWidgetArea);
topWidget->setWidget(m_dmxWidget);
addDockWidget(Qt::TopDockWidgetArea, topWidget);
ola = new olaThread(this, set->getLayersNumber());
Q_CHECK_PTR(ola);
ola->blockSignals(true);
connect(set, SIGNAL(registerUniverse(int)), ola, SLOT(registerUniverse(int)));
connect(ola, SIGNAL (universeReceived(int)), m_dmxWidget, SLOT(updateWatchDMX(int)));
connect(ola, SIGNAL(dmxOutput(int, int, int)), this, SLOT(dmxInput(int, int, int)));
ola->registerUniverse();
ola->start(QThread::TimeCriticalPriority );
connect(ui.actionOpen_conf, SIGNAL(triggered()), this, SLOT(openFile()));
connect(ui.actionSave_conf, SIGNAL(triggered()), this, SLOT(saveFile()));
connect(ui.action_Settings, SIGNAL(triggered()), this, SLOT(settings()));
m_ola = new olaThread(this, set->getLayersNumber());
Q_CHECK_PTR(m_ola);
m_ola->blockSignals(true);
connect(m_ola, SIGNAL (universeReceived(int)), m_dmxWidget, SLOT(updateWatchDMX(int)));
connect(m_ola, SIGNAL(dmxOutput(int, int, int)), this, SLOT(dmxInput(int, int, int)));
m_ola->registerUniverse();
m_ola->start(QThread::TimeCriticalPriority );
connect(ui.actionLaunch_OLA_Setup, SIGNAL(triggered()), this, SLOT(olasetup()));
aw->startEngine();
m_aw->startEngine();
qDebug("Init Complete.");
ola->blockSignals(false);
ola->resendDmx();
m_ola->blockSignals(false);
m_ola->resendDmx();
}
libreMediaServerAudio::~libreMediaServerAudio()
{
ola->stop();
aw->stopEngine();
}
void libreMediaServerAudio::openFile()
{
QFileDialog dialog(this);
if (!dialog.exec())
return;
QStringList fileNames;
fileNames = dialog.selectedFiles();
QFile file(fileNames.at(0));
// open(&file);
}
void libreMediaServerAudio::saveFile()
{
QFileDialog dialog(this);
if (!dialog.exec())
return;
QStringList fileNames;
fileNames = dialog.selectedFiles();
QFile file(fileNames.at(0));
// save(&file);
}
void libreMediaServerAudio::settings()
{
SettingsDialog *sd = new SettingsDialog();
sd->show();
m_ola->stop();
m_aw->stopEngine();
}
void libreMediaServerAudio::olasetup()
@ -109,30 +76,30 @@ void libreMediaServerAudio::dmxInput(int layer, int channel, int value)
int aux;
switch(channel){
case DMX_FOLDER:
aux = ola->getValue(layer, DMX_FILE);
mediaFile = MediaLibrary::getInstance()->requestNewFile(value, aux);
aux = m_ola->getValue(layer, DMX_FILE);
mediaFile = m_mediaLibrary->requestNewFile(value, aux);
if (QFile::exists(mediaFile))
aw->mediaLoaded(layer, mediaFile);
m_aw->mediaLoaded(layer, mediaFile);
break;
case DMX_FILE:
aux = ola->getValue(layer, DMX_FOLDER);
mediaFile = MediaLibrary::getInstance()->requestNewFile(aux, value);
aux = m_ola->getValue(layer, DMX_FOLDER);
mediaFile = m_mediaLibrary->requestNewFile(aux, value);
if (QFile::exists(mediaFile))
aw->mediaLoaded(layer, mediaFile);
m_aw->mediaLoaded(layer, mediaFile);
break;
case VOLUME_COARSE:
case VOLUME_FINE:
aw->volChanged(layer, (value / 65025.0f));
m_aw->volChanged(layer, (value / 65025.0f));
break;
case PAN:
aw->panChanged(layer, value);
m_aw->panChanged(layer, value);
break;
case PITCH:
aw->pitchChanged(layer, value);
m_aw->pitchChanged(layer, value);
break;
case ENTRY_POINT_COARSE:
case ENTRY_POINT_FINE:
aw->entryPointChanged(layer, value);
m_aw->entryPointChanged(layer, value);
break;
case PLAYBACK:
if (value == 0)
@ -140,16 +107,16 @@ void libreMediaServerAudio::dmxInput(int layer, int channel, int value)
aux = value / 25;
switch (aux) {
case 0 :
aw->playbackChanged(layer, PlayingOnce);
m_aw->playbackChanged(layer, PlayingOnce);
break;
case 1 :
aw->playbackChanged(layer, Stopped);
m_aw->playbackChanged(layer, Stopped);
break;
case 2 :
aw->playbackChanged(layer, Paused);
m_aw->playbackChanged(layer, Paused);
break;
case 3 :
aw->playbackChanged(layer, PlayingLoop);
m_aw->playbackChanged(layer, PlayingLoop);
break;
default :
break;
@ -158,9 +125,3 @@ void libreMediaServerAudio::dmxInput(int layer, int channel, int value)
break;
}
}
void libreMediaServerAudio::audioDeviceChanged(int id)
{
aw->stopEngine();
aw->startEngine(id);
}

View file

@ -20,31 +20,17 @@
#ifndef LIBREMEDIASERVERAUDIO_H
#define LIBREMEDIASERVERAUDIO_H
#include <QMainWindow>
#include <QDockWidget>
#include <QFile>
#include <QFileInfo>
#include <QFileDialog>
#include <QTextStream>
#include <QWebView>
#include <QApplication>
#include <QVBoxLayout>
#include <QString>
#include <QList>
#include <QtGlobal>
#include "audiowidget.h"
#include "medialibrary.h"
#include "olathread.h"
#include "settings.h"
#include "dmxwidget.h"
#include "settingsdialog.h"
#include "defines.h"
#include "ui_libremediaserver-audio.h"
class QMenu;
class libreMediaServerAudio : public QMainWindow
{
Q_OBJECT
@ -55,25 +41,14 @@ public:
Ui::LibreMediaServerAudio ui;
private:
AudioWidget *aw;
AudioWidget *m_aw;
dmxWidget *m_dmxWidget;
olaThread *ola;
void open_start();
void save_finish();
void open(QFile *file);
void save(QFile *file);
public slots:
void audioDeviceChanged(int id);
olaThread *m_ola;
MediaLibrary *m_mediaLibrary;
private slots:
void olasetup();
void dmxInput(int layer, int channel, int value);
void openFile();
void saveFile();
void settings();
};
#endif // LIBREMEDIASERVERAUDIO_H

View file

@ -28,18 +28,9 @@
<property name="title">
<string>File</string>
</property>
<addaction name="actionOpen_conf"/>
<addaction name="actionSave_conf"/>
<addaction name="action_Settings"/>
<addaction name="actionLaunch_OLA_Setup"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
<string>Help</string>
</property>
</widget>
<addaction name="menuFile"/>
<addaction name="menuHelp"/>
</widget>
<action name="actionExit">
<property name="text">

View file

@ -1,15 +1,5 @@
#include "medialibrary.h"
MediaLibrary *MediaLibrary::_instance = 0;
MediaLibrary *MediaLibrary::getInstance() {
if (_instance == 0) {
_instance = new MediaLibrary();
Q_CHECK_PTR(_instance);
}
return _instance;
}
MediaLibrary::MediaLibrary(QObject *parent) :
QObject(parent)

View file

@ -1,25 +1,32 @@
#ifndef MEDIALIBRARY_H
#define MEDIALIBRARY_H
#include <QObject>
#include <QDir>
#include <QDebug>
#include "defines.h"
#include "settings.h"
#include "defines.h"
// Media Information for MELIn packages. v1.0
struct MediaFile {
quint8 Number; // 0-based contiguous index of the media.
QString MediaName;// Media name.
quint32 MediaLength;// Media length (in frames).
};
// Media Library for ELin packages v1.0
struct MediaFolder {
quint8 m_Id; // Library id.
QString m_Name;// Library name.
quint8 m_ElementCount;// Number of elements in the library.
QList<MediaFile> m_MediaInformation; // Pointer to the Medias Information List of this Library
};
class MediaLibrary : public QObject
{
Q_OBJECT
friend class libreMediaserverAudio; // Not working... WHY?
friend class Settings; // working...
public:
static MediaLibrary *getInstance();
MediaLibrary(QObject *parent = 0);
/**
* @brief request a new file from the media library
* @param int folder - the folder required
@ -27,42 +34,11 @@ public:
* @return QString the file required with full path
*/
QString requestNewFile(int folder, int layer);
/**
* @brief Inicia la biblioteca de medios
*/
void initMediaLibrary();
protected:
/**
* @brief Reload the media library on change of path or change the media files
*/
inline void rescanMediaLibrary() {
if (m_media != NULL)
delete m_media;
initMediaLibrary();
}
private:
explicit MediaLibrary(QObject *parent = 0);
static MediaLibrary *_instance;
// Wich structure is more efficient for us?
// QList, QMap, QSet, QVector?
QList<MediaFolder> *m_media; // Library to save the folders/media libraries and index each media file inside
/**
* @brief Returns a list withe the medias contained in a folder
* @param QDir - the directory when are the media
* @return QList<MediaFile> The list with the medias in a folder
*/
QList<MediaFile> getMediaInformation(QDir dir); // Get all the information of each media file in a dir
signals:
public slots:
QList<MediaFolder> *m_media;
QList<MediaFile> getMediaInformation(QDir dir);
};

View file

@ -183,15 +183,11 @@ ma_result MiniAudioEngine::printFormatInfo(int layer)
return result;
}
// Expects between 0 and 1 vol value in db
// Expects between 0 and 1 vol value
void MiniAudioEngine::volChanged(int layer, float vol)
{
//float result;
if (m_mediaLoaded[layer] == false)
return;
//result = ma_volume_linear_to_db(1.00000000 + (vol / 8.0));
//qInfo("vol %f %f", vol, result);
ma_sound_group_set_volume(&m_currentSound[layer], vol);
}

View file

@ -3,8 +3,8 @@
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
#include "defines.h" //MAX_LAYERS
#include <stdio.h> // for printf
#include "defines.h" // MAX_LAYERS
#include <QDebug> // prints messages
class MiniAudioEngine
{

View file

@ -73,27 +73,27 @@ void olaThread::NewDmx(const ola::client::DMXMetadata &data,
if (m_dmx[i.layer][j] != value) {
m_dmx[i.layer][j] = value;
switch (j) {
case 0:
value = (value * 0x100) + buffer.Get(i.address + 6);
case VOLUME_COARSE:
value = (value * 0x100) + buffer.Get(i.address + VOLUME_FINE);
emit dmxOutput(i.layer,j,value);
volSent = true;
break;
case 7:
value = (value * 0x100) + buffer.Get(i.address + 8);
case ENTRY_POINT_COARSE:
value = (value * 0x100) + buffer.Get(i.address + ENTRY_POINT_FINE);
emit dmxOutput(i.layer,j,value);
entrySent = true;
break;
case 6:
case VOLUME_FINE:
if (volSent == false)
{
value = (buffer.Get(i.address) * 0x100) + value;
value = (buffer.Get(i.address + VOLUME_COARSE) * 0x100) + value;
emit dmxOutput(i.layer,j,value);
}
break;
case 8:
case ENTRY_POINT_FINE:
if (entrySent == false)
{
value = (buffer.Get(i.address + 7) * 0x100) + value;
value = (buffer.Get(i.address + ENTRY_POINT_COARSE) * 0x100) + value;
emit dmxOutput(i.layer,j,value);
}
break;

View file

@ -1,9 +1,6 @@
#ifndef OLATHREAD_H
#define OLATHREAD_H
#include <string>
#include <QObject>
#include <QThread>
#include <ola/DmxBuffer.h>
@ -14,9 +11,9 @@
#include <ola/client/ClientTypes.h>
#include <ola/Callback.h>
#include "defines.h"
#include "dmxPersonality.h"
#include "settings.h"
#include "defines.h"
class olaThread : public QThread
{
@ -35,11 +32,9 @@ public:
inline int getValue(int layer, int channel) {
return m_dmx[layer][channel];
}
void resendDmx();
private:
void run ();
ola::client::OlaClientWrapper *m_clientWrapper;
ola::client::OlaClient *m_client;

View file

@ -17,12 +17,6 @@ Settings::Settings(QObject *parent) :
m_layersNumber = 0;
}
void Settings::setPathMedia(QString path)
{
m_pathmedia = path;
MediaLibrary::getInstance()->rescanMediaLibrary();
}
// Read the dmx settings for dmx.xml At the moment we need:
// - The path to the medias folder tree
// - The number of sources/layers controlled by DMX
@ -92,60 +86,3 @@ void Settings::readFromFile(QString file) {
void Settings::readFile() {
readFromFile(DEFAULT_FILE);
}
void Settings::changeLayerSetup(int layer, int universe, int address)
{
dmxSetting temp;
temp.address = address;
temp.universe = universe;
temp.layer = layer;
m_settings.replace(layer, temp);
if (!m_universe.contains(temp.universe)) {
m_universe.insert(temp.universe);
}
}
void Settings::addLayer()
{
dmxSetting temp;
temp.address = -1;
temp.universe = -1;
temp.layer = -1;
m_settings.append(temp);
}
void Settings::removeLayer(int layer)
{
m_settings.removeAt(layer);
}
/*
void Settings::writeFile(QString filename)
{
QFile* xmlFile = new QFile(filename);
if (!xmlFile->open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::critical(NULL,"Load XML File Problem",
QString("Couldn't open %1 to load settings for olaInterface").arg(file),
QMessageBox::Ok);
return;
}
QXmlStreamWriter* xmlWriter = new QXmlStreamWriter(xmlFile);
QXmlStreamWriter stream(&output);
stream.setAutoFormatting(true);
stream.writeStartDocument();
stream.writeStartElement("dmxSettings");
stream.writeAttribute("href", "http://qt.nokia.com/");
stream.writeTextElement("title", "Qt Home");
stream.writeEndElement();
stream.writeEndDocument();
}
void Settings::writeFile()
{
writeFile(DEFAULT_FILE);
}
*/

View file

@ -1,7 +1,6 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#include <QObject>
#include <QXmlStreamReader>
#include <QFile>
#include <QMessageBox>
@ -19,23 +18,10 @@ public:
static Settings *getInstance();
inline QSet<int> getUniverses() { return m_universe; }
inline QString getPathMedia() { return m_pathmedia; }
void setPathMedia(QString path);
inline QList<dmxSetting> getDmxSettings() { return m_settings; }
inline int getLayersNumber() { return m_layersNumber; }
inline int getUniverseNumber() { return m_universe.size(); }
void readFile();
void changeLayerSetup(int layer, int universe, int address);
void removeLayer(int layer);
void addLayer();
inline void setLayersNumber(int layersNumber)
{
if (layersNumber <= MAX_LAYERS)
m_layersNumber = layersNumber;
else
m_layersNumber = MAX_LAYERS;
}
inline int getAudioDeviceId() { return m_audioDeviceId; }
inline void setAudioDeviceId(int id) { m_audioDeviceId = id; }
private:
static Settings *_instance;
@ -47,14 +33,7 @@ private:
explicit Settings(QObject *parent = 0);
void readFromFile(QString file);
// void writeFile(QString filename); // Not implemented yet
// void writeFile(); // Not implemented yet
signals:
void pathChanged(QString path);
void layersNumber(int number);
void registerUniverse(int universe);
void audioDeviceChanged(int id);
};
#endif // SETTINGS_H

View file

@ -4,8 +4,8 @@
#include <QDialog>
#include <QVBoxLayout>
#include <QFileDialog>
#include "settings.h"
#include "layersettingswidget.h"
namespace Ui {
class SettingsDialog;

View file

@ -2,17 +2,10 @@
#define SLIDERGROUP_H
#include <QGroupBox>
#include <QSpinBox>
#include <QLabel>
#include <QBoxLayout>
#include <QDoubleSpinBox>
#include <QVBoxLayout>
#include <QSlider>
QT_BEGIN_NAMESPACE
class QDial;
class QScrollBar;
class QSlider;
QT_END_NAMESPACE
class SliderGroup : public QGroupBox
{
Q_OBJECT