| 1 |
// Copyright 2007 "Gilles Degottex" |
| 2 |
|
| 3 |
// This file is part of "fmit" |
| 4 |
|
| 5 |
// "fmit" is free software; you can redistribute it and/or modify |
| 6 |
// it under the terms of the GNU General Public License as published by |
| 7 |
// the Free Software Foundation; either version 2 of the License, or |
| 8 |
// (at your option) any later version. |
| 9 |
// |
| 10 |
// "fmit" is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
// GNU General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with this program; if not, write to the Free Software |
| 17 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
|
| 19 |
#include "GLStatistics.h" |
| 20 |
|
| 21 |
#include <iostream> |
| 22 |
#include <limits> |
| 23 |
using namespace std; |
| 24 |
#include <qtimer.h> |
| 25 |
#include <qtooltip.h> |
| 26 |
#include <qimage.h> |
| 27 |
#include <qboxlayout.h> |
| 28 |
#include <qwidgetaction.h> |
| 29 |
#include <QPainter> |
| 30 |
#include <Music/Music.h> |
| 31 |
|
| 32 |
void GLStatistics::AverageNote::init() |
| 33 |
{ |
| 34 |
err_mean = 0.0; |
| 35 |
err_std = 0.0; |
| 36 |
} |
| 37 |
GLStatistics::AverageNote::AverageNote() |
| 38 |
: ht(-1000) |
| 39 |
{ |
| 40 |
init(); |
| 41 |
} |
| 42 |
GLStatistics::AverageNote::AverageNote(int h) |
| 43 |
: ht(h) |
| 44 |
{ |
| 45 |
init(); |
| 46 |
} |
| 47 |
GLStatistics::AverageNote::AverageNote(int h, int num, int den) |
| 48 |
: ht(h) |
| 49 |
{ |
| 50 |
init(); |
| 51 |
factor = QString::number(num)+"/"+QString::number(den); |
| 52 |
} |
| 53 |
GLStatistics::AverageNote::AverageNote(int h, float cents) |
| 54 |
: ht(h) |
| 55 |
{ |
| 56 |
init(); |
| 57 |
factor = QString::number(cents); |
| 58 |
} |
| 59 |
QString GLStatistics::AverageNote::getName() const |
| 60 |
{ |
| 61 |
return QString::fromStdString(Music::h2n(ht))+factor; |
| 62 |
} |
| 63 |
void GLStatistics::AverageNote::addErr(float err) |
| 64 |
{ |
| 65 |
// mean estimation |
| 66 |
if(!errs.empty()) |
| 67 |
err_mean *= errs.size(); |
| 68 |
errs.push_back(err); |
| 69 |
err_mean += err; |
| 70 |
err_mean /= errs.size(); |
| 71 |
|
| 72 |
// standard deviation estimation |
| 73 |
err_std = 0.0; |
| 74 |
for(size_t i=0; i<errs.size(); i++) |
| 75 |
{ |
| 76 |
float de = errs[i]-err_mean; |
| 77 |
err_std += de*de; |
| 78 |
} |
| 79 |
if(errs.size()>1) |
| 80 |
{ |
| 81 |
err_std /= errs.size()-1; // unbiased estimation of the variance |
| 82 |
err_std = sqrt(err_std); |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
void GLStatistics::addNote(int ht, float err) |
| 87 |
{ |
| 88 |
m_current_ht = ht; |
| 89 |
|
| 90 |
if(isHidden() && !setting_keep_hidden->isChecked()) |
| 91 |
return; |
| 92 |
|
| 93 |
if(ht<setting_scale_min->minimum() || ht>setting_scale_max->maximum()) |
| 94 |
return; |
| 95 |
|
| 96 |
// cout << "ht=" << ht << endl; |
| 97 |
|
| 98 |
if(!setting_scale_auto->isChecked()) |
| 99 |
{ |
| 100 |
resizeScale(); |
| 101 |
|
| 102 |
// drop ht outside of scale |
| 103 |
if(ht<setting_scale_min->value() || ht>setting_scale_max->value()) |
| 104 |
return; |
| 105 |
|
| 106 |
// add note |
| 107 |
m_avg_notes[ht-setting_scale_min->value()].addErr(err); |
| 108 |
} |
| 109 |
else |
| 110 |
{ |
| 111 |
if(m_avg_notes.empty()) |
| 112 |
{ |
| 113 |
m_avg_notes.resize(1); |
| 114 |
m_avg_notes[0] = AverageNote(ht); |
| 115 |
setting_scale_min->setValue(ht); |
| 116 |
setting_scale_max->setValue(ht); |
| 117 |
} |
| 118 |
else if(ht<setting_scale_min->value()) |
| 119 |
{ |
| 120 |
// cout << "min: "; |
| 121 |
int min_ht = ht; |
| 122 |
vector<AverageNote> avg_notes(setting_scale_max->value()-min_ht+1); |
| 123 |
for(int i=0; i<setting_scale_min->value()-min_ht; i++) |
| 124 |
avg_notes[i].ht = min_ht+i; |
| 125 |
for(size_t i=0; i<m_avg_notes.size(); i++) |
| 126 |
avg_notes[setting_scale_min->value()-min_ht+i] = m_avg_notes[i]; |
| 127 |
m_avg_notes = avg_notes; |
| 128 |
setting_scale_min->setValue(ht); |
| 129 |
/* for(size_t i=0; i<m_avg_notes.size(); i++) |
| 130 |
cout << m_avg_notes[i].ht << " "; |
| 131 |
cout << "[" << setting_scale_min->value() << ":" << setting_scale_max->value() << "]" << endl;*/ |
| 132 |
} |
| 133 |
else if(ht>setting_scale_max->value()) |
| 134 |
{ |
| 135 |
// cout << "max: "; |
| 136 |
int max_ht = ht; |
| 137 |
vector<AverageNote> avg_notes(max_ht-setting_scale_min->value()+1); |
| 138 |
for(size_t i=0; i<m_avg_notes.size(); i++) |
| 139 |
avg_notes[i] = m_avg_notes[i]; |
| 140 |
for(size_t i=m_avg_notes.size(); i<avg_notes.size(); i++) |
| 141 |
avg_notes[i].ht = setting_scale_min->value()+i; |
| 142 |
m_avg_notes = avg_notes; |
| 143 |
setting_scale_max->setValue(ht); |
| 144 |
/* for(size_t i=0; i<m_avg_notes.size(); i++) |
| 145 |
cout << m_avg_notes[i].ht << " "; |
| 146 |
cout << "[" << setting_scale_min->value() << ":" << setting_scale_max->value() << "]" << endl;*/ |
| 147 |
} |
| 148 |
|
| 149 |
// cout << setting_scale_min->value()-ht << endl; |
| 150 |
|
| 151 |
m_avg_notes[ht-setting_scale_min->value()].addErr(err); |
| 152 |
} |
| 153 |
} |
| 154 |
void GLStatistics::addNote(int ht, int num, int den, float err) |
| 155 |
{ |
| 156 |
Q_UNUSED(num) |
| 157 |
Q_UNUSED(den) |
| 158 |
Q_UNUSED(err) |
| 159 |
|
| 160 |
m_current_ht = ht; |
| 161 |
} |
| 162 |
void GLStatistics::addNote(int ht, float cents, float err) |
| 163 |
{ |
| 164 |
Q_UNUSED(cents) |
| 165 |
Q_UNUSED(err) |
| 166 |
|
| 167 |
m_current_ht = ht; |
| 168 |
} |
| 169 |
|
| 170 |
void GLStatistics::resizeScale() |
| 171 |
{ |
| 172 |
if(setting_scale_auto->isChecked() || setting_scale_max->value()-setting_scale_min->value()+1<1) |
| 173 |
return; |
| 174 |
|
| 175 |
if(m_avg_notes.size()==0 || m_avg_notes[0].ht!=setting_scale_min->value() || m_avg_notes[m_avg_notes.size()-1].ht!=setting_scale_max->value()) |
| 176 |
{ |
| 177 |
vector<AverageNote> avg_notes(setting_scale_max->value()-setting_scale_min->value()+1); |
| 178 |
for(int i=0; i<int(m_avg_notes.size()); i++) |
| 179 |
{ |
| 180 |
int in = i+m_avg_notes[0].ht-setting_scale_min->value(); |
| 181 |
if(in>=0 && in<int(avg_notes.size())) |
| 182 |
avg_notes[in] = m_avg_notes[i]; |
| 183 |
} |
| 184 |
for(size_t i=0; i<avg_notes.size(); i++) |
| 185 |
avg_notes[i].ht = setting_scale_min->value()+i; |
| 186 |
m_avg_notes = avg_notes; |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
GLStatistics::GLStatistics(QWidget* parent) |
| 191 |
: QOpenGLWidget(parent) |
| 192 |
, View(tr("Statistics"), this) |
| 193 |
, m_font("Helvetica") |
| 194 |
{ |
| 195 |
// settings |
| 196 |
setting_show->setIcon(QIcon(":/fmit/ui/images/module_statistics.svg")); |
| 197 |
setting_show->setChecked(false); |
| 198 |
hide(); |
| 199 |
|
| 200 |
setting_reset = new QAction(tr("Reset statistics"), this); |
| 201 |
setting_reset->setShortcut('r'); |
| 202 |
connect(setting_reset, SIGNAL(triggered()), this, SLOT(reset())); |
| 203 |
m_popup_menu.addAction(setting_reset); |
| 204 |
|
| 205 |
setting_keep_hidden = new QAction(tr("Keep notes when hidden"), this); |
| 206 |
setting_keep_hidden->setCheckable(true); |
| 207 |
setting_keep_hidden->setChecked(false); |
| 208 |
connect(setting_keep_hidden, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 209 |
m_popup_menu.addAction(setting_keep_hidden); |
| 210 |
|
| 211 |
QHBoxLayout* keepActionLayout = new QHBoxLayout(&m_popup_menu); |
| 212 |
|
| 213 |
QLabel* keepActionTitle = new QLabel(tr("Keep n values"), &m_popup_menu); |
| 214 |
keepActionLayout->addWidget(keepActionTitle); |
| 215 |
|
| 216 |
setting_keep_n_values = new QSpinBox(&m_popup_menu); |
| 217 |
setting_keep_n_values->setObjectName("setting_keep_n_values"); |
| 218 |
setting_keep_n_values->setMinimum(1); |
| 219 |
setting_keep_n_values->setMaximum(500); |
| 220 |
setting_keep_n_values->setSingleStep(3); |
| 221 |
setting_keep_n_values->setValue(100); |
| 222 |
setting_keep_n_values->setToolTip(tr("Keep this number of values in the computation of the statistics")); |
| 223 |
connect(setting_keep_n_values, SIGNAL(valueChanged(int)), this, SLOT(update())); |
| 224 |
keepActionLayout->addWidget(setting_keep_n_values); |
| 225 |
|
| 226 |
QWidget* keepActionWidget = new QWidget(&m_popup_menu); |
| 227 |
keepActionWidget->setLayout(keepActionLayout); |
| 228 |
|
| 229 |
QWidgetAction* keepAction = new QWidgetAction(&m_popup_menu); |
| 230 |
keepAction->setDefaultWidget(keepActionWidget); |
| 231 |
m_popup_menu.addAction(keepAction); |
| 232 |
|
| 233 |
setting_keep_n_values->setEnabled(false); |
| 234 |
s_settings->add(setting_keep_n_values); |
| 235 |
|
| 236 |
setting_show_std = new QAction(tr("Show standard deviation"), this); |
| 237 |
setting_show_std->setCheckable(true); |
| 238 |
setting_show_std->setChecked(true); |
| 239 |
connect(setting_show_std, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 240 |
m_popup_menu.addAction(setting_show_std); |
| 241 |
|
| 242 |
setting_scale_auto = new QAction(tr("Scale auto"), this); |
| 243 |
setting_scale_auto->setCheckable(true); |
| 244 |
setting_scale_auto->setChecked(true); |
| 245 |
setting_scale_auto->setEnabled(false); |
| 246 |
connect(setting_scale_auto, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 247 |
m_popup_menu.addAction(setting_scale_auto); |
| 248 |
|
| 249 |
QHBoxLayout* scaleMinActionLayout = new QHBoxLayout(&m_popup_menu); |
| 250 |
|
| 251 |
QLabel* scaleMinActionTitle = new QLabel(tr("Scale min"), &m_popup_menu); |
| 252 |
scaleMinActionLayout->addWidget(scaleMinActionTitle); |
| 253 |
|
| 254 |
setting_scale_min = new QSpinBox(&m_popup_menu); |
| 255 |
setting_scale_min->setObjectName("setting_scale_min"); |
| 256 |
setting_scale_min->setMinimum(-96); |
| 257 |
setting_scale_min->setMaximum(96); |
| 258 |
setting_scale_min->setSingleStep(6); |
| 259 |
setting_scale_min->setValue(-12); |
| 260 |
setting_scale_min->setToolTip(tr("Scale min value (in semi-tones)")); |
| 261 |
connect(setting_scale_min, SIGNAL(valueChanged(int)), this, SLOT(update())); |
| 262 |
scaleMinActionLayout->addWidget(setting_scale_min); |
| 263 |
|
| 264 |
QWidget* scaleMinActionWidget = new QWidget(&m_popup_menu); |
| 265 |
scaleMinActionWidget->setLayout(scaleMinActionLayout); |
| 266 |
|
| 267 |
QWidgetAction* scaleMinAction = new QWidgetAction(&m_popup_menu); |
| 268 |
scaleMinAction->setDefaultWidget(scaleMinActionWidget); |
| 269 |
m_popup_menu.addAction(scaleMinAction); |
| 270 |
|
| 271 |
setting_scale_min->setEnabled(false); |
| 272 |
s_settings->add(setting_scale_min); |
| 273 |
connect(setting_scale_auto, SIGNAL(toggled(bool)), setting_scale_min, SLOT(setDisabled(bool))); |
| 274 |
connect(setting_scale_min, SIGNAL(valueChanged(int)), this, SLOT(resizeScale())); |
| 275 |
|
| 276 |
QHBoxLayout* scaleMaxActionLayout = new QHBoxLayout(&m_popup_menu); |
| 277 |
|
| 278 |
QLabel* scaleMaxActionTitle = new QLabel(tr("Scale max"), &m_popup_menu); |
| 279 |
scaleMaxActionLayout->addWidget(scaleMaxActionTitle); |
| 280 |
|
| 281 |
setting_scale_max = new QSpinBox(&m_popup_menu); |
| 282 |
setting_scale_max->setObjectName("setting_scale_max"); |
| 283 |
setting_scale_max->setMinimum(-96); |
| 284 |
setting_scale_max->setMaximum(96); |
| 285 |
setting_scale_max->setSingleStep(6); |
| 286 |
setting_scale_max->setValue(+12); |
| 287 |
setting_scale_max->setToolTip(tr("Scale max value (in semi-tones)")); |
| 288 |
connect(setting_scale_max, SIGNAL(valueChanged(int)), this, SLOT(update())); |
| 289 |
scaleMaxActionLayout->addWidget(setting_scale_max); |
| 290 |
|
| 291 |
QWidget* scaleMaxActionWidget = new QWidget(&m_popup_menu); |
| 292 |
scaleMaxActionWidget->setLayout(scaleMaxActionLayout); |
| 293 |
|
| 294 |
QWidgetAction* scaleMaxAction = new QWidgetAction(&m_popup_menu); |
| 295 |
scaleMaxAction->setDefaultWidget(scaleMaxActionWidget); |
| 296 |
m_popup_menu.addAction(scaleMaxAction); |
| 297 |
|
| 298 |
setting_scale_max->setEnabled(false); |
| 299 |
s_settings->add(setting_scale_max); |
| 300 |
connect(setting_scale_auto, SIGNAL(toggled(bool)), setting_scale_max, SLOT(setDisabled(bool))); |
| 301 |
connect(setting_scale_max, SIGNAL(valueChanged(int)), this, SLOT(resizeScale())); |
| 302 |
|
| 303 |
setting_showTolerance = new QAction(tr("Show tolerance"), this); |
| 304 |
setting_showTolerance->setCheckable(true); |
| 305 |
setting_showTolerance->setChecked(true); |
| 306 |
connect(setting_showTolerance, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 307 |
m_popup_menu.addAction(setting_showTolerance); |
| 308 |
|
| 309 |
setting_useCents = new QAction(tr("Use cents"), this); |
| 310 |
setting_useCents->setCheckable(true); |
| 311 |
setting_useCents->setChecked(true); |
| 312 |
connect(setting_useCents, SIGNAL(toggled(bool)), this, SLOT(update())); |
| 313 |
m_popup_menu.addAction(setting_useCents); |
| 314 |
|
| 315 |
QHBoxLayout* scaleActionLayout = new QHBoxLayout(&m_popup_menu); |
| 316 |
|
| 317 |
QLabel* scaleActionTitle = new QLabel(tr("Scale range"), &m_popup_menu); |
| 318 |
scaleActionLayout->addWidget(scaleActionTitle); |
| 319 |
|
| 320 |
setting_spinScale = new QSpinBox(&m_popup_menu); |
| 321 |
setting_spinScale->setMinimum(5); |
| 322 |
setting_spinScale->setMaximum(50); |
| 323 |
setting_spinScale->setSingleStep(1); |
| 324 |
setting_spinScale->setValue(50); |
| 325 |
setting_spinScale->setToolTip(tr("Scale range (in cents)")); |
| 326 |
connect(setting_spinScale, SIGNAL(valueChanged(int)), this, SLOT(update())); |
| 327 |
scaleActionLayout->addWidget(setting_spinScale); |
| 328 |
|
| 329 |
QWidget* scaleActionWidget = new QWidget(&m_popup_menu); |
| 330 |
scaleActionWidget->setLayout(scaleActionLayout); |
| 331 |
|
| 332 |
QWidgetAction* scaleAction = new QWidgetAction(&m_popup_menu); |
| 333 |
scaleAction->setDefaultWidget(scaleActionWidget); |
| 334 |
m_popup_menu.addAction(scaleAction); |
| 335 |
} |
| 336 |
|
| 337 |
void GLStatistics::save() |
| 338 |
{ |
| 339 |
s_settings->setValue("setting_keep_hidden", setting_keep_hidden->isChecked()); |
| 340 |
s_settings->setValue("setting_show_std", setting_show_std->isChecked()); |
| 341 |
s_settings->setValue("setting_scale_auto", setting_scale_auto->isChecked()); |
| 342 |
} |
| 343 |
void GLStatistics::load() |
| 344 |
{ |
| 345 |
setting_keep_hidden->setChecked(s_settings->value("setting_keep_hidden", setting_keep_hidden->isChecked()).toBool()); |
| 346 |
setting_show_std->setChecked(s_settings->value("setting_show_std", setting_show_std->isChecked()).toBool()); |
| 347 |
setting_scale_auto->setChecked(s_settings->value("setting_scale_auto", setting_scale_auto->isChecked()).toBool()); |
| 348 |
} |
| 349 |
void GLStatistics::clearSettings() |
| 350 |
{ |
| 351 |
s_settings->remove("setting_keep_hidden"); |
| 352 |
s_settings->remove("setting_show_std"); |
| 353 |
s_settings->remove("setting_scale_auto"); |
| 354 |
} |
| 355 |
|
| 356 |
void GLStatistics::reset() |
| 357 |
{ |
| 358 |
m_avg_notes.clear(); |
| 359 |
if(setting_scale_auto->isChecked()) |
| 360 |
{ |
| 361 |
setting_scale_min->setValue(0); |
| 362 |
setting_scale_max->setValue(0); |
| 363 |
} |
| 364 |
resizeScale(); |
| 365 |
update(); |
| 366 |
} |
| 367 |
|
| 368 |
void GLStatistics::initializeGL() |
| 369 |
{ |
| 370 |
// Set the clear color to black |
| 371 |
glClearColor(1.0, 1.0, 1.0, 0.0); |
| 372 |
|
| 373 |
// glShadeModel( GL_FLAT ); |
| 374 |
glShadeModel( GL_SMOOTH ); |
| 375 |
|
| 376 |
glLoadIdentity(); |
| 377 |
} |
| 378 |
|
| 379 |
void GLStatistics::drawTicksCent(int r, int dx, int dy) |
| 380 |
{ |
| 381 |
// only work within range that is a pure multiple of r |
| 382 |
float range = int(setting_spinScale->value()/r)*r; |
| 383 |
|
| 384 |
float scale = 50.0f/setting_spinScale->value(); |
| 385 |
|
| 386 |
if((height()-dy)*r/100.0f*scale>2) |
| 387 |
{ |
| 388 |
for(float i=-range; i<=range; i+=r) |
| 389 |
{ |
| 390 |
int y = int((height()-dy)*i/100.0f*scale) + (height()-dy)/2 + dy; |
| 391 |
glVertex2i(dx, y); |
| 392 |
glVertex2i(width(), y); |
| 393 |
} |
| 394 |
} |
| 395 |
} |
| 396 |
void GLStatistics::drawTextTickCent(int r, int dy) |
| 397 |
{ |
| 398 |
// only work within range that is a pure multiple of r |
| 399 |
int range = int(setting_spinScale->value()/r)*r; |
| 400 |
|
| 401 |
QPainter painter(this); |
| 402 |
m_font.setPixelSize(14); |
| 403 |
painter.setFont(m_font); |
| 404 |
QFontMetrics fm(m_font); |
| 405 |
|
| 406 |
float scale = 50.0f/setting_spinScale->value(); |
| 407 |
QString txt; |
| 408 |
for(int i=-range; i<range; i+=r) |
| 409 |
{ |
| 410 |
txt = QString::number(i); |
| 411 |
if(i>=0) txt = QString(" ")+txt; |
| 412 |
if(i==0) txt = QString(" ")+txt; |
| 413 |
painter.drawText(2, (height()-dy)/2 - int((height()-dy)*i/100.0f*scale) +fm.xHeight()/2, txt); |
| 414 |
} |
| 415 |
painter.end(); |
| 416 |
} |
| 417 |
|
| 418 |
void GLStatistics::paintGL() |
| 419 |
{ |
| 420 |
// cout << "GLStatistics::paintGL " << m_notes.size() << endl; |
| 421 |
|
| 422 |
glClear(GL_COLOR_BUFFER_BIT); |
| 423 |
|
| 424 |
glLineWidth(1.0f); |
| 425 |
float human_tol = Music::f2hf(441.0,440.0); |
| 426 |
float scale; |
| 427 |
if(setting_useCents->isChecked()) |
| 428 |
scale = 50.0f/setting_spinScale->value(); |
| 429 |
else |
| 430 |
scale = int(50/setting_spinScale->value()); |
| 431 |
|
| 432 |
// name |
| 433 |
glColor3f(0.75,0.75,0.75); |
| 434 |
QPainter painter(this); |
| 435 |
m_font.setPixelSize(20); |
| 436 |
painter.setFont(m_font); |
| 437 |
painter.drawText(2, 20, tr("Statistics")); |
| 438 |
painter.end(); |
| 439 |
|
| 440 |
int char_size = 9; |
| 441 |
int ticks_size = 2+3*char_size; |
| 442 |
int grid_width = width()-ticks_size; |
| 443 |
// int dy = char_size/2; |
| 444 |
int legend_height = 40; |
| 445 |
int grid_height = height()-legend_height; |
| 446 |
|
| 447 |
// draw green rect |
| 448 |
if(setting_showTolerance->isChecked()) |
| 449 |
{ |
| 450 |
int green_ytop = int((scale*human_tol+0.5)*grid_height) + legend_height; |
| 451 |
int green_ybottom = int((-scale*human_tol+0.5)*grid_height) + legend_height; |
| 452 |
|
| 453 |
glBegin(GL_QUADS); |
| 454 |
glColor3f(168/256.0,221/256.0,182/256.0); |
| 455 |
glVertex2i(ticks_size, green_ytop); |
| 456 |
glVertex2i(ticks_size, green_ybottom); |
| 457 |
glVertex2i(width(), green_ybottom); |
| 458 |
glVertex2i(width(), green_ytop); |
| 459 |
glEnd(); |
| 460 |
|
| 461 |
// draw green lines |
| 462 |
glBegin(GL_LINES); |
| 463 |
glColor3f(0.48,0.80,0.57); |
| 464 |
glVertex2i(ticks_size, green_ytop); |
| 465 |
glVertex2i(width(), green_ytop); |
| 466 |
glVertex2i(ticks_size, green_ybottom); |
| 467 |
glVertex2i(width(), green_ybottom); |
| 468 |
glEnd(); |
| 469 |
} |
| 470 |
|
| 471 |
// std |
| 472 |
if(setting_show_std->isChecked()) |
| 473 |
{ |
| 474 |
glBegin(GL_QUADS); |
| 475 |
glLineWidth(1.0f); |
| 476 |
glColor3f(0.85, 0.85, 0.85); |
| 477 |
for(size_t i=0; i<m_avg_notes.size(); i++) |
| 478 |
{ |
| 479 |
if(!m_avg_notes[i].errs.empty()) |
| 480 |
{ |
| 481 |
int top = int((scale*(m_avg_notes[i].err_mean+m_avg_notes[i].err_std)+0.5)*grid_height) + legend_height; |
| 482 |
top = max(top, legend_height); |
| 483 |
int bottom = int((scale*(m_avg_notes[i].err_mean-m_avg_notes[i].err_std)+0.5)*grid_height) + legend_height; |
| 484 |
bottom = max(bottom, legend_height); |
| 485 |
int left = ticks_size+int(i*float(grid_width)/m_avg_notes.size())+1; |
| 486 |
int right = ticks_size+int((i+1)*float(grid_width)/m_avg_notes.size()); |
| 487 |
|
| 488 |
glVertex2i(left, top); |
| 489 |
glVertex2i(left, bottom); |
| 490 |
glVertex2i(right, bottom); |
| 491 |
glVertex2i(right, top); |
| 492 |
} |
| 493 |
} |
| 494 |
glEnd(); |
| 495 |
} |
| 496 |
|
| 497 |
// horiz lines |
| 498 |
if(setting_useCents->isChecked()) |
| 499 |
{ |
| 500 |
glBegin(GL_LINES); |
| 501 |
float gray = 0.87; |
| 502 |
// glColor3f(gray, gray, gray); |
| 503 |
// drawTicksCent(1, ticks_size); |
| 504 |
gray = 0.875; |
| 505 |
glColor3f(gray, gray, gray); |
| 506 |
drawTicksCent(2, ticks_size, legend_height); |
| 507 |
gray = 0.75; |
| 508 |
glColor3f(gray, gray, gray); |
| 509 |
drawTicksCent(10, ticks_size, legend_height); |
| 510 |
glEnd(); |
| 511 |
} |
| 512 |
else |
| 513 |
{ |
| 514 |
glBegin(GL_LINES); |
| 515 |
float gray = 0.5; |
| 516 |
glColor3f(gray, gray, gray); |
| 517 |
glVertex2i(ticks_size, grid_height/2+legend_height); |
| 518 |
glVertex2i(width(), grid_height/2+legend_height); |
| 519 |
gray = 0.75; |
| 520 |
glColor3f(gray, gray, gray); |
| 521 |
glVertex2i(ticks_size, grid_height/4+legend_height); |
| 522 |
glVertex2i(width(), grid_height/4+legend_height); |
| 523 |
glVertex2i(ticks_size, 3*grid_height/4+legend_height); |
| 524 |
glVertex2i(width(), 3*grid_height/4+legend_height); |
| 525 |
gray = 0.87; |
| 526 |
glColor3f(gray, gray, gray); |
| 527 |
glVertex2i(ticks_size, grid_height/8+legend_height); |
| 528 |
glVertex2i(width(), grid_height/8+legend_height); |
| 529 |
glVertex2i(ticks_size, 7*grid_height/8+legend_height); |
| 530 |
glVertex2i(width(), 7*grid_height/8+legend_height); |
| 531 |
glVertex2i(ticks_size, 3*grid_height/8+legend_height); |
| 532 |
glVertex2i(width(), 3*grid_height/8+legend_height); |
| 533 |
glVertex2i(ticks_size, 5*grid_height/8+legend_height); |
| 534 |
glVertex2i(width(), 5*grid_height/8+legend_height); |
| 535 |
glEnd(); |
| 536 |
} |
| 537 |
|
| 538 |
// center line |
| 539 |
// glBegin(GL_LINES); |
| 540 |
// glColor3f(0,0,0); |
| 541 |
// glVertex2i(ticks_size, grid_height/2+legend_height); |
| 542 |
// glVertex2i(width(), grid_height/2+legend_height); |
| 543 |
// glEnd(); |
| 544 |
|
| 545 |
// text marks |
| 546 |
float gray = 0.5; |
| 547 |
glColor3f(gray, gray, gray); |
| 548 |
if(setting_useCents->isChecked()) |
| 549 |
{ |
| 550 |
int grad = 10; |
| 551 |
if(setting_spinScale->value() <= 25) grad=5; |
| 552 |
if(setting_spinScale->value() <= 10) grad=1; |
| 553 |
drawTextTickCent(grad, legend_height); |
| 554 |
} |
| 555 |
else |
| 556 |
{ |
| 557 |
painter.begin(this); |
| 558 |
m_font.setPixelSize(14); |
| 559 |
painter.setFont(m_font); |
| 560 |
QFontMetrics fm(m_font); |
| 561 |
string sfraq, sufraq; |
| 562 |
sufraq = string("1/")+QString::number(int(50/setting_spinScale->value())*2).toStdString(); |
| 563 |
sfraq = string("-")+sufraq; |
| 564 |
painter.drawText(2, 3*grid_height/4+fm.xHeight()/2, QString(sfraq.c_str())); |
| 565 |
sfraq = string("+")+sufraq; |
| 566 |
painter.drawText(2, grid_height/4+fm.xHeight()/2, QString(sfraq.c_str())); |
| 567 |
sufraq = string("1/")+QString::number(int(50/setting_spinScale->value())*4).toStdString(); |
| 568 |
sfraq = string("-")+sufraq; |
| 569 |
painter.drawText(2, 5*grid_height/8+fm.xHeight()/2, QString(sfraq.c_str())); |
| 570 |
sfraq = string("+")+sufraq; |
| 571 |
painter.drawText(2, 3*grid_height/8+fm.xHeight()/2, QString(sfraq.c_str())); |
| 572 |
painter.end(); |
| 573 |
} |
| 574 |
|
| 575 |
// vertical lines |
| 576 |
glBegin(GL_LINES); |
| 577 |
gray = 0.5; |
| 578 |
glColor3f(gray, gray, gray); |
| 579 |
for(size_t i=0; i<m_avg_notes.size(); i++) |
| 580 |
{ |
| 581 |
int x = ticks_size+int(i*float(grid_width)/m_avg_notes.size()); |
| 582 |
glVertex2i(x, legend_height); |
| 583 |
glVertex2i(x, height()); |
| 584 |
} |
| 585 |
glEnd(); |
| 586 |
|
| 587 |
// note names |
| 588 |
glColor3f(0, 0, 1); |
| 589 |
painter.begin(this); |
| 590 |
m_font.setPixelSize(14); |
| 591 |
painter.setFont(m_font); |
| 592 |
QFontMetrics fm(m_font); |
| 593 |
for(size_t i=0; i<m_avg_notes.size(); i++) |
| 594 |
{ |
| 595 |
QString str = m_avg_notes[i].getName(); |
| 596 |
|
| 597 |
QRect rect = fm.boundingRect(str); |
| 598 |
painter.drawText(ticks_size+(i+0.5)*float(grid_width)/m_avg_notes.size()-rect.width()/2, height()-4-17, str); |
| 599 |
} |
| 600 |
|
| 601 |
// sizes |
| 602 |
glColor3f(0, 0, 1); |
| 603 |
for(size_t i=0; i<m_avg_notes.size(); i++) |
| 604 |
{ |
| 605 |
if(!m_avg_notes[i].errs.empty()) |
| 606 |
{ |
| 607 |
QString str = QString::number(m_avg_notes[i].errs.size()); |
| 608 |
|
| 609 |
QRect rect = fm.boundingRect(str); |
| 610 |
painter.drawText(ticks_size+(i+0.5)*float(grid_width)/m_avg_notes.size()-rect.width()/2, height()-4, str); |
| 611 |
} |
| 612 |
} |
| 613 |
painter.end(); |
| 614 |
|
| 615 |
// means |
| 616 |
glLineWidth(2.0f); |
| 617 |
glBegin(GL_LINES); |
| 618 |
glColor3f(0, 0, 0); |
| 619 |
for(size_t i=0; i<m_avg_notes.size(); i++) |
| 620 |
{ |
| 621 |
if(!m_avg_notes[i].errs.empty()) |
| 622 |
{ |
| 623 |
int y = int((scale*(m_avg_notes[i].err_mean)+0.5)*grid_height) + legend_height; |
| 624 |
int left = ticks_size+int(i*float(grid_width)/m_avg_notes.size())+1; |
| 625 |
int right = ticks_size+int((i+1)*float(grid_width)/m_avg_notes.size()); |
| 626 |
|
| 627 |
glVertex2i(left, y); |
| 628 |
glVertex2i(right, y); |
| 629 |
} |
| 630 |
} |
| 631 |
glEnd(); |
| 632 |
|
| 633 |
// Marks around current note |
| 634 |
glBegin(GL_LINES); |
| 635 |
gray = 0; |
| 636 |
glColor3f(gray, gray, gray); |
| 637 |
for(size_t i=0; i<m_avg_notes.size(); i++) |
| 638 |
{ |
| 639 |
if(m_avg_notes[i].ht==m_current_ht) |
| 640 |
{ |
| 641 |
int x = ticks_size+int(i*float(grid_width)/m_avg_notes.size()); |
| 642 |
glVertex2i(x, legend_height); |
| 643 |
glVertex2i(x, height()); |
| 644 |
x = ticks_size+int((i+1)*float(grid_width)/m_avg_notes.size()); |
| 645 |
glVertex2i(x, legend_height); |
| 646 |
glVertex2i(x, height()); |
| 647 |
} |
| 648 |
} |
| 649 |
glEnd(); |
| 650 |
|
| 651 |
glFlush(); |
| 652 |
} |
| 653 |
|
| 654 |
void GLStatistics::resizeGL( int w, int h ) |
| 655 |
{ |
| 656 |
// Set the new viewport size |
| 657 |
glViewport(0, 0, (GLint)w, (GLint)h); |
| 658 |
|
| 659 |
// Choose the projection matrix to be the matrix |
| 660 |
// manipulated by the following calls |
| 661 |
glMatrixMode(GL_PROJECTION); |
| 662 |
|
| 663 |
// Set the projection matrix to be the identity matrix |
| 664 |
glLoadIdentity(); |
| 665 |
|
| 666 |
// Define the dimensions of the Orthographic Viewing Volume |
| 667 |
glOrtho(0.0, w, 0.0, h, 0.0, 1.0); |
| 668 |
|
| 669 |
// Choose the modelview matrix to be the matrix |
| 670 |
// manipulated by further calls |
| 671 |
glMatrixMode(GL_MODELVIEW); |
| 672 |
} |