Entropy Piano Tuner  1.1.3 (documentation not yet complete)
An open-source experimental software for piano tuning by entropy minimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
recordingstatusgraphicsview.cpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright 2015 Haye Hinrichsen, Christoph Wick
3  *
4  * This file is part of Entropy Piano Tuner.
5  *
6  * Entropy Piano Tuner is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * Entropy Piano Tuner is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * Entropy Piano Tuner. If not, see http://www.gnu.org/licenses/.
18  *****************************************************************************/
19 
21 #include "../core/messages/messagenewfftcalculated.h"
22 #include "../core/messages/messagemodechanged.h"
23 #include <QBoxLayout>
24 #include <QDebug>
25 
26 const QRectF RecordingStatusGraphicsView::SCENE_RECT(-50, -50, 100, 100);
27 
29  : QGraphicsView(parent),
30  mScene(SCENE_RECT)
31 {
32  setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
33  setWhatsThis(tr("This item displays the status of the recorder. A red circle indicates that the audio signal is currently recorded. A blue rotating circle is shown when the program processes the recorded signal. A green pause symbol is displayed if you can record the next key."));
34 
35  // no background, and no border!
36  setStyleSheet("background: transparent; border: none");
37 
38  setScene(&mScene);
39 
40  // record
41  mRecordItems.push_back(mScene.addEllipse(-44, -42, 91, 91, QPen(Qt::darkRed), QBrush(Qt::darkRed)));
42  mRecordItems.push_back(mScene.addEllipse(-45, -45, 90, 90, QPen(), QBrush(Qt::red)));
43 
44  // pause rects
45  mPauseItems.push_back(mScene.addRect(-45, -45, 35, 90, QPen(Qt::darkGreen), QBrush(Qt::darkGreen)));
46  mPauseItems.push_back(mScene.addRect(-45, -45, 31, 87, QPen(Qt::lightGray), QBrush(Qt::green)));
47  mPauseItems.push_back(mScene.addRect(10, -45, 35, 90, QPen(Qt::darkGreen), QBrush(Qt::darkGreen)));
48  mPauseItems.push_back(mScene.addRect(10, -45, 31, 87, QPen(Qt::lightGray), QBrush(Qt::green)));
49 
50 
51  // progress arcs
52  QPainterPath path;
53  path.arcMoveTo(-45, -45, 90, 90, 0);
54  path.arcTo(-45, -45, 90, 90, 0, 360);
55  QConicalGradient gradient(0, 0, 0);
56  gradient.setColorAt(0, QColor(0, 0, 0, 255));
57  gradient.setColorAt(1, QColor(0, 0, 0, 0));
58  mProgressItems.push_back(mScene.addPath(path, QPen(QBrush(gradient), 10, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)));
59 
60  path = QPainterPath();
61  path.arcMoveTo(-45, -45, 90, 90, 0);
62  path.arcTo(-45, -45, 90, 90, 0, 360);
63  gradient = QConicalGradient(0, 0, 0);
64  gradient.setColorAt(0, QColor(50, 50, 255, 255));
65  gradient.setColorAt(1, QColor(50, 50, 255, 0));
66  mProgressItems.push_back(mScene.addPath(path, QPen(QBrush(gradient), 8, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)));
67 
68  QObject::connect(&mProgressTimer, SIGNAL(timeout()), this, SLOT(onProcess()));
69 
70  // hide all, show pause
74 }
75 
77 {
78 
79 }
80 
82  double h = height();
83  return QSize(h, h);
84 }
85 
86 void RecordingStatusGraphicsView::showEvent(QShowEvent *event) {
87  fitInView(SCENE_RECT, Qt::KeepAspectRatio);
88  QGraphicsView::showEvent(event);
89 }
90 
91 void RecordingStatusGraphicsView::resizeEvent(QResizeEvent *event) {
92  fitInView(SCENE_RECT, Qt::KeepAspectRatio);
93  updateGeometry();
94  QGraphicsView::resizeEvent(event);
95 }
96 
98  switch (m->getType()) {
100  qDebug() << "Analysis started";
102  setItemVisible(mPauseItems, false);
104  mProgressTimer.start(1000.0 / 24); // 24 fps
105  break;
107  qDebug() << "Analysis ended";
111  mProgressTimer.stop();
112  break;
114  qDebug() << "Recording started";
117  setItemVisible(mPauseItems, false);
118  mProgressTimer.stop();
119  break;
120  default:
121  break;
122  }
123 }
124 
125 void RecordingStatusGraphicsView::setItemVisible(const std::vector<QGraphicsItem*> &items, bool visible) {
126  for (auto item : items) {
127  item->setVisible(visible);
128  }
129 }
130 
132  for (auto item : mProgressItems) {
133  item->setRotation(item->rotation() + 5);
134  }
135 }
RecordingStatusGraphicsView(QWidget *parent)
Default constructor.
std::shared_ptr< Message > MessagePtr
Global type of a shared message pointer.
Definition: message.h:98
virtual ~RecordingStatusGraphicsView()
Emptry virtual destructor.
void handleMessage(MessagePtr m) overridefinal
Message handling.
static const QRectF SCENE_RECT
The scene rect of the QGraphicsScene.
QGraphicsScene mScene
The graphics scene.
void onProcess()
Called by the timer to rotate the blue circle.
std::vector< QGraphicsItem * > mPauseItems
Items that are used to draw the pause state.
QTimer mProgressTimer
Timer to shoot a onProgress() at a fixed time intervall.
void showEvent(QShowEvent *event) override
Reimplemented show event that will fit the SCENE_RECT into the view.
void setItemVisible(const std::vector< QGraphicsItem * > &items, bool visible)
Function to show or hide a group of items.
analysis of the signal started
Definition: message.h:53
void resizeEvent(QResizeEvent *event) override
Reimplemented resize event that will fit the SCENE_RECT into the view.
std::vector< QGraphicsItem * > mRecordItems
Items that are used to draw the recording state.
std::vector< QGraphicsItem * > mProgressItems
Items that are used to draw the analysing state.
analysis of the signal ended
Definition: message.h:54
keystroke recognized and recording started
Definition: message.h:51
virtual QSize sizeHint() const overridefinal