26 #include "../messages/messagenewfftcalculated.h"
27 #include "../messages/messagefinalkey.h"
28 #include "../messages/messageprojectfile.h"
29 #include "../messages/messagemodechanged.h"
30 #include "../math/mathtools.h"
120 auto xposition = [a,b,
this] (
double f) {
return a + b*log(f/
mConcertPitch); };
125 const double exponent = 0.3;
132 double x = xposition(p.first);
135 auto pos1 = mPolygon->begin();
136 while (pos1!=mPolygon->end() and pos1->first < p.first*0.995) pos1++;
138 while (pos2!=mPolygon->end() and pos2->first < p.first*1.005) pos2++;
139 auto comp = [] (
const std::pair<double,double> &a,
const std::pair<double,double> &b)
140 {
return a.second < b.second; };
141 auto maxelem = std::max_element(pos1,pos2, comp);
142 if (maxelem != mPolygon->end())
144 double y = 1-0.95*pow(maxelem->second, exponent);
145 const double dx=0.003;
146 const double dy=0.02;
157 std::vector<GraphicsViewAdapter::Point> points;
161 for (
auto &p : *mPolygon)
163 double x=xposition(p.first);
164 if (x>=0 and x<=1) points.push_back({x, 1-0.95*pow(p.second,exponent)});
192 switch (m->getType())
197 auto mpf(std::static_pointer_cast<MessageProjectFile>(m));
199 mNumberOfKeys = mpf->getPiano().getKeyboard().getNumberOfKeys();
200 mKeyNumberOfA4 = mpf->getPiano().getKeyboard().getKeyNumberOfA4();
208 auto mmc(std::static_pointer_cast<MessageModeChanged>(m));
215 auto mnfc(std::static_pointer_cast<MessageNewFFTCalculated>(m));
216 if (mnfc->hasError())
243 auto mnfc(std::static_pointer_cast<MessageFinalKey>(m));
244 mKey = mnfc->getFinalKey();
sent by SignalAnalyzer if FFT is ready
virtual GraphicsItem * drawChart(const std::vector< Point > &points, PenType pen=PEN_THIN_BLACK)=0
Abstract function: Draw a chart (polygon).
std::shared_ptr< Message > MessagePtr
Global type of a shared message pointer.
called when the recording was cleared
GraphicsViewAdapter * mGraphics
Pointer to the graphics view adapter.
OperationMode mCurrentOperationMode
Current mode of operation.
void setItemRole(RoleType role)
Setter function for mRole.
int mNumberOfKeys
Total number of keys.
virtual void handleMessage(MessagePtr m) override
Message dispatcher for FourierSpectrumGraphDrawer.
Message that a change was made with the current project file.
bool requestRedraw(bool force=false)
Check whether the content has to be redrawn.
int mSamplingRate
copy of sample rate
Message that the operation mode has changed.
void updateSpectrum()
Function for updating the red curve showing the spectrum.
std::list< GraphicsItem * > GraphicItemsList
A list of GraphicItem (global)
Mode for recording the piano keys.
void redraw(bool force=false)
Function to completely redraw the scene.
virtual void draw() overridefinal
Draw the spectrum.
virtual GraphicsItem * drawFilledRect(double x, double y, double w, double h, PenType pen=PEN_THIN_BLACK, FillTypes fill=FILL_RED)=0
Abstract function: Draw a filled rectangle.
double mConcertPitch
Target freuqency of A4.
int mKeyNumberOfA4
Index of A4 key.
virtual void clear()
Clear the whole view.
GraphicItemsList getGraphicItemsByRole(RoleType role)
Get a list of graphic items that match with the given role.
Message that progress of any kind was made by the calculator.
std::shared_ptr< Key > mKey
Shared pointer to selected key, holding the peaks.
final key information after recording
Abstract base class for implementations rendering graphics.
std::shared_ptr< FFTPolygon > mPolygon
Shared pointer to spectral polygon.
Class for a single item in a graphics view.
virtual GraphicsItem * drawLine(double x1, double y1, double x2, double y2, PenType pen=PEN_THIN_BLACK)=0
Abstract function: Draw a line.
GraphicsItem * getGraphicItemByRole(RoleType role)
Get the first of all graphics elements with a given role.
virtual void clear() overridefinal
Clear the spectrum.
std::map< double, double > PeakListType
Type for a peak map.
FourierSpectrumGraphDrawer(GraphicsViewAdapter *graphics)
Constructor of a FourierSpectrumGraphDrawer.
Abstract base class for drawing 2d graphics.