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
volumecontrolgroupbox.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 
20 #include "volumecontrolgroupbox.h"
21 #include <QHBoxLayout>
22 #include <QVBoxLayout>
23 #include <QLine>
24 #include <QFrame>
25 #include <QLabel>
26 #include <QToolButton>
27 #include <QShortcut>
28 #include <QKeySequence>
29 
30 #include "displaysize.h"
31 
33  DisplaySizeDependingGroupBox(parent, new QVBoxLayout,
35  | ((DisplaySizeDefines::getSingleton()->showVolumeGroupBoxInTuningMode()) ? toFlag(MODE_TUNING) : 0))
36 {
37  setTitle(tr("Volume control"));
38  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
39 
40  QVBoxLayout *mainLayout = qobject_cast<QVBoxLayout*>(mMainWidgetContainer->layout());
41  mainLayout->setSpacing(0);
42 
44  mVolumeControlLevel->setFormat(QString());
45  if (!mGroupBox) {
46  mVolumeControlLevel->setFormat(tr("Volume"));
47  }
48  mainLayout->addWidget(mVolumeControlLevel);
49 
50  QHBoxLayout *linesLayout = new QHBoxLayout;
51  mLinesLayout = linesLayout;
52  mainLayout->addLayout(linesLayout);
53 
54  class Line : public QFrame {
55  public:
56  Line() {
57  setFrameShape(QFrame::VLine);
58  setFrameShadow(QFrame::Plain);
59  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
60  setLineWidth(3);
61  }
62  private:
63  virtual QSize minimumSizeHint() const override final {
64  return QSize(DisplaySizeDefines::getSingleton()->getSmallIconSize() / 8,
65  DisplaySizeDefines::getSingleton()->getSmallIconSize() / 4);
66  }
67  virtual QSize sizeHint() const override final {
68  return QSize(DisplaySizeDefines::getSingleton()->getSmallIconSize() / 8,
69  DisplaySizeDefines::getSingleton()->getSmallIconSize());
70  }
71  };
72 
73  Line *offLine = new Line;
74  Line *onLine = new Line;
75 
76  linesLayout->addStretch();
77  linesLayout->addWidget(offLine);
78  linesLayout->addStretch();
79  linesLayout->addWidget(onLine);
80  linesLayout->addStretch();
81 
82 
83  QHBoxLayout *textLayout = new QHBoxLayout;
84  mTextLayout = textLayout;
85  mainLayout->addLayout(textLayout);
86  textLayout->setMargin(0);
87  textLayout->setSpacing(0);
88  textLayout->addStretch();
89 
90  QLabel *offLabel = new QLabel("Off");
91  offLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
92  textLayout->addWidget(offLabel);
93 
94  QHBoxLayout *onLayout = new QHBoxLayout;
95  onLayout->setMargin(0);
96  textLayout->addLayout(onLayout);
97 
98  QLabel *onLabel = new QLabel("On");
99  onLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
100  onLayout->addWidget(onLabel);
101  onLayout->addStretch();
102 
103  QToolButton *refreshButton = new QToolButton;
104  onLayout->addWidget(refreshButton);
105  refreshButton->setIcon(QIcon(":/media/images/refresh.png"));
106  refreshButton->setIconSize(QSize(1, 1) * DisplaySizeDefines::getSingleton()->getMediumIconSize());
107  QObject::connect(refreshButton, SIGNAL(clicked(bool)), this, SLOT(onRefreshClicked()));
108 
109  QToolButton *muteMicroButton = new QToolButton;
110  onLayout->addWidget(muteMicroButton);
111  muteMicroButton->setCheckable(true);
112  QIcon muteMicroIcons;
113  muteMicroIcons.addFile(QStringLiteral(":/media/images/micro_active.png"), QSize(), QIcon::Normal, QIcon::Off);
114  muteMicroIcons.addFile(QStringLiteral(":/media/images/micro_mute.png"), QSize(), QIcon::Normal, QIcon::On);
115  muteMicroButton->setIcon(muteMicroIcons);
116  muteMicroButton->setIconSize(QSize(1, 1) * DisplaySizeDefines::getSingleton()->getMediumIconSize());
117  QObject::connect(muteMicroButton, SIGNAL(toggled(bool)), this, SLOT(onMicroMuteToggled(bool)));
118  new QShortcut(QKeySequence(Qt::Key_M), muteMicroButton, SLOT(toggle()));
119 
120  if (DisplaySizeDefines::getSingleton()->showMuteOutputButton()) {
121  QToolButton *muteSpeakerButton = new QToolButton;
122  onLayout->addWidget(muteSpeakerButton);
123  muteSpeakerButton->setCheckable(true);
124  QIcon muteSpeakerIcons;
125  muteSpeakerIcons.addFile(QStringLiteral(":/media/images/speaker_active.png"), QSize(), QIcon::Normal, QIcon::Off);
126  muteSpeakerIcons.addFile(QStringLiteral(":/media/images/speaker_mute.png"), QSize(), QIcon::Normal, QIcon::On);
127  muteSpeakerButton->setIcon(muteSpeakerIcons);
128  muteSpeakerButton->setIconSize(QSize(1, 1) * DisplaySizeDefines::getSingleton()->getMediumIconSize());
129  QObject::connect(muteSpeakerButton, SIGNAL(toggled(bool)), this, SLOT(onSpeakerMuteToggled(bool)));
130  new QShortcut(QKeySequence(Qt::Key_S), muteSpeakerButton, SLOT(toggle()));
131  muteSpeakerButton->setWhatsThis(tr("Click this button to mute the speaker or headphone."));
132  }
133 
134  mainLayout->addStretch();
135 
136  // some rudementary values
137  updateLevels(0.1, 0.5);
138 
139 
140 
141  // set what's this textsClick this button to reset the automatic calibration of the input volume.
142  this->setWhatsThis(tr("This widgets provides settings and information about the input level of the input device."));
143  offLabel->setWhatsThis(tr("If the input level drops below this mark the recorder stops and does not process the input signal."));
144  onLabel->setWhatsThis(tr("If the input level reaches this threshold the recorder starts analyzing the signal of the input device until the level drops below the 'Off' mark."));
145  refreshButton->setWhatsThis(tr("Click this button to reset the automatic calibration of the input volume."));
146  muteMicroButton->setWhatsThis(tr("Click this button to mute the input device."));
147  offLine->setWhatsThis(offLabel->whatsThis());
148  onLine->setWhatsThis(onLabel->whatsThis());
149 }
150 
151 void VolumeControlGroupBox::updateLevels(double stopLevel, double onLevel) {
152  int max = 10000;
153  int pos0 = stopLevel * max;
154  int pos1 = onLevel * max;
155 
156  mTextLayout->setStretch(0, pos0);
157  mTextLayout->setStretch(1, pos1 - pos0);
158  mTextLayout->setStretch(2, max - pos1);
159 
160  mLinesLayout->setStretch(0, pos0);
161  mLinesLayout->setStretch(1, 0);
162  mLinesLayout->setStretch(2, pos1 - pos0);
163  mLinesLayout->setStretch(3, 0);
164  mLinesLayout->setStretch(4, max - pos1);
165 }
166 
168  emit refreshInputLevels();
169 }
170 
172  emit muteMicroToggled(b);
173 }
174 
176  emit muteSpeakerToggled(b);
177 }
VolumeControlGroupBox(QWidget *parent)
void muteSpeakerToggled(bool)
Mode for recording the piano keys.
Definition: prerequisites.h:69
void muteMicroToggled(bool)
int toFlag(OperationMode mode)
Definition: prerequisites.h:76
void updateLevels(double stopLevel, double onLevel)
Mode for manually tuning the piano.
Definition: prerequisites.h:71
VolumeControlLevel * mVolumeControlLevel
static const std::unique_ptr< DisplaySizeDefines > & getSingleton()
Definition: displaysize.cpp:29
Do nothing.
Definition: prerequisites.h:68
QProgressBar to display the current input level.