Chris@224
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@224
|
2
|
Chris@224
|
3 /*
|
Chris@224
|
4 Sonic Visualiser
|
Chris@224
|
5 An audio file viewer and annotation editor.
|
Chris@224
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@224
|
7 This file copyright 2006-2007 Chris Cannam and QMUL.
|
Chris@224
|
8
|
Chris@224
|
9 This program is free software; you can redistribute it and/or
|
Chris@224
|
10 modify it under the terms of the GNU General Public License as
|
Chris@224
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@224
|
12 License, or (at your option) any later version. See the file
|
Chris@224
|
13 COPYING included with this distribution for more information.
|
Chris@224
|
14 */
|
Chris@216
|
15
|
Chris@216
|
16 #include "MainWindow.h"
|
Chris@216
|
17 #include "data/osc/OSCQueue.h"
|
Chris@216
|
18
|
Chris@216
|
19 #include "layer/WaveformLayer.h"
|
Chris@216
|
20 #include "view/ViewManager.h"
|
Chris@216
|
21 #include "view/Pane.h"
|
Chris@216
|
22 #include "view/PaneStack.h"
|
Chris@216
|
23 #include "data/model/WaveFileModel.h"
|
Chris@248
|
24 #include "widgets/CommandHistory.h"
|
Chris@1035
|
25 #include "audio/AudioCallbackPlaySource.h"
|
Chris@216
|
26 #include "framework/Document.h"
|
Chris@216
|
27 #include "data/fileio/WavFileWriter.h"
|
Chris@249
|
28 #include "transform/TransformFactory.h"
|
Chris@1386
|
29 #include "widgets/LevelPanWidget.h"
|
Chris@1431
|
30 #include "widgets/LevelPanToolButton.h"
|
Chris@216
|
31 #include "widgets/AudioDial.h"
|
Chris@216
|
32
|
Chris@1035
|
33 #include <bqaudioio/SystemPlaybackTarget.h>
|
Chris@1035
|
34
|
Chris@216
|
35 #include <QFileInfo>
|
Chris@2441
|
36 #include <QTime>
|
Chris@2441
|
37 #include <QElapsedTimer>
|
Chris@2441
|
38
|
Chris@2441
|
39 #define NOW (QTime::currentTime().toString(Qt::ISODateWithMs))
|
Chris@216
|
40
|
Chris@216
|
41 void
|
Chris@216
|
42 MainWindow::handleOSCMessage(const OSCMessage &message)
|
Chris@216
|
43 {
|
Chris@2441
|
44 QElapsedTimer timer;
|
Chris@2441
|
45 timer.start();
|
Chris@2441
|
46
|
Chris@2441
|
47 SVDEBUG << "OSCHandler at " << NOW << ": handling message: "
|
Chris@2441
|
48 << message.toString() << endl;
|
Chris@216
|
49
|
Chris@216
|
50 if (message.getMethod() == "open") {
|
Chris@216
|
51
|
Chris@216
|
52 if (message.getArgCount() == 1 &&
|
Chris@216
|
53 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
54 QString path = message.getArg(0).toString();
|
Chris@2441
|
55 if (open(path, ReplaceMainModel) == FileOpenSucceeded) {
|
Chris@2441
|
56 SVDEBUG << "OSCHandler: Opened path \""
|
Chris@2441
|
57 << path << "\"" << endl;
|
Chris@2441
|
58 } else {
|
Chris@2441
|
59 SVCERR << "OSCHandler: File open failed for path \""
|
Chris@2441
|
60 << path << "\"" << endl;
|
Chris@216
|
61 }
|
Chris@216
|
62 //!!! we really need to spin here and not return until the
|
Chris@216
|
63 // file has been completely decoded...
|
Chris@216
|
64 }
|
Chris@216
|
65
|
Chris@216
|
66 } else if (message.getMethod() == "openadditional") {
|
Chris@216
|
67
|
Chris@216
|
68 if (message.getArgCount() == 1 &&
|
Chris@216
|
69 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
70 QString path = message.getArg(0).toString();
|
Chris@2441
|
71 if (open(path, CreateAdditionalModel) == FileOpenSucceeded) {
|
Chris@2441
|
72 SVDEBUG << "OSCHandler: Opened additional path \""
|
Chris@2441
|
73 << path << "\"" << endl;
|
Chris@2441
|
74 } else {
|
Chris@2441
|
75 SVCERR << "OSCHandler: File open failed for path \""
|
Chris@665
|
76 << path << "\"" << endl;
|
Chris@216
|
77 }
|
Chris@216
|
78 }
|
Chris@216
|
79
|
Chris@216
|
80 } else if (message.getMethod() == "recent" ||
|
Chris@216
|
81 message.getMethod() == "last") {
|
Chris@216
|
82
|
Chris@216
|
83 int n = 0;
|
Chris@216
|
84 if (message.getMethod() == "recent" &&
|
Chris@216
|
85 message.getArgCount() == 1 &&
|
Chris@216
|
86 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@216
|
87 n = message.getArg(0).toInt() - 1;
|
Chris@216
|
88 }
|
Chris@216
|
89 std::vector<QString> recent = m_recentFiles.getRecent();
|
Chris@216
|
90 if (n >= 0 && n < int(recent.size())) {
|
Chris@2441
|
91 QString path = recent[n];
|
Chris@2441
|
92 if (open(path, ReplaceMainModel) == FileOpenSucceeded) {
|
Chris@2441
|
93 SVDEBUG << "OSCHandler: Opened recent path \""
|
Chris@2441
|
94 << path << "\"" << endl;
|
Chris@2441
|
95 } else {
|
Chris@2441
|
96 SVCERR << "OSCHandler: File open failed for path \""
|
Chris@2441
|
97 << path << "\"" << endl;
|
Chris@216
|
98 }
|
Chris@216
|
99 }
|
Chris@216
|
100
|
Chris@216
|
101 } else if (message.getMethod() == "save") {
|
Chris@216
|
102
|
Chris@216
|
103 QString path;
|
Chris@216
|
104 if (message.getArgCount() == 1 &&
|
Chris@216
|
105 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
106 path = message.getArg(0).toString();
|
Chris@216
|
107 if (QFileInfo(path).exists()) {
|
Chris@2441
|
108 SVCERR << "OSCHandler: Refusing to overwrite existing file in save" << endl;
|
Chris@2441
|
109 } else if (saveSessionFile(path)) {
|
Chris@2441
|
110 SVDEBUG << "OSCHandler: Saved session to path \""
|
Chris@2441
|
111 << path << "\"" << endl;
|
Chris@216
|
112 } else {
|
Chris@2441
|
113 SVCERR << "OSCHandler: Save failed to path \""
|
Chris@2441
|
114 << path << "\"" << endl;
|
Chris@216
|
115 }
|
Chris@216
|
116 }
|
Chris@216
|
117
|
Chris@216
|
118 } else if (message.getMethod() == "export") {
|
Chris@216
|
119
|
Chris@216
|
120 QString path;
|
Chris@216
|
121 if (getMainModel()) {
|
Chris@216
|
122 if (message.getArgCount() == 1 &&
|
Chris@216
|
123 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
124 path = message.getArg(0).toString();
|
Chris@216
|
125 if (QFileInfo(path).exists()) {
|
Chris@2441
|
126 SVCERR << "OSCHandler: Refusing to overwrite existing file in export" << endl;
|
Chris@216
|
127 } else {
|
Chris@216
|
128 WavFileWriter writer(path,
|
Chris@216
|
129 getMainModel()->getSampleRate(),
|
Chris@428
|
130 getMainModel()->getChannelCount(),
|
Chris@428
|
131 WavFileWriter::WriteToTemporary);
|
Chris@216
|
132 MultiSelection ms = m_viewManager->getSelection();
|
Chris@2441
|
133 if (writer.writeModel
|
Chris@2441
|
134 (getMainModel().get(),
|
Chris@2441
|
135 ms.getSelections().empty() ? nullptr : &ms)) {
|
Chris@2441
|
136 SVDEBUG << "OSCHandler: Exported audio to path \""
|
Chris@2441
|
137 << path << "\"" << endl;
|
Chris@216
|
138 } else {
|
Chris@2441
|
139 SVCERR << "OSCHandler: Export failed to path \""
|
Chris@2441
|
140 << path << "\"" << endl;
|
Chris@216
|
141 }
|
Chris@216
|
142 }
|
Chris@216
|
143 }
|
Chris@216
|
144 }
|
Chris@216
|
145
|
Chris@2242
|
146 } else if (message.getMethod() == "exportlayer") {
|
Chris@2242
|
147
|
Chris@2242
|
148 QString path;
|
Chris@2242
|
149 if (message.getArgCount() == 1 &&
|
Chris@2242
|
150 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@2242
|
151 path = message.getArg(0).toString();
|
Chris@2242
|
152 if (QFileInfo(path).exists()) {
|
Chris@2242
|
153 SVDEBUG << "OSCHandler: Refusing to overwrite existing file in layer export" << endl;
|
Chris@2242
|
154 } else {
|
Chris@2242
|
155 Pane *currentPane = nullptr;
|
Chris@2242
|
156 Layer *currentLayer = nullptr;
|
Chris@2242
|
157 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
Chris@2242
|
158 if (currentPane) currentLayer = currentPane->getSelectedLayer();
|
Chris@2242
|
159 if (currentLayer) {
|
Chris@2242
|
160 QString error;
|
Chris@2435
|
161 if (!exportLayerTo(currentLayer, currentPane, path, error)) {
|
Chris@2242
|
162 SVCERR << "OSCHandler: Failed to export current layer to " << path << ": " << error << endl;
|
Chris@2242
|
163 }
|
Chris@2242
|
164 } else {
|
Chris@2242
|
165 SVCERR << "OSCHandler: No current layer to export" << endl;
|
Chris@2242
|
166 }
|
Chris@2242
|
167 }
|
Chris@2242
|
168 }
|
Chris@2242
|
169
|
Chris@216
|
170 } else if (message.getMethod() == "jump" ||
|
Chris@216
|
171 message.getMethod() == "play") {
|
Chris@216
|
172
|
Chris@216
|
173 if (getMainModel()) {
|
Chris@216
|
174
|
Chris@922
|
175 sv_frame_t frame = m_viewManager->getPlaybackFrame();
|
Chris@216
|
176 bool selection = false;
|
Chris@216
|
177 bool play = (message.getMethod() == "play");
|
Chris@216
|
178
|
Chris@216
|
179 if (message.getArgCount() == 1) {
|
Chris@216
|
180
|
Chris@216
|
181 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
182 message.getArg(0).toString() == "selection") {
|
Chris@216
|
183
|
Chris@216
|
184 selection = true;
|
Chris@216
|
185
|
Chris@216
|
186 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
187 message.getArg(0).toString() == "end") {
|
Chris@216
|
188
|
Chris@216
|
189 frame = getMainModel()->getEndFrame();
|
Chris@216
|
190
|
Chris@216
|
191 } else if (message.getArg(0).canConvert(QVariant::Double)) {
|
Chris@216
|
192
|
Chris@216
|
193 double time = message.getArg(0).toDouble();
|
Chris@216
|
194 if (time < 0.0) time = 0.0;
|
Chris@216
|
195
|
Chris@216
|
196 frame = lrint(time * getMainModel()->getSampleRate());
|
Chris@216
|
197 }
|
Chris@216
|
198 }
|
Chris@216
|
199
|
Chris@216
|
200 if (frame > getMainModel()->getEndFrame()) {
|
Chris@216
|
201 frame = getMainModel()->getEndFrame();
|
Chris@216
|
202 }
|
Chris@216
|
203
|
Chris@216
|
204 if (play) {
|
Chris@216
|
205 m_viewManager->setPlaySelectionMode(selection);
|
Chris@216
|
206 }
|
Chris@216
|
207
|
Chris@216
|
208 if (selection) {
|
Chris@216
|
209 MultiSelection::SelectionList sl = m_viewManager->getSelections();
|
Chris@216
|
210 if (!sl.empty()) {
|
Chris@216
|
211 frame = sl.begin()->getStartFrame();
|
Chris@216
|
212 }
|
Chris@216
|
213 }
|
Chris@216
|
214
|
Chris@1617
|
215 SVDEBUG << "OSCHandler: Setting playback frame to " << frame << endl;
|
Chris@1617
|
216
|
Chris@216
|
217 m_viewManager->setPlaybackFrame(frame);
|
Chris@216
|
218
|
Chris@1617
|
219 if (play) {
|
Chris@1617
|
220 if (!m_playSource->isPlaying()) {
|
Chris@1617
|
221 SVDEBUG << "OSCHandler: Play source is not yet playing, calling play()" << endl;
|
Chris@1617
|
222 // handles audio device suspend/resume etc, as
|
Chris@1617
|
223 // well as calling m_playSource->play(frame)
|
Chris@1617
|
224 MainWindow::play();
|
Chris@1617
|
225 } else {
|
Chris@1617
|
226 SVDEBUG << "OSCHandler: Play source is already playing, not starting it" << endl;
|
Chris@1617
|
227 }
|
Chris@1617
|
228 } else {
|
Chris@1617
|
229 SVDEBUG << "OSCHandler: Jump only requested, not starting playback" << endl;
|
Chris@216
|
230 }
|
Chris@216
|
231 }
|
Chris@216
|
232
|
Chris@313
|
233 } else if (message.getMethod() == "ffwd") {
|
Chris@313
|
234
|
Chris@313
|
235 if (message.getArgCount() == 1) {
|
Chris@313
|
236
|
Chris@313
|
237 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@313
|
238 message.getArg(0).toString() == "similar") {
|
Chris@313
|
239
|
Chris@2441
|
240 SVDEBUG << "OSCHandler: Calling ffwdSimilar" << endl;
|
Chris@313
|
241 ffwdSimilar();
|
Chris@313
|
242 }
|
Chris@313
|
243 } else {
|
Chris@313
|
244
|
Chris@2441
|
245 SVDEBUG << "OSCHandler: Calling ffwd" << endl;
|
Chris@313
|
246 ffwd();
|
Chris@313
|
247 }
|
Chris@313
|
248
|
Chris@313
|
249 } else if (message.getMethod() == "rewind") {
|
Chris@313
|
250
|
Chris@313
|
251 if (message.getArgCount() == 1) {
|
Chris@313
|
252
|
Chris@313
|
253 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@313
|
254 message.getArg(0).toString() == "similar") {
|
Chris@313
|
255
|
Chris@2441
|
256 SVDEBUG << "OSCHandler: Calling rewindSimilar" << endl;
|
Chris@313
|
257 rewindSimilar();
|
Chris@313
|
258 }
|
Chris@313
|
259 } else {
|
Chris@313
|
260
|
Chris@2441
|
261 SVDEBUG << "OSCHandler: Calling rewind" << endl;
|
Chris@313
|
262 rewind();
|
Chris@313
|
263 }
|
Chris@313
|
264
|
Chris@216
|
265 } else if (message.getMethod() == "stop") {
|
Chris@216
|
266
|
Chris@2441
|
267 if (m_playSource->isPlaying()) {
|
Chris@2441
|
268 // As with play, we want to use the MainWindow function
|
Chris@2441
|
269 // rather than call m_playSource directly because that way
|
Chris@2441
|
270 // the audio driver suspend/resume etc is handled properly
|
Chris@2441
|
271 SVDEBUG << "OSCHandler: Calling stop" << endl;
|
Chris@2441
|
272 MainWindow::stop();
|
Chris@2441
|
273 } else {
|
Chris@2441
|
274 SVDEBUG << "OSCHandler: Not playing, doing nothing" << endl;
|
Chris@2441
|
275 }
|
Chris@216
|
276
|
Chris@216
|
277 } else if (message.getMethod() == "loop") {
|
Chris@216
|
278
|
Chris@216
|
279 if (message.getArgCount() == 1 &&
|
Chris@216
|
280 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
281
|
Chris@216
|
282 QString str = message.getArg(0).toString();
|
Chris@216
|
283 if (str == "on") {
|
Chris@2441
|
284 SVDEBUG << "OSCHandler: Enabling loop mode" << endl;
|
Chris@216
|
285 m_viewManager->setPlayLoopMode(true);
|
Chris@216
|
286 } else if (str == "off") {
|
Chris@2441
|
287 SVDEBUG << "OSCHandler: Disabling loop mode" << endl;
|
Chris@216
|
288 m_viewManager->setPlayLoopMode(false);
|
Chris@216
|
289 }
|
Chris@216
|
290 }
|
Chris@216
|
291
|
Chris@216
|
292 } else if (message.getMethod() == "solo") {
|
Chris@216
|
293
|
Chris@216
|
294 if (message.getArgCount() == 1 &&
|
Chris@216
|
295 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
296
|
Chris@216
|
297 QString str = message.getArg(0).toString();
|
Chris@216
|
298 if (str == "on") {
|
Chris@2441
|
299 SVDEBUG << "OSCHandler: Enabling solo mode" << endl;
|
Chris@216
|
300 m_viewManager->setPlaySoloMode(true);
|
Chris@216
|
301 } else if (str == "off") {
|
Chris@2441
|
302 SVDEBUG << "OSCHandler: Disabling solo mode" << endl;
|
Chris@216
|
303 m_viewManager->setPlaySoloMode(false);
|
Chris@216
|
304 }
|
Chris@216
|
305 }
|
Chris@216
|
306
|
Chris@216
|
307 } else if (message.getMethod() == "select" ||
|
Chris@216
|
308 message.getMethod() == "addselect") {
|
Chris@216
|
309
|
Chris@216
|
310 if (getMainModel()) {
|
Chris@216
|
311
|
Chris@920
|
312 sv_frame_t f0 = getMainModel()->getStartFrame();
|
Chris@920
|
313 sv_frame_t f1 = getMainModel()->getEndFrame();
|
Chris@216
|
314
|
Chris@216
|
315 bool done = false;
|
Chris@216
|
316
|
Chris@216
|
317 if (message.getArgCount() == 2 &&
|
Chris@216
|
318 message.getArg(0).canConvert(QVariant::Double) &&
|
Chris@216
|
319 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@216
|
320
|
Chris@216
|
321 double t0 = message.getArg(0).toDouble();
|
Chris@216
|
322 double t1 = message.getArg(1).toDouble();
|
Chris@216
|
323 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
|
Chris@216
|
324 if (t0 < 0.0) t0 = 0.0;
|
Chris@216
|
325 if (t1 < 0.0) t1 = 0.0;
|
Chris@216
|
326
|
Chris@216
|
327 f0 = lrint(t0 * getMainModel()->getSampleRate());
|
Chris@216
|
328 f1 = lrint(t1 * getMainModel()->getSampleRate());
|
Chris@2441
|
329
|
Chris@2441
|
330 SVDEBUG << "OSCHandler: Converted selection extents to frames "
|
Chris@2441
|
331 << f0 << " and " << f1 << endl;
|
Chris@216
|
332
|
Chris@216
|
333 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@2126
|
334 Layer *layer = nullptr;
|
Chris@216
|
335 if (pane) layer = pane->getSelectedLayer();
|
Chris@216
|
336 if (layer) {
|
Chris@730
|
337 int resolution;
|
Chris@216
|
338 layer->snapToFeatureFrame(pane, f0, resolution,
|
Chris@2380
|
339 Layer::SnapLeft, -1);
|
Chris@216
|
340 layer->snapToFeatureFrame(pane, f1, resolution,
|
Chris@2380
|
341 Layer::SnapRight, -1);
|
Chris@2441
|
342
|
Chris@2441
|
343 SVDEBUG << "OSCHandler: Snapped selection extents to "
|
Chris@2441
|
344 << f0 << " and " << f1 << " for current layer \""
|
Chris@2441
|
345 << layer->getLayerPresentationName() << "\""
|
Chris@2441
|
346 << endl;
|
Chris@216
|
347 }
|
Chris@216
|
348
|
Chris@216
|
349 } else if (message.getArgCount() == 1 &&
|
Chris@216
|
350 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
351
|
Chris@216
|
352 QString str = message.getArg(0).toString();
|
Chris@216
|
353 if (str == "none") {
|
Chris@2441
|
354 SVDEBUG << "OSCHandler: Clearing selection" << endl;
|
Chris@216
|
355 m_viewManager->clearSelections();
|
Chris@216
|
356 done = true;
|
Chris@2441
|
357 } else if (str == "all") {
|
Chris@2441
|
358 SVDEBUG << "OSCHandler: Selecting all" << endl;
|
Chris@2441
|
359 f0 = getModelsStartFrame();
|
Chris@2441
|
360 f0 = getModelsEndFrame();
|
Chris@216
|
361 }
|
Chris@216
|
362 }
|
Chris@216
|
363
|
Chris@216
|
364 if (!done) {
|
Chris@216
|
365 if (message.getMethod() == "select") {
|
Chris@216
|
366 m_viewManager->setSelection(Selection(f0, f1));
|
Chris@216
|
367 } else {
|
Chris@216
|
368 m_viewManager->addSelection(Selection(f0, f1));
|
Chris@216
|
369 }
|
Chris@216
|
370 }
|
Chris@2441
|
371
|
Chris@2441
|
372 SVDEBUG << "OSCHandler: Selection now is "
|
Chris@2441
|
373 << m_viewManager->getSelection().toString() << endl;
|
Chris@2441
|
374
|
Chris@2441
|
375 } else {
|
Chris@2441
|
376 SVCERR << "OSCHandler: No main model, can't modify selection"
|
Chris@2441
|
377 << endl;
|
Chris@216
|
378 }
|
Chris@216
|
379
|
Chris@216
|
380 } else if (message.getMethod() == "add") {
|
Chris@216
|
381
|
Chris@216
|
382 if (getMainModel()) {
|
Chris@216
|
383
|
Chris@216
|
384 if (message.getArgCount() >= 1 &&
|
Chris@216
|
385 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
386
|
Chris@216
|
387 int channel = -1;
|
Chris@216
|
388 if (message.getArgCount() == 2 &&
|
Chris@216
|
389 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@216
|
390 channel = message.getArg(0).toInt();
|
Chris@216
|
391 if (channel < -1 ||
|
Chris@216
|
392 channel > int(getMainModel()->getChannelCount())) {
|
Chris@2441
|
393 SVCERR << "WARNING: OSCHandler: channel "
|
Chris@665
|
394 << channel << " out of range" << endl;
|
Chris@216
|
395 channel = -1;
|
Chris@216
|
396 }
|
Chris@216
|
397 }
|
Chris@216
|
398
|
Chris@216
|
399 QString str = message.getArg(0).toString();
|
Chris@216
|
400
|
Chris@216
|
401 LayerFactory::LayerType type =
|
Chris@216
|
402 LayerFactory::getInstance()->getLayerTypeForName(str);
|
Chris@216
|
403
|
Chris@216
|
404 if (type == LayerFactory::UnknownLayer) {
|
Chris@2441
|
405 SVCERR << "WARNING: OSCHandler: unknown layer "
|
Chris@2441
|
406 << "type " << str << endl;
|
Chris@216
|
407 } else {
|
Chris@216
|
408
|
Chris@232
|
409 LayerConfiguration configuration(type,
|
Chris@2300
|
410 getMainModelId(),
|
Chris@232
|
411 channel);
|
Chris@2441
|
412
|
Chris@2441
|
413 QString pname = LayerFactory::getInstance()->
|
Chris@2441
|
414 getLayerPresentationName(type);
|
Chris@216
|
415
|
Chris@2441
|
416 addPane(configuration, tr("Add %1 Pane") .arg(pname));
|
Chris@2441
|
417
|
Chris@2441
|
418 SVDEBUG << "OSCHandler: Added pane \"" << pname
|
Chris@2441
|
419 << "\"" << endl;
|
Chris@216
|
420 }
|
Chris@216
|
421 }
|
Chris@216
|
422 }
|
Chris@216
|
423
|
Chris@216
|
424 } else if (message.getMethod() == "undo") {
|
Chris@216
|
425
|
Chris@2441
|
426 SVDEBUG << "OSCHandler: Calling undo" << endl;
|
Chris@216
|
427 CommandHistory::getInstance()->undo();
|
Chris@216
|
428
|
Chris@216
|
429 } else if (message.getMethod() == "redo") {
|
Chris@216
|
430
|
Chris@2441
|
431 SVDEBUG << "OSCHandler: Calling redo" << endl;
|
Chris@216
|
432 CommandHistory::getInstance()->redo();
|
Chris@216
|
433
|
Chris@216
|
434 } else if (message.getMethod() == "set") {
|
Chris@216
|
435
|
Chris@216
|
436 if (message.getArgCount() == 2 &&
|
Chris@216
|
437 message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
438 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@216
|
439
|
Chris@216
|
440 QString property = message.getArg(0).toString();
|
Chris@216
|
441 float value = (float)message.getArg(1).toDouble();
|
Chris@216
|
442
|
Chris@216
|
443 if (property == "gain") {
|
Chris@216
|
444 if (value < 0.0) value = 0.0;
|
Chris@1386
|
445 m_mainLevelPan->setLevel(value);
|
Chris@216
|
446 if (m_playTarget) m_playTarget->setOutputGain(value);
|
Chris@1617
|
447 } else if (property == "speed") {
|
Chris@1617
|
448 m_playSpeed->setMappedValue(value);
|
Chris@216
|
449 } else if (property == "speedup") {
|
Chris@1617
|
450
|
Chris@1617
|
451 // The speedup method existed before the speed method
|
Chris@1617
|
452 // and is a bit weirder.
|
Chris@1617
|
453 //
|
Chris@1617
|
454 // For speed(x), x is a percentage of normal speed, so
|
Chris@1617
|
455 // x=100 means play at the normal speed, x=50 means
|
Chris@1617
|
456 // half speed, x=200 double speed etc.
|
Chris@1617
|
457 //
|
Chris@1617
|
458 // For speedup(x), x was some sort of modifier of
|
Chris@1617
|
459 // percentage thing, so x=0 meant play at the normal
|
Chris@1617
|
460 // speed, x=50 meant play at 150% of normal speed,
|
Chris@1617
|
461 // x=100 meant play at double speed, and x=-100 rather
|
Chris@1617
|
462 // bizarrely meant play at half speed. We handle this
|
Chris@1617
|
463 // now by converting to speed percentage as follows:
|
Chris@1617
|
464
|
Chris@1617
|
465 double percentage = 100.0;
|
Chris@1617
|
466 if (value > 0.f) {
|
Chris@1617
|
467 percentage = percentage + value;
|
Chris@1617
|
468 } else {
|
Chris@1617
|
469 percentage = 10000.0 / (percentage - value);
|
Chris@1617
|
470 }
|
Chris@1617
|
471 SVDEBUG << "OSCHandler: converted speedup(" << value
|
Chris@1617
|
472 << ") into speed(" << percentage << ")" << endl;
|
Chris@1617
|
473
|
Chris@1617
|
474 m_playSpeed->setMappedValue(percentage);
|
Chris@1617
|
475
|
Chris@216
|
476 } else if (property == "overlays") {
|
Chris@216
|
477 if (value < 0.5) {
|
Chris@216
|
478 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@216
|
479 } else if (value < 1.5) {
|
Chris@701
|
480 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@216
|
481 } else {
|
Chris@216
|
482 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@216
|
483 }
|
Chris@216
|
484 } else if (property == "zoomwheels") {
|
Chris@216
|
485 m_viewManager->setZoomWheelsEnabled(value > 0.5);
|
Chris@216
|
486 } else if (property == "propertyboxes") {
|
Chris@216
|
487 bool toggle = ((value < 0.5) !=
|
Chris@2339
|
488 (m_paneStack->getLayoutStyle() ==
|
Chris@2339
|
489 PaneStack::HiddenPropertyStacksLayout));
|
Chris@216
|
490 if (toggle) togglePropertyBoxes();
|
Chris@216
|
491 }
|
Chris@216
|
492
|
Chris@216
|
493 } else {
|
Chris@2126
|
494 PropertyContainer *container = nullptr;
|
Chris@216
|
495 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@216
|
496 if (pane &&
|
Chris@216
|
497 message.getArgCount() == 3 &&
|
Chris@216
|
498 message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
499 message.getArg(1).canConvert(QVariant::String) &&
|
Chris@216
|
500 message.getArg(2).canConvert(QVariant::String)) {
|
Chris@216
|
501 if (message.getArg(0).toString() == "pane") {
|
Chris@216
|
502 container = pane->getPropertyContainer(0);
|
Chris@216
|
503 } else if (message.getArg(0).toString() == "layer") {
|
Chris@216
|
504 container = pane->getSelectedLayer();
|
Chris@216
|
505 }
|
Chris@216
|
506 }
|
Chris@216
|
507 if (container) {
|
Chris@216
|
508 QString nameString = message.getArg(1).toString();
|
Chris@216
|
509 QString valueString = message.getArg(2).toString();
|
Chris@248
|
510 Command *c = container->getSetPropertyCommand
|
Chris@248
|
511 (nameString, valueString);
|
Chris@248
|
512 if (c) CommandHistory::getInstance()->addCommand(c, true, true);
|
Chris@216
|
513 }
|
Chris@216
|
514 }
|
Chris@216
|
515
|
Chris@216
|
516 } else if (message.getMethod() == "setcurrent") {
|
Chris@216
|
517
|
Chris@216
|
518 int paneIndex = -1, layerIndex = -1;
|
Chris@216
|
519 bool wantLayer = false;
|
Chris@216
|
520
|
Chris@216
|
521 if (message.getArgCount() >= 1 &&
|
Chris@216
|
522 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@216
|
523
|
Chris@216
|
524 paneIndex = message.getArg(0).toInt() - 1;
|
Chris@216
|
525
|
Chris@216
|
526 if (message.getArgCount() >= 2 &&
|
Chris@216
|
527 message.getArg(1).canConvert(QVariant::Int)) {
|
Chris@216
|
528 wantLayer = true;
|
Chris@216
|
529 layerIndex = message.getArg(1).toInt() - 1;
|
Chris@216
|
530 }
|
Chris@216
|
531 }
|
Chris@216
|
532
|
Chris@216
|
533 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
|
Chris@216
|
534 Pane *pane = m_paneStack->getPane(paneIndex);
|
Chris@216
|
535 m_paneStack->setCurrentPane(pane);
|
Chris@2441
|
536 SVDEBUG << "OSCHandler: Set current pane to index "
|
Chris@2441
|
537 << paneIndex << " (pane id " << pane->getId()
|
Chris@2441
|
538 << ")" << endl;
|
Chris@216
|
539 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
|
Chris@2437
|
540 Layer *layer = pane->getFixedOrderLayer(layerIndex);
|
Chris@216
|
541 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@2441
|
542 SVDEBUG << "OSCHandler: Set current layer to index "
|
Chris@2441
|
543 << layerIndex << " (layer \""
|
Chris@2441
|
544 << layer->getLayerPresentationName() << "\")" << endl;
|
Chris@216
|
545 } else if (wantLayer && layerIndex == -1) {
|
Chris@2126
|
546 m_paneStack->setCurrentLayer(pane, nullptr);
|
Chris@2441
|
547 } else if (wantLayer) {
|
Chris@2441
|
548 SVCERR << "OSCHandler: Layer index "
|
Chris@2441
|
549 << layerIndex << " out of range for pane" << endl;
|
Chris@2441
|
550 }
|
Chris@216
|
551 }
|
Chris@216
|
552
|
Chris@216
|
553 } else if (message.getMethod() == "delete") {
|
Chris@216
|
554
|
Chris@216
|
555 if (message.getArgCount() == 1 &&
|
Chris@216
|
556 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
557
|
Chris@216
|
558 QString target = message.getArg(0).toString();
|
Chris@216
|
559
|
Chris@216
|
560 if (target == "pane") {
|
Chris@216
|
561
|
Chris@2441
|
562 SVDEBUG << "OSCHandler: Calling deleteCurrentPane" << endl;
|
Chris@216
|
563 deleteCurrentPane();
|
Chris@216
|
564
|
Chris@216
|
565 } else if (target == "layer") {
|
Chris@216
|
566
|
Chris@2441
|
567 SVDEBUG << "OSCHandler: Calling deleteCurrentLayer" << endl;
|
Chris@216
|
568 deleteCurrentLayer();
|
Chris@216
|
569
|
Chris@216
|
570 } else {
|
Chris@216
|
571
|
Chris@2441
|
572 SVCERR << "WARNING: OSCHandler: Unknown delete target \""
|
Chris@2441
|
573 << target << "\"" << endl;
|
Chris@216
|
574 }
|
Chris@216
|
575 }
|
Chris@216
|
576
|
Chris@216
|
577 } else if (message.getMethod() == "zoom") {
|
Chris@216
|
578
|
Chris@216
|
579 if (message.getArgCount() == 1) {
|
Chris@216
|
580 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
581 message.getArg(0).toString() == "in") {
|
Chris@216
|
582 zoomIn();
|
Chris@216
|
583 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
584 message.getArg(0).toString() == "out") {
|
Chris@216
|
585 zoomOut();
|
Chris@216
|
586 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
587 message.getArg(0).toString() == "default") {
|
Chris@216
|
588 zoomDefault();
|
Chris@312
|
589 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@312
|
590 message.getArg(0).toString() == "fit") {
|
Chris@312
|
591 zoomToFit();
|
Chris@216
|
592 } else if (message.getArg(0).canConvert(QVariant::Double)) {
|
Chris@216
|
593 double level = message.getArg(0).toDouble();
|
Chris@216
|
594 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@2011
|
595 ZoomLevel zoomLevel;
|
Chris@2011
|
596 if (level >= 0.66) {
|
Chris@2011
|
597 zoomLevel = ZoomLevel(ZoomLevel::FramesPerPixel,
|
Chris@2011
|
598 int(round(level)));
|
Chris@2011
|
599 } else {
|
Chris@2011
|
600 zoomLevel = ZoomLevel(ZoomLevel::PixelsPerFrame,
|
Chris@2011
|
601 int(round(1.0 / level)));
|
Chris@2011
|
602 }
|
Chris@2011
|
603 if (currentPane) {
|
Chris@2441
|
604 SVDEBUG << "OSCHandler: Setting zoom level to "
|
Chris@2441
|
605 << zoomLevel << endl;
|
Chris@2011
|
606 currentPane->setZoomLevel(zoomLevel);
|
Chris@2441
|
607 } else {
|
Chris@2441
|
608 SVCERR << "OSCHandler: No current pane, can't set zoom"
|
Chris@2441
|
609 << endl;
|
Chris@2011
|
610 }
|
Chris@216
|
611 }
|
Chris@216
|
612 }
|
Chris@216
|
613
|
Chris@216
|
614 } else if (message.getMethod() == "zoomvertical") {
|
Chris@216
|
615
|
Chris@216
|
616 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@2126
|
617 Layer *layer = nullptr;
|
Chris@216
|
618 if (pane && pane->getLayerCount() > 0) {
|
Chris@216
|
619 layer = pane->getLayer(pane->getLayerCount() - 1);
|
Chris@216
|
620 }
|
Chris@216
|
621 int defaultStep = 0;
|
Chris@216
|
622 int steps = 0;
|
Chris@216
|
623 if (layer) {
|
Chris@216
|
624 steps = layer->getVerticalZoomSteps(defaultStep);
|
Chris@216
|
625 if (message.getArgCount() == 1 && steps > 0) {
|
Chris@216
|
626 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
627 message.getArg(0).toString() == "in") {
|
Chris@216
|
628 int step = layer->getCurrentVerticalZoomStep() + 1;
|
Chris@216
|
629 if (step < steps) layer->setVerticalZoomStep(step);
|
Chris@216
|
630 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
631 message.getArg(0).toString() == "out") {
|
Chris@216
|
632 int step = layer->getCurrentVerticalZoomStep() - 1;
|
Chris@216
|
633 if (step >= 0) layer->setVerticalZoomStep(step);
|
Chris@216
|
634 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
635 message.getArg(0).toString() == "default") {
|
Chris@216
|
636 layer->setVerticalZoomStep(defaultStep);
|
Chris@216
|
637 }
|
Chris@216
|
638 } else if (message.getArgCount() == 2) {
|
Chris@216
|
639 if (message.getArg(0).canConvert(QVariant::Double) &&
|
Chris@216
|
640 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@216
|
641 double min = message.getArg(0).toDouble();
|
Chris@216
|
642 double max = message.getArg(1).toDouble();
|
Chris@216
|
643 layer->setDisplayExtents(min, max);
|
Chris@216
|
644 }
|
Chris@216
|
645 }
|
Chris@216
|
646 }
|
Chris@216
|
647
|
Chris@216
|
648 } else if (message.getMethod() == "quit") {
|
Chris@2440
|
649
|
Chris@2440
|
650 SVDEBUG << "OSCHandler: Exiting abruptly" << endl;
|
Chris@2440
|
651 m_documentModified = false; // so we don't ask to save
|
Chris@216
|
652 close();
|
Chris@216
|
653
|
Chris@216
|
654 } else if (message.getMethod() == "resize") {
|
Chris@216
|
655
|
Chris@216
|
656 if (message.getArgCount() == 2) {
|
Chris@216
|
657
|
Chris@216
|
658 int width = 0, height = 0;
|
Chris@216
|
659
|
Chris@216
|
660 if (message.getArg(1).canConvert(QVariant::Int)) {
|
Chris@216
|
661
|
Chris@216
|
662 height = message.getArg(1).toInt();
|
Chris@216
|
663
|
Chris@216
|
664 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@216
|
665 message.getArg(0).toString() == "pane") {
|
Chris@216
|
666
|
Chris@216
|
667 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@216
|
668 if (pane) pane->resize(pane->width(), height);
|
Chris@216
|
669
|
Chris@216
|
670 } else if (message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@216
|
671
|
Chris@216
|
672 width = message.getArg(0).toInt();
|
Chris@216
|
673 resize(width, height);
|
Chris@216
|
674 }
|
Chris@216
|
675 }
|
Chris@216
|
676 }
|
Chris@216
|
677
|
Chris@216
|
678 } else if (message.getMethod() == "transform") {
|
Chris@216
|
679
|
Chris@2441
|
680 if (message.getArgCount() == 1 &&
|
Chris@216
|
681 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@216
|
682
|
Chris@2441
|
683 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@2441
|
684
|
Chris@2441
|
685 if (getMainModel() && pane) {
|
Chris@216
|
686
|
Chris@2441
|
687 TransformId transformId = message.getArg(0).toString();
|
Chris@2441
|
688
|
Chris@2441
|
689 Transform transform = TransformFactory::getInstance()->
|
Chris@2441
|
690 getDefaultTransformFor(transformId);
|
Chris@2441
|
691
|
Chris@2441
|
692 SVDEBUG << "OSCHandler: Running transform on main model:"
|
Chris@2441
|
693 << transform.toXmlString() << endl;
|
Chris@1770
|
694
|
Chris@2441
|
695 Layer *newLayer = m_document->createDerivedLayer
|
Chris@2441
|
696 (transform, getMainModelId());
|
Chris@2441
|
697
|
Chris@2441
|
698 if (newLayer) {
|
Chris@2441
|
699 m_document->addLayerToView(pane, newLayer);
|
Chris@2441
|
700 m_recentTransforms.add(transformId);
|
Chris@2441
|
701 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@2441
|
702 } else {
|
Chris@2441
|
703 SVCERR << "OSCHandler: Transform failed to run" << endl;
|
Chris@2441
|
704 }
|
Chris@2441
|
705 } else {
|
Chris@2441
|
706 SVCERR << "OSCHandler: Lack main model or pane, "
|
Chris@2441
|
707 << "can't run transform" << endl;
|
Chris@216
|
708 }
|
Chris@2441
|
709 }
|
Chris@216
|
710
|
Chris@216
|
711 } else {
|
Chris@2441
|
712 SVCERR << "WARNING: OSCHandler: Unknown or unsupported "
|
Chris@665
|
713 << "method \"" << message.getMethod()
|
Chris@665
|
714 << "\"" << endl;
|
Chris@216
|
715 }
|
Chris@2441
|
716
|
Chris@2441
|
717 SVDEBUG << "OSCHandler at " << NOW << ": finished message: "
|
Chris@2441
|
718 << message.toString() << " in " << timer.elapsed() << "ms" << endl;
|
Chris@216
|
719 }
|