Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beginning channel range support #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,26 @@ Makefile*
#QtCtreator Qml
*.qmlproject.user
*.qmlproject.user.*
.DS_Store

.DS_Store
*.vsp
*.obj
*.exe
*.ilk
*.pdb
Debug\*
Release\*
*.psess
*.tlog
*.log
src/debug/*
src/release/*

*.qm
*.sln
*.vspx
*.VC.db
*.vcxproj*
*.suo
.vs/*
x64/*
25 changes: 12 additions & 13 deletions src/BPMOscControler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void BPMOscControler::save(QSettings& settings) {
}


inline int round(float value) { return (fmod(value,1.0) < 0.5) ? value : value + 1; }

// Called by the bpm detector to make the controller send the new bpm to the clients
void BPMOscControler::transmitBPM(float bpm)
Expand All @@ -63,18 +62,18 @@ void BPMOscControler::transmitBPM(float bpm)
continue;
}
QString message(command);
message.replace("<BPM>", QString::number(round(bpm)));
message.replace("<BPM1>", QString::number(round(bpm)));
message.replace("<BPM1-2>", QString::number(round(bpm*0.5)));
message.replace("<BPM1-4>", QString::number(round(bpm*0.25)));
message.replace("<BPM1-8>", QString::number(round(bpm*0.125)));
message.replace("<BPM1-16>", QString::number(round(bpm*0.0625)));
message.replace("<BPM1-32>", QString::number(round(bpm*0.03125)));
message.replace("<BPM2>", QString::number(round(bpm*2)));
message.replace("<BPM4>", QString::number(round(bpm*4)));
message.replace("<BPM8>", QString::number(round(bpm*8)));
message.replace("<BPM16>", QString::number(round(bpm*16)));
message.replace("<BPM32>", QString::number(round(bpm*32)));
message.replace("<BPM>", QString::number(qRound(bpm)));
message.replace("<BPM1>", QString::number(qRound(bpm)));
message.replace("<BPM1-2>", QString::number(qRound(bpm*0.5)));
message.replace("<BPM1-4>", QString::number(qRound(bpm*0.25)));
message.replace("<BPM1-8>", QString::number(qRound(bpm*0.125)));
message.replace("<BPM1-16>", QString::number(qRound(bpm*0.0625)));
message.replace("<BPM1-32>", QString::number(qRound(bpm*0.03125)));
message.replace("<BPM2>", QString::number(qRound(bpm*2)));
message.replace("<BPM4>", QString::number(qRound(bpm*4)));
message.replace("<BPM8>", QString::number(qRound(bpm*8)));
message.replace("<BPM16>", QString::number(qRound(bpm*16)));
message.replace("<BPM32>", QString::number(qRound(bpm*32)));
m_osc.sendMessage(message);
}

Expand Down
9 changes: 7 additions & 2 deletions src/MainController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <QDateTime>
#include <QScreen>
#include <QFileDialog>
#include <QQmlDebuggingEnabler>



MainController::MainController(QQmlApplicationEngine* qmlEngine, QObject *parent)
Expand All @@ -56,6 +58,7 @@ MainController::MainController(QQmlApplicationEngine* qmlEngine, QObject *parent

initializeGenerators();
connectGeneratorsWithGui();
QQmlDebuggingEnabler enabler;
}

MainController::~MainController()
Expand Down Expand Up @@ -163,8 +166,10 @@ void MainController::connectGeneratorsWithGui()

QQuickWindow *MainController::getMainWindow() const
{
QQuickWindow* window = qobject_cast<QQuickWindow*>(m_qmlEngine->rootObjects()[0]);
return window;
QList<QObject*> objects = m_qmlEngine->rootObjects();
if(objects.isEmpty())
return 0;
return qobject_cast<QQuickWindow*>(m_qmlEngine->rootObjects()[0]);
}

bool MainController::settingsFormatIsValid(QSettings &settings) const
Expand Down
44 changes: 41 additions & 3 deletions src/TriggerGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ TriggerGenerator::TriggerGenerator(QString name, OSCNetworkManager* osc, bool is
bool TriggerGenerator::checkForTrigger(ScaledSpectrum &spectrum, bool forceRelease)
{
qreal value;

if (m_isBandpass) {
value = spectrum.getMaxLevel(m_midFreq, m_width);
} else {
value = spectrum.getMaxLevel();
}
if (m_invert) value = 1 - value;

if (m_invert) value = 1 - value;
// check for trigger:
if ((!m_isActive && value >= m_threshold) && !forceRelease) {
// activate trigger:
Expand All @@ -61,10 +61,35 @@ bool TriggerGenerator::checkForTrigger(ScaledSpectrum &spectrum, bool forceRelea
m_isActive = false;
m_filter.triggerOff();
}
qreal diff = qAbs(m_lastValue - value);
// If a range message is set, we need to do some math.
if (m_rangeCount > 0 && diff > 0.001) {
// Divide into range based on threshold
int scaledValue = value * 100; // number between 0 - 100
int perSection = scaledValue / m_rangeCount;
int numberToDisplay = m_groupingHash.value(scaledValue);
qDebug() << "OSC Range: " << m_oscParameters.getRangeMessage()[0] + " numberToDisplay " << numberToDisplay;


const int startChan = m_oscParameters.getRangeMessage()[1].toInt();
// Four Paramaters, Start channel, end channel, start value, end value
const QString cmd = m_oscParameters.getRangeMessage()[0] /*cmd*/
+ QString::number(startChan) // %1 is the
+ "," + QString::number(startChan + numberToDisplay)
+ ",01," + QString::number(numberToDisplay*perSection);
m_osc->sendMessage(cmd);

