[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Traverso-commit] traverso/src/traverso CMakeLists.txt widgets/Co...
From: |
Remon Sijrier |
Subject: |
[Traverso-commit] traverso/src/traverso CMakeLists.txt widgets/Co... |
Date: |
Fri, 15 Feb 2008 20:14:20 +0000 |
CVSROOT: /sources/traverso
Module name: traverso
Changes by: Remon Sijrier <r_sijrier> 08/02/15 20:14:20
Modified files:
src/traverso : CMakeLists.txt
Added files:
src/traverso/widgets: CorrelationMeterWidget.cpp
CorrelationMeterWidget.h MeterWidget.cpp
MeterWidget.h SpectralMeterWidget.cpp
SpectralMeterWidget.h
Removed files:
src/traverso : CorrelationMeterWidget.cpp
CorrelationMeterWidget.h
SpectralMeterWidget.cpp SpectralMeterWidget.h
Log message:
* move correlation/fft-meterwidget to widgets, extract common code into
new class MeterWidget/View
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/CMakeLists.txt?cvsroot=traverso&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/CorrelationMeterWidget.cpp?cvsroot=traverso&r1=1.35&r2=0
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/CorrelationMeterWidget.h?cvsroot=traverso&r1=1.14&r2=0
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/SpectralMeterWidget.cpp?cvsroot=traverso&r1=1.56&r2=0
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/SpectralMeterWidget.h?cvsroot=traverso&r1=1.26&r2=0
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/CorrelationMeterWidget.cpp?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/CorrelationMeterWidget.h?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/MeterWidget.cpp?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/MeterWidget.h?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/SpectralMeterWidget.cpp?cvsroot=traverso&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/traverso/src/traverso/widgets/SpectralMeterWidget.h?cvsroot=traverso&rev=1.1
Patches:
Index: CMakeLists.txt
===================================================================
RCS file: /sources/traverso/traverso/src/traverso/CMakeLists.txt,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- CMakeLists.txt 23 Jan 2008 17:32:49 -0000 1.10
+++ CMakeLists.txt 15 Feb 2008 20:14:19 -0000 1.11
@@ -29,8 +29,6 @@
PluginSelectorDialog.cpp
Interface.cpp
VUMeter.cpp
-CorrelationMeterWidget.cpp
-SpectralMeterWidget.cpp
QuickDriverConfigWidget.cpp
dialogs/settings/Pages.cpp
dialogs/settings/SettingsDialog.cpp
@@ -48,7 +46,10 @@
dialogs/CDWritingDialog.cpp
widgets/InfoWidgets.cpp
widgets/MessageWidget.cpp
+widgets/MeterWidget.cpp
widgets/ResourcesWidget.cpp
+widgets/CorrelationMeterWidget.cpp
+widgets/SpectralMeterWidget.cpp
)
SET(TRAVERSO_UI_FILES
@@ -82,13 +83,11 @@
SET(TRAVERSO_GUI_MOC_CLASSES
BusMonitor.h
-CorrelationMeterWidget.h
Interface.h
PluginSelectorDialog.h
QuickDriverConfigWidget.h
Traverso.h
VUMeter.h
-SpectralMeterWidget.h
dialogs/BusSelectorDialog.h
dialogs/CDWritingDialog.h
dialogs/ExportDialog.h
@@ -106,6 +105,9 @@
widgets/InfoWidgets.h
widgets/ResourcesWidget.h
widgets/MessageWidget.h
+widgets/MeterWidget.h
+widgets/SpectralMeterWidget.h
+widgets/CorrelationMeterWidget.h
)
QT4_ADD_RESOURCES(TRAVERSO_RESOURCES
@@ -249,6 +251,12 @@
)
ENDIF(HAVE_PORTAUDIO)
+IF(HAVE_PULSEAUDIO)
+ TARGET_LINK_LIBRARIES(traverso
+ pulse-simple
+ )
+ENDIF(HAVE_PULSEAUDIO)
+
IF(HAVE_SLV2)
IF(USE_SYSTEM_SLV2_LIBRARY)
TARGET_LINK_LIBRARIES(traverso
Index: widgets/CorrelationMeterWidget.cpp
===================================================================
RCS file: widgets/CorrelationMeterWidget.cpp
diff -N widgets/CorrelationMeterWidget.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ widgets/CorrelationMeterWidget.cpp 15 Feb 2008 20:14:20 -0000 1.1
@@ -0,0 +1,177 @@
+/*
+ Copyright (C) 2005-2006 Nicola Doebelin
+
+ This file is part of Traverso
+
+ Traverso 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.
+
+ This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+
+#include "CorrelationMeterWidget.h"
+#include <PluginChain.h>
+#include <CorrelationMeter.h>
+#include <Command.h>
+#include <ProjectManager.h>
+#include <Project.h>
+#include <InputEngine.h>
+#include <Sheet.h>
+#include <Themer.h>
+#include <ContextPointer.h>
+#include <Config.h>
+#include <cmath> // used for fabs
+#include <QDebug>
+
+// Always put me below _all_ includes, this is needed
+// in case we run with memory leak detection enabled!
+#include "Debugger.h"
+
+static const float SMOOTH_SHIFT = 0.05;
+
+CorrelationMeterWidget::CorrelationMeterWidget(QWidget* parent)
+ : MeterWidget(parent, new CorrelationMeterView(this))
+{
+ PENTERCONS;
+}
+
+
+CorrelationMeterView::CorrelationMeterView(CorrelationMeterWidget* widget)
+ : MeterView(widget)
+{
+ gradPhase.setColorAt(0.0,
themer()->get_color("CorrelationMeter:foreground:side"));
+ gradPhase.setColorAt(0.5,
themer()->get_color("CorrelationMeter:foreground:center"));
+ gradPhase.setColorAt(1.0,
themer()->get_color("CorrelationMeter:foreground:side"));
+
+ load_configuration();
+}
+
+void CorrelationMeterView::paint(QPainter *painter, const
QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+
+ PENTER3;
+
+ float r = 90.0f / range;
+
+ painter->fillRect(0, 0, m_widget->width(), m_widget->height(),
themer()->get_color("CorrelationMeter:background"));
+
+ int lend = int(0.5*m_widget->width() - (-coeff + 1.0) * r *
m_widget->width() * (1.0 - fabs(direction)));
+ int rend = int(0.5*m_widget->width() + (-coeff + 1.0) * r *
m_widget->width() * (1.0 - fabs(direction)));
+
+ int wdt = abs(lend - rend);
+ int centerOffset = int(m_widget->width() * r * direction);
+
+ int lpos = int((0.50 - r) * m_widget->width());
+ int cpos = m_widget->width()/2;
+ int rpos = int((0.50 + r) * m_widget->width());
+
+ gradPhase.setStart(QPointF(float(lend + centerOffset), 0.0));
+ gradPhase.setFinalStop(QPointF(float(rend + centerOffset), 0.0));
+ painter->fillRect(lend + centerOffset, 0, wdt, m_widget->height(),
gradPhase);
+
+ // center line
+ QPen pen(themer()->get_color("CorrelationMeter:centerline"));
+ pen.setWidth(3);
+ painter->setPen(pen);
+ painter->drawLine(m_widget->width()/2 + centerOffset, 0,
m_widget->width()/2 + centerOffset, m_widget->height());
+
+ painter->setPen(themer()->get_color("CorrelationMeter:grid"));
+ painter->drawLine(cpos, 0, cpos, m_widget->height());
+ if (range > 180) {
+ painter->drawLine(lpos, 0, lpos, m_widget->height());
+ painter->drawLine(rpos, 0, rpos, m_widget->height());
+ }
+
+
painter->setFont(themer()->get_font("CorrelationMeter:fontscale:label"));
+ QFontMetrics fm(themer()->get_font("CorrelationMeter:fontscale:label"));
+
+ if (m_widget->height() < 2*fm.height()) {
+ return;
+ }
+
+ painter->setPen(themer()->get_color("CorrelationMeter:text"));
+ painter->fillRect(0, 0, m_widget->width(), fm.height() + 1,
themer()->get_color("CorrelationMeter:margin"));
+ painter->drawText(cpos - fm.width("C")/2, fm.ascent() + 1, "C");
+
+ if (range == 180) {
+ painter->drawText(1, fm.ascent() + 1, "L");
+ painter->drawText(m_widget->width() - fm.width("R") - 1,
fm.ascent() + 1, "R");
+ } else {
+ painter->drawText(lpos - fm.width("L")/2, fm.ascent() + 1, "L");
+ painter->drawText(rpos - fm.width("R")/2, fm.ascent() + 1, "R");
+ }
+}
+
+void CorrelationMeterView::update_data()
+{
+ if (!m_meter) {
+ return;
+ }
+
+ // MultiMeter::get_data() will assign it's data to coef and direction
+ // if no data was available, return, so we _only_ update the widget when
+ // it needs to be!
+ if (((CorrelationMeter*)m_meter)->get_data(coeff, direction) == 0) {
+ return;
+ }
+
+ update();
+}
+
+void CorrelationMeterView::set_sheet(Sheet *sheet)
+{
+ MeterView::set_sheet(sheet);
+
+ PluginChain* chain = m_sheet->get_plugin_chain();
+
+ foreach(Plugin* plugin, chain->get_plugin_list()) {
+ m_meter = dynamic_cast<CorrelationMeter*>(plugin);
+
+ if (m_meter) {
+ return;
+ }
+ }
+
+ m_meter = new CorrelationMeter();
+ m_meter->init();
+ Command::process_command( chain->add_plugin(m_meter, false) );
+}
+
+
+Command* CorrelationMeterView::set_mode()
+{
+ switch (range) {
+ case 180 : range = 240; break;
+ case 240 : range = 360; break;
+ case 360 : range = 180; break;
+ }
+ update();
+ save_configuration();
+ return 0;
+}
+
+void CorrelationMeterView::save_configuration()
+{
+ config().set_property("CorrelationMeter", "Range", range);
+}
+
+void CorrelationMeterView::load_configuration()
+{
+ range = config().get_property("CorrelationMeter", "Range", 360).toInt();
+}
+
+
+//eof
Index: widgets/CorrelationMeterWidget.h
===================================================================
RCS file: widgets/CorrelationMeterWidget.h
diff -N widgets/CorrelationMeterWidget.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ widgets/CorrelationMeterWidget.h 15 Feb 2008 20:14:20 -0000 1.1
@@ -0,0 +1,69 @@
+/*
+ Copyright (C) 2005-2006 Nicola Doebelin
+
+ This file is part of Traverso
+
+ Traverso 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.
+
+ This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef CORRELATIONMETERWIDGET_H
+#define CORRELATIONMETERWIDGET_H
+
+#include "MeterWidget.h"
+
+class Command;
+class QLinearGradient;
+class QColor;
+
+
+class CorrelationMeterWidget : public MeterWidget
+{
+
+public:
+ CorrelationMeterWidget(QWidget* parent);
+};
+
+class CorrelationMeterView : public MeterView
+{
+ Q_OBJECT
+
+ Q_CLASSINFO("set_mode", tr("Toggle display range"))
+
+public:
+ CorrelationMeterView(CorrelationMeterWidget* widget);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
+
+private:
+ float coeff;
+ float direction;
+ QLinearGradient gradPhase;
+ int range;
+
+ void save_configuration();
+ void load_configuration();
+
+private slots:
+ void update_data();
+ void set_sheet(Sheet* sheet);
+
+public slots:
+ Command* set_mode();
+
+};
+
+#endif
+
Index: widgets/MeterWidget.cpp
===================================================================
RCS file: widgets/MeterWidget.cpp
diff -N widgets/MeterWidget.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ widgets/MeterWidget.cpp 15 Feb 2008 20:14:20 -0000 1.1
@@ -0,0 +1,229 @@
+/*
+ Copyright (C) 2005-2006 Nicola Doebelin
+
+ This file is part of Traverso
+
+ Traverso 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.
+
+ This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+
+#include "MeterWidget.h"
+
+#include "Command.h"
+#include "ContextPointer.h"
+#include "InputEngine.h"
+#include "PluginChain.h"
+#include "ProjectManager.h"
+#include "Project.h"
+#include "Sheet.h"
+#include "Themer.h"
+
+#include <QDebug>
+
+// Always put me below _all_ includes, this is needed
+// in case we run with memory leak detection enabled!
+#include "Debugger.h"
+
+static const int STOP_DELAY = 6000; // in ms
+
+MeterWidget::MeterWidget(QWidget* parent, MeterView* item)
+ : ViewPort(parent)
+ , m_item(item)
+{
+ PENTERCONS;
+ setMinimumWidth(40);
+ setMinimumHeight(10);
+
+ QGraphicsScene* scene = new QGraphicsScene(this);
+ setScene(scene);
+
+ if (m_item) {
+ scene->addItem(m_item);
+ m_item->setPos(0,0);
+ }
+
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+}
+
+MeterWidget::~MeterWidget()
+{
+}
+
+void MeterWidget::resizeEvent( QResizeEvent * )
+{
+ if (m_item) {
+ m_item->resize();
+ }
+}
+
+void MeterWidget::hideEvent(QHideEvent * event)
+{
+ QWidget::hideEvent(event);
+ if (m_item) {
+ m_item->hide_event();
+ }
+}
+
+
+void MeterWidget::showEvent(QShowEvent * event)
+{
+ QWidget::showEvent(event);
+ if (m_item) {
+ m_item->show_event();
+ }
+}
+
+QSize MeterWidget::minimumSizeHint() const
+{
+ return QSize(150, 50);
+}
+
+QSize MeterWidget::sizeHint() const
+{
+ return QSize(220, 50);
+}
+
+void MeterWidget::get_pointed_context_items(QList<ContextItem* > &list)
+{
+ printf("MeterWidget::get_pointed_view_items\n");
+ QList<QGraphicsItem *> itemlist =
items(cpointer().on_first_input_event_x(), cpointer().on_first_input_event_y());
+ foreach(QGraphicsItem* item, itemlist) {
+ if (ViewItem::is_viewitem(item)) {
+ list.append((ViewItem*)item);
+ }
+ }
+
+ printf("itemlist size is %d\n", itemlist.size());
+}
+
+
+MeterView::MeterView(MeterWidget* widget)
+ : ViewItem(0, 0)
+ , m_widget(widget)
+ , m_meter(0)
+ , m_sheet(0)
+{
+ // Nicola: Not sure if we need to initialize here, perhaps a
+ // call to resize would suffice ?
+ m_boundingRect = QRectF();
+
+ // Connections to core:
+ connect(&pm(), SIGNAL(projectLoaded(Project*)), this,
SLOT(set_project(Project*)));
+ connect(&timer, SIGNAL(timeout()), this, SLOT(update_data()));
+ m_delayTimer.setSingleShot(true);
+ connect(&m_delayTimer, SIGNAL(timeout()), this, SLOT(delay_timeout()));
+}
+
+MeterView::~MeterView()
+{
+ if (m_meter) {
+ // FIXME!
+// delete m_meter;
+ }
+}
+
+void MeterView::resize()
+{
+ PENTER;
+
+ prepareGeometryChange();
+ // Nicola: Make this as large as the MeterWidget
+ // by setting the boundingrect.
+ m_boundingRect = QRectF(0, 0, m_widget->width(), m_widget->height());
+}
+
+void MeterView::set_project(Project *project)
+{
+ if (project) {
+ connect(project, SIGNAL(currentSheetChanged(Sheet *)), this,
SLOT(set_sheet(Sheet*)));
+ m_project = project;
+ } else {
+ m_project = 0;
+ set_sheet(0);
+ timer.stop();
+ }
+}
+
+void MeterView::set_sheet(Sheet *sheet)
+{
+ if (m_widget->parentWidget()->isHidden()) {
+ m_sheet = sheet;
+ return;
+ }
+
+
+ if (m_sheet) {
+ if (m_meter) {
+ // FIXME The removed plugin still needs to be
deleted!!!!!!
+
Command::process_command(m_sheet->get_plugin_chain()->remove_plugin(m_meter,
false));
+ timer.stop();
+ disconnect(m_sheet, SIGNAL(transferStopped()), this,
SLOT(transport_stopped()));
+ disconnect(m_sheet, SIGNAL(transferStarted()), this,
SLOT(transport_started()));
+ }
+ }
+
+ m_sheet = sheet;
+
+ if ( ! m_sheet ) {
+ return;
+ }
+
+ connect(m_sheet, SIGNAL(transferStopped()), this,
SLOT(transport_stopped()));
+ connect(m_sheet, SIGNAL(transferStarted()), this,
SLOT(transport_started()));
+}
+
+void MeterView::hide_event()
+{
+ if (m_sheet) {
+ if (m_meter) {
+
Command::process_command(m_sheet->get_plugin_chain()->remove_plugin(m_meter,
false));
+ timer.stop();
+ }
+ }
+}
+
+void MeterView::show_event()
+{
+ if (m_sheet) {
+ if (m_meter) {
+
Command::process_command(m_sheet->get_plugin_chain()->add_plugin(m_meter,
false));
+ timer.start(40);
+ } else {
+ set_sheet(m_sheet);
+ }
+ }
+}
+
+void MeterView::transport_started()
+{
+ timer.start(40);
+ m_delayTimer.stop();
+}
+
+void MeterView::transport_stopped()
+{
+ m_delayTimer.start(STOP_DELAY);
+}
+
+void MeterView::delay_timeout()
+{
+ timer.stop();
+}
+
+
+//eof
+
Index: widgets/MeterWidget.h
===================================================================
RCS file: widgets/MeterWidget.h
diff -N widgets/MeterWidget.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ widgets/MeterWidget.h 15 Feb 2008 20:14:20 -0000 1.1
@@ -0,0 +1,89 @@
+/*
+ Copyright (C) 2008 Remon Sijrier
+
+ This file is part of Traverso
+
+ Traverso 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.
+
+ This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef METER_WIDGET_H
+#define METER_WIDGET_H
+
+#include <QWidget>
+#include <QTimer>
+
+#include <ViewPort.h>
+#include <ViewItem.h>
+
+class MeterView;
+class Sheet;
+class Project;
+class Plugin;
+
+class MeterWidget : public ViewPort
+{
+
+public:
+ MeterWidget(QWidget* parent, MeterView* item);
+ ~MeterWidget();
+
+ void get_pointed_context_items(QList<ContextItem* > &list);
+
+protected:
+ void resizeEvent( QResizeEvent* e);
+ void hideEvent ( QHideEvent * event );
+ void showEvent ( QShowEvent * event );
+ QSize minimumSizeHint () const;
+ QSize sizeHint () const;
+ MeterView* m_item;
+};
+
+class MeterView : public ViewItem
+{
+ Q_OBJECT
+
+public:
+ MeterView(MeterWidget* widget);
+ ~MeterView();
+
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem
*option, QWidget *widget) {};
+ virtual void resize();
+ void hide_event();
+ void show_event();
+
+ void set_sheet( Sheet* );
+
+protected:
+ MeterWidget* m_widget;
+ Plugin* m_meter;
+ QTimer timer;
+ QTimer m_delayTimer;
+ Project* m_project;
+ Sheet* m_sheet;
+
+public slots:
+ void set_project( Project* );
+
+private slots:
+ virtual void update_data() {};
+ void transport_started();
+ void transport_stopped();
+ void delay_timeout();
+};
+
+#endif
+
+
Index: widgets/SpectralMeterWidget.cpp
===================================================================
RCS file: widgets/SpectralMeterWidget.cpp
diff -N widgets/SpectralMeterWidget.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ widgets/SpectralMeterWidget.cpp 15 Feb 2008 20:14:20 -0000 1.1
@@ -0,0 +1,1085 @@
+/*
+ Copyright (C) 2006 Nicola Doebelin
+
+ This file is part of Traverso
+
+ Traverso 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.
+
+ This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#include "SpectralMeterWidget.h"
+#include <Config.h>
+#include <Information.h>
+#include <PluginChain.h>
+#include <SpectralMeter.h>
+#include <Command.h>
+#include <ProjectManager.h>
+#include <Project.h>
+#include <AudioDevice.h>
+#include <InputEngine.h>
+#include <Sheet.h>
+#include <ContextPointer.h>
+#include <Themer.h>
+
+#include <QFileDialog>
+#include <QInputDialog>
+#include <QTextStream>
+
+#include <math.h>
+#include <limits.h>
+
+// Always put me below _all_ includes, this is needed
+// in case we run with memory leak detection enabled!
+#include "Debugger.h"
+
+#define SMOOTH_FACTOR 0.98
+#define DB_FLOOR -140.0
+
+static const float DEFAULT_VAL = -999.0f;
+static const int UPDATE_INTERVAL = 40;
+static const uint MAX_SAMPLES = UINT_MAX;
+
+
+SpectralMeterWidget::SpectralMeterWidget(QWidget* parent)
+ : MeterWidget(parent, 0)
+{
+ PENTERCONS;
+}
+
+
+SpectralMeterView * SpectralMeterWidget::get_item()
+{
+ if (!m_item) {
+ m_item = new SpectralMeterView(this);
+
+ scene()->addItem(m_item);
+ m_item->setPos(0,0);
+ m_item->resize();
+
+ Project* project = pm().get_project();
+ m_item->set_project(project);
+ if (project) {
+ m_item->set_sheet(project->get_current_sheet());
+ }
+
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ }
+
+ return (SpectralMeterView*)m_item;
+}
+
+
+
+
+SpectralMeterView::SpectralMeterView(SpectralMeterWidget* widget)
+ : MeterView(widget)
+{
+
+ m_config = new SpectralMeterConfigWidget(m_widget);
+ load_configuration();
+
+ upper_freq_log = log10(upper_freq);
+ lower_freq_log = log10(lower_freq);
+ sample_rate = audiodevice().get_sample_rate();
+ show_average = false;
+ update_average = true;
+ sample_weight = 1;
+
+ QFontMetrics fm(themer()->get_font("FFTMeter:fontscale:label"));
+ margin_l = 5;
+ margin_r = fm.width("-XX") + 5;
+ margin_t = fm.ascent()/2 + 5;
+ margin_b = fm.ascent() + fm.descent() + 10;
+
+
+ for (int i = 0; i < 4; ++i) {
+ m_freq_labels.push_back(10.0f * pow(10.0,i));
+ m_freq_labels.push_back(20.0f * pow(10.0,i));
+ m_freq_labels.push_back(30.0f * pow(10.0,i));
+ m_freq_labels.push_back(40.0f * pow(10.0,i));
+ m_freq_labels.push_back(50.0f * pow(10.0,i));
+ m_freq_labels.push_back(60.0f * pow(10.0,i));
+ m_freq_labels.push_back(70.0f * pow(10.0,i));
+ m_freq_labels.push_back(80.0f * pow(10.0,i));
+ m_freq_labels.push_back(90.0f * pow(10.0,i));
+ }
+
+ connect(m_config, SIGNAL(configChanged()), this,
SLOT(load_configuration()));
+
+}
+
+void SpectralMeterView::paint(QPainter *painter, const
QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+
+ painter->drawPixmap(0, 0, bgPixmap);
+
+ // draw the bars
+ if (m_spectrum.size()) {
+ QRect rect;
+ QBrush brush(themer()->get_color("FFTMeter:foreground"),
Qt::SolidPattern);
+ painter->setClipRegion(m_rect);
+ painter->setBrush(brush);
+ painter->setPen(Qt::NoPen);
+
+ int spc = 0;
+ if (num_bands < 64) spc = 1;
+
+ // draw the freq bands
+ for (uint i = 0; i < (uint)m_spectrum.size(); ++i) {
+ if (m_bands.at(i+1) < lower_db) {
+ continue;
+ }
+
+ rect.setTopLeft(QPoint((int)freq2xpos(m_bands.at(i)) +
spc, (int)db2ypos(m_spectrum.at(i))));
+
rect.setBottomRight(QPoint((int)freq2xpos(m_bands.at(i+1)) - spc,
(int)db2ypos(DB_FLOOR)));
+ painter->drawRect(rect);
+ }
+
+ // draw the average line if requested
+ if (show_average) {
+
painter->setPen(themer()->get_color("FFTMeter:curve:average"));
+ QPoint pt;
+ QPoint po((int)m_map_idx2xpos.at(0),
(int)db2ypos(m_avg_db.at(0)));
+ for (uint i = 0; i < (uint)m_avg_db.size(); ++i) {
+ pt.setX((int)m_map_idx2xpos.at(i));
+ pt.setY((int)db2ypos(m_avg_db.at(i)));
+ painter->drawLine(po, pt);
+ po = pt;
+ }
+ }
+ }
+}
+
+void SpectralMeterView::resize()
+{
+ PENTER;
+
+ prepareGeometryChange();
+
+
+ // Make the axis labels disappear when the widget becomes too small
+ int x = 0, y = 0, w = m_widget->width(), h = m_widget->height();
+ m_boundingRect = QRectF(0, 0, w, h);
+
+ if (m_widget->width() >= 200) {
+ x = margin_l;
+ w -= (margin_l + margin_r);
+ }
+
+ if (m_widget->height() >= 120) {
+ y = margin_t;
+ h -= (margin_t + margin_b);
+ }
+
+
+ m_rect.setRect(x, y, w, h);
+
+ // update the vectors mapping indices and frequencies to widget
coordinates
+ update_freq_map();
+
+ // re-draw the background pixmap
+ update_background();
+}
+
+void SpectralMeterView::update_background()
+{
+ // draw the background image
+ bgPixmap = QPixmap((int)m_boundingRect.width(),
(int)m_boundingRect.height());
+ bgPixmap.fill(themer()->get_color("FFTMeter:margin"));
+
+ QPainter painter(&bgPixmap);
+ painter.fillRect(m_rect, themer()->get_color("FFTMeter:background"));
+ painter.setFont(themer()->get_font("FFTMeter:fontscale:label"));
+ QFontMetrics fm(themer()->get_font("FFTMeter:fontscale:label"));
+
+ QString spm;
+
+ // draw horizontal lines + labels
+ for (float i = upper_db; i >= lower_db; i -= 10.0f) {
+ float f = db2ypos(i);
+
+ painter.setPen(themer()->get_color("FFTMeter:grid"));
+ painter.drawLine(QPointF(m_rect.x(), f),
QPointF(m_rect.right(), f));
+
+ painter.setPen(themer()->get_color("FFTMeter:text"));
+ spm.sprintf("%2.0f", i);
+ painter.drawText(m_rect.right() + 1, (int)f + fm.ascent()/2,
spm);
+ }
+
+ // draw frequency labels and tickmarks
+ float last_pos = 1.0;
+ for (int i = 0; i < m_freq_labels.size(); ++i) {
+ // check if we have space to draw the labels by checking if the
+ // m_rect is borderless
+ if (!m_rect.top()) {
+ break;
+ }
+
+ float f = freq2xpos(m_freq_labels.at(i));
+
+ // check if the freq is in the visible range
+ if (!f) {
+ continue;
+ }
+
+ spm.sprintf("%2.0f", m_freq_labels.at(i));
+ float s = (float)fm.width(spm)/2.0f;
+
+
+ // draw text only if there is enough space for it
+ if (((f - s) > last_pos) && ((f + s) <
float(m_boundingRect.width()-1))) {
+ painter.setPen(themer()->get_color("FFTMeter:text"));
+ painter.drawText(QPointF(f - s, m_boundingRect.height()
- fm.descent() - 3), spm);
+ last_pos = f + s + 1.0;
+
painter.setPen(themer()->get_color("FFTMeter:tickmarks:main"));
+ } else {
+
painter.setPen(themer()->get_color("FFTMeter:tickmarks:sub"));
+ }
+
+ painter.drawLine(QPointF(f, m_rect.bottom()), QPointF(f,
m_rect.bottom() + 3));
+ }
+}
+
+void SpectralMeterView::update_data()
+{
+ if (!m_meter) {
+ return;
+ }
+
+ // if no data was available, return, so we _only_ update the widget when
+ // it needs to be!
+
+ int ret = ((SpectralMeter*)m_meter)->get_data(specl, specr);
+
+ // switch off the update of the average curve if silence is played back.
+ if (ret == -1) {
+ update_average = false;
+ } else {
+ update_average = true;
+ }
+
+ // do nothing if the buffer is not ready.
+ if (ret == 0) {
+ return;
+ }
+
+ // process the data
+ reduce_bands();
+
+ // paint the widget
+ update();
+}
+
+void SpectralMeterView::set_sheet(Sheet *sheet)
+{
+ MeterView::set_sheet(sheet);
+
+ PluginChain* chain = m_sheet->get_plugin_chain();
+ sample_rate = audiodevice().get_sample_rate();
+
+ foreach(Plugin* plugin, chain->get_plugin_list()) {
+ m_meter = qobject_cast<SpectralMeter*>(plugin);
+
+ if (m_meter) {
+ return;
+ }
+ }
+
+ m_meter = new SpectralMeter();
+ m_meter->init();
+ Command::process_command(chain->add_plugin(m_meter, false));
+}
+
+void SpectralMeterView::reduce_bands()
+{
+ // check if we have to update some variables
+ if ((m_spectrum.size() != (int)num_bands)
+ || (fft_size != (uint)qMin(specl.size(), specr.size()))
+ || ((uint)m_map_idx2freq.size() != fft_size)) {
+ update_layout();
+ }
+
+ // calculate the sample weight for the average curve
+ double sweight = 1.0 / (double)sample_weight;
+ double oweight = 1.0 - sweight;
+
+ // loop through the freq bands and determine the db-values
+ for (int i = 0; i < m_spectrum.size(); ++i) {
+ float val = freq2db(m_bands.at(i), m_bands.at(i+1));
+ float hist = DB_FLOOR + (m_spectrum.at(i) - DB_FLOOR) *
SMOOTH_FACTOR;
+ m_spectrum[i] = qMax(val, hist);
+ }
+
+ // fill the average sample curve
+ if (show_average && update_average) {
+ for (int i = 0; i < m_avg_db.size(); ++i) {
+ float val = 5.0 * (log10(specl.at(i) * specr.at(i)) +
xfactor);
+ float v = val * sweight + m_avg_db.at(i) * oweight;
+ m_avg_db[i] = v;
+ }
+
+ // progress the sample weighting for the average curve
+ if (sample_weight < (MAX_SAMPLES - 1)) {
+ ++sample_weight;
+ }
+ }
+}
+
+// call this function if the size, number of bands, ranges etc. changed.
+// it re-calculates some variables
+void SpectralMeterView::update_layout()
+{
+ timer.stop();
+
+ // recalculate a couple of variables
+ fft_size = qMin(specl.size(), specr.size()); // number of
frequencies (size of the FFT)
+ xfactor = 4.0f * log10(2.0f / float(fft_size)); // a constant factor
for conversion to dB
+ upper_freq_log = log10(upper_freq);
+ lower_freq_log = log10(lower_freq);
+ freq_step = (upper_freq_log - lower_freq_log)/(num_bands);
+ sample_weight = 1;
+
+ // recreate the vector containing the levels and frequency bands
+ m_spectrum.fill(DEFAULT_VAL, num_bands);
+ m_avg_db.fill(DEFAULT_VAL, fft_size);
+
+ // recreate the vector containing border frequencies of the freq bands
+ m_bands.clear();
+ for (uint i = 0; i <= num_bands; ++i) {
+ m_bands.push_back(pow(10.0, lower_freq_log + i*freq_step));
+ }
+
+ // update related stuff
+ update_freq_map();
+
+ timer.start(UPDATE_INTERVAL);
+}
+
+// converts db-values into widget y-coordinates
+float SpectralMeterView::db2ypos(float f)
+{
+ return ((f - upper_db) * m_rect.height()/(lower_db - upper_db)) +
m_rect.top();
+}
+
+// converts frequencies into widget x-coordinates
+float SpectralMeterView::freq2xpos(float f)
+{
+ if ((f < lower_freq) || (f > upper_freq)) {
+ return 0.0;
+ }
+
+ float d = log10(f) - lower_freq_log;
+ return (float)m_rect.x() + d * m_rect.width() / (upper_freq_log -
lower_freq_log);
+}
+
+// determines the highest db value for frequency rang fl-fu. Does all the
interpolation etc.
+float SpectralMeterView::freq2db(float fl, float fu)
+{
+ float lfreq = qMin(fl, fu);
+ float ufreq = qMax(fl, fu);
+ float fidxl = lfreq * (2.0f * fft_size) / (float)sample_rate;
+ float fidxu = ufreq * (2.0f * fft_size) / (float)sample_rate;
+
+ int idxl = int(floor(fidxl - 1.0f));
+ int idxu = int(ceil(fidxu - 1.0f));
+
+ if (idxl < 0) {
+ idxl = 0;
+ }
+
+ if ((uint)idxu >= fft_size) {
+ idxu = fft_size - 1;
+ }
+
+ // distinguishing some cases to save cpu cycles.
+
+ // if we're outside the range covered by the FFT, return DB_FLOOR
+ if (idxu <= 0) {
+ return DB_FLOOR;
+ }
+ if (idxl >= (int)fft_size) {
+ return DB_FLOOR;
+ }
+
+ // they are the same (which shouldn't happen)
+ if (idxu - idxl == 0) {
+ return DB_FLOOR;
+ }
+
+ // if we have exactly one bin in the freq range, return it's db-value
and exit
+ if (idxu - idxl == 2) {
+ return 5.0f * (log10(specl.at(idxl + 1) * specr.at(idxl + 1)) +
xfactor);
+ }
+
+ // if no bin is in between, we have to interpolate in order to get an
accurate value
+ if (idxu - idxl == 1) {
+ float v = fidxu - fidxl;
+ float dbvl = specl.at(idxl) * specr.at(idxl);
+ float dbvu = specl.at(idxu) * specr.at(idxu);
+ return 5.0 * (log10(dbvl + v * (dbvu - dbvl)) + xfactor);
+ }
+
+ // if several bins are in between, search the highest db value
+ float val = 0.0;
+ for (int i = idxl; i <=idxu; ++i) {
+ val = qMax(val, specl.at(i) * specr.at(i));
+ }
+
+ return 5.0 * (log10(val) + xfactor);
+}
+
+// updates a vector mapping fft indices (0, ..., fft_size) to widget
x-positions
+// and one mapping fft indices to frequency
+void SpectralMeterView::update_freq_map()
+{
+ m_map_idx2xpos.clear();
+ m_map_idx2freq.clear();
+ for (uint i = 0; i < fft_size; ++i) {
+ float freq = float(i+1) * (float)sample_rate / (2.0f *
fft_size);
+ m_map_idx2freq.push_back(freq);
+ m_map_idx2xpos.push_back(freq2xpos(freq));
+ }
+}
+
+// opens the properties dialog
+Command* SpectralMeterView::edit_properties()
+{
+ if (!m_meter) {
+ return 0;
+ }
+
+ m_config->show();
+
+ return 0;
+}
+
+// is called upon closing the properties dialog
+void SpectralMeterView::load_configuration()
+{
+ upper_freq = config().get_property("SpectralMeter", "UpperFrequenty",
22050).toInt();
+ lower_freq = config().get_property("SpectralMeter", "LowerFrequenty",
20).toInt();
+ num_bands = config().get_property("SpectralMeter", "NumberOfBands",
16).toInt();
+ upper_db = config().get_property("SpectralMeter", "UpperdB", 0).toInt();
+ lower_db = config().get_property("SpectralMeter", "LowerdB",
-90).toInt();
+ show_average = config().get_property("SpectralMeter", "ShowAvarage",
0).toInt();
+
+ if (m_meter) {
+
((SpectralMeter*)m_meter)->set_fr_size(config().get_property("SpectralMeter",
"FFTSize", 2048).toInt());
+
((SpectralMeter*)m_meter)->set_windowing_function(config().get_property("SpectralMeter",
"WindowingFunction", 1).toInt());
+ ((SpectralMeter*)m_meter)->init();
+ }
+
+ update_layout();
+ update_background();
+}
+
+Command* SpectralMeterView::set_mode()
+{
+ show_average = !show_average;
+ update_layout();
+ return 0;
+}
+
+Command* SpectralMeterView::reset()
+{
+ sample_weight = 1;
+ return 0;
+}
+
+Command* SpectralMeterView::screen_capture( )
+{
+ QImage image(m_widget->size(), QImage::Format_RGB32);
+ QPainter painter(&image);
+ m_widget->render(&painter);
+
+ QString fn = QFileDialog::getSaveFileName (0, tr("Screen Capture file
name"), QDir::homePath());
+
+ // if aborted exit here
+ if (fn.isEmpty()) {
+ return 0;
+ }
+
+ if ( ! image.save(fn, "PNG")) {
+ info().warning(tr("FFT: Unable to write captured image to hard
disk"));
+ }
+
+ return 0;
+}
+
+Command* SpectralMeterView::export_avarage_curve()
+{
+ // check if all requirements are met
+ if ((!show_average) || (!m_project)) {
+ printf("No average data available.\n");
+ info().warning(tr("FFT: No avarage curve used, not data to
export!"));
+ info().information(tr("FFT: Enable avarage curve with < M > to
generate data"));
+ return 0;
+ }
+
+ // check if there actually is data to export
+ int s = qMin(m_map_idx2freq.size(), m_avg_db.size());
+ if (!s) {
+ printf("No average data available.\n");
+ info().warning(tr("FFT: No avarage data to export!"));
+ return 0;
+ }
+
+ QStringList oFormats;
+
+ QString formatA = "plain text";
+ QString formatB = "XMGrace";
+
+ oFormats.append(formatA);
+ oFormats.append(formatB);
+
+ bool ok;
+ QString format = QInputDialog::getItem( 0, tr("Select output format"),
tr("Output format:"),
+ oFormats, 0, false, &ok );
+
+ if (!ok) {
+ printf("Aborted.");
+ return 0;
+ }
+
+ QString fn = QFileDialog::getSaveFileName (0, tr("Export average dB
curve"), m_project->get_root_dir());
+
+ // if aborted exit here
+ if (fn.isEmpty()) {
+ return 0;
+ }
+
+ QFile file(fn);
+
+ // check if the selected file can be opened for writing
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ printf("Could not open file for writing.");
+ return 0;
+ }
+
+ QTextStream out(&file);
+ QString separator = " ";
+ QString str;
+
+ if (format == formatA) {
+ // export the data in text format
+ for (int i = 0; i < s; ++i) {
+ out << str.sprintf("%.6f %.6f\n", m_map_idx2freq.at(i),
m_avg_db.at(i));
+ }
+
+ return 0;
+ }
+
+ if (format == formatB) {
+ // export the data in XMGrace format
+ out << get_xmgr_string();
+ return 0;
+ }
+
+ return 0;
+}
+
+QString SpectralMeterView::get_xmgr_string()
+{
+ QString s = "# Grace project file\n";
+ s += "#\n";
+ s += "@version 50120\n";
+ s += "@page size 842, 594\n";
+ s += "@page scroll 5\%\n";
+ s += "@page inout 5\%\n";
+ s += "@link page off\n";
+ s += "@map font 39 to \"Courier\", \"Courier\"\n";
+ s += "@map font 40 to \"Courier-Bold\", \"Courier-Bold\"\n";
+ s += "@map font 11 to \"Courier-BoldOblique\",
\"Courier-BoldOblique\"\n";
+ s += "@map font 9 to \"Courier-Oblique\", \"Courier-Oblique\"\n";
+ s += "@map font 4 to \"Helvetica\", \"Helvetica\"\n";
+ s += "@map font 6 to \"Helvetica-Bold\", \"Helvetica-Bold\"\n";
+ s += "@map font 7 to \"Helvetica-BoldOblique\",
\"Helvetica-BoldOblique\"\n";
+ s += "@map font 15 to \"Helvetica-Narrow\", \"Helvetica-Narrow\"\n";
+ s += "@map font 16 to \"Helvetica-Narrow-Bold\",
\"Helvetica-Narrow-Bold\"\n";
+ s += "@map font 17 to \"Helvetica-Narrow-BoldOblique\",
\"Helvetica-Narrow-BoldOblique\"\n";
+ s += "@map font 18 to \"Helvetica-Narrow-Oblique\",
\"Helvetica-Narrow-Oblique\"\n";
+ s += "@map font 5 to \"Helvetica-Oblique\", \"Helvetica-Oblique\"\n";
+ s += "@map font 20 to \"NewCenturySchlbk-Bold\",
\"NewCenturySchlbk-Bold\"\n";
+ s += "@map font 21 to \"NewCenturySchlbk-BoldItalic\",
\"NewCenturySchlbk-BoldItalic\"\n";
+ s += "@map font 22 to \"NewCenturySchlbk-Italic\",
\"NewCenturySchlbk-Italic\"\n";
+ s += "@map font 23 to \"NewCenturySchlbk-Roman\",
\"NewCenturySchlbk-Roman\"\n";
+ s += "@map font 24 to \"Palatino-Bold\", \"Palatino-Bold\"\n";
+ s += "@map font 25 to \"Palatino-BoldItalic\",
\"Palatino-BoldItalic\"\n";
+ s += "@map font 26 to \"Palatino-Italic\", \"Palatino-Italic\"\n";
+ s += "@map font 27 to \"Palatino-Roman\", \"Palatino-Roman\"\n";
+ s += "@map font 12 to \"Symbol\", \"Symbol\"\n";
+ s += "@map font 2 to \"Times-Bold\", \"Times-Bold\"\n";
+ s += "@map font 3 to \"Times-BoldItalic\", \"Times-BoldItalic\"\n";
+ s += "@map font 1 to \"Times-Italic\", \"Times-Italic\"\n";
+ s += "@map font 0 to \"Times-Roman\", \"Times-Roman\"\n";
+ s += "@map font 33 to \"ZapfChancery-MediumItalic\",
\"ZapfChancery-MediumItalic\"\n";
+ s += "@map font 13 to \"ZapfDingbats\", \"ZapfDingbats\"\n";
+ s += "@map font 35 to \"CharterBT-Bold\", \"CharterBT-Bold\"\n";
+ s += "@map font 36 to \"CharterBT-BoldItalic\",
\"CharterBT-BoldItalic\"\n";
+ s += "@map font 37 to \"CharterBT-Italic\", \"CharterBT-Italic\"\n";
+ s += "@map font 38 to \"CharterBT-Roman\", \"CharterBT-Roman\"\n";
+ s += "@map font 41 to \"Courier-BoldItalic\", \"Courier-BoldItalic\"\n";
+ s += "@map font 42 to \"Courier-Italic\", \"Courier-Italic\"\n";
+ s += "@map font 43 to \"Hershey-Gothic-English\",
\"Hershey-Gothic-English\"\n";
+ s += "@map font 44 to \"Hershey-Gothic-German\",
\"Hershey-Gothic-German\"\n";
+ s += "@map font 45 to \"Hershey-Gothic-Italian\",
\"Hershey-Gothic-Italian\"\n";
+ s += "@map font 46 to \"Hershey-Plain-Duplex\",
\"Hershey-Plain-Duplex\"\n";
+ s += "@map font 47 to \"Hershey-Plain-Duplex-Italic\",
\"Hershey-Plain-Duplex-Italic\"\n";
+ s += "@map font 48 to \"Hershey-Plain-Triplex\",
\"Hershey-Plain-Triplex\"\n";
+ s += "@map font 49 to \"Hershey-Plain-Triplex-Italic\",
\"Hershey-Plain-Triplex-Italic\"\n";
+ s += "@map font 50 to \"Hershey-Script-Complex\",
\"Hershey-Script-Complex\"\n";
+ s += "@map font 51 to \"Hershey-Script-Simplex\",
\"Hershey-Script-Simplex\"\n";
+ s += "@map font 52 to \"LuxiMono\", \"LuxiMono\"\n";
+ s += "@map font 53 to \"LuxiMono-Bold\", \"LuxiMono-Bold\"\n";
+ s += "@map font 54 to \"LuxiMono-BoldOblique\",
\"LuxiMono-BoldOblique\"\n";
+ s += "@map font 55 to \"LuxiMono-Oblique\", \"LuxiMono-Oblique\"\n";
+ s += "@map font 56 to \"LuxiSans\", \"LuxiSans\"\n";
+ s += "@map font 57 to \"LuxiSans-Bold\", \"LuxiSans-Bold\"\n";
+ s += "@map font 58 to \"LuxiSans-BoldOblique\",
\"LuxiSans-BoldOblique\"\n";
+ s += "@map font 59 to \"LuxiSans-Oblique\", \"LuxiSans-Oblique\"\n";
+ s += "@map font 60 to \"LuxiSerif\", \"LuxiSerif\"\n";
+ s += "@map font 61 to \"LuxiSerif-Bold\", \"LuxiSerif-Bold\"\n";
+ s += "@map font 62 to \"LuxiSerif-BoldOblique\",
\"LuxiSerif-BoldOblique\"\n";
+ s += "@map font 63 to \"LuxiSerif-Oblique\", \"LuxiSerif-Oblique\"\n";
+ s += "@map font 64 to \"Utopia-Bold\", \"Utopia-Bold\"\n";
+ s += "@map font 65 to \"Utopia-BoldItalic\", \"Utopia-BoldItalic\"\n";
+ s += "@map font 66 to \"Utopia-Italic\", \"Utopia-Italic\"\n";
+ s += "@map font 67 to \"Utopia-Regular\", \"Utopia-Regular\"\n";
+ s += "@map color 0 to (255, 255, 255), \"white\"\n";
+ s += "@map color 1 to (0, 0, 0), \"black\"\n";
+ s += "@map color 2 to (255, 0, 0), \"red\"\n";
+ s += "@map color 3 to (0, 255, 0), \"green\"\n";
+ s += "@map color 4 to (0, 0, 255), \"blue\"\n";
+ s += "@map color 5 to (255, 255, 0), \"yellow\"\n";
+ s += "@map color 6 to (188, 143, 143), \"brown\"\n";
+ s += "@map color 7 to (220, 220, 220), \"grey\"\n";
+ s += "@map color 8 to (148, 0, 211), \"violet\"\n";
+ s += "@map color 9 to (0, 255, 255), \"cyan\"\n";
+ s += "@map color 10 to (255, 0, 255), \"magenta\"\n";
+ s += "@map color 11 to (255, 165, 0), \"orange\"\n";
+ s += "@map color 12 to (114, 33, 188), \"indigo\"\n";
+ s += "@map color 13 to (103, 7, 72), \"maroon\"\n";
+ s += "@map color 14 to (64, 224, 208), \"turquoise\"\n";
+ s += "@map color 15 to (0, 139, 0), \"green4\"\n";
+ s += "@reference date 0\n";
+ s += "@date wrap off\n";
+ s += "@date wrap year 1950\n";
+ s += "@default linewidth 1.0\n";
+ s += "@default linestyle 1\n";
+ s += "@default color 1\n";
+ s += "@default pattern 1\n";
+ s += "@default font 0\n";
+ s += "@default char size 1.000000\n";
+ s += "@default symbol size 1.000000\n";
+ s += "@default sformat \"\%.8g\"\n";
+ s += "@background color 0\n";
+ s += "@page background fill on\n";
+ s += "@timestamp off\n";
+ s += "@timestamp 0.03, 0.03\n";
+ s += "@timestamp color 1\n";
+ s += "@timestamp rot 0\n";
+ s += "@timestamp font 0\n";
+ s += "@timestamp char size 1.000000\n";
+ s += "@timestamp def \"Sun Jan 21 12:56:47 2007\"\n";
+ s += "@r0 off\n";
+ s += "@link r0 to g0\n";
+ s += "@r0 type above\n";
+ s += "@r0 linestyle 1\n";
+ s += "@r0 linewidth 1.0\n";
+ s += "@r0 color 1\n";
+ s += "@r0 line 0, 0, 0, 0\n";
+ s += "@r1 off\n";
+ s += "@link r1 to g0\n";
+ s += "@r1 type above\n";
+ s += "@r1 linestyle 1\n";
+ s += "@r1 linewidth 1.0\n";
+ s += "@r1 color 1\n";
+ s += "@r1 line 0, 0, 0, 0\n";
+ s += "@r2 off\n";
+ s += "@link r2 to g0\n";
+ s += "@r2 type above\n";
+ s += "@r2 linestyle 1\n";
+ s += "@r2 linewidth 1.0\n";
+ s += "@r2 color 1\n";
+ s += "@r2 line 0, 0, 0, 0\n";
+ s += "@r3 off\n";
+ s += "@link r3 to g0\n";
+ s += "@r3 type above\n";
+ s += "@r3 linestyle 1\n";
+ s += "@r3 linewidth 1.0\n";
+ s += "@r3 color 1\n";
+ s += "@r3 line 0, 0, 0, 0\n";
+ s += "@r4 off\n";
+ s += "@link r4 to g0\n";
+ s += "@r4 type above\n";
+ s += "@r4 linestyle 1\n";
+ s += "@r4 linewidth 1.0\n";
+ s += "@r4 color 1\n";
+ s += "@r4 line 0, 0, 0, 0\n";
+ s += "@g0 on\n";
+ s += "@g0 hidden false\n";
+ s += "@g0 type XY\n";
+ s += "@g0 stacked false\n";
+ s += "@g0 bar hgap 0.000000\n";
+ s += "@g0 fixedpoint off\n";
+ s += "@g0 fixedpoint type 0\n";
+ s += "@g0 fixedpoint xy 0.000000, 0.000000\n";
+ s += "@g0 fixedpoint format general general\n";
+ s += "@g0 fixedpoint prec 6, 6\n";
+ s += "@with g0\n";
+ s += "@ world 20, -90, 20000, 0\n";
+ s += "@ stack world 0, 0, 0, 0\n";
+ s += "@ znorm 1\n";
+ s += "@ view 0.130000, 0.120000, 1.300000, 0.920000\n";
+ s += "@ title \"\"\n";
+ s += "@ title font 0\n";
+ s += "@ title size 1.500000\n";
+ s += "@ title color 1\n";
+ s += "@ subtitle \"\"\n";
+ s += "@ subtitle font 0\n";
+ s += "@ subtitle size 1.000000\n";
+ s += "@ subtitle color 1\n";
+ s += "@ xaxes scale Logarithmic\n";
+ s += "@ yaxes scale Normal\n";
+ s += "@ xaxes invert off\n";
+ s += "@ yaxes invert off\n";
+ s += "@ xaxis on\n";
+ s += "@ xaxis type zero false\n";
+ s += "@ xaxis offset 0.000000 , 0.000000\n";
+ s += "@ xaxis bar on\n";
+ s += "@ xaxis bar color 1\n";
+ s += "@ xaxis bar linestyle 1\n";
+ s += "@ xaxis bar linewidth 1.0\n";
+ s += "@ xaxis label \"Frequency (Hz)\"\n";
+ s += "@ xaxis label layout para\n";
+ s += "@ xaxis label place auto\n";
+ s += "@ xaxis label char size 1.000000\n";
+ s += "@ xaxis label font 0\n";
+ s += "@ xaxis label color 1\n";
+ s += "@ xaxis label place normal\n";
+ s += "@ xaxis tick on\n";
+ s += "@ xaxis tick major 10\n";
+ s += "@ xaxis tick minor ticks 9\n";
+ s += "@ xaxis tick default 6\n";
+ s += "@ xaxis tick place rounded true\n";
+ s += "@ xaxis tick in\n";
+ s += "@ xaxis tick major size 0.500000\n";
+ s += "@ xaxis tick major color 1\n";
+ s += "@ xaxis tick major linewidth 1.0\n";
+ s += "@ xaxis tick major linestyle 1\n";
+ s += "@ xaxis tick major grid on\n";
+ s += "@ xaxis tick minor color 1\n";
+ s += "@ xaxis tick minor linewidth 1.0\n";
+ s += "@ xaxis tick minor linestyle 2\n";
+ s += "@ xaxis tick minor grid on\n";
+ s += "@ xaxis tick minor size 0.250000\n";
+ s += "@ xaxis ticklabel on\n";
+ s += "@ xaxis ticklabel format general\n";
+ s += "@ xaxis ticklabel prec 5\n";
+ s += "@ xaxis ticklabel formula \"\"\n";
+ s += "@ xaxis ticklabel append \"\"\n";
+ s += "@ xaxis ticklabel prepend \"\"\n";
+ s += "@ xaxis ticklabel angle 0\n";
+ s += "@ xaxis ticklabel skip 0\n";
+ s += "@ xaxis ticklabel stagger 0\n";
+ s += "@ xaxis ticklabel place normal\n";
+ s += "@ xaxis ticklabel offset auto\n";
+ s += "@ xaxis ticklabel offset 0.000000 , 0.010000\n";
+ s += "@ xaxis ticklabel start type auto\n";
+ s += "@ xaxis ticklabel start 0.000000\n";
+ s += "@ xaxis ticklabel stop type auto\n";
+ s += "@ xaxis ticklabel stop 0.000000\n";
+ s += "@ xaxis ticklabel char size 0.750000\n";
+ s += "@ xaxis ticklabel font 0\n";
+ s += "@ xaxis ticklabel color 1\n";
+ s += "@ xaxis tick place both\n";
+ s += "@ xaxis tick spec type both\n";
+ s += "@ xaxis tick spec 37\n";
+ s += "@ xaxis tick major 0, 10\n";
+ s += "@ xaxis ticklabel 0, \"10\"\n";
+ s += "@ xaxis tick major 1, 20\n";
+ s += "@ xaxis ticklabel 1, \"20\"\n";
+ s += "@ xaxis tick minor 2, 30\n";
+ s += "@ xaxis tick minor 3, 40\n";
+ s += "@ xaxis tick major 4, 50\n";
+ s += "@ xaxis ticklabel 4, \"50\"\n";
+ s += "@ xaxis tick minor 5, 60\n";
+ s += "@ xaxis tick minor 6, 70\n";
+ s += "@ xaxis tick minor 7, 80\n";
+ s += "@ xaxis tick minor 8, 90\n";
+ s += "@ xaxis tick major 9, 100\n";
+ s += "@ xaxis ticklabel 9, \"100\"\n";
+ s += "@ xaxis tick major 10, 200\n";
+ s += "@ xaxis ticklabel 10, \"200\"\n";
+ s += "@ xaxis tick minor 11, 300\n";
+ s += "@ xaxis tick minor 12, 400\n";
+ s += "@ xaxis tick major 13, 500\n";
+ s += "@ xaxis ticklabel 13, \"500\"\n";
+ s += "@ xaxis tick minor 14, 600\n";
+ s += "@ xaxis tick minor 15, 700\n";
+ s += "@ xaxis tick minor 16, 800\n";
+ s += "@ xaxis tick minor 17, 900\n";
+ s += "@ xaxis tick major 18, 1000\n";
+ s += "@ xaxis ticklabel 18, \"1000\"\n";
+ s += "@ xaxis tick major 19, 2000\n";
+ s += "@ xaxis ticklabel 19, \"2000\"\n";
+ s += "@ xaxis tick minor 20, 3000\n";
+ s += "@ xaxis tick minor 21, 4000\n";
+ s += "@ xaxis tick major 22, 5000\n";
+ s += "@ xaxis ticklabel 22, \"5000\"\n";
+ s += "@ xaxis tick minor 23, 6000\n";
+ s += "@ xaxis tick minor 24, 7000\n";
+ s += "@ xaxis tick minor 25, 8000\n";
+ s += "@ xaxis tick minor 26, 9000\n";
+ s += "@ xaxis tick major 27, 10000\n";
+ s += "@ xaxis ticklabel 27, \"10000\"\n";
+ s += "@ xaxis tick major 28, 20000\n";
+ s += "@ xaxis ticklabel 28, \"20000\"\n";
+ s += "@ xaxis tick minor 29, 30000\n";
+ s += "@ xaxis tick minor 30, 40000\n";
+ s += "@ xaxis tick minor 31, 50000\n";
+ s += "@ xaxis tick minor 32, 60000\n";
+ s += "@ xaxis tick minor 33, 70000\n";
+ s += "@ xaxis tick minor 34, 80000\n";
+ s += "@ xaxis tick minor 35, 90000\n";
+ s += "@ xaxis tick minor 36, 100000\n";
+ s += "@ xaxis ticklabel 36, \"1e+05\"\n";
+ s += "@ yaxis on\n";
+ s += "@ yaxis type zero false\n";
+ s += "@ yaxis offset 0.000000 , 0.000000\n";
+ s += "@ yaxis bar on\n";
+ s += "@ yaxis bar color 1\n";
+ s += "@ yaxis bar linestyle 1\n";
+ s += "@ yaxis bar linewidth 1.0\n";
+ s += "@ yaxis label \"Level (dB)\"\n";
+ s += "@ yaxis label layout para\n";
+ s += "@ yaxis label place auto\n";
+ s += "@ yaxis label char size 1.000000\n";
+ s += "@ yaxis label font 0\n";
+ s += "@ yaxis label color 1\n";
+ s += "@ yaxis label place normal\n";
+ s += "@ yaxis tick on\n";
+ s += "@ yaxis tick major 10\n";
+ s += "@ yaxis tick minor ticks 1\n";
+ s += "@ yaxis tick default 6\n";
+ s += "@ yaxis tick place rounded true\n";
+ s += "@ yaxis tick in\n";
+ s += "@ yaxis tick major size 0.500000\n";
+ s += "@ yaxis tick major color 1\n";
+ s += "@ yaxis tick major linewidth 1.0\n";
+ s += "@ yaxis tick major linestyle 1\n";
+ s += "@ yaxis tick major grid on\n";
+ s += "@ yaxis tick minor color 1\n";
+ s += "@ yaxis tick minor linewidth 1.0\n";
+ s += "@ yaxis tick minor linestyle 2\n";
+ s += "@ yaxis tick minor grid on\n";
+ s += "@ yaxis tick minor size 0.250000\n";
+ s += "@ yaxis ticklabel on\n";
+ s += "@ yaxis ticklabel format general\n";
+ s += "@ yaxis ticklabel prec 5\n";
+ s += "@ yaxis ticklabel formula \"\"\n";
+ s += "@ yaxis ticklabel append \"\"\n";
+ s += "@ yaxis ticklabel prepend \"\"\n";
+ s += "@ yaxis ticklabel angle 0\n";
+ s += "@ yaxis ticklabel skip 0\n";
+ s += "@ yaxis ticklabel stagger 0\n";
+ s += "@ yaxis ticklabel place normal\n";
+ s += "@ yaxis ticklabel offset auto\n";
+ s += "@ yaxis ticklabel offset 0.000000 , 0.010000\n";
+ s += "@ yaxis ticklabel start type auto\n";
+ s += "@ yaxis ticklabel start 0.000000\n";
+ s += "@ yaxis ticklabel stop type auto\n";
+ s += "@ yaxis ticklabel stop 0.000000\n";
+ s += "@ yaxis ticklabel char size 0.750000\n";
+ s += "@ yaxis ticklabel font 0\n";
+ s += "@ yaxis ticklabel color 1\n";
+ s += "@ yaxis tick place both\n";
+ s += "@ yaxis tick spec type none\n";
+ s += "@ altxaxis off\n";
+ s += "@ altyaxis off\n";
+ s += "@ legend on\n";
+ s += "@ legend loctype view\n";
+ s += "@ legend 0.84941423, 0.8\n";
+ s += "@ legend box color 1\n";
+ s += "@ legend box pattern 1\n";
+ s += "@ legend box linewidth 1.0\n";
+ s += "@ legend box linestyle 1\n";
+ s += "@ legend box fill color 0\n";
+ s += "@ legend box fill pattern 1\n";
+ s += "@ legend font 0\n";
+ s += "@ legend char size 1.000000\n";
+ s += "@ legend color 1\n";
+ s += "@ legend length 4\n";
+ s += "@ legend vgap 1\n";
+ s += "@ legend hgap 1\n";
+ s += "@ legend invert false\n";
+ s += "@ frame type 0\n";
+ s += "@ frame linestyle 1\n";
+ s += "@ frame linewidth 1.0\n";
+ s += "@ frame color 1\n";
+ s += "@ frame pattern 1\n";
+ s += "@ frame background color 0\n";
+ s += "@ frame background pattern 0\n";
+ s += "@ s0 hidden false\n";
+ s += "@ s0 type xy\n";
+ s += "@ s0 symbol 9\n";
+ s += "@ s0 symbol size 0.500000\n";
+ s += "@ s0 symbol color 2\n";
+ s += "@ s0 symbol pattern 1\n";
+ s += "@ s0 symbol fill color 2\n";
+ s += "@ s0 symbol fill pattern 0\n";
+ s += "@ s0 symbol linewidth 1.0\n";
+ s += "@ s0 symbol linestyle 1\n";
+ s += "@ s0 symbol char 65\n";
+ s += "@ s0 symbol char font 0\n";
+ s += "@ s0 symbol skip 0\n";
+ s += "@ s0 line type 1\n";
+ s += "@ s0 line linestyle 1\n";
+ s += "@ s0 line linewidth 2.0\n";
+ s += "@ s0 line color 1\n";
+ s += "@ s0 line pattern 1\n";
+ s += "@ s0 baseline type 0\n";
+ s += "@ s0 baseline off\n";
+ s += "@ s0 dropline off\n";
+ s += "@ s0 fill type 0\n";
+ s += "@ s0 fill rule 0\n";
+ s += "@ s0 fill color 1\n";
+ s += "@ s0 fill pattern 1\n";
+ s += "@ s0 avalue off\n";
+ s += "@ s0 avalue type 2\n";
+ s += "@ s0 avalue char size 1.000000\n";
+ s += "@ s0 avalue font 0\n";
+ s += "@ s0 avalue color 1\n";
+ s += "@ s0 avalue rot 0\n";
+ s += "@ s0 avalue format general\n";
+ s += "@ s0 avalue prec 3\n";
+ s += "@ s0 avalue prepend \"\"\n";
+ s += "@ s0 avalue append \"\"\n";
+ s += "@ s0 avalue offset 0.000000 , 0.000000\n";
+ s += "@ s0 errorbar off\n";
+ s += "@ s0 errorbar place both\n";
+ s += "@ s0 errorbar color 2\n";
+ s += "@ s0 errorbar pattern 1\n";
+ s += "@ s0 errorbar size 1.000000\n";
+ s += "@ s0 errorbar linewidth 1.0\n";
+ s += "@ s0 errorbar linestyle 1\n";
+ s += "@ s0 errorbar riser linewidth 1.0\n";
+ s += "@ s0 errorbar riser linestyle 1\n";
+ s += "@ s0 errorbar riser clip off\n";
+ s += "@ s0 errorbar riser clip length 0.100000\n";
+ s += "@ s0 comment \"Exported from Traverso\"\n";
+ s += "@ s0 legend \"\"\n";
+ s += "@target G0.S0\n";
+ s += "@type xy\n";
+
+ int n = qMin(m_map_idx2freq.size(), m_avg_db.size());
+ QString str;
+
+ for (int i = 0; i < n; ++i) {
+ s += str.sprintf("%.6f %.6f\n", m_map_idx2freq.at(i),
m_avg_db.at(i));
+ }
+
+ s += "&\n";
+
+ return s;
+}
+
+
+/*******************************************/
+/* SpectralMeterConfWidget */
+/*******************************************/
+
+SpectralMeterConfigWidget::SpectralMeterConfigWidget( QWidget * parent )
+ : QDialog(parent)
+{
+ setupUi(this);
+ groupBoxAdvanced->hide();
+
+ load_configuration();
+
+ connect(buttonAdvanced, SIGNAL(toggled(bool)), this,
SLOT(advancedButton_toggled(bool)));
+}
+
+void SpectralMeterConfigWidget::on_buttonApply_clicked()
+{
+ save_configuration();
+ emit configChanged();
+}
+
+void SpectralMeterConfigWidget::on_buttonClose_clicked( )
+{
+ hide();
+}
+
+void SpectralMeterConfigWidget::advancedButton_toggled(bool b)
+{
+ if (b) {
+ groupBoxAdvanced->show();
+ } else {
+ groupBoxAdvanced->hide();
+ }
+}
+
+void SpectralMeterConfigWidget::save_configuration( )
+{
+ config().set_property( "SpectralMeter",
+ "UpperFrequenty",
+ qMax(spinBoxLowerFreq->value(),
spinBoxUpperFreq->value()) );
+ config().set_property( "SpectralMeter",
+ "LowerFrequenty",
+ qMin(spinBoxLowerFreq->value(),
spinBoxUpperFreq->value()) );
+ config().set_property( "SpectralMeter",
+ "UpperdB",
+ qMax(spinBoxUpperDb->value(),
spinBoxLowerDb->value()) );
+ config().set_property( "SpectralMeter",
+ "LowerdB",
+ qMin(spinBoxUpperDb->value(),
spinBoxLowerDb->value()) );
+ config().set_property("SpectralMeter", "NumberOfBands",
spinBoxNumBands->value() );
+ config().set_property("SpectralMeter", "ShowAvarage",
checkBoxAverage->isChecked() );
+
+ config().set_property("SpectralMeter", "FFTSize",
comboBoxFftSize->currentText().toInt() );
+ config().set_property("SpectralMeter", "WindowingFunction",
comboBoxWindowing->currentIndex() );
+}
+
+void SpectralMeterConfigWidget::load_configuration( )
+{
+ int value;
+ value = config().get_property("SpectralMeter", "UpperFrequenty",
22050).toInt();
+ spinBoxUpperFreq->setValue(value);
+ value = config().get_property("SpectralMeter", "LowerFrequenty",
20).toInt();
+ spinBoxLowerFreq->setValue(value);
+ value = config().get_property("SpectralMeter", "UpperdB", 0).toInt();
+ spinBoxUpperDb->setValue(value);
+ value = config().get_property("SpectralMeter", "LowerdB", -90).toInt();
+ spinBoxLowerDb->setValue(value);
+ value = config().get_property("SpectralMeter", "NumberOfBands",
16).toInt();
+ spinBoxNumBands->setValue(value);
+ value = config().get_property("SpectralMeter", "ShowAvarage",
0).toInt();
+ checkBoxAverage->setChecked(value);
+ value = config().get_property("SpectralMeter", "FFTSize", 2048).toInt();
+ QString str;
+ str = QString("%1").arg(value);
+ int idx = comboBoxFftSize->findText(str);
+ idx = idx == -1 ? 3 : idx;
+ comboBoxFftSize->setCurrentIndex(idx);
+ value = config().get_property("SpectralMeter", "WindowingFunction",
1).toInt();
+ comboBoxWindowing->setCurrentIndex(value);
+}
+
+//eof
+
Index: widgets/SpectralMeterWidget.h
===================================================================
RCS file: widgets/SpectralMeterWidget.h
diff -N widgets/SpectralMeterWidget.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ widgets/SpectralMeterWidget.h 15 Feb 2008 20:14:20 -0000 1.1
@@ -0,0 +1,145 @@
+/*
+ Copyright (C) 2006 Nicola Doebelin
+
+ This file is part of Traverso
+
+ Traverso 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.
+
+ This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+*/
+
+#ifndef SPECTRALMETERWIDGET_H
+#define SPECTRALMETERWIDGET_H
+
+#include "MeterWidget.h"
+
+#include <QVector>
+#include "ui_SpectralMeterConfigWidget.h"
+#include <QDialog>
+
+class Sheet;
+class Project;
+class QRect;
+class QPixmap;
+class Command;
+class SpectralMeterView;
+
+
+class SpectralMeterConfigWidget : public QDialog, private
Ui::SpectralMeterConfigWidget
+{
+ Q_OBJECT
+
+public:
+ SpectralMeterConfigWidget(QWidget* parent = 0);
+
+private:
+ void save_configuration();
+ void load_configuration();
+
+private slots:
+ void on_buttonClose_clicked();
+ void on_buttonApply_clicked();
+ void advancedButton_toggled(bool);
+
+signals:
+ void configChanged();
+
+};
+
+class SpectralMeterWidget : public MeterWidget
+{
+public:
+ SpectralMeterWidget(QWidget* parent);
+
+private:
+ SpectralMeterView* get_item();
+};
+
+
+class SpectralMeterView : public MeterView
+{
+ Q_OBJECT
+
+ Q_CLASSINFO("edit_properties", tr("Settings..."))
+ Q_CLASSINFO("set_mode", tr("Toggle avarage curve"))
+ Q_CLASSINFO("reset", tr("Reset average curve"))
+ Q_CLASSINFO("export_avarage_curve", tr("Export avarage curve"))
+ Q_CLASSINFO("screen_capture", tr("Capture Screen"))
+
+
+public:
+ SpectralMeterView(SpectralMeterWidget* widget);
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
+ virtual void resize();
+
+private:
+ QVector<float> specl;
+ QVector<float> specr;
+ QVector<float> m_spectrum;
+ QVector<float> m_history;
+ QVector<float> m_bands;
+ QVector<float> m_freq_labels;
+ QVector<float> m_avg_db;
+ QVector<float> m_map_idx2xpos;
+ QVector<float> m_map_idx2freq;
+ QRect m_rect;
+ SpectralMeterConfigWidget *m_config;
+ QPixmap bgPixmap;
+ uint num_bands;
+ uint sample_rate;
+ float upper_freq;
+ float lower_freq;
+ float upper_db;
+ float lower_db;
+ int margin_l;
+ int margin_r;
+ int margin_t;
+ int margin_b;
+ uint sample_weight;
+
+ uint fft_size;
+ float xfactor;
+ float upper_freq_log;
+ float lower_freq_log;
+ float freq_step;
+ int bar_offset;
+ bool show_average;
+ bool update_average;
+
+ void reduce_bands();
+ void update_layout();
+ void update_freq_map();
+ float db2ypos(float);
+ float freq2xpos(float);
+ void update_background();
+ float freq2db(float, float);
+ QString get_xmgr_string();
+
+private slots:
+ void update_data();
+
+public slots:
+ void load_configuration();
+ void set_sheet(Sheet* sheet);
+
+ Command* edit_properties();
+ Command* set_mode();
+ Command* reset();
+ Command* export_avarage_curve();
+ Command* screen_capture();
+};
+
+#endif
+
Index: CorrelationMeterWidget.cpp
===================================================================
RCS file: CorrelationMeterWidget.cpp
diff -N CorrelationMeterWidget.cpp
--- CorrelationMeterWidget.cpp 15 Feb 2008 17:34:11 -0000 1.35
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,340 +0,0 @@
-/*
- Copyright (C) 2005-2006 Nicola Doebelin
-
- This file is part of Traverso
-
- Traverso 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.
-
- This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-
-*/
-
-
-#include "CorrelationMeterWidget.h"
-#include <PluginChain.h>
-#include <CorrelationMeter.h>
-#include <Command.h>
-#include <ProjectManager.h>
-#include <Project.h>
-#include <InputEngine.h>
-#include <Sheet.h>
-#include <Themer.h>
-#include <ContextPointer.h>
-#include <Config.h>
-#include <cmath> // used for fabs
-#include <QDebug>
-
-// Always put me below _all_ includes, this is needed
-// in case we run with memory leak detection enabled!
-#include "Debugger.h"
-
-static const float SMOOTH_SHIFT = 0.05;
-static const int STOP_DELAY = 6000; // in ms
-
-CorrelationMeterWidget::CorrelationMeterWidget(QWidget* parent)
- : ViewPort(parent)
-{
- PENTERCONS;
- setMinimumWidth(40);
- setMinimumHeight(10);
-
- m_item = new CorrelationMeterView(this);
-
- QGraphicsScene* scene = new QGraphicsScene(this);
- setScene(scene);
- scene->addItem(m_item);
- m_item->setPos(0,0);
-
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
-}
-
-CorrelationMeterWidget::~CorrelationMeterWidget()
-{
-}
-
-void CorrelationMeterWidget::resizeEvent( QResizeEvent * )
-{
- m_item->resize();
-}
-
-void CorrelationMeterWidget::hideEvent(QHideEvent * event)
-{
- QWidget::hideEvent(event);
- m_item->hide_event();
-}
-
-
-void CorrelationMeterWidget::showEvent(QShowEvent * event)
-{
- QWidget::showEvent(event);
- m_item->show_event();
-}
-
-QSize CorrelationMeterWidget::minimumSizeHint() const
-{
- return QSize(150, 50);
-}
-
-QSize CorrelationMeterWidget::sizeHint() const
-{
- return QSize(220, 50);
-}
-
-void CorrelationMeterWidget::get_pointed_context_items(QList<ContextItem* >
&list)
-{
- printf("CorrelationMeterWidget::get_pointed_view_items\n");
- QList<QGraphicsItem *> itemlist =
items(cpointer().on_first_input_event_x(), cpointer().on_first_input_event_y());
- foreach(QGraphicsItem* item, itemlist) {
- if (ViewItem::is_viewitem(item)) {
- list.append((ViewItem*)item);
- }
- }
-
- printf("itemlist size is %d\n", itemlist.size());
-}
-
-
-
-
-
-CorrelationMeterView::CorrelationMeterView(CorrelationMeterWidget* widget)
- : ViewItem(0, 0)
- , m_widget(widget)
- , m_meter(0)
- , m_sheet(0)
-{
- gradPhase.setColorAt(0.0,
themer()->get_color("CorrelationMeter:foreground:side"));
- gradPhase.setColorAt(0.5,
themer()->get_color("CorrelationMeter:foreground:center"));
- gradPhase.setColorAt(1.0,
themer()->get_color("CorrelationMeter:foreground:side"));
-
- load_configuration();
-
- // Nicola: Not sure if we need to initialize here, perhaps a
- // call to resize would suffice ?
- m_boundingRect = QRectF();
-
- // Connections to core:
- connect(&pm(), SIGNAL(projectLoaded(Project*)), this,
SLOT(set_project(Project*)));
- connect(&timer, SIGNAL(timeout()), this, SLOT(update_data()));
- m_delayTimer.setSingleShot(true);
- connect(&m_delayTimer, SIGNAL(timeout()), this, SLOT(delay_timeout()));
-}
-
-CorrelationMeterView::~CorrelationMeterView()
-{
- if (m_meter) {
- delete m_meter;
- }
-}
-
-void CorrelationMeterView::paint(QPainter *painter, const
QStyleOptionGraphicsItem *option, QWidget *widget)
-{
- Q_UNUSED(option);
- Q_UNUSED(widget);
-
- PENTER3;
-
- float r = 90.0f / range;
-
- painter->fillRect(0, 0, m_widget->width(), m_widget->height(),
themer()->get_color("CorrelationMeter:background"));
-
- int lend = int(0.5*m_widget->width() - (-coeff + 1.0) * r *
m_widget->width() * (1.0 - fabs(direction)));
- int rend = int(0.5*m_widget->width() + (-coeff + 1.0) * r *
m_widget->width() * (1.0 - fabs(direction)));
-
- int wdt = abs(lend - rend);
- int centerOffset = int(m_widget->width() * r * direction);
-
- int lpos = int((0.50 - r) * m_widget->width());
- int cpos = m_widget->width()/2;
- int rpos = int((0.50 + r) * m_widget->width());
-
- gradPhase.setStart(QPointF(float(lend + centerOffset), 0.0));
- gradPhase.setFinalStop(QPointF(float(rend + centerOffset), 0.0));
- painter->fillRect(lend + centerOffset, 0, wdt, m_widget->height(),
gradPhase);
-
- // center line
- QPen pen(themer()->get_color("CorrelationMeter:centerline"));
- pen.setWidth(3);
- painter->setPen(pen);
- painter->drawLine(m_widget->width()/2 + centerOffset, 0,
m_widget->width()/2 + centerOffset, m_widget->height());
-
- painter->setPen(themer()->get_color("CorrelationMeter:grid"));
- painter->drawLine(cpos, 0, cpos, m_widget->height());
- if (range > 180) {
- painter->drawLine(lpos, 0, lpos, m_widget->height());
- painter->drawLine(rpos, 0, rpos, m_widget->height());
- }
-
-
painter->setFont(themer()->get_font("CorrelationMeter:fontscale:label"));
- QFontMetrics fm(themer()->get_font("CorrelationMeter:fontscale:label"));
-
- if (m_widget->height() < 2*fm.height()) {
- return;
- }
-
- painter->setPen(themer()->get_color("CorrelationMeter:text"));
- painter->fillRect(0, 0, m_widget->width(), fm.height() + 1,
themer()->get_color("CorrelationMeter:margin"));
- painter->drawText(cpos - fm.width("C")/2, fm.ascent() + 1, "C");
-
- if (range == 180) {
- painter->drawText(1, fm.ascent() + 1, "L");
- painter->drawText(m_widget->width() - fm.width("R") - 1,
fm.ascent() + 1, "R");
- } else {
- painter->drawText(lpos - fm.width("L")/2, fm.ascent() + 1, "L");
- painter->drawText(rpos - fm.width("R")/2, fm.ascent() + 1, "R");
- }
-}
-
-void CorrelationMeterView::resize()
-{
- PENTER;
-
- prepareGeometryChange();
- // Nicola: Make this as large as the CorrelationMeterWidget
- // by setting the boundingrect.
- m_boundingRect = QRectF(0, 0, m_widget->width(), m_widget->height());
-}
-
-void CorrelationMeterView::update_data()
-{
- if (!m_meter) {
- return;
- }
-
- // MultiMeter::get_data() will assign it's data to coef and direction
- // if no data was available, return, so we _only_ update the widget when
- // it needs to be!
- if (m_meter->get_data(coeff, direction) == 0) {
- return;
- }
-
- update();
-}
-
-void CorrelationMeterView::set_project(Project *project)
-{
- if (project) {
- connect(project, SIGNAL(currentSheetChanged(Sheet *)), this,
SLOT(set_sheet(Sheet*)));
- } else {
- set_sheet(0);
- timer.stop();
- }
-}
-
-void CorrelationMeterView::set_sheet(Sheet *sheet)
-{
- if (m_widget->parentWidget()->isHidden()) {
- m_sheet = sheet;
- return;
- }
-
-
- if (m_sheet) {
- if (m_meter) {
- // FIXME The removed plugin still needs to be
deleted!!!!!!
-
Command::process_command(m_sheet->get_plugin_chain()->remove_plugin(m_meter,
false));
- timer.stop();
- disconnect(m_sheet, SIGNAL(transferStopped()), this,
SLOT(transport_stopped()));
- disconnect(m_sheet, SIGNAL(transferStarted()), this,
SLOT(transport_started()));
- }
- }
-
- m_sheet = sheet;
-
- if ( ! m_sheet ) {
- return;
- }
-
- connect(m_sheet, SIGNAL(transferStopped()), this,
SLOT(transport_stopped()));
- connect(m_sheet, SIGNAL(transferStarted()), this,
SLOT(transport_started()));
-
- PluginChain* chain = m_sheet->get_plugin_chain();
-
- foreach(Plugin* plugin, chain->get_plugin_list()) {
- m_meter = dynamic_cast<CorrelationMeter*>(plugin);
-
- if (m_meter) {
- return;
- }
- }
-
- m_meter = new CorrelationMeter();
- m_meter->init();
- Command::process_command( chain->add_plugin(m_meter, false) );
-}
-
-void CorrelationMeterView::hide_event()
-{
- if (m_sheet) {
- if (m_meter) {
-
Command::process_command(m_sheet->get_plugin_chain()->remove_plugin(m_meter,
false));
- timer.stop();
- }
- }
-}
-
-void CorrelationMeterView::show_event()
-{
- if (m_sheet) {
- if (m_meter) {
-
Command::process_command(m_sheet->get_plugin_chain()->add_plugin(m_meter,
false));
- timer.start(40);
- } else {
- set_sheet(m_sheet);
- }
- }
-}
-
-
-
-Command* CorrelationMeterView::set_mode()
-{
- switch (range) {
- case 180 : range = 240; break;
- case 240 : range = 360; break;
- case 360 : range = 180; break;
- }
- update();
- save_configuration();
- return 0;
-}
-
-void CorrelationMeterView::transport_started()
-{
- timer.start(40);
- m_delayTimer.stop();
-}
-
-void CorrelationMeterView::transport_stopped()
-{
- m_delayTimer.start(STOP_DELAY);
-}
-
-void CorrelationMeterView::delay_timeout()
-{
- timer.stop();
-}
-
-void CorrelationMeterView::save_configuration()
-{
- config().set_property("CorrelationMeter", "Range", range);
-}
-
-void CorrelationMeterView::load_configuration()
-{
- range = config().get_property("CorrelationMeter", "Range", 360).toInt();
-}
-
-
-//eof
Index: CorrelationMeterWidget.h
===================================================================
RCS file: CorrelationMeterWidget.h
diff -N CorrelationMeterWidget.h
--- CorrelationMeterWidget.h 15 Feb 2008 16:53:19 -0000 1.14
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,104 +0,0 @@
-/*
- Copyright (C) 2005-2006 Nicola Doebelin
-
- This file is part of Traverso
-
- Traverso 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.
-
- This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-
-*/
-
-#ifndef CORRELATIONMETERWIDGET_H
-#define CORRELATIONMETERWIDGET_H
-
-#include <QWidget>
-#include <QTimer>
-
-#include <ViewPort.h>
-#include <ViewItem.h>
-
-class CorrelationMeter;
-class CorrelationMeterView;
-class Sheet;
-class Project;
-class Command;
-class QLinearGradient;
-class QColor;
-
-
-class CorrelationMeterWidget : public ViewPort
-{
-
-public:
- CorrelationMeterWidget(QWidget* parent);
- ~CorrelationMeterWidget();
-
- void get_pointed_context_items(QList<ContextItem* > &list);
-
-protected:
- void resizeEvent( QResizeEvent* e);
- void hideEvent ( QHideEvent * event );
- void showEvent ( QShowEvent * event );
- QSize minimumSizeHint () const;
- QSize sizeHint () const;
-
-private:
- CorrelationMeterView* m_item;
-
-};
-
-class CorrelationMeterView : public ViewItem
-{
- Q_OBJECT
-
- Q_CLASSINFO("set_mode", tr("Toggle display range"))
-
-public:
- CorrelationMeterView(CorrelationMeterWidget* widget);
- ~CorrelationMeterView();
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
- void resize();
- void hide_event();
- void show_event();
-
-private:
- CorrelationMeterWidget* m_widget;
- QTimer timer;
- QTimer m_delayTimer;
- float coeff;
- float direction;
- CorrelationMeter* m_meter;
- Sheet* m_sheet;
- QLinearGradient gradPhase;
- int range;
-
- void save_configuration();
- void load_configuration();
-
-private slots:
- void set_project( Project* );
- void set_sheet( Sheet* );
- void update_data();
- void transport_started();
- void transport_stopped();
- void delay_timeout();
-
-public slots:
- Command* set_mode();
-
-};
-
-#endif
-
Index: SpectralMeterWidget.cpp
===================================================================
RCS file: SpectralMeterWidget.cpp
diff -N SpectralMeterWidget.cpp
--- SpectralMeterWidget.cpp 15 Feb 2008 17:34:11 -0000 1.56
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,1228 +0,0 @@
-/*
- Copyright (C) 2006 Nicola Doebelin
-
- This file is part of Traverso
-
- Traverso 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.
-
- This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-
-*/
-
-#include "SpectralMeterWidget.h"
-#include <Config.h>
-#include <Information.h>
-#include <PluginChain.h>
-#include <SpectralMeter.h>
-#include <Command.h>
-#include <ProjectManager.h>
-#include <Project.h>
-#include <AudioDevice.h>
-#include <InputEngine.h>
-#include <Sheet.h>
-#include <ContextPointer.h>
-#include <Themer.h>
-
-#include <QFileDialog>
-#include <QInputDialog>
-#include <QTextStream>
-
-#include <math.h>
-#include <limits.h>
-
-// Always put me below _all_ includes, this is needed
-// in case we run with memory leak detection enabled!
-#include "Debugger.h"
-
-#define SMOOTH_FACTOR 0.98
-#define DB_FLOOR -140.0
-
-static const float DEFAULT_VAL = -999.0f;
-static const int UPDATE_INTERVAL = 40;
-static const uint MAX_SAMPLES = UINT_MAX;
-static const int STOP_DELAY = 10000; // in ms
-
-
-SpectralMeterWidget::SpectralMeterWidget(QWidget* parent)
- : ViewPort(parent)
-{
- PENTERCONS;
- m_item = 0;
-}
-
-SpectralMeterWidget::~SpectralMeterWidget()
-{
-}
-
-void SpectralMeterWidget::resizeEvent( QResizeEvent * )
-{
- PENTER;
- get_item()->resize();
-}
-
-void SpectralMeterWidget::hideEvent(QHideEvent * event)
-{
- PENTER;
- QWidget::hideEvent(event);
- get_item()->hide_event();
-}
-
-
-void SpectralMeterWidget::showEvent(QShowEvent * event)
-{
- PENTER;
- QWidget::showEvent(event);
- get_item()->show_event();
-}
-
-QSize SpectralMeterWidget::minimumSizeHint() const
-{
- return QSize(150, 50);
-}
-
-QSize SpectralMeterWidget::sizeHint() const
-{
- return QSize(300, 50);
-}
-
-void SpectralMeterWidget::get_pointed_context_items(QList<ContextItem* > &list)
-{
- QList<QGraphicsItem *> itemlist =
items(cpointer().on_first_input_event_x(), cpointer().on_first_input_event_y());
- foreach(QGraphicsItem* item, itemlist) {
- if (ViewItem::is_viewitem(item)) {
- list.append((ViewItem*)item);
- }
- }
-}
-
-SpectralMeterView * SpectralMeterWidget::get_item()
-{
- if (!m_item) {
- setMinimumWidth(40);
- setMinimumHeight(10);
-
- m_item = new SpectralMeterView(this);
-
- QGraphicsScene* scene = new QGraphicsScene(this);
- setScene(scene);
- scene->addItem(m_item);
- m_item->setPos(0,0);
- m_item->resize();
-
- Project* project = pm().get_project();
- m_item->set_project(project);
- if (project) {
- m_item->set_sheet(project->get_current_sheet());
- }
-
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- }
-
- return m_item;
-}
-
-
-
-
-SpectralMeterView::SpectralMeterView(SpectralMeterWidget* widget)
- : ViewItem(0, 0)
- , m_widget(widget)
- , m_meter(0)
- , m_sheet(0)
-{
-
- m_config = new SpectralMeterConfigWidget(m_widget);
- m_boundingRect = QRectF(0, 0, m_widget->width(), m_widget->height());
- load_configuration();
-
- upper_freq_log = log10(upper_freq);
- lower_freq_log = log10(lower_freq);
- sample_rate = audiodevice().get_sample_rate();
- show_average = false;
- update_average = true;
- sample_weight = 1;
-
- QFontMetrics fm(themer()->get_font("FFTMeter:fontscale:label"));
- margin_l = 5;
- margin_r = fm.width("-XX") + 5;
- margin_t = fm.ascent()/2 + 5;
- margin_b = fm.ascent() + fm.descent() + 10;
-
-
- for (int i = 0; i < 4; ++i) {
- m_freq_labels.push_back(10.0f * pow(10.0,i));
- m_freq_labels.push_back(20.0f * pow(10.0,i));
- m_freq_labels.push_back(30.0f * pow(10.0,i));
- m_freq_labels.push_back(40.0f * pow(10.0,i));
- m_freq_labels.push_back(50.0f * pow(10.0,i));
- m_freq_labels.push_back(60.0f * pow(10.0,i));
- m_freq_labels.push_back(70.0f * pow(10.0,i));
- m_freq_labels.push_back(80.0f * pow(10.0,i));
- m_freq_labels.push_back(90.0f * pow(10.0,i));
- }
-
- connect(m_config, SIGNAL(configChanged()), this,
SLOT(load_configuration()));
-
- // Connections to core:
- connect(&pm(), SIGNAL(projectLoaded(Project*)), this,
SLOT(set_project(Project*)));
- connect(&timer, SIGNAL(timeout()), this, SLOT(update_data()));
- m_delayTimer.setSingleShot(true);
- connect(&m_delayTimer, SIGNAL(timeout()), this, SLOT(delay_timeout()));
-}
-
-SpectralMeterView::~SpectralMeterView()
-{
- if (m_meter) {
- delete m_meter;
- }
-}
-
-void SpectralMeterView::paint(QPainter *painter, const
QStyleOptionGraphicsItem *option, QWidget *widget)
-{
- Q_UNUSED(option);
- Q_UNUSED(widget);
-
- painter->drawPixmap(0, 0, bgPixmap);
-
- // draw the bars
- if (m_spectrum.size()) {
- QRect rect;
- QBrush brush(themer()->get_color("FFTMeter:foreground"),
Qt::SolidPattern);
- painter->setClipRegion(m_rect);
- painter->setBrush(brush);
- painter->setPen(Qt::NoPen);
-
- int spc = 0;
- if (num_bands < 64) spc = 1;
-
- // draw the freq bands
- for (uint i = 0; i < (uint)m_spectrum.size(); ++i) {
- if (m_bands.at(i+1) < lower_db) {
- continue;
- }
-
- rect.setTopLeft(QPoint((int)freq2xpos(m_bands.at(i)) +
spc, (int)db2ypos(m_spectrum.at(i))));
-
rect.setBottomRight(QPoint((int)freq2xpos(m_bands.at(i+1)) - spc,
(int)db2ypos(DB_FLOOR)));
- painter->drawRect(rect);
- }
-
- // draw the average line if requested
- if (show_average) {
-
painter->setPen(themer()->get_color("FFTMeter:curve:average"));
- QPoint pt;
- QPoint po((int)m_map_idx2xpos.at(0),
(int)db2ypos(m_avg_db.at(0)));
- for (uint i = 0; i < (uint)m_avg_db.size(); ++i) {
- pt.setX((int)m_map_idx2xpos.at(i));
- pt.setY((int)db2ypos(m_avg_db.at(i)));
- painter->drawLine(po, pt);
- po = pt;
- }
- }
- }
-}
-
-void SpectralMeterView::resize()
-{
- PENTER;
-
- prepareGeometryChange();
-
-
- // Make the axis labels disappear when the widget becomes too small
- int x = 0, y = 0, w = m_widget->width(), h = m_widget->height();
- m_boundingRect = QRectF(0, 0, w, h);
-
- if (m_widget->width() >= 200) {
- x = margin_l;
- w -= (margin_l + margin_r);
- }
-
- if (m_widget->height() >= 120) {
- y = margin_t;
- h -= (margin_t + margin_b);
- }
-
-
- m_rect.setRect(x, y, w, h);
-
- // update the vectors mapping indices and frequencies to widget
coordinates
- update_freq_map();
-
- // re-draw the background pixmap
- update_background();
-}
-
-void SpectralMeterView::update_background()
-{
- // draw the background image
- bgPixmap = QPixmap((int)m_boundingRect.width(),
(int)m_boundingRect.height());
- bgPixmap.fill(themer()->get_color("FFTMeter:margin"));
-
- QPainter painter(&bgPixmap);
- painter.fillRect(m_rect, themer()->get_color("FFTMeter:background"));
- painter.setFont(themer()->get_font("FFTMeter:fontscale:label"));
- QFontMetrics fm(themer()->get_font("FFTMeter:fontscale:label"));
-
- QString spm;
-
- // draw horizontal lines + labels
- for (float i = upper_db; i >= lower_db; i -= 10.0f) {
- float f = db2ypos(i);
-
- painter.setPen(themer()->get_color("FFTMeter:grid"));
- painter.drawLine(QPointF(m_rect.x(), f),
QPointF(m_rect.right(), f));
-
- painter.setPen(themer()->get_color("FFTMeter:text"));
- spm.sprintf("%2.0f", i);
- painter.drawText(m_rect.right() + 1, (int)f + fm.ascent()/2,
spm);
- }
-
- // draw frequency labels and tickmarks
- float last_pos = 1.0;
- for (int i = 0; i < m_freq_labels.size(); ++i) {
- // check if we have space to draw the labels by checking if the
- // m_rect is borderless
- if (!m_rect.top()) {
- break;
- }
-
- float f = freq2xpos(m_freq_labels.at(i));
-
- // check if the freq is in the visible range
- if (!f) {
- continue;
- }
-
- spm.sprintf("%2.0f", m_freq_labels.at(i));
- float s = (float)fm.width(spm)/2.0f;
-
-
- // draw text only if there is enough space for it
- if (((f - s) > last_pos) && ((f + s) <
float(m_boundingRect.width()-1))) {
- painter.setPen(themer()->get_color("FFTMeter:text"));
- painter.drawText(QPointF(f - s, m_boundingRect.height()
- fm.descent() - 3), spm);
- last_pos = f + s + 1.0;
-
painter.setPen(themer()->get_color("FFTMeter:tickmarks:main"));
- } else {
-
painter.setPen(themer()->get_color("FFTMeter:tickmarks:sub"));
- }
-
- painter.drawLine(QPointF(f, m_rect.bottom()), QPointF(f,
m_rect.bottom() + 3));
- }
-}
-
-void SpectralMeterView::update_data()
-{
- if (!m_meter) {
- return;
- }
-
- // if no data was available, return, so we _only_ update the widget when
- // it needs to be!
-
- int ret = m_meter->get_data(specl, specr);
-
- // switch off the update of the average curve if silence is played back.
- if (ret == -1) {
- update_average = false;
- } else {
- update_average = true;
- }
-
- // do nothing if the buffer is not ready.
- if (ret == 0) {
- return;
- }
-
- // process the data
- reduce_bands();
-
- // paint the widget
- update();
-}
-
-void SpectralMeterView::set_project(Project *project)
-{
- if (project) {
- connect(project, SIGNAL(currentSheetChanged(Sheet *)), this,
SLOT(set_sheet(Sheet*)));
- m_project = project;
- } else {
- set_sheet(0);
- timer.stop();
- }
-}
-
-void SpectralMeterView::set_sheet(Sheet *sheet)
-{
- if (m_widget->parentWidget()->isHidden()) {
- m_sheet = sheet;
- return;
- }
-
-
- if (m_sheet) {
- if (m_meter) {
- // FIXME The removed plugin still needs to be
deleted!!!!!!
-
Command::process_command(m_sheet->get_plugin_chain()->remove_plugin(m_meter,
false));
- timer.stop();
- disconnect(m_sheet, SIGNAL(transferStarted()), this,
SLOT(transfer_started()));
- disconnect(m_sheet, SIGNAL(transferStopped()), this,
SLOT(transfer_stopped()));
- }
- }
-
- m_sheet = sheet;
-
- if ( ! m_sheet ) {
- return;
- }
-
- connect(m_sheet, SIGNAL(transferStarted()), this,
SLOT(transfer_started()));
- connect(m_sheet, SIGNAL(transferStopped()), this,
SLOT(transfer_stopped()));
-
- PluginChain* chain = m_sheet->get_plugin_chain();
- sample_rate = audiodevice().get_sample_rate();
-
- foreach(Plugin* plugin, chain->get_plugin_list()) {
- m_meter = qobject_cast<SpectralMeter*>(plugin);
-
- if (m_meter) {
- return;
- }
- }
-
- m_meter = new SpectralMeter();
- m_meter->init();
- Command::process_command( chain->add_plugin(m_meter, false) );
-}
-
-
-void SpectralMeterView::hide_event()
-{
- if (m_sheet) {
- if (m_meter) {
-
Command::process_command(m_sheet->get_plugin_chain()->remove_plugin(m_meter,
false));
- timer.stop();
- }
- }
-}
-
-void SpectralMeterView::show_event()
-{
- if (m_sheet) {
- if (m_meter) {
-
Command::process_command(m_sheet->get_plugin_chain()->add_plugin(m_meter,
false));
- timer.start(UPDATE_INTERVAL);
- } else {
- set_sheet(m_sheet);
- }
- }
-}
-
-
-void SpectralMeterView::reduce_bands()
-{
- // check if we have to update some variables
- if ((m_spectrum.size() != (int)num_bands)
- || (fft_size != (uint)qMin(specl.size(), specr.size()))
- || ((uint)m_map_idx2freq.size() != fft_size)) {
- update_layout();
- }
-
- // calculate the sample weight for the average curve
- double sweight = 1.0 / (double)sample_weight;
- double oweight = 1.0 - sweight;
-
- // loop through the freq bands and determine the db-values
- for (int i = 0; i < m_spectrum.size(); ++i) {
- float val = freq2db(m_bands.at(i), m_bands.at(i+1));
- float hist = DB_FLOOR + (m_spectrum.at(i) - DB_FLOOR) *
SMOOTH_FACTOR;
- m_spectrum[i] = qMax(val, hist);
- }
-
- // fill the average sample curve
- if (show_average && update_average) {
- for (int i = 0; i < m_avg_db.size(); ++i) {
- float val = 5.0 * (log10(specl.at(i) * specr.at(i)) +
xfactor);
- float v = val * sweight + m_avg_db.at(i) * oweight;
- m_avg_db[i] = v;
- }
-
- // progress the sample weighting for the average curve
- if (sample_weight < (MAX_SAMPLES - 1)) {
- ++sample_weight;
- }
- }
-}
-
-// call this function if the size, number of bands, ranges etc. changed.
-// it re-calculates some variables
-void SpectralMeterView::update_layout()
-{
- timer.stop();
-
- // recalculate a couple of variables
- fft_size = qMin(specl.size(), specr.size()); // number of
frequencies (size of the FFT)
- xfactor = 4.0f * log10(2.0f / float(fft_size)); // a constant factor
for conversion to dB
- upper_freq_log = log10(upper_freq);
- lower_freq_log = log10(lower_freq);
- freq_step = (upper_freq_log - lower_freq_log)/(num_bands);
- sample_weight = 1;
-
- // recreate the vector containing the levels and frequency bands
- m_spectrum.fill(DEFAULT_VAL, num_bands);
- m_avg_db.fill(DEFAULT_VAL, fft_size);
-
- // recreate the vector containing border frequencies of the freq bands
- m_bands.clear();
- for (uint i = 0; i <= num_bands; ++i) {
- m_bands.push_back(pow(10.0, lower_freq_log + i*freq_step));
- }
-
- // update related stuff
- update_freq_map();
-
- timer.start(UPDATE_INTERVAL);
-}
-
-// converts db-values into widget y-coordinates
-float SpectralMeterView::db2ypos(float f)
-{
- return ((f - upper_db) * m_rect.height()/(lower_db - upper_db)) +
m_rect.top();
-}
-
-// converts frequencies into widget x-coordinates
-float SpectralMeterView::freq2xpos(float f)
-{
- if ((f < lower_freq) || (f > upper_freq)) {
- return 0.0;
- }
-
- float d = log10(f) - lower_freq_log;
- return (float)m_rect.x() + d * m_rect.width() / (upper_freq_log -
lower_freq_log);
-}
-
-// determines the highest db value for frequency rang fl-fu. Does all the
interpolation etc.
-float SpectralMeterView::freq2db(float fl, float fu)
-{
- float lfreq = qMin(fl, fu);
- float ufreq = qMax(fl, fu);
- float fidxl = lfreq * (2.0f * fft_size) / (float)sample_rate;
- float fidxu = ufreq * (2.0f * fft_size) / (float)sample_rate;
-
- int idxl = int(floor(fidxl - 1.0f));
- int idxu = int(ceil(fidxu - 1.0f));
-
- if (idxl < 0) {
- idxl = 0;
- }
-
- if ((uint)idxu >= fft_size) {
- idxu = fft_size - 1;
- }
-
- // distinguishing some cases to save cpu cycles.
-
- // if we're outside the range covered by the FFT, return DB_FLOOR
- if (idxu <= 0) {
- return DB_FLOOR;
- }
- if (idxl >= (int)fft_size) {
- return DB_FLOOR;
- }
-
- // they are the same (which shouldn't happen)
- if (idxu - idxl == 0) {
- return DB_FLOOR;
- }
-
- // if we have exactly one bin in the freq range, return it's db-value
and exit
- if (idxu - idxl == 2) {
- return 5.0f * (log10(specl.at(idxl + 1) * specr.at(idxl + 1)) +
xfactor);
- }
-
- // if no bin is in between, we have to interpolate in order to get an
accurate value
- if (idxu - idxl == 1) {
- float v = fidxu - fidxl;
- float dbvl = specl.at(idxl) * specr.at(idxl);
- float dbvu = specl.at(idxu) * specr.at(idxu);
- return 5.0 * (log10(dbvl + v * (dbvu - dbvl)) + xfactor);
- }
-
- // if several bins are in between, search the highest db value
- float val = 0.0;
- for (int i = idxl; i <=idxu; ++i) {
- val = qMax(val, specl.at(i) * specr.at(i));
- }
-
- return 5.0 * (log10(val) + xfactor);
-}
-
-// updates a vector mapping fft indices (0, ..., fft_size) to widget
x-positions
-// and one mapping fft indices to frequency
-void SpectralMeterView::update_freq_map()
-{
- m_map_idx2xpos.clear();
- m_map_idx2freq.clear();
- for (uint i = 0; i < fft_size; ++i) {
- float freq = float(i+1) * (float)sample_rate / (2.0f *
fft_size);
- m_map_idx2freq.push_back(freq);
- m_map_idx2xpos.push_back(freq2xpos(freq));
- }
-}
-
-// opens the properties dialog
-Command* SpectralMeterView::edit_properties()
-{
- if (!m_meter) {
- return 0;
- }
-
- m_config->show();
-
- return 0;
-}
-
-// is called upon closing the properties dialog
-void SpectralMeterView::load_configuration()
-{
- upper_freq = config().get_property("SpectralMeter", "UpperFrequenty",
22050).toInt();
- lower_freq = config().get_property("SpectralMeter", "LowerFrequenty",
20).toInt();
- num_bands = config().get_property("SpectralMeter", "NumberOfBands",
16).toInt();
- upper_db = config().get_property("SpectralMeter", "UpperdB", 0).toInt();
- lower_db = config().get_property("SpectralMeter", "LowerdB",
-90).toInt();
- show_average = config().get_property("SpectralMeter", "ShowAvarage",
0).toInt();
-
- if (m_meter) {
- m_meter->set_fr_size(config().get_property("SpectralMeter",
"FFTSize", 2048).toInt());
-
m_meter->set_windowing_function(config().get_property("SpectralMeter",
"WindowingFunction", 1).toInt());
- m_meter->init();
- }
-
- update_layout();
- update_background();
-}
-
-void SpectralMeterView::transfer_started()
-{
- // restarts the average curve
- sample_weight = 1;
- timer.start(UPDATE_INTERVAL);
- m_delayTimer.stop();
-}
-
-void SpectralMeterView::transfer_stopped()
-{
- m_delayTimer.start(STOP_DELAY);
-}
-
-void SpectralMeterView::delay_timeout()
-{
- timer.stop();
-}
-
-Command* SpectralMeterView::set_mode()
-{
- show_average = !show_average;
- update_layout();
- return 0;
-}
-
-Command* SpectralMeterView::reset()
-{
- sample_weight = 1;
- return 0;
-}
-
-Command* SpectralMeterView::screen_capture( )
-{
- QImage image(m_widget->size(), QImage::Format_RGB32);
- QPainter painter(&image);
- m_widget->render(&painter);
-
- QString fn = QFileDialog::getSaveFileName (0, tr("Screen Capture file
name"), QDir::homePath());
-
- // if aborted exit here
- if (fn.isEmpty()) {
- return 0;
- }
-
- if ( ! image.save(fn, "PNG")) {
- info().warning(tr("FFT: Unable to write captured image to hard
disk"));
- }
-
- return 0;
-}
-
-Command* SpectralMeterView::export_avarage_curve()
-{
- // check if all requirements are met
- if ((!show_average) || (!m_project)) {
- printf("No average data available.\n");
- info().warning(tr("FFT: No avarage curve used, not data to
export!"));
- info().information(tr("FFT: Enable avarage curve with < M > to
generate data"));
- return 0;
- }
-
- // check if there actually is data to export
- int s = qMin(m_map_idx2freq.size(), m_avg_db.size());
- if (!s) {
- printf("No average data available.\n");
- info().warning(tr("FFT: No avarage data to export!"));
- return 0;
- }
-
- QStringList oFormats;
-
- QString formatA = "plain text";
- QString formatB = "XMGrace";
-
- oFormats.append(formatA);
- oFormats.append(formatB);
-
- bool ok;
- QString format = QInputDialog::getItem( 0, tr("Select output format"),
tr("Output format:"),
- oFormats, 0, false, &ok );
-
- if (!ok) {
- printf("Aborted.");
- return 0;
- }
-
- QString fn = QFileDialog::getSaveFileName (0, tr("Export average dB
curve"), m_project->get_root_dir());
-
- // if aborted exit here
- if (fn.isEmpty()) {
- return 0;
- }
-
- QFile file(fn);
-
- // check if the selected file can be opened for writing
- if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
- printf("Could not open file for writing.");
- return 0;
- }
-
- QTextStream out(&file);
- QString separator = " ";
- QString str;
-
- if (format == formatA) {
- // export the data in text format
- for (int i = 0; i < s; ++i) {
- out << str.sprintf("%.6f %.6f\n", m_map_idx2freq.at(i),
m_avg_db.at(i));
- }
-
- return 0;
- }
-
- if (format == formatB) {
- // export the data in XMGrace format
- out << get_xmgr_string();
- return 0;
- }
-
- return 0;
-}
-
-QString SpectralMeterView::get_xmgr_string()
-{
- QString s = "# Grace project file\n";
- s += "#\n";
- s += "@version 50120\n";
- s += "@page size 842, 594\n";
- s += "@page scroll 5\%\n";
- s += "@page inout 5\%\n";
- s += "@link page off\n";
- s += "@map font 39 to \"Courier\", \"Courier\"\n";
- s += "@map font 40 to \"Courier-Bold\", \"Courier-Bold\"\n";
- s += "@map font 11 to \"Courier-BoldOblique\",
\"Courier-BoldOblique\"\n";
- s += "@map font 9 to \"Courier-Oblique\", \"Courier-Oblique\"\n";
- s += "@map font 4 to \"Helvetica\", \"Helvetica\"\n";
- s += "@map font 6 to \"Helvetica-Bold\", \"Helvetica-Bold\"\n";
- s += "@map font 7 to \"Helvetica-BoldOblique\",
\"Helvetica-BoldOblique\"\n";
- s += "@map font 15 to \"Helvetica-Narrow\", \"Helvetica-Narrow\"\n";
- s += "@map font 16 to \"Helvetica-Narrow-Bold\",
\"Helvetica-Narrow-Bold\"\n";
- s += "@map font 17 to \"Helvetica-Narrow-BoldOblique\",
\"Helvetica-Narrow-BoldOblique\"\n";
- s += "@map font 18 to \"Helvetica-Narrow-Oblique\",
\"Helvetica-Narrow-Oblique\"\n";
- s += "@map font 5 to \"Helvetica-Oblique\", \"Helvetica-Oblique\"\n";
- s += "@map font 20 to \"NewCenturySchlbk-Bold\",
\"NewCenturySchlbk-Bold\"\n";
- s += "@map font 21 to \"NewCenturySchlbk-BoldItalic\",
\"NewCenturySchlbk-BoldItalic\"\n";
- s += "@map font 22 to \"NewCenturySchlbk-Italic\",
\"NewCenturySchlbk-Italic\"\n";
- s += "@map font 23 to \"NewCenturySchlbk-Roman\",
\"NewCenturySchlbk-Roman\"\n";
- s += "@map font 24 to \"Palatino-Bold\", \"Palatino-Bold\"\n";
- s += "@map font 25 to \"Palatino-BoldItalic\",
\"Palatino-BoldItalic\"\n";
- s += "@map font 26 to \"Palatino-Italic\", \"Palatino-Italic\"\n";
- s += "@map font 27 to \"Palatino-Roman\", \"Palatino-Roman\"\n";
- s += "@map font 12 to \"Symbol\", \"Symbol\"\n";
- s += "@map font 2 to \"Times-Bold\", \"Times-Bold\"\n";
- s += "@map font 3 to \"Times-BoldItalic\", \"Times-BoldItalic\"\n";
- s += "@map font 1 to \"Times-Italic\", \"Times-Italic\"\n";
- s += "@map font 0 to \"Times-Roman\", \"Times-Roman\"\n";
- s += "@map font 33 to \"ZapfChancery-MediumItalic\",
\"ZapfChancery-MediumItalic\"\n";
- s += "@map font 13 to \"ZapfDingbats\", \"ZapfDingbats\"\n";
- s += "@map font 35 to \"CharterBT-Bold\", \"CharterBT-Bold\"\n";
- s += "@map font 36 to \"CharterBT-BoldItalic\",
\"CharterBT-BoldItalic\"\n";
- s += "@map font 37 to \"CharterBT-Italic\", \"CharterBT-Italic\"\n";
- s += "@map font 38 to \"CharterBT-Roman\", \"CharterBT-Roman\"\n";
- s += "@map font 41 to \"Courier-BoldItalic\", \"Courier-BoldItalic\"\n";
- s += "@map font 42 to \"Courier-Italic\", \"Courier-Italic\"\n";
- s += "@map font 43 to \"Hershey-Gothic-English\",
\"Hershey-Gothic-English\"\n";
- s += "@map font 44 to \"Hershey-Gothic-German\",
\"Hershey-Gothic-German\"\n";
- s += "@map font 45 to \"Hershey-Gothic-Italian\",
\"Hershey-Gothic-Italian\"\n";
- s += "@map font 46 to \"Hershey-Plain-Duplex\",
\"Hershey-Plain-Duplex\"\n";
- s += "@map font 47 to \"Hershey-Plain-Duplex-Italic\",
\"Hershey-Plain-Duplex-Italic\"\n";
- s += "@map font 48 to \"Hershey-Plain-Triplex\",
\"Hershey-Plain-Triplex\"\n";
- s += "@map font 49 to \"Hershey-Plain-Triplex-Italic\",
\"Hershey-Plain-Triplex-Italic\"\n";
- s += "@map font 50 to \"Hershey-Script-Complex\",
\"Hershey-Script-Complex\"\n";
- s += "@map font 51 to \"Hershey-Script-Simplex\",
\"Hershey-Script-Simplex\"\n";
- s += "@map font 52 to \"LuxiMono\", \"LuxiMono\"\n";
- s += "@map font 53 to \"LuxiMono-Bold\", \"LuxiMono-Bold\"\n";
- s += "@map font 54 to \"LuxiMono-BoldOblique\",
\"LuxiMono-BoldOblique\"\n";
- s += "@map font 55 to \"LuxiMono-Oblique\", \"LuxiMono-Oblique\"\n";
- s += "@map font 56 to \"LuxiSans\", \"LuxiSans\"\n";
- s += "@map font 57 to \"LuxiSans-Bold\", \"LuxiSans-Bold\"\n";
- s += "@map font 58 to \"LuxiSans-BoldOblique\",
\"LuxiSans-BoldOblique\"\n";
- s += "@map font 59 to \"LuxiSans-Oblique\", \"LuxiSans-Oblique\"\n";
- s += "@map font 60 to \"LuxiSerif\", \"LuxiSerif\"\n";
- s += "@map font 61 to \"LuxiSerif-Bold\", \"LuxiSerif-Bold\"\n";
- s += "@map font 62 to \"LuxiSerif-BoldOblique\",
\"LuxiSerif-BoldOblique\"\n";
- s += "@map font 63 to \"LuxiSerif-Oblique\", \"LuxiSerif-Oblique\"\n";
- s += "@map font 64 to \"Utopia-Bold\", \"Utopia-Bold\"\n";
- s += "@map font 65 to \"Utopia-BoldItalic\", \"Utopia-BoldItalic\"\n";
- s += "@map font 66 to \"Utopia-Italic\", \"Utopia-Italic\"\n";
- s += "@map font 67 to \"Utopia-Regular\", \"Utopia-Regular\"\n";
- s += "@map color 0 to (255, 255, 255), \"white\"\n";
- s += "@map color 1 to (0, 0, 0), \"black\"\n";
- s += "@map color 2 to (255, 0, 0), \"red\"\n";
- s += "@map color 3 to (0, 255, 0), \"green\"\n";
- s += "@map color 4 to (0, 0, 255), \"blue\"\n";
- s += "@map color 5 to (255, 255, 0), \"yellow\"\n";
- s += "@map color 6 to (188, 143, 143), \"brown\"\n";
- s += "@map color 7 to (220, 220, 220), \"grey\"\n";
- s += "@map color 8 to (148, 0, 211), \"violet\"\n";
- s += "@map color 9 to (0, 255, 255), \"cyan\"\n";
- s += "@map color 10 to (255, 0, 255), \"magenta\"\n";
- s += "@map color 11 to (255, 165, 0), \"orange\"\n";
- s += "@map color 12 to (114, 33, 188), \"indigo\"\n";
- s += "@map color 13 to (103, 7, 72), \"maroon\"\n";
- s += "@map color 14 to (64, 224, 208), \"turquoise\"\n";
- s += "@map color 15 to (0, 139, 0), \"green4\"\n";
- s += "@reference date 0\n";
- s += "@date wrap off\n";
- s += "@date wrap year 1950\n";
- s += "@default linewidth 1.0\n";
- s += "@default linestyle 1\n";
- s += "@default color 1\n";
- s += "@default pattern 1\n";
- s += "@default font 0\n";
- s += "@default char size 1.000000\n";
- s += "@default symbol size 1.000000\n";
- s += "@default sformat \"\%.8g\"\n";
- s += "@background color 0\n";
- s += "@page background fill on\n";
- s += "@timestamp off\n";
- s += "@timestamp 0.03, 0.03\n";
- s += "@timestamp color 1\n";
- s += "@timestamp rot 0\n";
- s += "@timestamp font 0\n";
- s += "@timestamp char size 1.000000\n";
- s += "@timestamp def \"Sun Jan 21 12:56:47 2007\"\n";
- s += "@r0 off\n";
- s += "@link r0 to g0\n";
- s += "@r0 type above\n";
- s += "@r0 linestyle 1\n";
- s += "@r0 linewidth 1.0\n";
- s += "@r0 color 1\n";
- s += "@r0 line 0, 0, 0, 0\n";
- s += "@r1 off\n";
- s += "@link r1 to g0\n";
- s += "@r1 type above\n";
- s += "@r1 linestyle 1\n";
- s += "@r1 linewidth 1.0\n";
- s += "@r1 color 1\n";
- s += "@r1 line 0, 0, 0, 0\n";
- s += "@r2 off\n";
- s += "@link r2 to g0\n";
- s += "@r2 type above\n";
- s += "@r2 linestyle 1\n";
- s += "@r2 linewidth 1.0\n";
- s += "@r2 color 1\n";
- s += "@r2 line 0, 0, 0, 0\n";
- s += "@r3 off\n";
- s += "@link r3 to g0\n";
- s += "@r3 type above\n";
- s += "@r3 linestyle 1\n";
- s += "@r3 linewidth 1.0\n";
- s += "@r3 color 1\n";
- s += "@r3 line 0, 0, 0, 0\n";
- s += "@r4 off\n";
- s += "@link r4 to g0\n";
- s += "@r4 type above\n";
- s += "@r4 linestyle 1\n";
- s += "@r4 linewidth 1.0\n";
- s += "@r4 color 1\n";
- s += "@r4 line 0, 0, 0, 0\n";
- s += "@g0 on\n";
- s += "@g0 hidden false\n";
- s += "@g0 type XY\n";
- s += "@g0 stacked false\n";
- s += "@g0 bar hgap 0.000000\n";
- s += "@g0 fixedpoint off\n";
- s += "@g0 fixedpoint type 0\n";
- s += "@g0 fixedpoint xy 0.000000, 0.000000\n";
- s += "@g0 fixedpoint format general general\n";
- s += "@g0 fixedpoint prec 6, 6\n";
- s += "@with g0\n";
- s += "@ world 20, -90, 20000, 0\n";
- s += "@ stack world 0, 0, 0, 0\n";
- s += "@ znorm 1\n";
- s += "@ view 0.130000, 0.120000, 1.300000, 0.920000\n";
- s += "@ title \"\"\n";
- s += "@ title font 0\n";
- s += "@ title size 1.500000\n";
- s += "@ title color 1\n";
- s += "@ subtitle \"\"\n";
- s += "@ subtitle font 0\n";
- s += "@ subtitle size 1.000000\n";
- s += "@ subtitle color 1\n";
- s += "@ xaxes scale Logarithmic\n";
- s += "@ yaxes scale Normal\n";
- s += "@ xaxes invert off\n";
- s += "@ yaxes invert off\n";
- s += "@ xaxis on\n";
- s += "@ xaxis type zero false\n";
- s += "@ xaxis offset 0.000000 , 0.000000\n";
- s += "@ xaxis bar on\n";
- s += "@ xaxis bar color 1\n";
- s += "@ xaxis bar linestyle 1\n";
- s += "@ xaxis bar linewidth 1.0\n";
- s += "@ xaxis label \"Frequency (Hz)\"\n";
- s += "@ xaxis label layout para\n";
- s += "@ xaxis label place auto\n";
- s += "@ xaxis label char size 1.000000\n";
- s += "@ xaxis label font 0\n";
- s += "@ xaxis label color 1\n";
- s += "@ xaxis label place normal\n";
- s += "@ xaxis tick on\n";
- s += "@ xaxis tick major 10\n";
- s += "@ xaxis tick minor ticks 9\n";
- s += "@ xaxis tick default 6\n";
- s += "@ xaxis tick place rounded true\n";
- s += "@ xaxis tick in\n";
- s += "@ xaxis tick major size 0.500000\n";
- s += "@ xaxis tick major color 1\n";
- s += "@ xaxis tick major linewidth 1.0\n";
- s += "@ xaxis tick major linestyle 1\n";
- s += "@ xaxis tick major grid on\n";
- s += "@ xaxis tick minor color 1\n";
- s += "@ xaxis tick minor linewidth 1.0\n";
- s += "@ xaxis tick minor linestyle 2\n";
- s += "@ xaxis tick minor grid on\n";
- s += "@ xaxis tick minor size 0.250000\n";
- s += "@ xaxis ticklabel on\n";
- s += "@ xaxis ticklabel format general\n";
- s += "@ xaxis ticklabel prec 5\n";
- s += "@ xaxis ticklabel formula \"\"\n";
- s += "@ xaxis ticklabel append \"\"\n";
- s += "@ xaxis ticklabel prepend \"\"\n";
- s += "@ xaxis ticklabel angle 0\n";
- s += "@ xaxis ticklabel skip 0\n";
- s += "@ xaxis ticklabel stagger 0\n";
- s += "@ xaxis ticklabel place normal\n";
- s += "@ xaxis ticklabel offset auto\n";
- s += "@ xaxis ticklabel offset 0.000000 , 0.010000\n";
- s += "@ xaxis ticklabel start type auto\n";
- s += "@ xaxis ticklabel start 0.000000\n";
- s += "@ xaxis ticklabel stop type auto\n";
- s += "@ xaxis ticklabel stop 0.000000\n";
- s += "@ xaxis ticklabel char size 0.750000\n";
- s += "@ xaxis ticklabel font 0\n";
- s += "@ xaxis ticklabel color 1\n";
- s += "@ xaxis tick place both\n";
- s += "@ xaxis tick spec type both\n";
- s += "@ xaxis tick spec 37\n";
- s += "@ xaxis tick major 0, 10\n";
- s += "@ xaxis ticklabel 0, \"10\"\n";
- s += "@ xaxis tick major 1, 20\n";
- s += "@ xaxis ticklabel 1, \"20\"\n";
- s += "@ xaxis tick minor 2, 30\n";
- s += "@ xaxis tick minor 3, 40\n";
- s += "@ xaxis tick major 4, 50\n";
- s += "@ xaxis ticklabel 4, \"50\"\n";
- s += "@ xaxis tick minor 5, 60\n";
- s += "@ xaxis tick minor 6, 70\n";
- s += "@ xaxis tick minor 7, 80\n";
- s += "@ xaxis tick minor 8, 90\n";
- s += "@ xaxis tick major 9, 100\n";
- s += "@ xaxis ticklabel 9, \"100\"\n";
- s += "@ xaxis tick major 10, 200\n";
- s += "@ xaxis ticklabel 10, \"200\"\n";
- s += "@ xaxis tick minor 11, 300\n";
- s += "@ xaxis tick minor 12, 400\n";
- s += "@ xaxis tick major 13, 500\n";
- s += "@ xaxis ticklabel 13, \"500\"\n";
- s += "@ xaxis tick minor 14, 600\n";
- s += "@ xaxis tick minor 15, 700\n";
- s += "@ xaxis tick minor 16, 800\n";
- s += "@ xaxis tick minor 17, 900\n";
- s += "@ xaxis tick major 18, 1000\n";
- s += "@ xaxis ticklabel 18, \"1000\"\n";
- s += "@ xaxis tick major 19, 2000\n";
- s += "@ xaxis ticklabel 19, \"2000\"\n";
- s += "@ xaxis tick minor 20, 3000\n";
- s += "@ xaxis tick minor 21, 4000\n";
- s += "@ xaxis tick major 22, 5000\n";
- s += "@ xaxis ticklabel 22, \"5000\"\n";
- s += "@ xaxis tick minor 23, 6000\n";
- s += "@ xaxis tick minor 24, 7000\n";
- s += "@ xaxis tick minor 25, 8000\n";
- s += "@ xaxis tick minor 26, 9000\n";
- s += "@ xaxis tick major 27, 10000\n";
- s += "@ xaxis ticklabel 27, \"10000\"\n";
- s += "@ xaxis tick major 28, 20000\n";
- s += "@ xaxis ticklabel 28, \"20000\"\n";
- s += "@ xaxis tick minor 29, 30000\n";
- s += "@ xaxis tick minor 30, 40000\n";
- s += "@ xaxis tick minor 31, 50000\n";
- s += "@ xaxis tick minor 32, 60000\n";
- s += "@ xaxis tick minor 33, 70000\n";
- s += "@ xaxis tick minor 34, 80000\n";
- s += "@ xaxis tick minor 35, 90000\n";
- s += "@ xaxis tick minor 36, 100000\n";
- s += "@ xaxis ticklabel 36, \"1e+05\"\n";
- s += "@ yaxis on\n";
- s += "@ yaxis type zero false\n";
- s += "@ yaxis offset 0.000000 , 0.000000\n";
- s += "@ yaxis bar on\n";
- s += "@ yaxis bar color 1\n";
- s += "@ yaxis bar linestyle 1\n";
- s += "@ yaxis bar linewidth 1.0\n";
- s += "@ yaxis label \"Level (dB)\"\n";
- s += "@ yaxis label layout para\n";
- s += "@ yaxis label place auto\n";
- s += "@ yaxis label char size 1.000000\n";
- s += "@ yaxis label font 0\n";
- s += "@ yaxis label color 1\n";
- s += "@ yaxis label place normal\n";
- s += "@ yaxis tick on\n";
- s += "@ yaxis tick major 10\n";
- s += "@ yaxis tick minor ticks 1\n";
- s += "@ yaxis tick default 6\n";
- s += "@ yaxis tick place rounded true\n";
- s += "@ yaxis tick in\n";
- s += "@ yaxis tick major size 0.500000\n";
- s += "@ yaxis tick major color 1\n";
- s += "@ yaxis tick major linewidth 1.0\n";
- s += "@ yaxis tick major linestyle 1\n";
- s += "@ yaxis tick major grid on\n";
- s += "@ yaxis tick minor color 1\n";
- s += "@ yaxis tick minor linewidth 1.0\n";
- s += "@ yaxis tick minor linestyle 2\n";
- s += "@ yaxis tick minor grid on\n";
- s += "@ yaxis tick minor size 0.250000\n";
- s += "@ yaxis ticklabel on\n";
- s += "@ yaxis ticklabel format general\n";
- s += "@ yaxis ticklabel prec 5\n";
- s += "@ yaxis ticklabel formula \"\"\n";
- s += "@ yaxis ticklabel append \"\"\n";
- s += "@ yaxis ticklabel prepend \"\"\n";
- s += "@ yaxis ticklabel angle 0\n";
- s += "@ yaxis ticklabel skip 0\n";
- s += "@ yaxis ticklabel stagger 0\n";
- s += "@ yaxis ticklabel place normal\n";
- s += "@ yaxis ticklabel offset auto\n";
- s += "@ yaxis ticklabel offset 0.000000 , 0.010000\n";
- s += "@ yaxis ticklabel start type auto\n";
- s += "@ yaxis ticklabel start 0.000000\n";
- s += "@ yaxis ticklabel stop type auto\n";
- s += "@ yaxis ticklabel stop 0.000000\n";
- s += "@ yaxis ticklabel char size 0.750000\n";
- s += "@ yaxis ticklabel font 0\n";
- s += "@ yaxis ticklabel color 1\n";
- s += "@ yaxis tick place both\n";
- s += "@ yaxis tick spec type none\n";
- s += "@ altxaxis off\n";
- s += "@ altyaxis off\n";
- s += "@ legend on\n";
- s += "@ legend loctype view\n";
- s += "@ legend 0.84941423, 0.8\n";
- s += "@ legend box color 1\n";
- s += "@ legend box pattern 1\n";
- s += "@ legend box linewidth 1.0\n";
- s += "@ legend box linestyle 1\n";
- s += "@ legend box fill color 0\n";
- s += "@ legend box fill pattern 1\n";
- s += "@ legend font 0\n";
- s += "@ legend char size 1.000000\n";
- s += "@ legend color 1\n";
- s += "@ legend length 4\n";
- s += "@ legend vgap 1\n";
- s += "@ legend hgap 1\n";
- s += "@ legend invert false\n";
- s += "@ frame type 0\n";
- s += "@ frame linestyle 1\n";
- s += "@ frame linewidth 1.0\n";
- s += "@ frame color 1\n";
- s += "@ frame pattern 1\n";
- s += "@ frame background color 0\n";
- s += "@ frame background pattern 0\n";
- s += "@ s0 hidden false\n";
- s += "@ s0 type xy\n";
- s += "@ s0 symbol 9\n";
- s += "@ s0 symbol size 0.500000\n";
- s += "@ s0 symbol color 2\n";
- s += "@ s0 symbol pattern 1\n";
- s += "@ s0 symbol fill color 2\n";
- s += "@ s0 symbol fill pattern 0\n";
- s += "@ s0 symbol linewidth 1.0\n";
- s += "@ s0 symbol linestyle 1\n";
- s += "@ s0 symbol char 65\n";
- s += "@ s0 symbol char font 0\n";
- s += "@ s0 symbol skip 0\n";
- s += "@ s0 line type 1\n";
- s += "@ s0 line linestyle 1\n";
- s += "@ s0 line linewidth 2.0\n";
- s += "@ s0 line color 1\n";
- s += "@ s0 line pattern 1\n";
- s += "@ s0 baseline type 0\n";
- s += "@ s0 baseline off\n";
- s += "@ s0 dropline off\n";
- s += "@ s0 fill type 0\n";
- s += "@ s0 fill rule 0\n";
- s += "@ s0 fill color 1\n";
- s += "@ s0 fill pattern 1\n";
- s += "@ s0 avalue off\n";
- s += "@ s0 avalue type 2\n";
- s += "@ s0 avalue char size 1.000000\n";
- s += "@ s0 avalue font 0\n";
- s += "@ s0 avalue color 1\n";
- s += "@ s0 avalue rot 0\n";
- s += "@ s0 avalue format general\n";
- s += "@ s0 avalue prec 3\n";
- s += "@ s0 avalue prepend \"\"\n";
- s += "@ s0 avalue append \"\"\n";
- s += "@ s0 avalue offset 0.000000 , 0.000000\n";
- s += "@ s0 errorbar off\n";
- s += "@ s0 errorbar place both\n";
- s += "@ s0 errorbar color 2\n";
- s += "@ s0 errorbar pattern 1\n";
- s += "@ s0 errorbar size 1.000000\n";
- s += "@ s0 errorbar linewidth 1.0\n";
- s += "@ s0 errorbar linestyle 1\n";
- s += "@ s0 errorbar riser linewidth 1.0\n";
- s += "@ s0 errorbar riser linestyle 1\n";
- s += "@ s0 errorbar riser clip off\n";
- s += "@ s0 errorbar riser clip length 0.100000\n";
- s += "@ s0 comment \"Exported from Traverso\"\n";
- s += "@ s0 legend \"\"\n";
- s += "@target G0.S0\n";
- s += "@type xy\n";
-
- int n = qMin(m_map_idx2freq.size(), m_avg_db.size());
- QString str;
-
- for (int i = 0; i < n; ++i) {
- s += str.sprintf("%.6f %.6f\n", m_map_idx2freq.at(i),
m_avg_db.at(i));
- }
-
- s += "&\n";
-
- return s;
-}
-
-
-/*******************************************/
-/* SpectralMeterConfWidget */
-/*******************************************/
-
-SpectralMeterConfigWidget::SpectralMeterConfigWidget( QWidget * parent )
- : QDialog(parent)
-{
- setupUi(this);
- groupBoxAdvanced->hide();
-
- load_configuration();
-
- connect(buttonAdvanced, SIGNAL(toggled(bool)), this,
SLOT(advancedButton_toggled(bool)));
-}
-
-void SpectralMeterConfigWidget::on_buttonApply_clicked()
-{
- save_configuration();
- emit configChanged();
-}
-
-void SpectralMeterConfigWidget::on_buttonClose_clicked( )
-{
- hide();
-}
-
-void SpectralMeterConfigWidget::advancedButton_toggled(bool b)
-{
- if (b) {
- groupBoxAdvanced->show();
- } else {
- groupBoxAdvanced->hide();
- }
-}
-
-void SpectralMeterConfigWidget::save_configuration( )
-{
- config().set_property( "SpectralMeter",
- "UpperFrequenty",
- qMax(spinBoxLowerFreq->value(),
spinBoxUpperFreq->value()) );
- config().set_property( "SpectralMeter",
- "LowerFrequenty",
- qMin(spinBoxLowerFreq->value(),
spinBoxUpperFreq->value()) );
- config().set_property( "SpectralMeter",
- "UpperdB",
- qMax(spinBoxUpperDb->value(),
spinBoxLowerDb->value()) );
- config().set_property( "SpectralMeter",
- "LowerdB",
- qMin(spinBoxUpperDb->value(),
spinBoxLowerDb->value()) );
- config().set_property("SpectralMeter", "NumberOfBands",
spinBoxNumBands->value() );
- config().set_property("SpectralMeter", "ShowAvarage",
checkBoxAverage->isChecked() );
-
- config().set_property("SpectralMeter", "FFTSize",
comboBoxFftSize->currentText().toInt() );
- config().set_property("SpectralMeter", "WindowingFunction",
comboBoxWindowing->currentIndex() );
-}
-
-void SpectralMeterConfigWidget::load_configuration( )
-{
- int value;
- value = config().get_property("SpectralMeter", "UpperFrequenty",
22050).toInt();
- spinBoxUpperFreq->setValue(value);
- value = config().get_property("SpectralMeter", "LowerFrequenty",
20).toInt();
- spinBoxLowerFreq->setValue(value);
- value = config().get_property("SpectralMeter", "UpperdB", 0).toInt();
- spinBoxUpperDb->setValue(value);
- value = config().get_property("SpectralMeter", "LowerdB", -90).toInt();
- spinBoxLowerDb->setValue(value);
- value = config().get_property("SpectralMeter", "NumberOfBands",
16).toInt();
- spinBoxNumBands->setValue(value);
- value = config().get_property("SpectralMeter", "ShowAvarage",
0).toInt();
- checkBoxAverage->setChecked(value);
- value = config().get_property("SpectralMeter", "FFTSize", 2048).toInt();
- QString str;
- str = QString("%1").arg(value);
- int idx = comboBoxFftSize->findText(str);
- idx = idx == -1 ? 3 : idx;
- comboBoxFftSize->setCurrentIndex(idx);
- value = config().get_property("SpectralMeter", "WindowingFunction",
1).toInt();
- comboBoxWindowing->setCurrentIndex(value);
-}
-
-//eof
-
Index: SpectralMeterWidget.h
===================================================================
RCS file: SpectralMeterWidget.h
diff -N SpectralMeterWidget.h
--- SpectralMeterWidget.h 15 Feb 2008 16:53:19 -0000 1.26
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,174 +0,0 @@
-/*
- Copyright (C) 2006 Nicola Doebelin
-
- This file is part of Traverso
-
- Traverso 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.
-
- This program 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-
-*/
-
-#ifndef SPECTRALMETERWIDGET_H
-#define SPECTRALMETERWIDGET_H
-
-#include <ViewPort.h>
-#include <ViewItem.h>
-#include <QTimer>
-#include <QVector>
-#include "ui_SpectralMeterConfigWidget.h"
-#include <QDialog>
-
-class Sheet;
-class Project;
-class QRect;
-class QPixmap;
-class SpectralMeter;
-class Command;
-class SpectralMeterView;
-
-
-class SpectralMeterConfigWidget : public QDialog, private
Ui::SpectralMeterConfigWidget
-{
- Q_OBJECT
-
-public:
- SpectralMeterConfigWidget(QWidget* parent = 0);
-
-private:
- void save_configuration();
- void load_configuration();
-
-private slots:
- void on_buttonClose_clicked();
- void on_buttonApply_clicked();
- void advancedButton_toggled(bool);
-
-signals:
- void configChanged();
-
-};
-
-class SpectralMeterWidget : public ViewPort
-{
-public:
- SpectralMeterWidget(QWidget* parent);
- ~SpectralMeterWidget();
-
- void get_pointed_context_items(QList<ContextItem* > &list);
-
-protected:
- void resizeEvent( QResizeEvent* e);
- void hideEvent ( QHideEvent * event );
- void showEvent ( QShowEvent * event );
- QSize minimumSizeHint () const;
- QSize sizeHint () const;
-
-private:
- SpectralMeterView* m_item;
- SpectralMeterView* get_item();
-};
-
-
-class SpectralMeterView : public ViewItem
-{
- Q_OBJECT
-
- Q_CLASSINFO("edit_properties", tr("Settings..."))
- Q_CLASSINFO("set_mode", tr("Toggle avarage curve"))
- Q_CLASSINFO("reset", tr("Reset average curve"))
- Q_CLASSINFO("export_avarage_curve", tr("Export avarage curve"))
- Q_CLASSINFO("screen_capture", tr("Capture Screen"))
-
-
-public:
- SpectralMeterView(SpectralMeterWidget* widget);
- ~SpectralMeterView();
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
-
- void resize();
- void hide_event();
-
-private:
- SpectralMeterWidget* m_widget;
- SpectralMeter* m_meter;
- Project* m_project;
- Sheet* m_sheet;
- QTimer timer;
- QTimer m_delayTimer;
- QVector<float> specl;
- QVector<float> specr;
- QVector<float> m_spectrum;
- QVector<float> m_history;
- QVector<float> m_bands;
- QVector<float> m_freq_labels;
- QVector<float> m_avg_db;
- QVector<float> m_map_idx2xpos;
- QVector<float> m_map_idx2freq;
- QRect m_rect;
- SpectralMeterConfigWidget *m_config;
- QPixmap bgPixmap;
- uint num_bands;
- uint sample_rate;
- float upper_freq;
- float lower_freq;
- float upper_db;
- float lower_db;
- int margin_l;
- int margin_r;
- int margin_t;
- int margin_b;
- uint sample_weight;
-
- uint fft_size;
- float xfactor;
- float upper_freq_log;
- float lower_freq_log;
- float freq_step;
- int bar_offset;
- bool show_average;
- bool update_average;
-
- void reduce_bands();
- void update_layout();
- void update_freq_map();
- float db2ypos(float);
- float freq2xpos(float);
- void update_background();
- float freq2db(float, float);
- QString get_xmgr_string();
-
-
-private slots:
- void update_data();
- void transfer_started();
- void transfer_stopped();
- void delay_timeout();
-
-
-public slots:
- void set_project( Project* );
- void load_configuration();
- void set_sheet( Sheet* );
- void show_event();
-
- Command* edit_properties();
- Command* set_mode();
- Command* reset();
- Command* export_avarage_curve();
- Command* screen_capture();
-};
-
-#endif
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Traverso-commit] traverso/src/traverso CMakeLists.txt widgets/Co...,
Remon Sijrier <=