Skip to content

Commit

Permalink
Merge pull request #13 from linuxmao-org/master
Browse files Browse the repository at this point in the history
maj depuis officiel
  • Loading branch information
olof29 authored Mar 24, 2019
2 parents 87f9c5b + 75d96f8 commit 80ac3a2
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 16 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_executable(Frontieres WIN32
sources/interface/CombiDialog.cpp
sources/interface/BankDialog.cpp
sources/interface/InstrumDialog.cpp
sources/interface/MonitorWidget.cpp
sources/dsp/Window.cpp
sources/model/MidiBank.cpp
sources/model/MidiCombi.cpp
Expand Down
9 changes: 6 additions & 3 deletions Frontieres.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
QT += widgets opengl
QT += widgets gui opengl
CONFIG += c++11
QMAKE_CFLAGS += -std=c99

Expand All @@ -10,7 +10,8 @@ INCLUDEPATH += $$PWD/libraries
DEFINES += APP_VERSION=\\\"0.0\\\"

DEFINES += __LINUX_ALSASEQ__
DEFINES += __UNIX_JACK__
DEFINES += __LINUX_ALSA__
DEFINES += __LINUX_PULSE__

INCLUDEPATH += $$PWD/libraries/QtFont3D
SOURCES += libraries/QtFont3D/QtFont3D.cpp
Expand All @@ -36,7 +37,7 @@ else {
}

linux: {
LIBS += -ljack
LIBS += -ljack -lpulse-simple -lpulse -lasound
}

LIBS += -lsndfile -lsoxr -llo
Expand All @@ -56,6 +57,7 @@ SOURCES += \
sources/interface/CloudDialog.cpp \
sources/interface/OptionsDialog.cpp \
sources/interface/Node.cpp \
sources/interface/MonitorWidget.cpp \
sources/dsp/Window.cpp \
sources/model/MidiBank.cpp \
sources/model/MidiCombi.cpp \
Expand Down Expand Up @@ -91,6 +93,7 @@ HEADERS += \
sources/interface/CloudDialog.h \
sources/interface/OptionsDialog.h \
sources/interface/Node.h \
sources/interface/MonitorWidget.h \
sources/dsp/Window.h \
sources/model/MidiBank.h \
sources/model/MidiCombi.h \
Expand Down
24 changes: 14 additions & 10 deletions sources/Frontieres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ QtFont3D *text_renderer = NULL;
ValueMin g_cloudValueMin;
ValueMax g_cloudValueMax;
CloudParams g_defaultCloudParams;

float dspMonitorValue = 0;

//--------------------------------------------------------------------------------
// FUNCTION PROTOTYPES
//--------------------------------------------------------------------------------
Expand Down Expand Up @@ -234,11 +237,21 @@ void audioCallback(BUFFERPREC *out, unsigned int numFrames, void *)
if (menuFlag == false) {
std::unique_lock<std::mutex> lock(::currentSceneMutex, std::try_to_lock);
if (lock.owns_lock()) {
auto tp1 = std::chrono::steady_clock::now(); // record time before computation

// generate audio by mixing all the clouds
Scene *scene = ::currentScene;
for (int i = 0, n = scene->m_clouds.size(); i < n; i++) {
Cloud &theCloud = *scene->m_clouds[i]->cloud;
theCloud.nextBuffer(out, numFrames);
}

auto tp2 = std::chrono::steady_clock::now(); // record time after computation

// compute time difference and CPU usage
double deltaTime = 1e-6 * std::chrono::duration_cast<std::chrono::microseconds>(tp2 - tp1).count();
double bufferTime = numFrames * samp_time_sec;
dspMonitorValue = deltaTime / bufferTime;
}
}
GTime::instance().sec += numFrames * samp_time_sec;
Expand Down Expand Up @@ -827,7 +840,7 @@ int main(int argc, char **argv)

// define the signal handler for term signals
sigActionTerm.sa_handler = +[](int)
{ char a = 1; write(signalFds[1], &a, 1); };
{ char a = 1; while (write(signalFds[1], &a, 1) == -1 && errno == EINTR); };
sigemptyset(&sigActionTerm.sa_mask);
for (int s : sigsTerm)
sigaddset(&sigActionTerm.sa_mask, s);
Expand Down Expand Up @@ -892,15 +905,6 @@ int main(int argc, char **argv)

cmdParser->process(app);

if (cmdParser->isSet(optHelp)) {
cmdParser->showHelp();
return 0;
}
if (cmdParser->isSet(optVersion)) {
cmdParser->showVersion();
return 0;
}

if (cmdParser->isSet(optNumChannels))
theChannelCount = cmdParser->value(optNumChannels).toUInt();
if (cmdParser->isSet(optAutoconnect))
Expand Down
3 changes: 3 additions & 0 deletions sources/Frontieres.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ void draw_string(float x, float y, float z, const QString &str, float scale = 1.

void updateMouseCoords(int x, int y);

// CPU usage value by audio processor (0,1)
extern float dspMonitorValue;

void printUsage();
void printParam();

Expand Down
77 changes: 77 additions & 0 deletions sources/interface/MonitorWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//------------------------------------------------------------------------------
// FRONTIÈRES: An interactive granular sampler.
//------------------------------------------------------------------------------
// More information is available at
// http::/ccrma.stanford.edu/~carlsonc/256a/Borderlands/index.html
//
//
// Copyright (C) 2018 Jean Pierre Cimalando
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "MonitorWidget.h"
#include <QPainter>
#include <QDebug>
#include <math.h>

MonitorWidget::MonitorWidget(QWidget *parent)
: QFrame(parent)
{
}

void MonitorWidget::feedSample(float sample)
{
unsigned w = width();

if ((int)w <= 0) {
historyIndex_ = 0;
historySize_ = 0;
history_.reset();
}
else if (historySize_ != w) {
historyIndex_ = 0;
historySize_ = w;
history_.reset(new float[w]());
}

history_[historyIndex_++] = sample;
if (historyIndex_ == historySize_) historyIndex_ = 0;

repaint();
}

void MonitorWidget::paintEvent(QPaintEvent *event)
{
QFrame::paintEvent(event);

QPainter p(this);
QRect r = rect();

if (r.width() <= 0 || r.height() <= 0)
return;

p.fillRect(r, Qt::black);

unsigned n = r.width();
if (historySize_ != n)
return;

for (unsigned i = 0; i < n; ++i) {
float s = history_[(historyIndex_ + i) % n];
QPoint xy = QPoint(r.x() + i, (int)lroundf((1 - s) * r.height()));
p.setPen(QColor(0x20, 0x4A, 0x87));
p.drawLine(QPoint(xy.x(), r.height()), xy);
p.setPen(QColor(0x72, 0x9F, 0xCF));
p.drawPoint(xy);
}
}
43 changes: 43 additions & 0 deletions sources/interface/MonitorWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//------------------------------------------------------------------------------
// FRONTIÈRES: An interactive granular sampler.
//------------------------------------------------------------------------------
// More information is available at
// http::/ccrma.stanford.edu/~carlsonc/256a/Borderlands/index.html
//
//
// Copyright (C) 2018 Jean Pierre Cimalando
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef MONITORWIDGET_H
#define MONITORWIDGET_H

#include <QFrame>
#include <memory>

class MonitorWidget : public QFrame
{
public:
explicit MonitorWidget(QWidget *parent = nullptr);
void feedSample(float sample);

protected:
void paintEvent(QPaintEvent *event) override;

private:
unsigned historyIndex_ = 0;
unsigned historySize_ = 0;
std::unique_ptr<float[]> history_;
};

#endif // MONITORWIDGET_H
19 changes: 16 additions & 3 deletions sources/interface/MyGLApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,22 @@ MyGLWindow *MyGLApplication::GLwindow()

void MyGLApplication::startIdleCallback(double fps)
{
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this]{ P->onIdle(); });
QTimer *timer = idleTimer;
if (!timer) {
idleTimer = timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this]{ P->onIdle(); });
}
timer->start(1e3 / fps);
}

