diff --git a/doc/HOME.rst b/doc/HOME.rst index bcd73c3..82ed836 100644 --- a/doc/HOME.rst +++ b/doc/HOME.rst @@ -20,6 +20,10 @@ General informations This documentation is formatted using the `reStructuredText `_ syntax, and is distributed under the Creative Commons BY-SA 4.0 license. -The `RudeConfig™ Open Source C++ Config File Library `_ is written and distributed under the `GNU GPL v2 `_. +The `Open Sound Control (OSC) packet manipulation library `_ is written and distributed under the `MIT license `_, with the following addition : + + "Any person wishing to distribute modifications to the Software is requested to send the modifications to `the original developer `_ so that they can be incorporated into the canonical version. It is also requested that these non-binding requests be included whenever the above license is reproduced." + +The `libaudiotool audio framework `_ is distributed under the `GNU GPL v3 `_. The application itself is distributed under the `Zlib License `_. diff --git a/doc/SETUP.rst b/doc/SETUP.rst index d6df819..fd49bbc 100644 --- a/doc/SETUP.rst +++ b/doc/SETUP.rst @@ -41,7 +41,7 @@ The following options are available : ``[files]`` section ~~~~~~~~~~~~~~~~~~~ -``export_folder`` +``folder`` Files save/load folder (string : path, ending with '/') Default : /home/pi/songs/ @@ -49,6 +49,13 @@ The following options are available : Songs files' extension (string : '*.') Default : *.song +``[gpio]`` section +~~~~~~~~~~~~~~~~~~ + +``led`` + LED's WiringPi identifier (to use with the ``gpio`` command) + Default : 6 + ``[osc]`` section ~~~~~~~~~~~~~~~~~ @@ -63,3 +70,8 @@ The following options are available : ``sender`` Server's OSC sender port (integer) Default : 9989 + +Run +--- + +To start the server, just run ``./be-server`` diff --git a/share/musique.sh b/share/musique.sh index ea9e6a5..ce4e68f 100755 --- a/share/musique.sh +++ b/share/musique.sh @@ -4,9 +4,17 @@ # Chercher tous les fichiers .song sur la clef USB # Les copiers dans /home/ubuntu/songs ###### -export DISPLAY=":0" -notify-send "Copying new songs... Please wait." -cp /media/song_usb/*.song /home/ubuntu/songs + +#export DISPLAY=":0" +#notify-send "Copying new songs... Please wait." + +gpio mode 5 out +gpio write 5 1 + +cp -n /media/song_usb/*.song /home/ubuntu/songs sync umount /media/song_usb -notify-send "Copying done, you can safely remove the USB key" + +gpio write 5 0 + +#notify-send "Copying done, you can safely remove the USB key" diff --git a/src/SerialManager.cpp b/src/SerialManager.cpp index ca2ebf5..99e2c5e 100644 --- a/src/SerialManager.cpp +++ b/src/SerialManager.cpp @@ -20,7 +20,7 @@ SerialManager::SerialManager(QObject *parent): } void SerialManager::stop() { - finished = true; + this->isRunning = false; } void SerialManager::run() { @@ -57,13 +57,14 @@ void SerialManager::run() { int PinPlayTime[8] = {0,0,0,0,0,0,0,0}; int pin = 0; int hitavg = 0; - bool run = true; - wiringPiSetupSys (); + this->isRunning = true; + + //wiringPiSetupSys (); mcp3004Setup(BASE,SPI_CHAN); - while (run){ + while (this->isRunning){ for(pin=0; pin<8; pin++){ diff --git a/src/SerialManager.h b/src/SerialManager.h index ff40575..fcc5faa 100644 --- a/src/SerialManager.h +++ b/src/SerialManager.h @@ -51,7 +51,7 @@ public slots: virtual void run(); private: - bool finished {false}; /*< Status of the reading */ + bool isRunning {false}; /*< Status of the reading */ std::shared_ptr port; /*< Port to open */ }; diff --git a/src/Server.cpp b/src/Server.cpp index 6b46bf2..cc9f753 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -8,9 +8,7 @@ #include #include -//#define CONFIG_FILE "~/.config/Boites Electriques/config.txt" -#define COMPANY_NAME "Rock & Chanson" -#define APP_NAME "Boites Electriques" +#include #define DEFAULT_EXTENSION "*.song" /*< Song files extension */ #define DEFAULT_FOLDER "/home/pi/songs/" /*< Files save/load folder*/ @@ -26,14 +24,39 @@ #define DEFAULT_PAN 0 #define DEFAULT_ACTIVATION false -Server::Server(int& argc, char *argv[]): - QCoreApplication(argc, argv){ +#define DEFAULT_LED 6 /*< wiringPi LED's GPIO identifier */ + +void Server::ledSetup(){ + wiringPiSetupSys(); + //pinMode(LED_VALUE, OUTPUT); + + QString c = QStringLiteral("gpio mode %1 out").arg(options->value("gpio/led").toInt()); + std::system(c.toStdString().c_str()); +} + +void Server::ledOn(){ + //digitalWrite(LED_VALUE, HIGH); + + QString c = QStringLiteral("gpio write %1 1").arg(options->value("gpio/led").toInt()); + std::system(c.toStdString().c_str()); +} + +void Server::ledOff(){ + //digitalWrite(LED_VALUE, LOW); + + QString c = QStringLiteral("gpio write %1 0").arg(options->value("gpio/led").toInt()); + std::system(c.toStdString().c_str()); +} + +Server::Server(QSettings* opt): + options(opt){ - options = new QSettings(QSettings::IniFormat, QSettings::UserScope, - COMPANY_NAME, APP_NAME); initConf(options); qDebug() << options->fileName(); + ledSetup(); + ledOn(); + player = new PlayThread(options); options->beginGroup("osc"); @@ -116,8 +139,9 @@ Server::Server(int& argc, char *argv[]): } Server::~Server() { - qDebug() << "Quitting server..."; + qDebug() << "Stopping server..."; stop(); + player->stop(); qDebug() << "PlayThread stopping..."; if(!player->wait(5000)) { @@ -138,11 +162,12 @@ Server::~Server() { qDebug() << "Deleting pointers..."; delete player; - delete options; - qDebug() << "Proper quitting OK"; + ledOff(); + delete options; - QCoreApplication::quit(); + qDebug() << "Stopping CoreApp..."; + QCoreApplication::exit(0); } int Server::getTempo() const { @@ -154,32 +179,35 @@ unsigned int Server::getThreshold() const { } bool Server::initConf(QSettings *c) { - QFile f(c->fileName()); - - if(!f.exists()){ - c->beginGroup("default"); - c->setValue("threshold", DEFAULT_THRESHOLD); - c->setValue("master", DEFAULT_MASTER_VOLUME); - c->setValue("volume", DEFAULT_VOLUME); - c->setValue("pan", DEFAULT_PAN); - c->setValue("activation", DEFAULT_ACTIVATION); - c->endGroup(); - - c->beginGroup("files"); - c->setValue("folder", DEFAULT_FOLDER); - c->setValue("extension", DEFAULT_EXTENSION); - c->endGroup(); - - c->beginGroup("osc"); - c->setValue("ip", DEFAULT_IP); - c->setValue("sender", DEFAULT_SENDER); - c->setValue("receiver", DEFAULT_RECEIVER); - c->endGroup(); - - return false; - } else - return true; + QList default_settings; + + default_settings.append(Settings("default/threshold", DEFAULT_THRESHOLD)); + default_settings.append(Settings("default/master", DEFAULT_MASTER_VOLUME)); + default_settings.append(Settings("default/volume", DEFAULT_VOLUME)); + default_settings.append(Settings("default/pan", DEFAULT_PAN)); + default_settings.append(Settings("default/activation", DEFAULT_ACTIVATION)); + + default_settings.append(Settings("files/folder", DEFAULT_FOLDER)); + default_settings.append(Settings("files/extension", DEFAULT_EXTENSION)); + + default_settings.append(Settings("gpio/led", DEFAULT_LED)); + + default_settings.append(Settings("osc/ip", DEFAULT_IP)); + default_settings.append(Settings("osc/sender", DEFAULT_SENDER)); + default_settings.append(Settings("osc/receiver", DEFAULT_RECEIVER)); + + QList::const_iterator it; + for(it = default_settings.constBegin(); it < default_settings.constEnd(); it++){ + if(!c->contains(it->key)) + c->setValue(it->key, it->value.toString()); + } + + QStringList lst = c->allKeys(); + for(QStringList::const_iterator k = lst.constBegin(); kvalue(*k).toString(); + + return false; } void Server::sendReady(bool isReady) { diff --git a/src/Server.h b/src/Server.h index 510d699..de1633e 100644 --- a/src/Server.h +++ b/src/Server.h @@ -19,12 +19,22 @@ class SaveManager; #define EXPORT_FOLDER "/home/pi/songs/" /*< Files save/load folder*/ #define FILES_EXTENSION "*.song" /*< Song files extension */ +struct Settings { + QString key; + QVariant value; + + Settings(QString k, QVariant v){ + key = k; + value = v; + } +}; + /** * @brief Main class * * Handles the events and dispatch the corresponding actions */ -class Server : public QCoreApplication { +class Server : public /*QCoreApplication*/ QObject { Q_OBJECT Q_PROPERTY(int tempo READ getTempo WRITE setTempo) @@ -55,6 +65,19 @@ class Server : public QCoreApplication { OscReceiver* receiver; /*< Receiving interface with OSC protocol */ OscSender* sender; /*< Sending interface with OSC protocol */ + /** + * @brief Setup WiringPi interface + */ + void ledSetup(); + /** + * @brief Activate the configured LED + */ + void ledOn(); + /** + * @brief Deactivate the configured LED + */ + void ledOff(); + /*************************** * TRANSMISSIONS TO CLIENT * ***************************/ @@ -221,10 +244,9 @@ class Server : public QCoreApplication { public: /** * @brief Constructor of the Server class - * @param argc Number of arguments - * @param argv Arguments array + * @param opt Configuration data */ - explicit Server(int& argc, char* argv[]); + explicit Server(QSettings* opt); ~Server(); /** @@ -262,13 +284,6 @@ class Server : public QCoreApplication { void resetThreshold(); public slots: - - /** - * @brief Stop properly the application - * @param sig Exit signal - */ -// static void quit(int sig); - /** * @brief Reset the values to default */ diff --git a/src/be-server.pro b/src/be-server.pro index 2caa1c8..a2dcbb5 100644 --- a/src/be-server.pro +++ b/src/be-server.pro @@ -36,7 +36,7 @@ HEADERS += \ INCLUDEPATH += $$PWD/../../libaudiotool/src/libwatermark DEPENDPATH += $$PWD/../../libaudiotool/src/libwatermark -LIBS+= -lgomp -lsndfile +LIBS+= -lgomp -lsndfile -lwiringpi #LIBS+= -lportaudiocpp -lportaudio LIBS+= -lrtaudio LIBS+= -lasound diff --git a/src/main.cpp b/src/main.cpp index 4a7d805..fbd2295 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,9 @@ #include #include +#define COMPANY_NAME "Rock & Chanson" +#define APP_NAME "Boites Electriques" + struct QuitStruct{ QuitStruct(){ std::signal(SIGINT, &QuitStruct::exitApp ); @@ -21,6 +24,27 @@ struct QuitStruct{ int main(int argc, char *argv[]) { QuitStruct qs; - Server s(argc, argv); - return s.exec(); + QCoreApplication app(argc, argv); + + QCommandLineParser p; + p.setApplicationDescription("Boites Electriques - Server"); + p.addHelpOption(); + QCommandLineOption configFile(QStringList()<<"c"<<"config", + QCoreApplication::translate("config", "Set config file path to "), + QCoreApplication::translate("config", "directory")); + p.addOption(configFile); + p.process(app); + + QSettings* opt; + if(p.isSet(configFile)){ + qDebug() << "Cust : " << p.value(configFile); + opt = new QSettings(p.value(configFile), QSettings::IniFormat); + } else { + opt = new QSettings(QSettings::IniFormat, QSettings::UserScope, + COMPANY_NAME, APP_NAME); + } + + Server s(opt); + + return app.exec(); }