annotate widgets/ItemEditDialog.cpp @ 72:1d176af87056

* Add support for frequency-domain inputs to Vamp plugins
author Chris Cannam
date Fri, 31 Mar 2006 17:40:14 +0000
parents bf306158803d
children ad1fe715b480
rev   line source
Chris@70 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@70 2
Chris@70 3 /*
Chris@70 4 Sonic Visualiser
Chris@70 5 An audio file viewer and annotation editor.
Chris@70 6 Centre for Digital Music, Queen Mary, University of London.
Chris@70 7 This file copyright 2006 Chris Cannam.
Chris@70 8
Chris@70 9 This program is free software; you can redistribute it and/or
Chris@70 10 modify it under the terms of the GNU General Public License as
Chris@70 11 published by the Free Software Foundation; either version 2 of the
Chris@70 12 License, or (at your option) any later version. See the file
Chris@70 13 COPYING included with this distribution for more information.
Chris@70 14 */
Chris@70 15
Chris@70 16 #include "ItemEditDialog.h"
Chris@70 17
Chris@70 18 #include <QLineEdit>
Chris@70 19 #include <QDoubleSpinBox>
Chris@70 20 #include <QGridLayout>
Chris@70 21 #include <QHBoxLayout>
Chris@70 22 #include <QLabel>
Chris@70 23 #include <QPushButton>
Chris@70 24
Chris@70 25
Chris@70 26 ItemEditDialog::ItemEditDialog(size_t sampleRate, int options, QWidget *parent) :
Chris@70 27 QDialog(parent),
Chris@70 28 m_sampleRate(sampleRate),
Chris@70 29 m_frame(0),
Chris@70 30 m_duration(0),
Chris@70 31 m_value(0.0)
Chris@70 32 {
Chris@70 33 QGridLayout *grid = new QGridLayout;
Chris@70 34 setLayout(grid);
Chris@70 35
Chris@70 36 int row = 0;
Chris@70 37 QLineEdit *line = 0;
Chris@70 38
Chris@70 39 if (options & ShowTime) {
Chris@70 40
Chris@70 41 grid->addWidget(new QLabel(tr("Frame time:")), row, 0);
Chris@70 42
Chris@70 43 line = new QLineEdit;
Chris@70 44 line->setValidator(new QIntValidator(this));
Chris@70 45 grid->addWidget(line, row, 1);
Chris@70 46 connect(line, SIGNAL(textChanged(QString)),
Chris@70 47 this, SLOT(frameTimeChanged(QString)));
Chris@70 48
Chris@70 49 ++row;
Chris@70 50
Chris@70 51 grid->addWidget(new QLabel(tr("Secs:")), row, 0);
Chris@70 52
Chris@70 53 line = new QLineEdit;
Chris@70 54 line->setValidator(new QIntValidator(this));
Chris@70 55 grid->addWidget(line, row, 1);
Chris@70 56 connect(line, SIGNAL(textChanged(QString)),
Chris@70 57 this, SLOT(realTimeSecsChanged(QString)));
Chris@70 58
Chris@70 59 ++row;
Chris@70 60
Chris@70 61 grid->addWidget(new QLabel(tr("Nsecs:")), row, 0);
Chris@70 62
Chris@70 63 line = new QLineEdit;
Chris@70 64 line->setValidator(new QIntValidator(this));
Chris@70 65 grid->addWidget(line, row, 1);
Chris@70 66 connect(line, SIGNAL(textChanged(QString)),
Chris@70 67 this, SLOT(realTimeSecsChanged(QString)));
Chris@70 68
Chris@70 69 ++row;
Chris@70 70 }
Chris@70 71
Chris@70 72 if (options & ShowDuration) {
Chris@70 73
Chris@70 74 grid->addWidget(new QLabel(tr("Frame duration:")), row, 0);
Chris@70 75
Chris@70 76 line = new QLineEdit;
Chris@70 77 line->setValidator(new QIntValidator(this));
Chris@70 78 grid->addWidget(line, row, 1);
Chris@70 79 connect(line, SIGNAL(textChanged(QString)),
Chris@70 80 this, SLOT(frameDurationChanged(QString)));
Chris@70 81
Chris@70 82 ++row;
Chris@70 83
Chris@70 84 grid->addWidget(new QLabel(tr("Secs:")), row, 0);
Chris@70 85
Chris@70 86 line = new QLineEdit;
Chris@70 87 line->setValidator(new QIntValidator(this));
Chris@70 88 grid->addWidget(line, row, 1);
Chris@70 89 connect(line, SIGNAL(textChanged(QString)),
Chris@70 90 this, SLOT(realDurationSecsChanged(QString)));
Chris@70 91
Chris@70 92 ++row;
Chris@70 93
Chris@70 94 grid->addWidget(new QLabel(tr("Nsecs:")), row, 0);
Chris@70 95
Chris@70 96 line = new QLineEdit;
Chris@70 97 line->setValidator(new QIntValidator(this));
Chris@70 98 grid->addWidget(line, row, 1);
Chris@70 99 connect(line, SIGNAL(textChanged(QString)),
Chris@70 100 this, SLOT(realDurationSecsChanged(QString)));
Chris@70 101
Chris@70 102 ++row;
Chris@70 103 }
Chris@70 104
Chris@70 105 if (options & ShowValue) {
Chris@70 106
Chris@70 107 grid->addWidget(new QLabel(tr("Value:")), row, 0);
Chris@70 108
Chris@70 109 QDoubleSpinBox *spinbox = new QDoubleSpinBox;
Chris@70 110 grid->addWidget(spinbox, row, 1);
Chris@70 111 connect(spinbox, SIGNAL(valueChanged(double)),
Chris@70 112 this, SLOT(valueChanged(double)));
Chris@70 113
Chris@70 114 ++row;
Chris@70 115 }
Chris@70 116
Chris@70 117 if (options & ShowText) {
Chris@70 118
Chris@70 119 grid->addWidget(new QLabel(tr("Text:")), row, 0);
Chris@70 120
Chris@70 121 line = new QLineEdit;
Chris@70 122 grid->addWidget(line, row, 1);
Chris@70 123 connect(line, SIGNAL(textChanged(QString)),
Chris@70 124 this, SLOT(textChanged(QString)));
Chris@70 125
Chris@70 126 ++row;
Chris@70 127 }
Chris@70 128
Chris@70 129 QHBoxLayout *hbox = new QHBoxLayout;
Chris@70 130 grid->addLayout(hbox, row, 0, 1, 2);
Chris@70 131
Chris@70 132 QPushButton *ok = new QPushButton(tr("OK"));
Chris@70 133 QPushButton *cancel = new QPushButton(tr("Cancel"));
Chris@70 134 hbox->addStretch(10);
Chris@70 135 hbox->addWidget(ok);
Chris@70 136 hbox->addWidget(cancel);
Chris@70 137 connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
Chris@70 138 connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
Chris@70 139 }
Chris@70 140
Chris@70 141 void
Chris@70 142 ItemEditDialog::setFrameTime(long frame)
Chris@70 143 {
Chris@70 144 m_frame = frame;
Chris@70 145 //!!!
Chris@70 146 }
Chris@70 147
Chris@70 148 long
Chris@70 149 ItemEditDialog::getFrameTime() const
Chris@70 150 {
Chris@70 151 return m_frame;
Chris@70 152 }
Chris@70 153
Chris@70 154 void
Chris@70 155 ItemEditDialog::setRealTime(RealTime rt)
Chris@70 156 {
Chris@70 157 m_frame = RealTime::realTime2Frame(rt, m_sampleRate);
Chris@70 158 //!!!
Chris@70 159 }
Chris@70 160
Chris@70 161 RealTime
Chris@70 162 ItemEditDialog::getRealTime() const
Chris@70 163 {
Chris@70 164 return RealTime::frame2RealTime(m_frame, m_sampleRate);
Chris@70 165 }
Chris@70 166
Chris@70 167 void
Chris@70 168 ItemEditDialog::setFrameDuration(long duration)
Chris@70 169 {
Chris@70 170 m_duration = duration;
Chris@70 171 //!!!
Chris@70 172 }
Chris@70 173
Chris@70 174 long
Chris@70 175 ItemEditDialog::getFrameDuration() const
Chris@70 176 {
Chris@70 177 return m_duration;
Chris@70 178 }
Chris@70 179
Chris@70 180 void
Chris@70 181 ItemEditDialog::setRealDuration(RealTime rt)
Chris@70 182 {
Chris@70 183 m_duration = RealTime::realTime2Frame(rt, m_sampleRate);
Chris@70 184 }
Chris@70 185
Chris@70 186 RealTime
Chris@70 187 ItemEditDialog::getRealDuration() const
Chris@70 188 {
Chris@70 189 return RealTime::frame2RealTime(m_duration, m_sampleRate);
Chris@70 190 }
Chris@70 191
Chris@70 192 void
Chris@70 193 ItemEditDialog::setValue(float v)
Chris@70 194 {
Chris@70 195 m_value = v;
Chris@70 196 //!!!
Chris@70 197 }
Chris@70 198
Chris@70 199 float
Chris@70 200 ItemEditDialog::getValue() const
Chris@70 201 {
Chris@70 202 return m_value;
Chris@70 203 }
Chris@70 204
Chris@70 205 void
Chris@70 206 ItemEditDialog::setText(QString text)
Chris@70 207 {
Chris@70 208 m_text = text;
Chris@70 209 //!!!
Chris@70 210 }
Chris@70 211
Chris@70 212 QString
Chris@70 213 ItemEditDialog::getText() const
Chris@70 214 {
Chris@70 215 return m_text;
Chris@70 216 }
Chris@70 217
Chris@70 218 void
Chris@70 219 ItemEditDialog::frameTimeChanged(QString s)
Chris@70 220 {
Chris@70 221 setFrameTime(s.toInt());
Chris@70 222 }
Chris@70 223
Chris@70 224 void
Chris@70 225 ItemEditDialog::realTimeSecsChanged(QString s)
Chris@70 226 {
Chris@70 227 RealTime rt = getRealTime();
Chris@70 228 rt.sec = s.toInt();
Chris@70 229 setRealTime(rt);
Chris@70 230 }
Chris@70 231
Chris@70 232 void
Chris@70 233 ItemEditDialog::realTimeNSecsChanged(QString s)
Chris@70 234 {
Chris@70 235 RealTime rt = getRealTime();
Chris@70 236 rt.nsec = s.toInt();
Chris@70 237 setRealTime(rt);
Chris@70 238 }
Chris@70 239
Chris@70 240 void
Chris@70 241 ItemEditDialog::frameDurationChanged(QString s)
Chris@70 242 {
Chris@70 243 setFrameDuration(s.toInt());
Chris@70 244 }
Chris@70 245
Chris@70 246 void
Chris@70 247 ItemEditDialog::realDurationSecsChanged(QString s)
Chris@70 248 {
Chris@70 249 RealTime rt = getRealDuration();
Chris@70 250 rt.sec = s.toInt();
Chris@70 251 setRealDuration(rt);
Chris@70 252 }
Chris@70 253
Chris@70 254 void
Chris@70 255 ItemEditDialog::realDurationNSecsChanged(QString s)
Chris@70 256 {
Chris@70 257 RealTime rt = getRealDuration();
Chris@70 258 rt.nsec = s.toInt();
Chris@70 259 setRealDuration(rt);
Chris@70 260 }
Chris@70 261
Chris@70 262 void
Chris@70 263 ItemEditDialog::valueChanged(double v)
Chris@70 264 {
Chris@70 265 setValue((float)v);
Chris@70 266 }
Chris@70 267
Chris@70 268 void
Chris@70 269 ItemEditDialog::textChanged(QString text)
Chris@70 270 {
Chris@70 271 setText(text);
Chris@70 272 }
Chris@70 273