comparison main/OSCHandler.cpp @ 2519:e9506f77388d

Implement exportimage and exportsvg; add some more useful output, esp. when method called with insufficient arguments
author Chris Cannam
date Wed, 29 Apr 2020 13:28:35 +0100
parents b3330c31ea0e
children 1891812e44b2
comparison
equal deleted inserted replaced
2518:f3f9114ff295 2519:e9506f77388d
59 SVCERR << "OSCHandler: File open failed for path \"" 59 SVCERR << "OSCHandler: File open failed for path \""
60 << path << "\"" << endl; 60 << path << "\"" << endl;
61 } 61 }
62 //!!! we really need to spin here and not return until the 62 //!!! we really need to spin here and not return until the
63 // file has been completely decoded... 63 // file has been completely decoded...
64 } else {
65 SVCERR << "OSCHandler: Usage: /open <filename>" << endl;
64 } 66 }
65 67
66 } else if (message.getMethod() == "openadditional") { 68 } else if (message.getMethod() == "openadditional") {
67 69
68 if (message.getArgCount() == 1 && 70 if (message.getArgCount() == 1 &&
73 << path << "\"" << endl; 75 << path << "\"" << endl;
74 } else { 76 } else {
75 SVCERR << "OSCHandler: File open failed for path \"" 77 SVCERR << "OSCHandler: File open failed for path \""
76 << path << "\"" << endl; 78 << path << "\"" << endl;
77 } 79 }
80 } else {
81 SVCERR << "OSCHandler: Usage: /openadditional <filename>" << endl;
78 } 82 }
79 83
80 } else if (message.getMethod() == "recent" || 84 } else if (message.getMethod() == "recent" ||
81 message.getMethod() == "last") { 85 message.getMethod() == "last") {
82 86
94 << path << "\"" << endl; 98 << path << "\"" << endl;
95 } else { 99 } else {
96 SVCERR << "OSCHandler: File open failed for path \"" 100 SVCERR << "OSCHandler: File open failed for path \""
97 << path << "\"" << endl; 101 << path << "\"" << endl;
98 } 102 }
103 } else {
104 SVCERR << "OSCHandler: Usage: /recent <n>" << endl;
105 SVCERR << " or /last" << endl;
99 } 106 }
100 107
101 } else if (message.getMethod() == "save") { 108 } else if (message.getMethod() == "save") {
102 109
103 QString path; 110 QString path;
111 << path << "\"" << endl; 118 << path << "\"" << endl;
112 } else { 119 } else {
113 SVCERR << "OSCHandler: Save failed to path \"" 120 SVCERR << "OSCHandler: Save failed to path \""
114 << path << "\"" << endl; 121 << path << "\"" << endl;
115 } 122 }
123 } else {
124 SVCERR << "OSCHandler: Usage: /save <filename>" << endl;
116 } 125 }
117 126
118 } else if (message.getMethod() == "export") { 127 } else if (message.getMethod() == "export") {
119 128
120 QString path; 129 QString path;
139 SVCERR << "OSCHandler: Export failed to path \"" 148 SVCERR << "OSCHandler: Export failed to path \""
140 << path << "\"" << endl; 149 << path << "\"" << endl;
141 } 150 }
142 } 151 }
143 } 152 }
153 } else {
154 SVCERR << "OSCHandler: Usage: /export <filename>" << endl;
144 } 155 }
145 156
146 } else if (message.getMethod() == "exportlayer") { 157 } else if (message.getMethod() == "exportlayer") {
147 158
148 QString path; 159 QString path;
149 if (message.getArgCount() == 1 && 160 if (message.getArgCount() == 1 &&
150 message.getArg(0).canConvert(QVariant::String)) { 161 message.getArg(0).canConvert(QVariant::String)) {
151 path = message.getArg(0).toString(); 162 path = message.getArg(0).toString();
152 if (QFileInfo(path).exists()) { 163 if (QFileInfo(path).exists()) {
153 SVDEBUG << "OSCHandler: Refusing to overwrite existing file in layer export" << endl; 164 SVCERR << "OSCHandler: Refusing to overwrite existing file in layer export" << endl;
154 } else { 165 } else {
155 Pane *currentPane = nullptr; 166 Pane *currentPane = nullptr;
156 Layer *currentLayer = nullptr; 167 Layer *currentLayer = nullptr;
157 if (m_paneStack) currentPane = m_paneStack->getCurrentPane(); 168 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
158 if (currentPane) currentLayer = currentPane->getSelectedLayer(); 169 if (currentPane) currentLayer = currentPane->getSelectedLayer();
172 } 183 }
173 } else { 184 } else {
174 SVCERR << "OSCHandler: No current layer to export" << endl; 185 SVCERR << "OSCHandler: No current layer to export" << endl;
175 } 186 }
176 } 187 }
188 } else {
189 SVCERR << "OSCHandler: Usage: /exportlayer <filename>" << endl;
190 }
191
192 } else if (message.getMethod() == "exportimage") {
193
194 QString path;
195 if (message.getArgCount() == 1 &&
196 message.getArg(0).canConvert(QVariant::String)) {
197 path = message.getArg(0).toString();
198 if (QFileInfo(path).exists()) {
199 SVCERR << "OSCHandler: Refusing to overwrite existing file in image export" << endl;
200 } else {
201 Pane *currentPane = nullptr;
202 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
203 MultiSelection ms = m_viewManager->getSelection();
204 if (currentPane) {
205 QImage *image = nullptr;
206 auto sel = ms.getSelections();
207 if (!sel.empty()) {
208 sv_frame_t sf0 = sel.begin()->getStartFrame();
209 sv_frame_t sf1 = sel.rbegin()->getEndFrame();
210 image = currentPane->renderPartToNewImage(sf0, sf1);
211 } else {
212 image = currentPane->renderToNewImage();
213 }
214 if (!image) {
215 SVCERR << "OSCHandler: Failed to create image from pane"
216 << endl;
217 } else if (!image->save(path, "PNG")) {
218 SVCERR << "OSCHandler: Export failed to image file \""
219 << path << "\"" << endl;
220 } else {
221 SVDEBUG << "OSCHandler: Exported pane to image file \""
222 << path << "\"" << endl;
223 }
224 delete image;
225 } else {
226 SVCERR << "OSCHandler: No current pane to export" << endl;
227 }
228 }
229 } else {
230 SVCERR << "OSCHandler: Usage: /exportimage <filename>" << endl;
231 }
232
233 } else if (message.getMethod() == "exportsvg") {
234
235 QString path;
236 if (message.getArgCount() == 1 &&
237 message.getArg(0).canConvert(QVariant::String)) {
238 path = message.getArg(0).toString();
239 if (QFileInfo(path).exists()) {
240 SVCERR << "OSCHandler: Refusing to overwrite existing file in SVG export" << endl;
241 } else {
242 Pane *currentPane = nullptr;
243 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
244 MultiSelection ms = m_viewManager->getSelection();
245 if (currentPane) {
246 bool result = false;
247 auto sel = ms.getSelections();
248 if (!sel.empty()) {
249 sv_frame_t sf0 = sel.begin()->getStartFrame();
250 sv_frame_t sf1 = sel.rbegin()->getEndFrame();
251 result = currentPane->renderPartToSvgFile(path, sf0, sf1);
252 } else {
253 result = currentPane->renderToSvgFile(path);
254 }
255 if (!result) {
256 SVCERR << "OSCHandler: Export failed to SVG file \""
257 << path << "\"" << endl;
258 } else {
259 SVDEBUG << "OSCHandler: Exported pane to SVG file \""
260 << path << "\"" << endl;
261 }
262 } else {
263 SVCERR << "OSCHandler: No current pane to export" << endl;
264 }
265 }
266 } else {
267 SVCERR << "OSCHandler: Usage: /exportsvg <filename>" << endl;
177 } 268 }
178 269
179 } else if (message.getMethod() == "jump" || 270 } else if (message.getMethod() == "jump" ||
180 message.getMethod() == "play") { 271 message.getMethod() == "play") {
181 272
355 << endl; 446 << endl;
356 } 447 }
357 448
358 } else if (message.getArgCount() == 1 && 449 } else if (message.getArgCount() == 1 &&
359 message.getArg(0).canConvert(QVariant::String)) { 450 message.getArg(0).canConvert(QVariant::String)) {
360 451
361 QString str = message.getArg(0).toString(); 452 QString str = message.getArg(0).toString();
362 if (str == "none") { 453 if (str == "none") {
363 SVDEBUG << "OSCHandler: Clearing selection" << endl; 454 SVDEBUG << "OSCHandler: Clearing selection" << endl;
364 m_viewManager->clearSelections(); 455 m_viewManager->clearSelections();
365 done = true; 456 done = true;
396 int channel = -1; 487 int channel = -1;
397 if (message.getArgCount() == 2 && 488 if (message.getArgCount() == 2 &&
398 message.getArg(0).canConvert(QVariant::Int)) { 489 message.getArg(0).canConvert(QVariant::Int)) {
399 channel = message.getArg(0).toInt(); 490 channel = message.getArg(0).toInt();
400 if (channel < -1 || 491 if (channel < -1 ||
401 channel > int(getMainModel()->getChannelCount())) { 492 channel >= int(getMainModel()->getChannelCount())) {
402 SVCERR << "WARNING: OSCHandler: channel " 493 SVCERR << "OSCHandler: channel " << channel
403 << channel << " out of range" << endl; 494 << " out of range (0 to "
495 << (getMainModel()->getChannelCount() - 1)
496 << ")" << endl;
404 channel = -1; 497 channel = -1;
405 } 498 }
406 } 499 }
407 500
408 QString str = message.getArg(0).toString(); 501 QString str = message.getArg(0).toString();
425 addPane(configuration, tr("Add %1 Pane") .arg(pname)); 518 addPane(configuration, tr("Add %1 Pane") .arg(pname));
426 519
427 SVDEBUG << "OSCHandler: Added pane \"" << pname 520 SVDEBUG << "OSCHandler: Added pane \"" << pname
428 << "\"" << endl; 521 << "\"" << endl;
429 } 522 }
523 } else {
524 SVCERR << "OSCHandler: Usage: /add <layertype> [<channel>]"
525 << endl;
430 } 526 }
431 } 527 }
432 528
433 } else if (message.getMethod() == "undo") { 529 } else if (message.getMethod() == "undo") {
434 530
510 if (message.getArg(0).toString() == "pane") { 606 if (message.getArg(0).toString() == "pane") {
511 container = pane->getPropertyContainer(0); 607 container = pane->getPropertyContainer(0);
512 } else if (message.getArg(0).toString() == "layer") { 608 } else if (message.getArg(0).toString() == "layer") {
513 container = pane->getSelectedLayer(); 609 container = pane->getSelectedLayer();
514 } 610 }
611 } else {
612 SVCERR << "OSCHandler: Usage: /set <control> <value>" << endl
613 << " or /set pane <control> <value>" << endl
614 << " or /set layer <control> <value>" << endl;
515 } 615 }
516 if (container) { 616 if (container) {
517 QString nameString = message.getArg(1).toString(); 617 QString nameString = message.getArg(1).toString();
518 QString valueString = message.getArg(2).toString(); 618 QString valueString = message.getArg(2).toString();
519 Command *c = container->getSetPropertyCommand 619 Command *c = container->getSetPropertyCommand
535 if (message.getArgCount() >= 2 && 635 if (message.getArgCount() >= 2 &&
536 message.getArg(1).canConvert(QVariant::Int)) { 636 message.getArg(1).canConvert(QVariant::Int)) {
537 wantLayer = true; 637 wantLayer = true;
538 layerIndex = message.getArg(1).toInt() - 1; 638 layerIndex = message.getArg(1).toInt() - 1;
539 } 639 }
640 } else {
641 SVCERR << "OSCHandler: Usage: /setcurrent <pane> [<layer>]" << endl;
540 } 642 }
541 643
542 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) { 644 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
543 Pane *pane = m_paneStack->getPane(paneIndex); 645 Pane *pane = m_paneStack->getPane(paneIndex);
544 m_paneStack->setCurrentPane(pane); 646 m_paneStack->setCurrentPane(pane);
579 } else { 681 } else {
580 682
581 SVCERR << "WARNING: OSCHandler: Unknown delete target \"" 683 SVCERR << "WARNING: OSCHandler: Unknown delete target \""
582 << target << "\"" << endl; 684 << target << "\"" << endl;
583 } 685 }
686 } else {
687 SVCERR << "OSCHandler: Usage: /delete pane" << endl
688 << " or /delete layer" << endl;
584 } 689 }
585 690
586 } else if (message.getMethod() == "zoom") { 691 } else if (message.getMethod() == "zoom") {
587 692
588 if (message.getArgCount() == 1) { 693 if (message.getArgCount() == 1) {
616 } else { 721 } else {
617 SVCERR << "OSCHandler: No current pane, can't set zoom" 722 SVCERR << "OSCHandler: No current pane, can't set zoom"
618 << endl; 723 << endl;
619 } 724 }
620 } 725 }
726 } else {
727 SVCERR << "OSCHandler: Usage: /zoom <level>" << endl
728 << " or /zoom in" << endl
729 << " or /zoom out" << endl
730 << " or /zoom fit" << endl
731 << " or /zoom default" << endl;
621 } 732 }
622 733
623 } else if (message.getMethod() == "zoomvertical") { 734 } else if (message.getMethod() == "zoomvertical") {
624 735
625 Pane *pane = m_paneStack->getCurrentPane(); 736 Pane *pane = m_paneStack->getCurrentPane();