Mercurial > hg > svgui
comparison widgets/CSVFormatDialog.cpp @ 559:5bcfc5606528
* Add option to import time+duration (or time+endtime) from CSV files
(importing to Region layers)
* Fix ffwd/rwd in Region layers so as to behave like time-value layers
author | Chris Cannam |
---|---|
date | Thu, 08 Jul 2010 14:22:28 +0000 |
parents | 24d1d1528717 |
children | e15afed2bfeb |
comparison
equal
deleted
inserted
replaced
558:9fc13f61ae74 | 559:5bcfc5606528 |
---|---|
29 CSVFormatDialog::CSVFormatDialog(QWidget *parent, CSVFormat format, | 29 CSVFormatDialog::CSVFormatDialog(QWidget *parent, CSVFormat format, |
30 size_t defaultSampleRate) : | 30 size_t defaultSampleRate) : |
31 QDialog(parent), | 31 QDialog(parent), |
32 m_modelType(CSVFormat::OneDimensionalModel), | 32 m_modelType(CSVFormat::OneDimensionalModel), |
33 m_timingType(CSVFormat::ExplicitTiming), | 33 m_timingType(CSVFormat::ExplicitTiming), |
34 m_durationType(CSVFormat::Durations), | |
34 m_timeUnits(CSVFormat::TimeAudioFrames), | 35 m_timeUnits(CSVFormat::TimeAudioFrames), |
35 m_separator(""), | 36 m_separator(""), |
36 m_behaviour(QString::KeepEmptyParts) | 37 m_behaviour(QString::KeepEmptyParts) |
37 { | 38 { |
38 setModal(true); | 39 setModal(true); |
39 setWindowTitle(tr("Select Data Format")); | 40 setWindowTitle(tr("Select Data Format")); |
40 | 41 |
41 m_modelType = format.getModelType(); | 42 m_modelType = format.getModelType(); |
42 m_timingType = format.getTimingType(); | 43 m_timingType = format.getTimingType(); |
44 m_durationType = format.getDurationType(); | |
43 m_timeUnits = format.getTimeUnits(); | 45 m_timeUnits = format.getTimeUnits(); |
44 m_separator = format.getSeparator(); | 46 m_separator = format.getSeparator(); |
45 m_sampleRate = format.getSampleRate(); | 47 m_sampleRate = format.getSampleRate(); |
46 m_windowSize = format.getWindowSize(); | 48 m_windowSize = format.getWindowSize(); |
47 m_behaviour = format.getSplitBehaviour(); | 49 m_behaviour = format.getSplitBehaviour(); |
56 layout->addWidget(new QLabel(tr("Each row specifies:")), 1, 0); | 58 layout->addWidget(new QLabel(tr("Each row specifies:")), 1, 0); |
57 | 59 |
58 m_modelTypeCombo = new QComboBox; | 60 m_modelTypeCombo = new QComboBox; |
59 m_modelTypeCombo->addItem(tr("A point in time")); | 61 m_modelTypeCombo->addItem(tr("A point in time")); |
60 m_modelTypeCombo->addItem(tr("A value at a time")); | 62 m_modelTypeCombo->addItem(tr("A value at a time")); |
63 m_modelTypeCombo->addItem(tr("A value across a time range")); | |
61 m_modelTypeCombo->addItem(tr("A set of values")); | 64 m_modelTypeCombo->addItem(tr("A set of values")); |
62 layout->addWidget(m_modelTypeCombo, 1, 1, 1, 2); | 65 layout->addWidget(m_modelTypeCombo, 1, 1, 1, 2); |
63 connect(m_modelTypeCombo, SIGNAL(activated(int)), | 66 connect(m_modelTypeCombo, SIGNAL(activated(int)), |
64 this, SLOT(modelTypeChanged(int))); | 67 this, SLOT(modelTypeChanged(int))); |
65 m_modelTypeCombo->setCurrentIndex(int(m_modelType)); | 68 m_modelTypeCombo->setCurrentIndex(int(m_modelType)); |
74 connect(m_timingTypeCombo, SIGNAL(activated(int)), | 77 connect(m_timingTypeCombo, SIGNAL(activated(int)), |
75 this, SLOT(timingTypeChanged(int))); | 78 this, SLOT(timingTypeChanged(int))); |
76 m_timingTypeCombo->setCurrentIndex(m_timingType == CSVFormat::ExplicitTiming ? | 79 m_timingTypeCombo->setCurrentIndex(m_timingType == CSVFormat::ExplicitTiming ? |
77 m_timeUnits == CSVFormat::TimeSeconds ? 0 : 1 : 2); | 80 m_timeUnits == CSVFormat::TimeSeconds ? 0 : 1 : 2); |
78 | 81 |
82 m_durationTypeLabel = new QLabel(tr("The second column contains:")); | |
83 layout->addWidget(m_durationTypeLabel, 3, 0); | |
84 | |
85 m_durationTypeCombo = new QComboBox; | |
86 m_durationTypeCombo->addItem(tr("Duration")); | |
87 m_durationTypeCombo->addItem(tr("End time")); | |
88 layout->addWidget(m_durationTypeCombo, 3, 1, 1, 2); | |
89 connect(m_durationTypeCombo, SIGNAL(activated(int)), | |
90 this, SLOT(durationTypeChanged(int))); | |
91 m_durationTypeCombo->setCurrentIndex(int(m_durationType)); | |
92 | |
79 m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):")); | 93 m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):")); |
80 layout->addWidget(m_sampleRateLabel, 3, 0); | 94 layout->addWidget(m_sampleRateLabel, 4, 0); |
81 | 95 |
82 size_t sampleRates[] = { | 96 size_t sampleRates[] = { |
83 8000, 11025, 12000, 22050, 24000, 32000, | 97 8000, 11025, 12000, 22050, 24000, 32000, |
84 44100, 48000, 88200, 96000, 176400, 192000 | 98 44100, 48000, 88200, 96000, 176400, 192000 |
85 }; | 99 }; |
90 m_sampleRateCombo->addItem(QString("%1").arg(sampleRates[i])); | 104 m_sampleRateCombo->addItem(QString("%1").arg(sampleRates[i])); |
91 if (sampleRates[i] == m_sampleRate) m_sampleRateCombo->setCurrentIndex(i); | 105 if (sampleRates[i] == m_sampleRate) m_sampleRateCombo->setCurrentIndex(i); |
92 } | 106 } |
93 m_sampleRateCombo->setEditable(true); | 107 m_sampleRateCombo->setEditable(true); |
94 | 108 |
95 layout->addWidget(m_sampleRateCombo, 3, 1); | 109 layout->addWidget(m_sampleRateCombo, 4, 1); |
96 connect(m_sampleRateCombo, SIGNAL(activated(QString)), | 110 connect(m_sampleRateCombo, SIGNAL(activated(QString)), |
97 this, SLOT(sampleRateChanged(QString))); | 111 this, SLOT(sampleRateChanged(QString))); |
98 connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)), | 112 connect(m_sampleRateCombo, SIGNAL(editTextChanged(QString)), |
99 this, SLOT(sampleRateChanged(QString))); | 113 this, SLOT(sampleRateChanged(QString))); |
100 | 114 |
101 m_windowSizeLabel = new QLabel(tr("Frame increment between rows:")); | 115 m_windowSizeLabel = new QLabel(tr("Frame increment between rows:")); |
102 layout->addWidget(m_windowSizeLabel, 4, 0); | 116 layout->addWidget(m_windowSizeLabel, 5, 0); |
103 | 117 |
104 m_windowSizeCombo = new QComboBox; | 118 m_windowSizeCombo = new QComboBox; |
105 m_windowSize = 1024; | 119 m_windowSize = 1024; |
106 for (int i = 0; i <= 16; ++i) { | 120 for (int i = 0; i <= 16; ++i) { |
107 int value = 1 << i; | 121 int value = 1 << i; |
108 m_windowSizeCombo->addItem(QString("%1").arg(value)); | 122 m_windowSizeCombo->addItem(QString("%1").arg(value)); |
109 if (value == int(m_windowSize)) m_windowSizeCombo->setCurrentIndex(i); | 123 if (value == int(m_windowSize)) m_windowSizeCombo->setCurrentIndex(i); |
110 } | 124 } |
111 m_windowSizeCombo->setEditable(true); | 125 m_windowSizeCombo->setEditable(true); |
112 | 126 |
113 layout->addWidget(m_windowSizeCombo, 4, 1); | 127 layout->addWidget(m_windowSizeCombo, 5, 1); |
114 connect(m_windowSizeCombo, SIGNAL(activated(QString)), | 128 connect(m_windowSizeCombo, SIGNAL(activated(QString)), |
115 this, SLOT(windowSizeChanged(QString))); | 129 this, SLOT(windowSizeChanged(QString))); |
116 connect(m_windowSizeCombo, SIGNAL(editTextChanged(QString)), | 130 connect(m_windowSizeCombo, SIGNAL(editTextChanged(QString)), |
117 this, SLOT(windowSizeChanged(QString))); | 131 this, SLOT(windowSizeChanged(QString))); |
118 | 132 |
119 layout->addWidget(new QLabel(tr("\nExample data from file:")), 5, 0, 1, 4); | 133 layout->addWidget(new QLabel(tr("\nExample data from file:")), 6, 0, 1, 4); |
120 | 134 |
121 m_exampleWidget = new QTableWidget | 135 m_exampleWidget = new QTableWidget |
122 (std::min(10, m_example.size()), m_maxExampleCols); | 136 (std::min(10, m_example.size()), m_maxExampleCols); |
123 | 137 |
124 layout->addWidget(m_exampleWidget, 6, 0, 1, 4); | 138 layout->addWidget(m_exampleWidget, 7, 0, 1, 4); |
125 layout->setColumnStretch(3, 10); | 139 layout->setColumnStretch(3, 10); |
126 layout->setRowStretch(6, 10); | 140 layout->setRowStretch(6, 10); |
127 | 141 |
128 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | | 142 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | |
129 QDialogButtonBox::Cancel); | 143 QDialogButtonBox::Cancel); |
130 layout->addWidget(bb, 7, 0, 1, 4); | 144 layout->addWidget(bb, 8, 0, 1, 4); |
131 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); | 145 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); |
132 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); | 146 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); |
133 | 147 |
134 setLayout(layout); | 148 setLayout(layout); |
135 | 149 |
150 modelTypeChanged(m_modelTypeCombo->currentIndex()); | |
136 timingTypeChanged(m_timingTypeCombo->currentIndex()); | 151 timingTypeChanged(m_timingTypeCombo->currentIndex()); |
152 durationTypeChanged(m_durationTypeCombo->currentIndex()); | |
137 } | 153 } |
138 | 154 |
139 CSVFormatDialog::~CSVFormatDialog() | 155 CSVFormatDialog::~CSVFormatDialog() |
140 { | 156 { |
141 } | 157 } |
144 CSVFormatDialog::getFormat() const | 160 CSVFormatDialog::getFormat() const |
145 { | 161 { |
146 CSVFormat format; | 162 CSVFormat format; |
147 format.setModelType(m_modelType); | 163 format.setModelType(m_modelType); |
148 format.setTimingType(m_timingType); | 164 format.setTimingType(m_timingType); |
165 format.setDurationType(m_durationType); | |
149 format.setTimeUnits(m_timeUnits); | 166 format.setTimeUnits(m_timeUnits); |
150 format.setSeparator(m_separator); | 167 format.setSeparator(m_separator); |
151 format.setSampleRate(m_sampleRate); | 168 format.setSampleRate(m_sampleRate); |
152 format.setWindowSize(m_windowSize); | 169 format.setWindowSize(m_windowSize); |
153 format.setSplitBehaviour(m_behaviour); | 170 format.setSplitBehaviour(m_behaviour); |
190 void | 207 void |
191 CSVFormatDialog::modelTypeChanged(int type) | 208 CSVFormatDialog::modelTypeChanged(int type) |
192 { | 209 { |
193 m_modelType = (CSVFormat::ModelType)type; | 210 m_modelType = (CSVFormat::ModelType)type; |
194 | 211 |
195 // if (m_modelType == CSVFormat::ThreeDimensionalModel) { | 212 if (m_modelType == CSVFormat::TwoDimensionalModelWithDuration) { |
196 // We can't load 3d models with explicit timing, because the 3d | 213 m_durationTypeCombo->setEnabled(true); |
197 // model is dense so we need a fixed sample increment | 214 m_durationTypeLabel->setEnabled(true); |
198 // m_timingTypeCombo->setCurrentIndex(2); | 215 } else { |
199 // timingTypeChanged(2); | 216 m_durationTypeCombo->setEnabled(false); |
200 // } | 217 m_durationTypeLabel->setEnabled(false); |
218 } | |
201 } | 219 } |
202 | 220 |
203 void | 221 void |
204 CSVFormatDialog::timingTypeChanged(int type) | 222 CSVFormatDialog::timingTypeChanged(int type) |
205 { | 223 { |
210 m_timeUnits = CSVFormat::TimeSeconds; | 228 m_timeUnits = CSVFormat::TimeSeconds; |
211 m_sampleRateCombo->setEnabled(false); | 229 m_sampleRateCombo->setEnabled(false); |
212 m_sampleRateLabel->setEnabled(false); | 230 m_sampleRateLabel->setEnabled(false); |
213 m_windowSizeCombo->setEnabled(false); | 231 m_windowSizeCombo->setEnabled(false); |
214 m_windowSizeLabel->setEnabled(false); | 232 m_windowSizeLabel->setEnabled(false); |
215 // if (m_modelType == CSVFormat::ThreeDimensionalModel) { | |
216 // m_modelTypeCombo->setCurrentIndex(1); | |
217 // modelTypeChanged(1); | |
218 // } | |
219 break; | 233 break; |
220 | 234 |
221 case 1: | 235 case 1: |
222 m_timingType = CSVFormat::ExplicitTiming; | 236 m_timingType = CSVFormat::ExplicitTiming; |
223 m_timeUnits = CSVFormat::TimeAudioFrames; | 237 m_timeUnits = CSVFormat::TimeAudioFrames; |
224 m_sampleRateCombo->setEnabled(true); | 238 m_sampleRateCombo->setEnabled(true); |
225 m_sampleRateLabel->setEnabled(true); | 239 m_sampleRateLabel->setEnabled(true); |
226 m_windowSizeCombo->setEnabled(false); | 240 m_windowSizeCombo->setEnabled(false); |
227 m_windowSizeLabel->setEnabled(false); | 241 m_windowSizeLabel->setEnabled(false); |
228 // if (m_modelType == CSVFormat::ThreeDimensionalModel) { | |
229 // m_modelTypeCombo->setCurrentIndex(1); | |
230 // modelTypeChanged(1); | |
231 // } | |
232 break; | 242 break; |
233 | 243 |
234 case 2: | 244 case 2: |
235 m_timingType = CSVFormat::ImplicitTiming; | 245 m_timingType = CSVFormat::ImplicitTiming; |
236 m_timeUnits = CSVFormat::TimeWindows; | 246 m_timeUnits = CSVFormat::TimeWindows; |
243 | 253 |
244 populateExample(); | 254 populateExample(); |
245 } | 255 } |
246 | 256 |
247 void | 257 void |
258 CSVFormatDialog::durationTypeChanged(int type) | |
259 { | |
260 m_durationType = (CSVFormat::DurationType)type; | |
261 } | |
262 | |
263 void | |
248 CSVFormatDialog::sampleRateChanged(QString rateString) | 264 CSVFormatDialog::sampleRateChanged(QString rateString) |
249 { | 265 { |
250 bool ok = false; | 266 bool ok = false; |
251 int sampleRate = rateString.toInt(&ok); | 267 int sampleRate = rateString.toInt(&ok); |
252 if (ok) m_sampleRate = sampleRate; | 268 if (ok) m_sampleRate = sampleRate; |