annotate main/PreferencesDialog.cpp @ 16:3715efc38f95

* substantial enhancements to time stretcher: -- use putInput/getOutput methods to ensure the audio source always feeds it enough input, avoiding underruns due to rounding error -- add a percussion detector and an optional "Sharpen" toggle to the main window, which invokes a very basic variable speed timestretcher
author Chris Cannam
date Wed, 13 Sep 2006 17:17:42 +0000
parents 8b34a6460545
children e3b32dc5180b
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "PreferencesDialog.h"
Chris@0 17
Chris@0 18 #include <QGridLayout>
Chris@0 19 #include <QComboBox>
Chris@0 20 #include <QCheckBox>
Chris@0 21 #include <QGroupBox>
Chris@0 22 #include <QDoubleSpinBox>
Chris@0 23 #include <QLabel>
Chris@0 24 #include <QPushButton>
Chris@0 25 #include <QHBoxLayout>
Chris@0 26 #include <QString>
Chris@0 27
Chris@0 28 #include <fftw3.h>
Chris@0 29
Chris@9 30 #include "widgets/WindowTypeSelector.h"
Chris@0 31 #include "base/Preferences.h"
Chris@0 32
Chris@0 33 PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WFlags flags) :
Chris@0 34 QDialog(parent, flags)
Chris@0 35 {
Chris@0 36 setWindowTitle(tr("Application Preferences"));
Chris@0 37
Chris@0 38 Preferences *prefs = Preferences::getInstance();
Chris@0 39
Chris@0 40 QGridLayout *grid = new QGridLayout;
Chris@0 41 setLayout(grid);
Chris@0 42
Chris@0 43 QGroupBox *groupBox = new QGroupBox;
Chris@0 44 groupBox->setTitle(tr("Sonic Visualiser Application Preferences"));
Chris@0 45 grid->addWidget(groupBox, 0, 0);
Chris@0 46
Chris@0 47 QGridLayout *subgrid = new QGridLayout;
Chris@0 48 groupBox->setLayout(subgrid);
Chris@0 49
Chris@0 50 // Create this first, as slots that get called from the ctor will
Chris@0 51 // refer to it
Chris@0 52 m_applyButton = new QPushButton(tr("Apply"));
Chris@0 53
Chris@9 54 int min, max, i;
Chris@0 55
Chris@9 56 m_windowType = WindowType(prefs->getPropertyRangeAndValue
Chris@9 57 ("Window Type", &min, &max));
Chris@9 58 m_windowTypeSelector = new WindowTypeSelector(m_windowType);
Chris@0 59
Chris@9 60 connect(m_windowTypeSelector, SIGNAL(windowTypeChanged(WindowType)),
Chris@9 61 this, SLOT(windowTypeChanged(WindowType)));
Chris@0 62
Chris@0 63 QCheckBox *smoothing = new QCheckBox;
Chris@0 64 m_smoothSpectrogram = prefs->getSmoothSpectrogram();
Chris@0 65 smoothing->setCheckState(m_smoothSpectrogram ?
Chris@0 66 Qt::Checked : Qt::Unchecked);
Chris@0 67
Chris@0 68 connect(smoothing, SIGNAL(stateChanged(int)),
Chris@0 69 this, SLOT(smoothSpectrogramChanged(int)));
Chris@0 70
Chris@0 71 QComboBox *propertyLayout = new QComboBox;
Chris@0 72 int pl = prefs->getPropertyRangeAndValue("Property Box Layout", &min, &max);
Chris@0 73 m_propertyLayout = pl;
Chris@0 74
Chris@0 75 for (i = min; i <= max; ++i) {
Chris@0 76 propertyLayout->addItem(prefs->getPropertyValueLabel("Property Box Layout", i));
Chris@0 77 }
Chris@0 78
Chris@0 79 propertyLayout->setCurrentIndex(pl);
Chris@0 80
Chris@0 81 connect(propertyLayout, SIGNAL(currentIndexChanged(int)),
Chris@0 82 this, SLOT(propertyLayoutChanged(int)));
Chris@0 83
Chris@0 84 m_tuningFrequency = prefs->getTuningFrequency();
Chris@0 85
Chris@0 86 QDoubleSpinBox *frequency = new QDoubleSpinBox;
Chris@0 87 frequency->setMinimum(100.0);
Chris@0 88 frequency->setMaximum(5000.0);
Chris@0 89 frequency->setSuffix(" Hz");
Chris@0 90 frequency->setSingleStep(1);
Chris@0 91 frequency->setValue(m_tuningFrequency);
Chris@0 92 frequency->setDecimals(2);
Chris@0 93
Chris@0 94 connect(frequency, SIGNAL(valueChanged(double)),
Chris@0 95 this, SLOT(tuningFrequencyChanged(double)));
Chris@0 96
Chris@0 97 int row = 0;
Chris@0 98
Chris@0 99 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 100 ("Property Box Layout"))),
Chris@0 101 row, 0);
Chris@0 102 subgrid->addWidget(propertyLayout, row++, 1, 1, 2);
Chris@0 103
Chris@0 104 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 105 ("Tuning Frequency"))),
Chris@0 106 row, 0);
Chris@0 107 subgrid->addWidget(frequency, row++, 1, 1, 2);
Chris@0 108
Chris@0 109 subgrid->addWidget(new QLabel(prefs->getPropertyLabel
Chris@0 110 ("Smooth Spectrogram")),
Chris@0 111 row, 0, 1, 2);
Chris@0 112 subgrid->addWidget(smoothing, row++, 2);
Chris@0 113
Chris@0 114 subgrid->addWidget(new QLabel(tr("%1:").arg(prefs->getPropertyLabel
Chris@0 115 ("Window Type"))),
Chris@0 116 row, 0);
Chris@9 117 subgrid->addWidget(m_windowTypeSelector, row++, 1, 2, 2);
Chris@9 118 subgrid->setRowStretch(row, 10);
Chris@9 119 row++;
Chris@0 120
Chris@0 121 QHBoxLayout *hbox = new QHBoxLayout;
Chris@0 122 grid->addLayout(hbox, 1, 0);
Chris@0 123
Chris@0 124 QPushButton *ok = new QPushButton(tr("OK"));
Chris@0 125 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@0 126 hbox->addStretch(10);
Chris@0 127 hbox->addWidget(ok);
Chris@0 128 hbox->addWidget(m_applyButton);
Chris@0 129 hbox->addWidget(cancel);
Chris@0 130 connect(ok, SIGNAL(clicked()), this, SLOT(okClicked()));
Chris@0 131 connect(m_applyButton, SIGNAL(clicked()), this, SLOT(applyClicked()));
Chris@0 132 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked()));
Chris@0 133
Chris@0 134 m_applyButton->setEnabled(false);
Chris@0 135 }
Chris@0 136
Chris@0 137 PreferencesDialog::~PreferencesDialog()
Chris@0 138 {
Chris@0 139 std::cerr << "PreferencesDialog::~PreferencesDialog()" << std::endl;
Chris@0 140 }
Chris@0 141
Chris@0 142 void
Chris@9 143 PreferencesDialog::windowTypeChanged(WindowType type)
Chris@0 144 {
Chris@0 145 m_windowType = type;
Chris@0 146 m_applyButton->setEnabled(true);
Chris@0 147 }
Chris@0 148
Chris@0 149 void
Chris@0 150 PreferencesDialog::smoothSpectrogramChanged(int state)
Chris@0 151 {
Chris@0 152 m_smoothSpectrogram = (state == Qt::Checked);
Chris@0 153 m_applyButton->setEnabled(true);
Chris@0 154 }
Chris@0 155
Chris@0 156 void
Chris@0 157 PreferencesDialog::propertyLayoutChanged(int layout)
Chris@0 158 {
Chris@0 159 m_propertyLayout = layout;
Chris@0 160 m_applyButton->setEnabled(true);
Chris@0 161 }
Chris@0 162
Chris@0 163 void
Chris@0 164 PreferencesDialog::tuningFrequencyChanged(double freq)
Chris@0 165 {
Chris@0 166 m_tuningFrequency = freq;
Chris@0 167 m_applyButton->setEnabled(true);
Chris@0 168 }
Chris@0 169
Chris@0 170 void
Chris@0 171 PreferencesDialog::okClicked()
Chris@0 172 {
Chris@0 173 applyClicked();
Chris@0 174 accept();
Chris@0 175 }
Chris@0 176
Chris@0 177 void
Chris@0 178 PreferencesDialog::applyClicked()
Chris@0 179 {
Chris@0 180 Preferences *prefs = Preferences::getInstance();
Chris@0 181 prefs->setWindowType(WindowType(m_windowType));
Chris@0 182 prefs->setSmoothSpectrogram(m_smoothSpectrogram);
Chris@0 183 prefs->setPropertyBoxLayout(Preferences::PropertyBoxLayout
Chris@0 184 (m_propertyLayout));
Chris@0 185 prefs->setTuningFrequency(m_tuningFrequency);
Chris@0 186 m_applyButton->setEnabled(false);
Chris@0 187 }
Chris@0 188
Chris@0 189 void
Chris@0 190 PreferencesDialog::cancelClicked()
Chris@0 191 {
Chris@0 192 reject();
Chris@0 193 }
Chris@0 194