annotate widgets/WindowTypeSelector.cpp @ 1400:decb7741d036

Different approach to x-coord calculation in slice layer - let's acknowledge that we really do have two different types of model, those whose "bins" are actually at a single value (frequency in the case of the spectrum) and those whose bins are just labels.
author Chris Cannam
date Thu, 15 Nov 2018 13:06:38 +0000
parents 6645b6b8356f
children
rev   line source
Chris@139 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@139 2
Chris@139 3 /*
Chris@139 4 Sonic Visualiser
Chris@139 5 An audio file viewer and annotation editor.
Chris@139 6 Centre for Digital Music, Queen Mary, University of London.
Chris@139 7 This file copyright 2006 Chris Cannam.
Chris@139 8
Chris@139 9 This program is free software; you can redistribute it and/or
Chris@139 10 modify it under the terms of the GNU General Public License as
Chris@139 11 published by the Free Software Foundation; either version 2 of the
Chris@139 12 License, or (at your option) any later version. See the file
Chris@139 13 COPYING included with this distribution for more information.
Chris@139 14 */
Chris@139 15
Chris@139 16 #include "WindowTypeSelector.h"
Chris@139 17
Chris@139 18 #include "WindowShapePreview.h"
Chris@139 19
Chris@139 20 #include <QVBoxLayout>
Chris@139 21 #include <QComboBox>
Chris@139 22
Chris@139 23 #include "base/Preferences.h"
Chris@139 24
Chris@908 25 WindowTypeSelector::WindowTypeSelector(WindowType defaultType)
Chris@908 26 {
Chris@908 27 init(defaultType);
Chris@908 28 }
Chris@908 29
Chris@908 30 WindowTypeSelector::WindowTypeSelector()
Chris@908 31 {
Chris@908 32 Preferences *prefs = Preferences::getInstance();
Chris@908 33 int min = 0, max = 0, deflt = 0;
Chris@908 34 WindowType type =
Chris@908 35 WindowType(prefs->getPropertyRangeAndValue("Window Type", &min, &max,
Chris@908 36 &deflt));
Chris@908 37 init(type);
Chris@908 38 }
Chris@908 39
Chris@908 40 void
Chris@908 41 WindowTypeSelector::init(WindowType defaultType)
Chris@139 42 {
Chris@139 43 QVBoxLayout *layout = new QVBoxLayout;
Chris@139 44 layout->setMargin(0);
Chris@139 45 setLayout(layout);
Chris@139 46
Chris@139 47 // The WindowType enum is in rather a ragbag order -- reorder it here
Chris@139 48 // in a more sensible order
Chris@139 49 m_windows = new WindowType[9];
Chris@139 50 m_windows[0] = HanningWindow;
Chris@139 51 m_windows[1] = HammingWindow;
Chris@139 52 m_windows[2] = BlackmanWindow;
Chris@139 53 m_windows[3] = BlackmanHarrisWindow;
Chris@139 54 m_windows[4] = NuttallWindow;
Chris@139 55 m_windows[5] = GaussianWindow;
Chris@139 56 m_windows[6] = ParzenWindow;
Chris@139 57 m_windows[7] = BartlettWindow;
Chris@139 58 m_windows[8] = RectangularWindow;
Chris@139 59
Chris@139 60 Preferences *prefs = Preferences::getInstance();
Chris@139 61
Chris@139 62 m_windowShape = new WindowShapePreview;
Chris@139 63
Chris@139 64 m_windowCombo = new QComboBox;
Chris@139 65 int window = int(defaultType);
Chris@139 66 int index = 0;
Chris@139 67
Chris@908 68 for (int i = 0; i <= 8; ++i) {
Chris@139 69 m_windowCombo->addItem(prefs->getPropertyValueLabel("Window Type",
Chris@139 70 m_windows[i]));
Chris@139 71 if (m_windows[i] == window) index = i;
Chris@139 72 }
Chris@139 73
Chris@139 74 m_windowCombo->setCurrentIndex(index);
Chris@139 75
Chris@139 76 layout->addWidget(m_windowShape);
Chris@139 77 layout->addWidget(m_windowCombo);
Chris@139 78
Chris@139 79 connect(m_windowCombo, SIGNAL(currentIndexChanged(int)),
Chris@139 80 this, SLOT(windowIndexChanged(int)));
Chris@974 81
Chris@974 82 m_windowType = defaultType;
Chris@974 83 m_windowShape->setWindowType(m_windowType);
Chris@139 84 }
Chris@139 85
Chris@139 86 WindowTypeSelector::~WindowTypeSelector()
Chris@139 87 {
Chris@139 88 delete[] m_windows;
Chris@139 89 }
Chris@139 90
Chris@139 91 WindowType
Chris@139 92 WindowTypeSelector::getWindowType() const
Chris@139 93 {
Chris@139 94 return m_windowType;
Chris@139 95 }
Chris@139 96
Chris@139 97 void
Chris@139 98 WindowTypeSelector::setWindowType(WindowType type)
Chris@139 99 {
Chris@139 100 if (type == m_windowType) return;
Chris@139 101 int index;
Chris@139 102 for (index = 0; index <= 8; ++index) {
Chris@139 103 if (m_windows[index] == type) break;
Chris@139 104 }
Chris@139 105 if (index <= 8) m_windowCombo->setCurrentIndex(index);
Chris@139 106 m_windowType = type;
Chris@139 107 m_windowShape->setWindowType(m_windowType);
Chris@139 108 }
Chris@139 109
Chris@139 110 void
Chris@139 111 WindowTypeSelector::windowIndexChanged(int index)
Chris@139 112 {
Chris@139 113 WindowType type = m_windows[index];
Chris@139 114 if (type == m_windowType) return;
Chris@139 115 m_windowType = type;
Chris@139 116 m_windowShape->setWindowType(m_windowType);
Chris@139 117 emit windowTypeChanged(type);
Chris@139 118 }
Chris@139 119