-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlots.cpp
76 lines (68 loc) · 2.48 KB
/
Plots.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Plots.hpp"
namespace ofxAudioData {
Plots::Plots(std::shared_ptr<ofxAudioData::Processor> processorPtr_, bool darkMode_) :
processorPtr(processorPtr_),
darkMode(darkMode_)
{
plots.resize(4);
plotValueIndexes.resize(4);
changePlot(0, static_cast<int>(ofxAudioAnalysisClient::AnalysisScalar::peakEnergy));
changePlot(1, static_cast<int>(ofxAudioAnalysisClient::AnalysisScalar::spectralCentroid));
changePlot(2, static_cast<int>(ofxAudioAnalysisClient::AnalysisScalar::highFrequencyContent));
changePlot(3, static_cast<int>(ofxAudioAnalysisClient::AnalysisScalar::pitch));
}
std::unique_ptr<ofxHistoryPlot> Plots::makePlot(float* plottedValuePtr, std::string name, float low, float high) {
float numSamples = ofGetWindowWidth() / 2;
auto plotPtr = std::make_unique<ofxHistoryPlot>(plottedValuePtr, name, numSamples, true);
if (low != 0.0 || high != 0.0) {
// plotPtr->setLowerRange(low);
plotPtr->setRange(low, high);
}
if (!darkMode) {
plotPtr->setColor(ofColor::black);
plotPtr->setBackgroundColor(ofColor(0, 0));
plotPtr->setGridColor(ofColor(240, 128));
} else {
plotPtr->setColor(ofColor::white);
}
plotPtr->setShowNumericalInfo(true);
plotPtr->setRespectBorders(true);
plotPtr->setDrawFromRight(true);
plotPtr->setCropToRect(true);
// plotPtr->update(0);
return plotPtr;
}
void Plots::resetPlots() {
for (const auto& plotPtr : plots) {
plotPtr->reset();
}
}
void Plots::changePlot(size_t plotIndex, size_t valueIndex) {
plots[plotIndex] = makePlot(processorPtr->getScalarValuePtr(valueIndex), scalarNames[valueIndex], minScalarValues[valueIndex], maxScalarValues[valueIndex]);
plotValueIndexes[plotIndex] = valueIndex;
}
void Plots::drawPlots(float width, float height) {
if (!plotsVisible) return;
for(int i = 0; i < 4; i++) {
plots[i]->draw(0, i * height, width, height);
}
}
bool Plots::keyPressed(int key, int plotIndex) {
if (key == '<') {
changePlot(plotIndex, (plotValueIndexes[plotIndex]+1) % static_cast<int>(ofxAudioAnalysisClient::AnalysisScalar::_count));
resetPlots();
} else if (key == '>') {
changePlot(plotIndex, (plotValueIndexes[plotIndex]-1+static_cast<int>(ofxAudioAnalysisClient::AnalysisScalar::_count)) % static_cast<int>(ofxAudioAnalysisClient::AnalysisScalar::_count));
resetPlots();
} else if (key == 'p') {
plotsVisible = !plotsVisible;
} else if (key == 'P') {
// SpectrumPlots toggle
plotsVisible = false;
return true;
} else {
return false;
}
return true;
}
}