// 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 "GLVolumeHistory.h" #include using namespace std; #include #include #include #include GLVolumeHistory::Note::Note(int h) : ht(h) { } GLVolumeHistory::Note::Note(int h, int num, int den) : ht(h) { factor = QString::number(num)+"/"+QString::number(den); } GLVolumeHistory::Note::Note(int h, float cents) : ht(h) { factor = QString::number(cents); } QString GLVolumeHistory::Note::getName() const { return QString::fromStdString(Music::h2n(ht))+factor; } GLVolumeHistory::GLVolumeHistory(QWidget* parent) : QOpenGLWidget(parent) , View(tr("Volume history"), this) , m_font("Helvetica") { setting_show->setCheckable(true); setting_show->setIcon(QIcon(":/fmit/ui/images/module_volumehistory.svg")); setting_show->setChecked(false); hide(); m_volume_treshold = -100; setting_keep = new QAction(tr("Keep previous notes"), this); setting_keep->setCheckable(true); setting_keep->setChecked(false); connect(setting_keep, SIGNAL(toggled(bool)), this, SLOT(keepPreviousNotes(bool))); m_popup_menu.addAction(setting_keep); } void GLVolumeHistory::save() { s_settings->setValue("keep", setting_keep->isChecked()); } void GLVolumeHistory::load() { setting_keep->setChecked(s_settings->value("keep", setting_keep->isChecked()).toBool()); } void GLVolumeHistory::clearSettings() { s_settings->remove("keep"); } void GLVolumeHistory::addNote(GLVolumeHistory::Note note) { m_notes.push_back(note); if(!setting_keep->isChecked()) while(m_notes.size()>1) m_notes.pop_front(); } void GLVolumeHistory::addVolume(float vol) { m_notes.back().volumes.push_back(vol); } void GLVolumeHistory::keepPreviousNotes(bool keep) { if(!keep) while(m_notes.size()>1) m_notes.pop_front(); } void GLVolumeHistory::setVolumeTreshold(int treshold) { m_volume_treshold = treshold; } void GLVolumeHistory::initializeGL() { // Set the clear color to black glClearColor(1.0, 1.0, 1.0, 0.0); // glShadeModel( GL_FLAT ); glShadeModel( GL_SMOOTH ); glLoadIdentity(); } void GLVolumeHistory::paintGL() { // cout << "GLVolumeHistory::paintGL " << m_notes.size() << endl; glClear(GL_COLOR_BUFFER_BIT); glLineWidth(1.0f); // name glColor3f(0.75,0.75,0.75); QPainter painter(this); m_font.setPixelSize(20); painter.setFont(m_font); painter.drawText(2, 20, tr("Volume")); painter.end(); int s = 2+fontMetrics().horizontalAdvance("50%"); // horiz lines if(2*height()/50>2) { glBegin(GL_LINES); float gray = 0.875; glColor3f(gray, gray, gray); for(int h=2; h<50; h+=2) { glVertex2i(s, h*height()/50); glVertex2i(width(), h*height()/50); } glEnd(); } if(10*height()/50>2) { glBegin(GL_LINES); float gray = 0.75; glColor3f(gray, gray, gray); for(int h=10; h<50; h+=10) { glVertex2i(s, h*height()/50); glVertex2i(width(), h*height()/50); } glEnd(); } glColor3f(0.5f,0.5f,0.5f); painter.begin(this); m_font.setPixelSize(14); painter.setFont(m_font); QFontMetrics fm(m_font); int dy = -fm.xHeight()/2; string sfraq = "[dB]"; painter.drawText(2, height()-2, QString(sfraq.c_str())); sfraq = "-10"; painter.drawText(2, 10*height()/50-dy, QString(sfraq.c_str())); sfraq = "-20"; painter.drawText(2, 20*height()/50-dy, QString(sfraq.c_str())); sfraq = "-30"; painter.drawText(2, 30*height()/50-dy, QString(sfraq.c_str())); sfraq = "-40"; painter.drawText(2, 40*height()/50-dy, QString(sfraq.c_str())); painter.end(); glColor3f(1.0,0.5,0.5); glLineWidth(2.0f); glBegin(GL_LINES); glVertex2f(s, height()+height()*m_volume_treshold/50); glVertex2f(width(), height()+height()*m_volume_treshold/50); glEnd(); // volumes if(!m_notes.empty()) { int total_size = 0; for(size_t i=0; i