// Copyright 2004 "Gilles Degottex" // This file is part of "fmit" // "fmit" is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // "fmit" is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "GLFreqStruct.h" #include using namespace std; #include #include #include #include #include #include using namespace Music; GLFreqStruct::GLFreqStruct(QWidget* parent) : QOpenGLWidget(parent) , View(tr("Harmonics"), this) , m_font("Helvetica") , m_components_max(1.0) { // settings setting_show->setIcon(QIcon(":/fmit/ui/images/module_harmonics.svg")); setting_show->setChecked(false); hide(); QHBoxLayout* numComponentsActionLayout = new QHBoxLayout(&m_popup_menu); QLabel* numComponentsActionTitle = new QLabel(tr("Number of harmonics"), &m_popup_menu); numComponentsActionLayout->addWidget(numComponentsActionTitle); setting_spinNumComponents = new QSpinBox(&m_popup_menu); setting_spinNumComponents->setMinimum(1); setting_spinNumComponents->setMaximum(128); setting_spinNumComponents->setSingleStep(1); setting_spinNumComponents->setValue(16); m_components.resize(setting_spinNumComponents->value()); setting_spinNumComponents->setToolTip(tr("Number of harmonics")); connect(setting_spinNumComponents, SIGNAL(valueChanged(int)), this, SLOT(spinNumComponentsChanged(int))); numComponentsActionLayout->addWidget(setting_spinNumComponents); QWidget* numComponentsActionWidget = new QWidget(&m_popup_menu); numComponentsActionWidget->setLayout(numComponentsActionLayout); QWidgetAction* numComponentsAction = new QWidgetAction(&m_popup_menu); numComponentsAction->setDefaultWidget(numComponentsActionWidget); m_popup_menu.addAction(numComponentsAction); for(size_t i=0; isetValue("spinNumComponents", setting_spinNumComponents->value()); } void GLFreqStruct::load() { setting_spinNumComponents->setValue(s_settings->value("spinNumComponents", setting_spinNumComponents->value()).toInt()); } void GLFreqStruct::clearSettings() { s_settings->remove("spinNumComponents"); } void GLFreqStruct::spinNumComponentsChanged(int num) { m_components.resize(num); } void GLFreqStruct::initializeGL() { // Set the clear color to black glClearColor(1.0, 1.0, 1.0, 0.0); glShadeModel( GL_FLAT ); // glShadeModel( GL_SMOOTH ); glLoadIdentity(); } void GLFreqStruct::paintGL() { if(m_components_max==0.0) return; glClear(GL_COLOR_BUFFER_BIT); int scale_height = 12; int s = 2+fontMetrics().horizontalAdvance("-40dB"); // double scale_factor = 1.0; // if(m_components_max>0.0) // scale_factor = 1.0/m_components_max; // bars glBegin(GL_QUADS); float step = float(width()-s)/m_components.size(); int space = (step>2)?1:0; for(size_t i=0; i