Mercurial > hg > sonic-visualiser
comparison main/OSCHandler.cpp @ 634:ba338234c001 imaf_enc
IMAF load code from Jesus Corral Garcia
author | Chris Cannam |
---|---|
date | Mon, 04 Nov 2013 17:15:52 +0000 |
parents | e583f57f1311 |
children | bfd68cc71a25 |
comparison
equal
deleted
inserted
replaced
633:a8da6db5a2c9 | 634:ba338234c001 |
---|---|
3 /* | 3 /* |
4 Sonic Visualiser | 4 Sonic Visualiser |
5 An audio file viewer and annotation editor. | 5 An audio file viewer and annotation editor. |
6 Centre for Digital Music, Queen Mary, University of London. | 6 Centre for Digital Music, Queen Mary, University of London. |
7 This file copyright 2006-2007 Chris Cannam and QMUL. | 7 This file copyright 2006-2007 Chris Cannam and QMUL. |
8 | 8 |
9 This program is free software; you can redistribute it and/or | 9 This program is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU General Public License as | 10 modify it under the terms of the GNU General Public License as |
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
33 #include <QFileInfo> | 33 #include <QFileInfo> |
34 | 34 |
35 void | 35 void |
36 MainWindow::handleOSCMessage(const OSCMessage &message) | 36 MainWindow::handleOSCMessage(const OSCMessage &message) |
37 { | 37 { |
38 SVDEBUG << "MainWindow::handleOSCMessage: thread id = " | 38 SVDEBUG << "MainWindow::handleOSCMessage: thread id = " |
39 << QThread::currentThreadId() << endl; | 39 << QThread::currentThreadId() << endl; |
40 | 40 |
41 // This large function should really be abstracted out. | 41 // This large function should really be abstracted out. |
42 | 42 |
43 if (message.getMethod() == "open") { | 43 if (message.getMethod() == "open") { |
152 frame = getMainModel()->getEndFrame(); | 152 frame = getMainModel()->getEndFrame(); |
153 } | 153 } |
154 | 154 |
155 if (play) { | 155 if (play) { |
156 m_viewManager->setPlaySelectionMode(selection); | 156 m_viewManager->setPlaySelectionMode(selection); |
157 } | 157 } |
158 | 158 |
159 if (selection) { | 159 if (selection) { |
160 MultiSelection::SelectionList sl = m_viewManager->getSelections(); | 160 MultiSelection::SelectionList sl = m_viewManager->getSelections(); |
161 if (!sl.empty()) { | 161 if (!sl.empty()) { |
162 frame = sl.begin()->getStartFrame(); | 162 frame = sl.begin()->getStartFrame(); |
197 | 197 |
198 rewind(); | 198 rewind(); |
199 } | 199 } |
200 | 200 |
201 } else if (message.getMethod() == "stop") { | 201 } else if (message.getMethod() == "stop") { |
202 | 202 |
203 if (m_playSource->isPlaying()) m_playSource->stop(); | 203 if (m_playSource->isPlaying()) m_playSource->stop(); |
204 | 204 |
205 } else if (message.getMethod() == "loop") { | 205 } else if (message.getMethod() == "loop") { |
206 | 206 |
207 if (message.getArgCount() == 1 && | 207 if (message.getArgCount() == 1 && |
239 bool done = false; | 239 bool done = false; |
240 | 240 |
241 if (message.getArgCount() == 2 && | 241 if (message.getArgCount() == 2 && |
242 message.getArg(0).canConvert(QVariant::Double) && | 242 message.getArg(0).canConvert(QVariant::Double) && |
243 message.getArg(1).canConvert(QVariant::Double)) { | 243 message.getArg(1).canConvert(QVariant::Double)) { |
244 | 244 |
245 double t0 = message.getArg(0).toDouble(); | 245 double t0 = message.getArg(0).toDouble(); |
246 double t1 = message.getArg(1).toDouble(); | 246 double t1 = message.getArg(1).toDouble(); |
247 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; } | 247 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; } |
248 if (t0 < 0.0) t0 = 0.0; | 248 if (t0 < 0.0) t0 = 0.0; |
249 if (t1 < 0.0) t1 = 0.0; | 249 if (t1 < 0.0) t1 = 0.0; |
250 | 250 |
251 f0 = lrint(t0 * getMainModel()->getSampleRate()); | 251 f0 = lrint(t0 * getMainModel()->getSampleRate()); |
252 f1 = lrint(t1 * getMainModel()->getSampleRate()); | 252 f1 = lrint(t1 * getMainModel()->getSampleRate()); |
253 | 253 |
254 Pane *pane = m_paneStack->getCurrentPane(); | 254 Pane *pane = m_paneStack->getCurrentPane(); |
255 Layer *layer = 0; | 255 Layer *layer = 0; |
256 if (pane) layer = pane->getSelectedLayer(); | 256 if (pane) layer = pane->getSelectedLayer(); |
257 if (layer) { | 257 if (layer) { |
258 size_t resolution; | 258 size_t resolution; |
299 channel = -1; | 299 channel = -1; |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 QString str = message.getArg(0).toString(); | 303 QString str = message.getArg(0).toString(); |
304 | 304 |
305 LayerFactory::LayerType type = | 305 LayerFactory::LayerType type = |
306 LayerFactory::getInstance()->getLayerTypeForName(str); | 306 LayerFactory::getInstance()->getLayerTypeForName(str); |
307 | 307 |
308 if (type == LayerFactory::UnknownLayer) { | 308 if (type == LayerFactory::UnknownLayer) { |
309 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer " | 309 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer " |
311 } else { | 311 } else { |
312 | 312 |
313 LayerConfiguration configuration(type, | 313 LayerConfiguration configuration(type, |
314 getMainModel(), | 314 getMainModel(), |
315 channel); | 315 channel); |
316 | 316 |
317 addPane(configuration, | 317 addPane(configuration, |
318 tr("Add %1 Pane") | 318 tr("Add %1 Pane") |
319 .arg(LayerFactory::getInstance()-> | 319 .arg(LayerFactory::getInstance()-> |
320 getLayerPresentationName(type))); | 320 getLayerPresentationName(type))); |
321 } | 321 } |
350 m_viewManager->setOverlayMode(ViewManager::NoOverlays); | 350 m_viewManager->setOverlayMode(ViewManager::NoOverlays); |
351 } else if (value < 1.5) { | 351 } else if (value < 1.5) { |
352 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays); | 352 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays); |
353 } else { | 353 } else { |
354 m_viewManager->setOverlayMode(ViewManager::AllOverlays); | 354 m_viewManager->setOverlayMode(ViewManager::AllOverlays); |
355 } | 355 } |
356 } else if (property == "zoomwheels") { | 356 } else if (property == "zoomwheels") { |
357 m_viewManager->setZoomWheelsEnabled(value > 0.5); | 357 m_viewManager->setZoomWheelsEnabled(value > 0.5); |
358 } else if (property == "propertyboxes") { | 358 } else if (property == "propertyboxes") { |
359 bool toggle = ((value < 0.5) != | 359 bool toggle = ((value < 0.5) != |
360 (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks)); | 360 (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks)); |
361 if (toggle) togglePropertyBoxes(); | 361 if (toggle) togglePropertyBoxes(); |
362 } | 362 } |
363 | 363 |
364 } else { | 364 } else { |
365 PropertyContainer *container = 0; | 365 PropertyContainer *container = 0; |
366 Pane *pane = m_paneStack->getCurrentPane(); | 366 Pane *pane = m_paneStack->getCurrentPane(); |
367 if (pane && | 367 if (pane && |
368 message.getArgCount() == 3 && | 368 message.getArgCount() == 3 && |
414 | 414 |
415 } else if (message.getMethod() == "delete") { | 415 } else if (message.getMethod() == "delete") { |
416 | 416 |
417 if (message.getArgCount() == 1 && | 417 if (message.getArgCount() == 1 && |
418 message.getArg(0).canConvert(QVariant::String)) { | 418 message.getArg(0).canConvert(QVariant::String)) { |
419 | 419 |
420 QString target = message.getArg(0).toString(); | 420 QString target = message.getArg(0).toString(); |
421 | 421 |
422 if (target == "pane") { | 422 if (target == "pane") { |
423 | 423 |
424 deleteCurrentPane(); | 424 deleteCurrentPane(); |
426 } else if (target == "layer") { | 426 } else if (target == "layer") { |
427 | 427 |
428 deleteCurrentLayer(); | 428 deleteCurrentLayer(); |
429 | 429 |
430 } else { | 430 } else { |
431 | 431 |
432 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target << std::endl; | 432 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target << std::endl; |
433 } | 433 } |
434 } | 434 } |
435 | 435 |
436 } else if (message.getMethod() == "zoom") { | 436 } else if (message.getMethod() == "zoom") { |
489 } | 489 } |
490 } | 490 } |
491 } | 491 } |
492 | 492 |
493 } else if (message.getMethod() == "quit") { | 493 } else if (message.getMethod() == "quit") { |
494 | 494 |
495 m_abandoning = true; | 495 m_abandoning = true; |
496 close(); | 496 close(); |
497 | 497 |
498 } else if (message.getMethod() == "resize") { | 498 } else if (message.getMethod() == "resize") { |
499 | 499 |
500 if (message.getArgCount() == 2) { | 500 if (message.getArgCount() == 2) { |
501 | 501 |
502 int width = 0, height = 0; | 502 int width = 0, height = 0; |
503 | 503 |
504 if (message.getArg(1).canConvert(QVariant::Int)) { | 504 if (message.getArg(1).canConvert(QVariant::Int)) { |
528 message.getArgCount() == 1 && | 528 message.getArgCount() == 1 && |
529 message.getArg(0).canConvert(QVariant::String)) { | 529 message.getArg(0).canConvert(QVariant::String)) { |
530 | 530 |
531 TransformId transformId = message.getArg(0).toString(); | 531 TransformId transformId = message.getArg(0).toString(); |
532 | 532 |
533 Transform transform = TransformFactory::getInstance()-> | 533 Transform transform = TransformFactory::getInstance()-> |
534 getDefaultTransformFor(transformId); | 534 getDefaultTransformFor(transformId); |
535 | 535 |
536 Layer *newLayer = m_document->createDerivedLayer | 536 Layer *newLayer = m_document->createDerivedLayer |
537 (transform, getMainModel()); | 537 (transform, getMainModel()); |
538 | 538 |
539 if (newLayer) { | 539 if (newLayer) { |
540 m_document->addLayerToView(pane, newLayer); | 540 m_document->addLayerToView(pane, newLayer); |
546 } else { | 546 } else { |
547 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported " | 547 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported " |
548 << "method \"" << message.getMethod().toStdString() | 548 << "method \"" << message.getMethod().toStdString() |
549 << "\"" << std::endl; | 549 << "\"" << std::endl; |
550 } | 550 } |
551 | 551 |
552 } | 552 } |