annotate main/OSCHandler.cpp @ 1371:b75831cdf795 mp3-gapless

Stop reporting sync errors only when we really are at eof, i.e. after the input callback has been called again (previously we just tested whether we'd buffered up all the input, which of course we do in one go at the start)
author Chris Cannam
date Tue, 29 Nov 2016 16:45:29 +0000
parents 28ccb621d1af
children 5e6e1e074080 05d35ce6ea72
rev   line source
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@216 29 #include "widgets/Fader.h"
Chris@216 30 #include "widgets/AudioDial.h"
Chris@216 31
Chris@1035 32 #include <bqaudioio/SystemPlaybackTarget.h>
Chris@1035 33
Chris@216 34 #include <QFileInfo>
Chris@216 35
Chris@216 36 void
Chris@216 37 MainWindow::handleOSCMessage(const OSCMessage &message)
Chris@216 38 {
Chris@438 39 SVDEBUG << "MainWindow::handleOSCMessage: thread id = "
Chris@433 40 << QThread::currentThreadId() << endl;
Chris@216 41
Chris@216 42 // This large function should really be abstracted out.
Chris@216 43
Chris@216 44 if (message.getMethod() == "open") {
Chris@216 45
Chris@216 46 if (message.getArgCount() == 1 &&
Chris@216 47 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 48 QString path = message.getArg(0).toString();
Chris@216 49 if (open(path, ReplaceMainModel) != FileOpenSucceeded) {
Chris@665 50 cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@665 51 << path << "\"" << endl;
Chris@216 52 }
Chris@216 53 //!!! we really need to spin here and not return until the
Chris@216 54 // file has been completely decoded...
Chris@216 55 }
Chris@216 56
Chris@216 57 } else if (message.getMethod() == "openadditional") {
Chris@216 58
Chris@216 59 if (message.getArgCount() == 1 &&
Chris@216 60 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 61 QString path = message.getArg(0).toString();
Chris@216 62 if (open(path, CreateAdditionalModel) != FileOpenSucceeded) {
Chris@665 63 cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@665 64 << path << "\"" << endl;
Chris@216 65 }
Chris@216 66 }
Chris@216 67
Chris@216 68 } else if (message.getMethod() == "recent" ||
Chris@216 69 message.getMethod() == "last") {
Chris@216 70
Chris@216 71 int n = 0;
Chris@216 72 if (message.getMethod() == "recent" &&
Chris@216 73 message.getArgCount() == 1 &&
Chris@216 74 message.getArg(0).canConvert(QVariant::Int)) {
Chris@216 75 n = message.getArg(0).toInt() - 1;
Chris@216 76 }
Chris@216 77 std::vector<QString> recent = m_recentFiles.getRecent();
Chris@216 78 if (n >= 0 && n < int(recent.size())) {
Chris@216 79 if (open(recent[n], ReplaceMainModel) != FileOpenSucceeded) {
Chris@665 80 cerr << "MainWindow::handleOSCMessage: File open failed for path \""
Chris@665 81 << recent[n] << "\"" << endl;
Chris@216 82 }
Chris@216 83 }
Chris@216 84
Chris@216 85 } else if (message.getMethod() == "save") {
Chris@216 86
Chris@216 87 QString path;
Chris@216 88 if (message.getArgCount() == 1 &&
Chris@216 89 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 90 path = message.getArg(0).toString();
Chris@216 91 if (QFileInfo(path).exists()) {
Chris@438 92 SVDEBUG << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << endl;
Chris@216 93 } else {
Chris@216 94 saveSessionFile(path);
Chris@216 95 }
Chris@216 96 }
Chris@216 97
Chris@216 98 } else if (message.getMethod() == "export") {
Chris@216 99
Chris@216 100 QString path;
Chris@216 101 if (getMainModel()) {
Chris@216 102 if (message.getArgCount() == 1 &&
Chris@216 103 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 104 path = message.getArg(0).toString();
Chris@216 105 if (QFileInfo(path).exists()) {
Chris@438 106 SVDEBUG << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << endl;
Chris@216 107 } else {
Chris@216 108 WavFileWriter writer(path,
Chris@216 109 getMainModel()->getSampleRate(),
Chris@428 110 getMainModel()->getChannelCount(),
Chris@428 111 WavFileWriter::WriteToTemporary);
Chris@216 112 MultiSelection ms = m_viewManager->getSelection();
Chris@216 113 if (!ms.getSelections().empty()) {
Chris@216 114 writer.writeModel(getMainModel(), &ms);
Chris@216 115 } else {
Chris@216 116 writer.writeModel(getMainModel());
Chris@216 117 }
Chris@216 118 }
Chris@216 119 }
Chris@216 120 }
Chris@216 121
Chris@216 122 } else if (message.getMethod() == "jump" ||
Chris@216 123 message.getMethod() == "play") {
Chris@216 124
Chris@216 125 if (getMainModel()) {
Chris@216 126
Chris@922 127 sv_frame_t frame = m_viewManager->getPlaybackFrame();
Chris@216 128 bool selection = false;
Chris@216 129 bool play = (message.getMethod() == "play");
Chris@216 130
Chris@216 131 if (message.getArgCount() == 1) {
Chris@216 132
Chris@216 133 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 134 message.getArg(0).toString() == "selection") {
Chris@216 135
Chris@216 136 selection = true;
Chris@216 137
Chris@216 138 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 139 message.getArg(0).toString() == "end") {
Chris@216 140
Chris@216 141 frame = getMainModel()->getEndFrame();
Chris@216 142
Chris@216 143 } else if (message.getArg(0).canConvert(QVariant::Double)) {
Chris@216 144
Chris@216 145 double time = message.getArg(0).toDouble();
Chris@216 146 if (time < 0.0) time = 0.0;
Chris@216 147
Chris@216 148 frame = lrint(time * getMainModel()->getSampleRate());
Chris@216 149 }
Chris@216 150 }
Chris@216 151
Chris@216 152 if (frame > getMainModel()->getEndFrame()) {
Chris@216 153 frame = getMainModel()->getEndFrame();
Chris@216 154 }
Chris@216 155
Chris@216 156 if (play) {
Chris@216 157 m_viewManager->setPlaySelectionMode(selection);
Chris@216 158 }
Chris@216 159
Chris@216 160 if (selection) {
Chris@216 161 MultiSelection::SelectionList sl = m_viewManager->getSelections();
Chris@216 162 if (!sl.empty()) {
Chris@216 163 frame = sl.begin()->getStartFrame();
Chris@216 164 }
Chris@216 165 }
Chris@216 166
Chris@216 167 m_viewManager->setPlaybackFrame(frame);
Chris@216 168
Chris@216 169 if (play && !m_playSource->isPlaying()) {
Chris@216 170 m_playSource->play(frame);
Chris@216 171 }
Chris@216 172 }
Chris@216 173
Chris@313 174 } else if (message.getMethod() == "ffwd") {
Chris@313 175
Chris@313 176 if (message.getArgCount() == 1) {
Chris@313 177
Chris@313 178 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@313 179 message.getArg(0).toString() == "similar") {
Chris@313 180
Chris@313 181 ffwdSimilar();
Chris@313 182 }
Chris@313 183 } else {
Chris@313 184
Chris@313 185 ffwd();
Chris@313 186 }
Chris@313 187
Chris@313 188 } else if (message.getMethod() == "rewind") {
Chris@313 189
Chris@313 190 if (message.getArgCount() == 1) {
Chris@313 191
Chris@313 192 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@313 193 message.getArg(0).toString() == "similar") {
Chris@313 194
Chris@313 195 rewindSimilar();
Chris@313 196 }
Chris@313 197 } else {
Chris@313 198
Chris@313 199 rewind();
Chris@313 200 }
Chris@313 201
Chris@216 202 } else if (message.getMethod() == "stop") {
Chris@216 203
Chris@216 204 if (m_playSource->isPlaying()) m_playSource->stop();
Chris@216 205
Chris@216 206 } else if (message.getMethod() == "loop") {
Chris@216 207
Chris@216 208 if (message.getArgCount() == 1 &&
Chris@216 209 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 210
Chris@216 211 QString str = message.getArg(0).toString();
Chris@216 212 if (str == "on") {
Chris@216 213 m_viewManager->setPlayLoopMode(true);
Chris@216 214 } else if (str == "off") {
Chris@216 215 m_viewManager->setPlayLoopMode(false);
Chris@216 216 }
Chris@216 217 }
Chris@216 218
Chris@216 219 } else if (message.getMethod() == "solo") {
Chris@216 220
Chris@216 221 if (message.getArgCount() == 1 &&
Chris@216 222 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 223
Chris@216 224 QString str = message.getArg(0).toString();
Chris@216 225 if (str == "on") {
Chris@216 226 m_viewManager->setPlaySoloMode(true);
Chris@216 227 } else if (str == "off") {
Chris@216 228 m_viewManager->setPlaySoloMode(false);
Chris@216 229 }
Chris@216 230 }
Chris@216 231
Chris@216 232 } else if (message.getMethod() == "select" ||
Chris@216 233 message.getMethod() == "addselect") {
Chris@216 234
Chris@216 235 if (getMainModel()) {
Chris@216 236
Chris@920 237 sv_frame_t f0 = getMainModel()->getStartFrame();
Chris@920 238 sv_frame_t f1 = getMainModel()->getEndFrame();
Chris@216 239
Chris@216 240 bool done = false;
Chris@216 241
Chris@216 242 if (message.getArgCount() == 2 &&
Chris@216 243 message.getArg(0).canConvert(QVariant::Double) &&
Chris@216 244 message.getArg(1).canConvert(QVariant::Double)) {
Chris@216 245
Chris@216 246 double t0 = message.getArg(0).toDouble();
Chris@216 247 double t1 = message.getArg(1).toDouble();
Chris@216 248 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
Chris@216 249 if (t0 < 0.0) t0 = 0.0;
Chris@216 250 if (t1 < 0.0) t1 = 0.0;
Chris@216 251
Chris@216 252 f0 = lrint(t0 * getMainModel()->getSampleRate());
Chris@216 253 f1 = lrint(t1 * getMainModel()->getSampleRate());
Chris@216 254
Chris@216 255 Pane *pane = m_paneStack->getCurrentPane();
Chris@216 256 Layer *layer = 0;
Chris@216 257 if (pane) layer = pane->getSelectedLayer();
Chris@216 258 if (layer) {
Chris@730 259 int resolution;
Chris@216 260 layer->snapToFeatureFrame(pane, f0, resolution,
Chris@216 261 Layer::SnapLeft);
Chris@216 262 layer->snapToFeatureFrame(pane, f1, resolution,
Chris@216 263 Layer::SnapRight);
Chris@216 264 }
Chris@216 265
Chris@216 266 } else if (message.getArgCount() == 1 &&
Chris@216 267 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 268
Chris@216 269 QString str = message.getArg(0).toString();
Chris@216 270 if (str == "none") {
Chris@216 271 m_viewManager->clearSelections();
Chris@216 272 done = true;
Chris@216 273 }
Chris@216 274 }
Chris@216 275
Chris@216 276 if (!done) {
Chris@216 277 if (message.getMethod() == "select") {
Chris@216 278 m_viewManager->setSelection(Selection(f0, f1));
Chris@216 279 } else {
Chris@216 280 m_viewManager->addSelection(Selection(f0, f1));
Chris@216 281 }
Chris@216 282 }
Chris@216 283 }
Chris@216 284
Chris@216 285 } else if (message.getMethod() == "add") {
Chris@216 286
Chris@216 287 if (getMainModel()) {
Chris@216 288
Chris@216 289 if (message.getArgCount() >= 1 &&
Chris@216 290 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 291
Chris@216 292 int channel = -1;
Chris@216 293 if (message.getArgCount() == 2 &&
Chris@216 294 message.getArg(0).canConvert(QVariant::Int)) {
Chris@216 295 channel = message.getArg(0).toInt();
Chris@216 296 if (channel < -1 ||
Chris@216 297 channel > int(getMainModel()->getChannelCount())) {
Chris@665 298 cerr << "WARNING: MainWindow::handleOSCMessage: channel "
Chris@665 299 << channel << " out of range" << endl;
Chris@216 300 channel = -1;
Chris@216 301 }
Chris@216 302 }
Chris@216 303
Chris@216 304 QString str = message.getArg(0).toString();
Chris@216 305
Chris@216 306 LayerFactory::LayerType type =
Chris@216 307 LayerFactory::getInstance()->getLayerTypeForName(str);
Chris@216 308
Chris@216 309 if (type == LayerFactory::UnknownLayer) {
Chris@665 310 cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
Chris@665 311 << "type " << str << endl;
Chris@216 312 } else {
Chris@216 313
Chris@232 314 LayerConfiguration configuration(type,
Chris@232 315 getMainModel(),
Chris@232 316 channel);
Chris@216 317
Chris@216 318 addPane(configuration,
Chris@216 319 tr("Add %1 Pane")
Chris@216 320 .arg(LayerFactory::getInstance()->
Chris@216 321 getLayerPresentationName(type)));
Chris@216 322 }
Chris@216 323 }
Chris@216 324 }
Chris@216 325
Chris@216 326 } else if (message.getMethod() == "undo") {
Chris@216 327
Chris@216 328 CommandHistory::getInstance()->undo();
Chris@216 329
Chris@216 330 } else if (message.getMethod() == "redo") {
Chris@216 331
Chris@216 332 CommandHistory::getInstance()->redo();
Chris@216 333
Chris@216 334 } else if (message.getMethod() == "set") {
Chris@216 335
Chris@216 336 if (message.getArgCount() == 2 &&
Chris@216 337 message.getArg(0).canConvert(QVariant::String) &&
Chris@216 338 message.getArg(1).canConvert(QVariant::Double)) {
Chris@216 339
Chris@216 340 QString property = message.getArg(0).toString();
Chris@216 341 float value = (float)message.getArg(1).toDouble();
Chris@216 342
Chris@216 343 if (property == "gain") {
Chris@216 344 if (value < 0.0) value = 0.0;
Chris@216 345 m_fader->setValue(value);
Chris@216 346 if (m_playTarget) m_playTarget->setOutputGain(value);
Chris@216 347 } else if (property == "speedup") {
Chris@216 348 m_playSpeed->setMappedValue(value);
Chris@216 349 } else if (property == "overlays") {
Chris@216 350 if (value < 0.5) {
Chris@216 351 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
Chris@216 352 } else if (value < 1.5) {
Chris@701 353 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
Chris@216 354 } else {
Chris@216 355 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
Chris@216 356 }
Chris@216 357 } else if (property == "zoomwheels") {
Chris@216 358 m_viewManager->setZoomWheelsEnabled(value > 0.5);
Chris@216 359 } else if (property == "propertyboxes") {
Chris@216 360 bool toggle = ((value < 0.5) !=
Chris@216 361 (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks));
Chris@216 362 if (toggle) togglePropertyBoxes();
Chris@216 363 }
Chris@216 364
Chris@216 365 } else {
Chris@216 366 PropertyContainer *container = 0;
Chris@216 367 Pane *pane = m_paneStack->getCurrentPane();
Chris@216 368 if (pane &&
Chris@216 369 message.getArgCount() == 3 &&
Chris@216 370 message.getArg(0).canConvert(QVariant::String) &&
Chris@216 371 message.getArg(1).canConvert(QVariant::String) &&
Chris@216 372 message.getArg(2).canConvert(QVariant::String)) {
Chris@216 373 if (message.getArg(0).toString() == "pane") {
Chris@216 374 container = pane->getPropertyContainer(0);
Chris@216 375 } else if (message.getArg(0).toString() == "layer") {
Chris@216 376 container = pane->getSelectedLayer();
Chris@216 377 }
Chris@216 378 }
Chris@216 379 if (container) {
Chris@216 380 QString nameString = message.getArg(1).toString();
Chris@216 381 QString valueString = message.getArg(2).toString();
Chris@248 382 Command *c = container->getSetPropertyCommand
Chris@248 383 (nameString, valueString);
Chris@248 384 if (c) CommandHistory::getInstance()->addCommand(c, true, true);
Chris@216 385 }
Chris@216 386 }
Chris@216 387
Chris@216 388 } else if (message.getMethod() == "setcurrent") {
Chris@216 389
Chris@216 390 int paneIndex = -1, layerIndex = -1;
Chris@216 391 bool wantLayer = false;
Chris@216 392
Chris@216 393 if (message.getArgCount() >= 1 &&
Chris@216 394 message.getArg(0).canConvert(QVariant::Int)) {
Chris@216 395
Chris@216 396 paneIndex = message.getArg(0).toInt() - 1;
Chris@216 397
Chris@216 398 if (message.getArgCount() >= 2 &&
Chris@216 399 message.getArg(1).canConvert(QVariant::Int)) {
Chris@216 400 wantLayer = true;
Chris@216 401 layerIndex = message.getArg(1).toInt() - 1;
Chris@216 402 }
Chris@216 403 }
Chris@216 404
Chris@216 405 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
Chris@216 406 Pane *pane = m_paneStack->getPane(paneIndex);
Chris@216 407 m_paneStack->setCurrentPane(pane);
Chris@216 408 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
Chris@216 409 Layer *layer = pane->getLayer(layerIndex);
Chris@216 410 m_paneStack->setCurrentLayer(pane, layer);
Chris@216 411 } else if (wantLayer && layerIndex == -1) {
Chris@216 412 m_paneStack->setCurrentLayer(pane, 0);
Chris@216 413 }
Chris@216 414 }
Chris@216 415
Chris@216 416 } else if (message.getMethod() == "delete") {
Chris@216 417
Chris@216 418 if (message.getArgCount() == 1 &&
Chris@216 419 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 420
Chris@216 421 QString target = message.getArg(0).toString();
Chris@216 422
Chris@216 423 if (target == "pane") {
Chris@216 424
Chris@216 425 deleteCurrentPane();
Chris@216 426
Chris@216 427 } else if (target == "layer") {
Chris@216 428
Chris@216 429 deleteCurrentLayer();
Chris@216 430
Chris@216 431 } else {
Chris@216 432
Chris@665 433 cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target << endl;
Chris@216 434 }
Chris@216 435 }
Chris@216 436
Chris@216 437 } else if (message.getMethod() == "zoom") {
Chris@216 438
Chris@216 439 if (message.getArgCount() == 1) {
Chris@216 440 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 441 message.getArg(0).toString() == "in") {
Chris@216 442 zoomIn();
Chris@216 443 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 444 message.getArg(0).toString() == "out") {
Chris@216 445 zoomOut();
Chris@216 446 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 447 message.getArg(0).toString() == "default") {
Chris@216 448 zoomDefault();
Chris@312 449 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@312 450 message.getArg(0).toString() == "fit") {
Chris@312 451 zoomToFit();
Chris@216 452 } else if (message.getArg(0).canConvert(QVariant::Double)) {
Chris@216 453 double level = message.getArg(0).toDouble();
Chris@216 454 Pane *currentPane = m_paneStack->getCurrentPane();
Chris@216 455 if (level < 1.0) level = 1.0;
Chris@922 456 if (currentPane) currentPane->setZoomLevel(int(lrint(level)));
Chris@216 457 }
Chris@216 458 }
Chris@216 459
Chris@216 460 } else if (message.getMethod() == "zoomvertical") {
Chris@216 461
Chris@216 462 Pane *pane = m_paneStack->getCurrentPane();
Chris@216 463 Layer *layer = 0;
Chris@216 464 if (pane && pane->getLayerCount() > 0) {
Chris@216 465 layer = pane->getLayer(pane->getLayerCount() - 1);
Chris@216 466 }
Chris@216 467 int defaultStep = 0;
Chris@216 468 int steps = 0;
Chris@216 469 if (layer) {
Chris@216 470 steps = layer->getVerticalZoomSteps(defaultStep);
Chris@216 471 if (message.getArgCount() == 1 && steps > 0) {
Chris@216 472 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 473 message.getArg(0).toString() == "in") {
Chris@216 474 int step = layer->getCurrentVerticalZoomStep() + 1;
Chris@216 475 if (step < steps) layer->setVerticalZoomStep(step);
Chris@216 476 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 477 message.getArg(0).toString() == "out") {
Chris@216 478 int step = layer->getCurrentVerticalZoomStep() - 1;
Chris@216 479 if (step >= 0) layer->setVerticalZoomStep(step);
Chris@216 480 } else if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 481 message.getArg(0).toString() == "default") {
Chris@216 482 layer->setVerticalZoomStep(defaultStep);
Chris@216 483 }
Chris@216 484 } else if (message.getArgCount() == 2) {
Chris@216 485 if (message.getArg(0).canConvert(QVariant::Double) &&
Chris@216 486 message.getArg(1).canConvert(QVariant::Double)) {
Chris@216 487 double min = message.getArg(0).toDouble();
Chris@216 488 double max = message.getArg(1).toDouble();
Chris@216 489 layer->setDisplayExtents(min, max);
Chris@216 490 }
Chris@216 491 }
Chris@216 492 }
Chris@216 493
Chris@216 494 } else if (message.getMethod() == "quit") {
Chris@216 495
Chris@216 496 m_abandoning = true;
Chris@216 497 close();
Chris@216 498
Chris@216 499 } else if (message.getMethod() == "resize") {
Chris@216 500
Chris@216 501 if (message.getArgCount() == 2) {
Chris@216 502
Chris@216 503 int width = 0, height = 0;
Chris@216 504
Chris@216 505 if (message.getArg(1).canConvert(QVariant::Int)) {
Chris@216 506
Chris@216 507 height = message.getArg(1).toInt();
Chris@216 508
Chris@216 509 if (message.getArg(0).canConvert(QVariant::String) &&
Chris@216 510 message.getArg(0).toString() == "pane") {
Chris@216 511
Chris@216 512 Pane *pane = m_paneStack->getCurrentPane();
Chris@216 513 if (pane) pane->resize(pane->width(), height);
Chris@216 514
Chris@216 515 } else if (message.getArg(0).canConvert(QVariant::Int)) {
Chris@216 516
Chris@216 517 width = message.getArg(0).toInt();
Chris@216 518 resize(width, height);
Chris@216 519 }
Chris@216 520 }
Chris@216 521 }
Chris@216 522
Chris@216 523 } else if (message.getMethod() == "transform") {
Chris@216 524
Chris@216 525 Pane *pane = m_paneStack->getCurrentPane();
Chris@216 526
Chris@216 527 if (getMainModel() &&
Chris@216 528 pane &&
Chris@216 529 message.getArgCount() == 1 &&
Chris@216 530 message.getArg(0).canConvert(QVariant::String)) {
Chris@216 531
Chris@224 532 TransformId transformId = message.getArg(0).toString();
Chris@216 533
Chris@224 534 Transform transform = TransformFactory::getInstance()->
Chris@224 535 getDefaultTransformFor(transformId);
Chris@224 536
Chris@216 537 Layer *newLayer = m_document->createDerivedLayer
Chris@224 538 (transform, getMainModel());
Chris@216 539
Chris@216 540 if (newLayer) {
Chris@216 541 m_document->addLayerToView(pane, newLayer);
Chris@224 542 m_recentTransforms.add(transformId);
Chris@216 543 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@216 544 }
Chris@216 545 }
Chris@216 546
Chris@216 547 } else {
Chris@665 548 cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
Chris@665 549 << "method \"" << message.getMethod()
Chris@665 550 << "\"" << endl;
Chris@216 551 }
Chris@216 552
Chris@216 553 }