int MyGLApplication::idleCallbackInterval() const
{
QTimer *timer = idleTimer;
if (!timer)
return 0;
return timer->interval();
}

bool MyGLApplication::loadSceneFile()
{
std::string nameSceneFile = Scene::askNameScene(FileDirection::Load);
Expand Down Expand Up @@ -267,7 +278,9 @@ void MyGLApplication::showMidiInstrumentDialog()

void MyGLApplication::Impl::onIdle()
{
window->screen()->update();
MyGLScreen *screen = window->screen();
if (screen->advanceFrame())
screen->update();
}

QString MyGLApplication::Impl::getQtTranslationDir() const
Expand Down
3 changes: 3 additions & 0 deletions sources/interface/MyGLApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "model/MidiCombi.h"

class MyGLWindow;
class QTimer;

class MyGLApplication : public QApplication {
Q_OBJECT
Expand All @@ -40,6 +41,7 @@ class MyGLApplication : public QApplication {

MyGLWindow *GLwindow();
void startIdleCallback(double fps);
int idleCallbackInterval() const;

bool loadSceneFile();
bool saveSceneFile();
Expand All @@ -66,6 +68,7 @@ class MyGLApplication : public QApplication {
CombiDialog *combiDialog;
BankDialog *bankDialog;
InstrumentDialog *instrumentDialog;
QTimer *idleTimer = nullptr;
};

#define theApplication \
Expand Down
Loading

0 comments on commit 80ac3a2

Please sign in to comment.