Skip to content

Commit

Permalink
Fixed server closing, added config file + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
carlou33 committed Sep 6, 2016
1 parent 5274da7 commit 0e719d7
Show file tree
Hide file tree
Showing 14 changed files with 542 additions and 170 deletions.
9 changes: 4 additions & 5 deletions MAKE-SERVER/be-server.pro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
QT += core gui serialport
QT += core serialport
QT -= gui

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

TARGET = be-server
TEMPLATE = app
Expand Down Expand Up @@ -30,9 +31,7 @@ HEADERS += Server.h \
SaveManager.h \
SerialManager.h

FORMS +=

INCLUDEPATH += $$PWD/../deps/libwatermark
INCLUDEPATH += $$PWD/../deps/libwatermark
DEPENDPATH += $$PWD/../deps/libwatermark

INCLUDEPATH += /usr/include/oscpack/ /home/pi/boiteselec-interfaceqt/deps/rtaudio-4.1.2/
Expand Down
25 changes: 25 additions & 0 deletions doc/HOME.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
===================
Boîtes électriques
===================

Table of content
================

*HOME*
Presentation of the application

*SETUP*
How to install and setup the server

*INTERACTION*
How client and server interact with each other.
(Description of the protocol)

General informations
====================

This documentation is formatted using the `reStructuredText <http://docutils.sourceforge.net/rst.html>`_ syntax, and is distributed under the Creative Commons BY-SA 4.0 license.

The `RudeConfig™ Open Source C++ Config File Library <http://rudeserver.com/config/>`_ is written and distributed under the `GNU GPL v2 <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>`_.

The application itself is distributed under the `Zlib License <https://opensource.org/licenses/Zlib>`_.
100 changes: 100 additions & 0 deletions doc/INTERACTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Interaction
===========

General informations
--------------------

To communicate, client and server use the OSC protocol.

By default, the server uses the IP address ``192.170.0.1``, with the port ``9988`` to send messages and ``9989`` to receive them.

Protocol
--------

**Note :**
``<int>`` designate an integer value, ``<str>`` a string one, and ``<bool>`` a boolean one.

Server
~~~~~~

The server can receive the following messages from the client :

``/box/update_threshold <int>``
Change the threshold value to ``<int>``.

``/box/reset_threshold <bool>``
Reset the threshold to its default value.

``/box/enable <int>``
Switch the track number ``<int>``'s state (activate or deactivate it).

``/box/volume <int 1> <int 2>``
Change the track number ``<int 1>``'s volume value to ``<int 2>``.

``/box/pan <int 1> <int 2>``
Change the track number ``<int 1>``'s pan value to ``<int 2>``.

``/box/mute <int> <bool>``
Mute (``<bool>`` = ``true``) or unmute (``false``) the track number ``<int>``.

``/box/solo <int> <bool>``
"Solo" (``<bool>`` = ``true``) or "unsolo" (``false``) the track number ``<int>``.

``/box/master <int>``
Change the master volume value to ``<int>``.

``/box/play <bool>``
Play the song

``/box/stop <bool>``
Stop the song

``/box/reset <bool>``
Stop the song and reset its options to their default values

``/box/refresh_song <bool>``
Refresh the song's informations

``/box/select_song <str>``
Select another song

``/box/sync <bool>``
Send the informations of the actual song and the current state of the player to the client

Client
~~~~~~

The client can receive the following messages from the server to access its informations :

``/box/beat <int>``
The actual server's beat count value = ``<int>``.

``/box/enable_out <int>``
The box number ``<int>`` has been activated.

``/box/enable_sync <int>``
The numbers of the activated tracks, where ``<int>`` is a binary number indicating them.
For example, for an 8-tracks song with its 2nd, 4th, 5th and 8th tracks activated, ``<int>`` = 10011010.

