SilentEye 0.4.1

modules/seformatwav/optionwidget.cpp

Go to the documentation of this file.
00001 //  This file is part of SilentEye.
00002 //
00003 //  SilentEye is free software: you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation, either version 3 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  SilentEye is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with SilentEye.  If not, see <http://www.gnu.org/licenses/>.
00015 
00016 #include "optionwidget.h"
00017 
00018 namespace SEFormatWAV {
00019 
00020     OptionWidget::OptionWidget(QWidget* parent)
00021         : QWidget(parent)
00022     {
00023         this->setObjectName("SEFormatWaveOptionWidget");
00024         m_logger = new Logger(this);
00025 
00026         m_dontUpdate = false;
00027 
00028         setupUi(this);
00029         advancedWidget->setVisible(false);
00030 
00031         settingsChanged();
00032 
00033         connect(advancedButton, SIGNAL(toggled(bool)), this, SLOT(advButtonPressed(bool)));
00034         connect(qualityComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(qualityChanged(int)));
00035         connect(channelsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsChanged(int)));
00036         connect(nbBitsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(settingsChanged(int)));
00037     }
00038 
00039     OptionWidget::~OptionWidget()
00040     {
00041         delete m_logger;
00042     }
00043 
00044     int OptionWidget::nbBits() const
00045     {
00046         return nbBitsSpinBox->value();
00047     }
00048 
00049     int OptionWidget::channels() const
00050     {
00051         return channelsComboBox->currentIndex() + 1;
00052     }
00053 
00054     AudioWav::DataDistribution OptionWidget::distribution() const
00055     {
00056         AudioWav::DataDistribution dist = AudioWav::EQUI;
00057         switch(distributionComboBox->currentIndex())
00058         {
00059             case 0:
00060                 dist = AudioWav::EQUI;
00061                 break;
00062             case 1:
00063                 dist = AudioWav::INLINE;
00064                 break;
00065             default:
00066                 m_logger->warning("Unhandle distribution switch value: " + QString::number(distributionComboBox->currentIndex()));
00067                 break;
00068         }
00069         return dist;
00070     }
00071 
00072     AudioWav::HeaderPosition OptionWidget::headerPosition() const
00073     {
00074         AudioWav::HeaderPosition pos = AudioWav::ENDING;
00075         switch(headerComboBox->currentIndex())
00076         {
00077             case 0:
00078                 pos = AudioWav::BEGINNING;
00079                 break;
00080             case 1:
00081                 pos = AudioWav::ENDING;
00082                 break;
00083             default:
00084                 m_logger->warning("Unhandle header switch value: " + headerComboBox->currentIndex());
00085                 break;
00086         }
00087         return pos;
00088     }
00089 
00090     void OptionWidget::advButtonPressed(bool value)
00091     {
00092         advancedWidget->setVisible(value);
00093     }
00094 
00095     void OptionWidget::qualityChanged(int value)
00096     {
00097         if (!m_dontUpdate)
00098         {
00099             m_dontUpdate = true;
00100             switch(value)
00101             {
00102                 case 0: // low
00103                     channelsComboBox->setCurrentIndex(1);
00104                     nbBitsSpinBox->setValue(5);
00105                     headerComboBox->setCurrentIndex(0);
00106                     break;
00107                 case 1: // normal
00108                     channelsComboBox->setCurrentIndex(1);
00109                     nbBitsSpinBox->setValue(3);
00110                     headerComboBox->setCurrentIndex(1);
00111                     break;
00112                 case 2: // high
00113                     channelsComboBox->setCurrentIndex(0);
00114                     nbBitsSpinBox->setValue(1);
00115                     headerComboBox->setCurrentIndex(1);
00116                     break;
00117                 default:
00118                     m_logger->warning("Unhandle quality mode switch value: " + QString::number(value));
00119                     break;
00120             }
00121             m_dontUpdate = false;
00122             settingsChanged();
00123         }
00124     }
00125 
00126     void OptionWidget::settingsChanged(int value)
00127     {
00128         Q_UNUSED(value);
00129 
00130         if (!m_dontUpdate)
00131         {
00132             m_dontUpdate = true;
00133             int nbChannel = channelsComboBox->currentIndex()+1;
00134 
00135             m_logger->debug("nb channel used: " + QString::number(nbChannel) + ", nb bits: " + QString::number(nbBits()));
00136 
00137             double quality = (1 - ((pow(2, nbBits()) * nbChannel) / 256.0)) * 100.0;
00138             pourcentLabel->setText(QString::number(quality) + "%");
00139             m_logger->debug("computed quality: " + QString::number(quality));
00140 
00141             if (quality > 95)
00142                 qualityComboBox->setCurrentIndex(2); // high
00143             else if (quality > 85)
00144                 qualityComboBox->setCurrentIndex(1); // normal
00145             else
00146                 qualityComboBox->setCurrentIndex(0); // low
00147 
00148             emit optionHasChanged();
00149             m_dontUpdate = false;
00150         }
00151     }
00152 
00153 }