Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
carlou33 committed Sep 9, 2016
1 parent 0c9406c commit 1767b59
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 183 deletions.
118 changes: 59 additions & 59 deletions src/PlayThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
#include <QDebug>

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

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

unsigned int PlayThread::getTracksCount() const {
return tracks.size();
return m_tracks.size();
}

Track* PlayThread::getTrack(const unsigned int track){
return (isValidTrack(track) ? tracks[track] : NULL);
return (isValidTrack(track) ? m_tracks[track] : NULL);
}

int PlayThread::getActivatedTracks() const{
int res = 0;
for(int i= 0; i<tracks.size(); i++)
res += (tracks[i]->isActivated() ? pow(2,i) : 0);
for(int i= 0; i<m_tracks.size(); i++)
res += (m_tracks[i]->isActivated() ? pow(2,i) : 0);

return res;
}
Expand All @@ -41,138 +41,138 @@ int PlayThread::getThreshold() const {
}

void PlayThread::run() {
manager->input()->reset();
bufferCount = 0;
isPlaying = true;
manager->execute();
m_manager->input()->reset();
m_bufferCount = 0;
m_isPlaying = true;
m_manager->execute();
}

void PlayThread::setMasterVolume(const unsigned int vol) {
masterVolume->setGain(vol / 10.0);
m_masterVolume->setGain(vol / 10.0);
}

void PlayThread::setVolume(const unsigned int track, const unsigned int vol) {
if(isValidTrack(track))
tracks[track]->setVolume(vol);
m_tracks[track]->setVolume(vol);
}

void PlayThread::setPan(const unsigned int track, const int pan) {
if(isValidTrack(track))
tracks[track]->setPan(pan);
m_tracks[track]->setPan(pan);
}

void PlayThread::setMute(const unsigned int track, const bool doMute) {
if(isValidTrack(track))
tracks[track]->setMute(doMute);
m_tracks[track]->setMute(doMute);
}

void PlayThread::timeHandle() {
if(++bufferCount > maxBufferCount)
bufferCount = 0;
if(++m_bufferCount > m_maxBufferCount)
m_bufferCount = 0;

emit actualBeatChanged(bufferCount * conf.bufferSize / double(conf.samplingRate));
emit actualBeatChanged(m_bufferCount * m_conf.bufferSize / double(m_conf.samplingRate));
}

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

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

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

for(int i=0; i<tracks.size(); i++)
tracks[i]->reset();
for(int i=0; i<m_tracks.size(); i++)
m_tracks[i]->reset();
}

void PlayThread::solo(const unsigned int track, const bool state) {
if(isValidTrack(track)) {
tracks[track]->setSolo(state);
m_tracks[track]->setSolo(state);

if(state) {
tracks[track]->setMute(false);
m_tracks[track]->setMute(false);

for(int i=0; i<tracks.size(); i++)
if(!tracks[i]->isSolo())
tracks[i]->setMute(true);
for(int i=0; i<m_tracks.size(); i++)
if(!m_tracks[i]->isSolo())
m_tracks[i]->setMute(true);
} else {
bool noMoreSolo = true;
for(int i=0; i<tracks.size() && noMoreSolo; i++)
if(tracks[i]->isSolo())
for(int i=0; i<m_tracks.size() && noMoreSolo; i++)
if(m_tracks[i]->isSolo())
noMoreSolo = false;

if(noMoreSolo)
for(int i=0; i<tracks.size(); i++)
tracks[i]->setMute( !tracks[i]->isActivated() );
for(int i=0; i<m_tracks.size(); i++)
m_tracks[i]->setMute( !m_tracks[i]->isActivated() );
else
tracks[track]->setMute( true );
m_tracks[track]->setMute( true );
}
}
}

void PlayThread::switchBox(const unsigned int track) {
if(isValidTrack(track))
tracks[track]->setActivated(!tracks[track]->isActivated());
m_tracks[track]->setActivated(!m_tracks[track]->isActivated());
}

void PlayThread::setThreshold(const unsigned int threshold){
m_threshold = (99 - threshold) * 4 + 100;
}

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