``/box/play <int>``
The selected song started playing (and that its tempo's value is ``<int>``).

``/box/ready <bool>``
The selected song is (``<bool>`` = ``true``) or not (``false``) loaded and ready to be played.

``/box/sensor <int>``
The actual server's threshold value = ``<int>``.

``/box/songs_list <str>``
The available songs list = ``<str>``.
``<str>`` is the concatenation of the songs' filenames, separated by the character ``|``.

``/box/title <str>``
The actual server song's name is ``<str>``.

``/box/tracks_count <int>``
The selected song's tracks count is ``<int>``.

``/box/tracks_list <str>``
Send the informations of the selected song's tracks, as ``<str>``.
``<str>` is the concatenation of the songs' tracks' names, separated by the character ``|``.
65 changes: 65 additions & 0 deletions doc/SETUP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Setup
=====

Installation
------------

Configuration
-------------

General informations
~~~~~~~~~~~~~~~~~~~~

The server's configuration is saved in the ``config.txt`` file in the same folder as the executable.
This file is formatted with the (almost) standard `INI file format <https://en.wikipedia.org/wiki/INI_file>`_.

The following options are available :

``[default]`` section
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``threshold``
Default threshold's value (integer)
Default : 200

``master``
Default master volume's value (integer)
Default : 50

``volume``
Default track's volume (integer)
Default : 50

``pan``
Default track's pan (integer)
Default : 0

``activation``
Default track's activation status (boolean : true or false)
Default : false

``[files]`` section
~~~~~~~~~~~~~~~~~~~

``export_folder``
Files save/load folder (string : path, ending with '/')
Default : /home/pi/songs/

``extension``
Songs files' extension (string : '*.<extension>')
Default : *.song
``[osc]`` section
~~~~~~~~~~~~~~~~~

``ip``
Client's OSC IP address (integer)
Default : 192.170.0.17

``receiver``
Server's OSC receiver port (integer)
Default : 9988

``sender``
Server's OSC sender port (integer)
Default : 9989
28 changes: 19 additions & 9 deletions src/PlayThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
#include <RtAudio.h>
#include <QDebug>

PlayThread::PlayThread() :
QThread(0) {
PlayThread::PlayThread(QSettings* c) :
QThread(0), options(c) {

options->beginGroup("default");
setThreshold(options->value("threshold").toInt());
options->endGroup();
}

unsigned int PlayThread::getTracksCount() const {
Expand Down Expand Up @@ -70,18 +74,22 @@ void PlayThread::timeHandle() {
}

void PlayThread::stop() {
manager->stop();
manager->input()->reset();
bufferCount = 0;
isPlaying = false;
if(this->isRunning()){
manager->stop();
manager->input()->reset();
bufferCount = 0;
isPlaying = false;
}
}

bool PlayThread::isStopped() const {
return !isPlaying;
}

void PlayThread::reset() {
setMasterVolume(DEFAULT_MASTER_VOLUME);
options->beginGroup("default");
setMasterVolume(options->value("master").toInt());
options->endGroup();

for(int i=0; i<tracks.size(); i++)
tracks[i]->reset();
Expand Down Expand Up @@ -122,7 +130,9 @@ void PlayThread::setThreshold(const unsigned int threshold){
}

void PlayThread::resetThreshold() {
setThreshold(DEFAULT_THRESHOLD);
options->beginGroup("default");
setThreshold(options->value("threshold").toInt());
options->endGroup();
}

void PlayThread::load(const SongData& s) {
Expand All @@ -140,7 +150,7 @@ void PlayThread::load(const SongData& s) {

#pragma omp parallel for
for(int i = 0; i < track_count; i++) {
Track* t = new Track(s.tracks[i], conf, i);
Track* t = new Track(s.tracks[i], conf, options, i);
connect(t, &Track::onActivationSwitch,
this, &PlayThread::onEnablementChanged);
tracks[i] = t;
Expand Down
10 changes: 4 additions & 6 deletions src/PlayThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Track.h"

#include <QThread>
#include <QSettings>
#include <manager/StreamingManager.h>
#include <unistd.h>
#include <io/inputs/FFMPEGFileInput.h>
Expand All @@ -25,10 +26,6 @@
template<typename T>
class StreamingManager;


#define DEFAULT_THRESHOLD 200 /*< Default raw threshold value */
#define DEFAULT_MASTER_VOLUME 50 /*< Default master volume value */

/**
* @brief The PlayThread class
*
Expand All @@ -37,7 +34,7 @@ class StreamingManager;
class PlayThread : public QThread {
Q_OBJECT
public:
explicit PlayThread();
explicit PlayThread(QSettings*);

/**
* @brief Give the number of the song's tracks
Expand Down Expand Up @@ -178,6 +175,7 @@ public slots:
void load(const SongData& s);

private:
QSettings* options;
Parameters<double> conf; /*< Configuration data */
std::shared_ptr<Amplify<double>> masterVolume {new Amplify<double>(conf)};
std::shared_ptr<StreamingManager<double>> manager;
Expand All @@ -188,7 +186,7 @@ public slots:
int maxBufferCount {}; /*< Total buffer count in a loop */

bool isPlaying {false};
int m_threshold {DEFAULT_THRESHOLD};
int m_threshold;

/**
* @brief Check if a given track exists
Expand Down
4 changes: 2 additions & 2 deletions src/SaveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void SaveManager::save(const QString savepath, Server* manager) {
int count = settings.value("General/trackCount").toInt();

for(int i = 0; i < count; ++ i) {
settings.setValue(QString("Track%1/volume").arg(i), manager->player.getTrack(i)->getVolume());
settings.setValue(QString("Track%1/pan").arg(i), manager->player.getTrack(i)->getPan());
settings.setValue(QString("Track%1/volume").arg(i), manager->player->getTrack(i)->getVolume());
settings.setValue(QString("Track%1/pan").arg(i), manager->player->getTrack(i)->getPan());
}

settings.sync();
Expand Down
3 changes: 2 additions & 1 deletion src/SerialManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include <QString>
#include <QStringList>
#include <QtSerialPort/QtSerialPort>
#include <memory>//#include <wiringPiSPI.h>
#include <memory>
#include <wiringPiSPI.h>
#include <wiringPi.h>
#include <mcp3004.h>

Expand Down
Loading

0 comments on commit 0e719d7

Please sign in to comment.