28 #include "../system/eptexception.h"
29 #include "../system/log.h"
30 #include "../messages/messagehandler.h"
31 #include "../messages/messageprojectfile.h"
32 #include "../messages/messagemodechanged.h"
33 #include "../messages/messagechangetuningcurve.h"
34 #include "../messages/messagekeyselectionchanged.h"
35 #include "../messages/messagekeydatachanged.h"
36 #include "../math/mathtools.h"
37 #include "../piano/piano.h"
38 #include "../core/system/log.h"
102 auto mpf(std::static_pointer_cast<MessageProjectFile>(m));
103 mPiano = &mpf->getPiano();
113 auto mkdc(std::static_pointer_cast<MessageKeyDataChanged>(m));
114 int index = mkdc->getIndex();
129 auto mmc(std::static_pointer_cast<MessageModeChanged>(m));
160 return 0.5 - 0.5 / atan(3.1) * atan(3*cents/
rangeInCents);
181 if (relX < 0 or relX > 1 or relY < 0 or relY > 1)
return;
188 LogI(
"The pitch of A4 cannot be changed manually.");
191 double yfrac=1 - relY;
193 LogW(
"Set tuningcurve manually keynumber=%d, cents=%d.",keynumber,cents);
194 MessageHandler::send<MessageChangeTuningCurve>
228 const double allowedDeviationInCents = 3;
307 if (not
mPiano)
return -1;
308 const Key &key = mPiano->getKey(keyindex);
311 auto ratioToCents = [
this](
double ratio)
319 if (B > 0)
return (log(B)+10.5)/8;
327 double f = mPiano->getDefiningTempFrequency(keyindex,0,440);
336 mPiano->getEqualTempFrequency(keyindex);
341 int keyA4 = mPiano->getKeyboard().getKeyNumberOfA4();
342 double fA4 = mPiano->getKey(keyA4).getRecordedFrequency();
344 mPiano->getEqualTempFrequency(keyindex,0,fA4);
359 mPiano->getEqualTempFrequency(keyindex);
double getRecordedFrequency() const
Get recorded frequency.
GraphicsItem * getGraphicItem(int keyIndex, RoleType role)
Get a single graphics element specified by its index and its role.
int mKeyNumberOfA4
Index of A4 (reference key)
std::shared_ptr< Message > MessagePtr
Global type of a shared message pointer.
called when the recording was cleared
Marker indicating overpull.
GraphicsViewAdapter * mGraphics
Pointer to the graphics view adapter.
void setItemRole(RoleType role)
Setter function for mRole.
double getDefiningTempFrequency(int keynumber, double cents=0, double A4=0) const
Compute the defining temperatent.
int mNumberOfKeys
Total number of keys (88)
Message that a change was made with the current project file.
virtual void setPosition(double x, double y)=0
Function to set the position of the element.
virtual void setZOrder(double z)
Set the z order of the element (here implemented without function)
double getMarkerPosition(int keyindex, RoleType role)
Compute the position of a marker.
Class describing a single piano key.
static const PenType fcmarkers
Pen type for computed frequency markers.
GraphicsItem::RoleType RoleType
Message that the operation mode has changed.
OperationMode mOperationMode
Current operation mode.
Mode where the entropy optimization is carried out.
virtual void draw() final
Main drawing function.
Mode for recording the piano keys.
TuningCurveGraphDrawer(GraphicsViewAdapter *graphics)
Constructor, calls the DrawerBase constructor and resets variables.
static const PenType bmarkers
Pen type for inharmonicity markers.
void redraw(bool force=false)
Function to completely redraw the scene.
#define EPT_EXCEPT(num, desc)
const Piano * mPiano
Pointer to the actual piano.
FillTypes
Available filling colors (e.g. to fill rectangles)
const Keyboard & getKeyboard() const
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 getComputedFrequency() const
Get computed frequency.
static const FillType allowdAreaFill
Filling for the allowed tuning area.
double getMeasuredInharmonicity() const
Get estimated inharmonicity.
static const PenType gridcolor
Pen type for background grid pentype.
static const PenType middleline
Pen type for bold middle line of grid.
static const PenType fgmarkers
Pen type for recorded frequency in background.
Inharmonicity marker (shown upside down)
static const PenType opmarkers
Pen type for tuned frequency markers.
static const PenType frmarkers
Pen type for recorded frequency markers.
Mode for manually tuning the piano.
PenType
Available pen types for drawing.
int getKeyNumberOfA4() const
Marker indicating recorded frequency.
Abstract base class for implementations rendering graphics.
double convertCentsToY(double cents)
Convert cents to y-coordinate between 0 and 1.
const double & getConcertPitch() const
static const PenType ftmarkers
Pen type for tuned frequency markers.
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.
virtual void handleMessage(MessagePtr m) override
Message listener and dispatcher.
double mConcertPitch
Chosen concert pitch in Hz.
static const int rangeInCents
Constant, defining the visible range above and below the equal temperament level in cents...
void updateMarkerPosition(int keyindex, RoleType role)
void setKeyIndexAndItemRole(int index, RoleType role)
Short function for setting the key index and the role.
void manuallyEditTuningCurveByClick(double relX, double relY)
Manually edit tuning curve by mouse click.
Marker indicating computed frequency.
void drawMarkers(int8_t key)
Draw the tuning markers in the tuning curve panel.
void drawGrid()
Draw the background grid in the tuning curve panel.
int getNumberOfKeys() const
double getTunedFrequency() const
Get tuned frequency.
Marker indicating tuned frequency.
static const PenType centlines
Pen type for thin grid indicating cents.
double getOverpull() const
Get overpull in cents.
Abstract base class for drawing 2d graphics.
PenType getMarkerPenType(RoleType role)
Get the pen type of a marker with a given role.