const QString zeroCmd = QString("/eos/user/0/newcmd/Chan/"
+ QString::number(startChan+ numberToDisplay + 1)
+ "/Thru/"
+ m_oscParameters.getRangeMessage()[2] /* endChan as string */
+ "/At/0#");
m_osc->sendMessage(zeroCmd);

}
// send level if levelMessage is set:
// and if difference to last value is greater than 0.001:
qreal diff = qAbs(m_lastValue - value);

if (diff > 0.001 && !m_oscParameters.getLevelMessage().isEmpty() && m_threshold > 0) {
qreal valueUnderThreshold = limit(0, (value / m_threshold), 1);
qreal minValue = m_oscParameters.getMinLevelValue();
Expand All @@ -78,6 +103,19 @@ bool TriggerGenerator::checkForTrigger(ScaledSpectrum &spectrum, bool forceRelea
return m_isActive;
}

void TriggerGenerator::generateRangeHash(int grouping)
{
const int endChan = m_oscParameters.getRangeMessage()[2].toInt();
const int startChan = m_oscParameters.getRangeMessage()[1].toInt();
m_rangeCount = endChan - startChan;
qDebug() << "Generating Hash for: " << startChan << " - " << endChan;
const int groupSpacing = qFloor(100 / (m_rangeCount+1));
for(int i = 0; i <= 100; i++ ) {
const int group = qFloor(i / (groupSpacing+1));
m_groupingHash.insert(i, group);
}
}

void TriggerGenerator::save(QSettings& settings) const
{
settings.setValue(m_name + "/threshold", m_threshold);
Expand Down
7 changes: 7 additions & 0 deletions src/TriggerGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,16 @@ class TriggerGenerator : public TriggerGeneratorInterface
// resets all parameters to default values
void resetParameters();

// ----------- Generate hash table for channel range lookups
void generateRangeHash(int grouping);

protected:
const QString m_name; // name of the Trigger (used for save, restore and UI)
OSCNetworkManager* m_osc; // pointer to OSCNetworkManager instance (i.e. of MainController)
// This is a lookup table generated to tell us which group a given value appears in
// It should be recalculated any time the channel range changes.
QHash<int, int> m_groupingHash;
int m_rangeCount; // Count of items in the range, calculated in generateRangeHash()
const bool m_invert; // true if signal values should be inverted (i.e. for "silence" trigger)
int m_midFreq; // middle frequency of bandpass in Hz
const int m_defaultMidFreq; // default midFreq in Hz, used for reset
Expand Down
11 changes: 9 additions & 2 deletions src/TriggerGuiController.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public slots:
QString getLevelMessage() const { return m_trigger->getOscParameters().getLevelMessage(); }
void setLevelMessage(const QString& value) {m_trigger->getOscParameters().setLevelMessage(value); emit presetChanged(); }

QStringList getRangeMessage() const { return m_trigger->getOscParameters().getRangeMessage(); }
void setRangeMessage(const QStringList& value) {m_trigger->getOscParameters().setRangeMessage(value); emit presetChanged(); }

qreal getMinLevelValue() const { return m_trigger->getOscParameters().getMinLevelValue(); }
void setMinLevelValue(const qreal& value) { m_trigger->getOscParameters().setMinLevelValue(value); emit presetChanged(); }

Expand All @@ -110,11 +113,15 @@ public slots:
void setLabelText(const QString& value) { m_trigger->getOscParameters().setLabelText(value); emit oscLabelTextChanged(); emit presetChanged(); }

// --- shortcut to set all OSC parameters:
void setOscMessages(QString on, QString off, QString level, qreal minLevel, qreal maxLevel, QString labelText)
{
void setOscMessages(QString on, QString off, QString level, QStringList range, qreal minLevel, qreal maxLevel, QString labelText)
{
qDebug() << "Range: " << range;
if(range.size() > 0)
m_trigger->generateRangeHash(range.size());
m_trigger->getOscParameters().setOnMessage(on);
m_trigger->getOscParameters().setOffMessage(off);
m_trigger->getOscParameters().setLevelMessage(level);
m_trigger->getOscParameters().setRangeMessage(range);
m_trigger->getOscParameters().setMinLevelValue(minLevel);
m_trigger->getOscParameters().setMaxLevelValue(maxLevel);
m_trigger->getOscParameters().setLabelText(labelText);
Expand Down
2 changes: 2 additions & 0 deletions src/TriggerOscParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void TriggerOscParameters::save(const QString name, QSettings &settings) const
settings.setValue(name + "/osc/onMessage", m_onMessage);
settings.setValue(name + "/osc/offMessage", m_offMessage);
settings.setValue(name + "/osc/levelMessage", m_levelMessage);
settings.setValue(name + "/osc/rangeMessage", m_rangeMessage);
settings.setValue(name + "/osc/minLevelValue", m_minLevelValue);
settings.setValue(name + "/osc/maxLevelValue", m_maxLevelValue);
settings.setValue(name + "/osc/labelText", m_labelText);
Expand All @@ -46,6 +47,7 @@ void TriggerOscParameters::restore(const QString name, QSettings &settings)
setOnMessage(settings.value(name + "/osc/onMessage").toString());
setOffMessage(settings.value(name + "/osc/offMessage").toString());
setLevelMessage(settings.value(name + "/osc/levelMessage").toString());
setRangeMessage(settings.value(name + "/osc/rangeMessage").toStringList());
setMinLevelValue(settings.value(name + "/osc/minLevelValue").toReal());
setMaxLevelValue(settings.value(name + "/osc/maxLevelValue").toReal());
setLabelText(settings.value(name + "/osc/labelText").toString());
Expand Down
7 changes: 7 additions & 0 deletions src/TriggerOscParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QString>
#include <QSettings>

#include <QDebug> //TODO REMOVE THIS

// A class to store OSC parameters (messages and min and max values).
class TriggerOscParameters
Expand All @@ -47,6 +48,11 @@ class TriggerOscParameters
// sets the OSC path where the level value should be sent to
void setLevelMessage(const QString& value) { m_levelMessage = value; }

// returns the OSC path where the level value should be sent to
QStringList getRangeMessage() const { return m_rangeMessage; }
// sets the OSC path where the level value should be sent to
void setRangeMessage(const QStringList& value) { qDebug() << value; m_rangeMessage = value; }

// returns the value to send when the trigger level is zero
qreal getMinLevelValue() const { return m_minLevelValue; }
// sets the value to send when the trigger level is zero
Expand Down Expand Up @@ -76,6 +82,7 @@ class TriggerOscParameters
QString m_onMessage; // On message ("/path/value=argument")
QString m_offMessage; // Off message ("/path/value=argument")
QString m_levelMessage; // Level message ("/path/value=")
QStringList m_rangeMessage;
qreal m_minLevelValue; // min value to be used for Level message
qreal m_maxLevelValue; // max value to be used for Level message
QString m_labelText; // Short description text of parameters to be displayed in UI
Expand Down
2 changes: 1 addition & 1 deletion src/qml/OscMessageDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Dialog {
text: "OK"
onClicked: {
var messages = mainArea.getMessages()
triggerController.setOscMessages(messages["on"], messages["off"], messages["level"], messages["levelMin"], messages["levelMax"], messages["shortText"])
triggerController.setOscMessages(messages["on"], messages["off"], messages["level"], messages["range"], messages["levelMin"], messages["levelMax"], messages["shortText"])
dialog.close()
controller.dialogIsClosed(dialog)
}
Expand Down
Loading