void PlayThread::load(const SongData& s) {
// Reset to 0
bufferCount = 0;
m_bufferCount = 0;
int track_count = s.tracks.size();
for(int i=0; i<tracks.size(); i++)
delete tracks[i];
tracks.clear();
manager.reset();
for(int i=0; i<m_tracks.size(); i++)
delete m_tracks[i];
m_tracks.clear();
m_manager.reset();

// Loading
tracks.resize(track_count);
m_tracks.resize(track_count);
std::vector<Input_p> chains(track_count);

#pragma omp parallel for
for(int i = 0; i < track_count; i++) {
Track* t = new Track(s.tracks[i], conf, options, i);
Track* t = new Track(s.tracks[i], m_conf, m_options, i);
connect(t, &Track::onActivationSwitch,
this, &PlayThread::onEnablementChanged);
tracks[i] = t;
m_tracks[i] = t;

auto file = new FFMPEGFileInput<double>(tracks[i]->getFile(), conf);
maxBufferCount = file->v(0).size() / conf.bufferSize;
emit beatCountChanged(file->v(0).size() / double(conf.samplingRate));
auto file = new FFMPEGFileInput<double>(m_tracks[i]->getFile(), m_conf);
m_maxBufferCount = file->v(0).size() / m_conf.bufferSize;
emit beatCountChanged(file->v(0).size() / double(m_conf.samplingRate));

chains[i] = Input_p(new SfxInputProxy<double>(new StereoAdapter<double>(new LoopInputProxy<double>(file)),
new Sequence<double>(conf, tracks[i]->getVolumePtr(), tracks[i]->getPanPtr(), tracks[i]->getMutePtr() )));
new Sequence<double>(m_conf, m_tracks[i]->getVolumePtr(), m_tracks[i]->getPanPtr(), m_tracks[i]->getMutePtr() )));

emit songLoaded(i+1,track_count);
}

// Master
auto input = Input_p(new SfxInputProxy<double>(new SummationProxy<double>(new InputMultiplexer<double>(conf, chains)), masterVolume));
auto input = Input_p(new SfxInputProxy<double>(new SummationProxy<double>(new InputMultiplexer<double>(m_conf, chains)), m_masterVolume));

// Manager
manager = std::make_shared<StreamingManager<double>>(std::move(input),
std::move(std::make_shared<RtAudioOutput<double>>(conf)),
m_manager = std::make_shared<StreamingManager<double>>(std::move(input),
std::move(std::make_shared<RtAudioOutput<double>>(m_conf)),
std::bind(&PlayThread::timeHandle, this),
conf);
m_conf);
}

bool PlayThread::isValidTrack(unsigned int track)
Expand Down
16 changes: 8 additions & 8 deletions src/PlayThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,17 +175,17 @@ 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;
QSettings* m_options;
Parameters<double> m_conf; /*< Configuration data */
std::shared_ptr<Amplify<double>> m_masterVolume {new Amplify<double>(m_conf)};
std::shared_ptr<StreamingManager<double>> m_manager;

QVector<Track*> tracks; /*< List of the current song's tracks */
QVector<Track*> m_tracks; /*< List of the current song's tracks */

int bufferCount {}; /*< Buffer in which we are s*/
int maxBufferCount {}; /*< Total buffer count in a loop */
int m_bufferCount {}; /*< Buffer in which we are s*/
int m_maxBufferCount {}; /*< Total buffer count in a loop */

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

/**
Expand Down
6 changes: 3 additions & 3 deletions src/SerialManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SerialManager::SerialManager(QObject *parent):
}

void SerialManager::stop() {
this->isRunning = false;
this->m_isRunning = false;
}

void SerialManager::run() {
Expand Down Expand Up @@ -58,13 +58,13 @@ void SerialManager::run() {
int pin = 0;
int hitavg = 0;

this->isRunning = true;
this->m_isRunning = true;

//wiringPiSetupSys ();

mcp3004Setup(BASE,SPI_CHAN);

while (this->isRunning){
while (this->m_isRunning){

for(pin=0; pin<8; pin++){

Expand Down
4 changes: 2 additions & 2 deletions src/SerialManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public slots:
virtual void run();

private:
bool isRunning {false}; /*< Status of the reading */
std::shared_ptr<QSerialPort> port; /*< Port to open */
bool m_isRunning {false}; /*< Status of the reading */
std::shared_ptr<QSerialPort> m_port; /*< Port to open */
};

#endif // SERIALMANAGER_H
Loading

0 comments on commit 1767b59

Please sign in to comment.