| 1 | /* |
| 2 | Copyright (C) 2008-2010 Andres Cabrera |
| 3 | [email protected] |
| 4 | |
| 5 | This file is part of CsoundQt. |
| 6 | |
| 7 | CsoundQt is free software; you can redistribute it |
| 8 | and/or modify it under the terms of the GNU Lesser General Public |
| 9 | License as published by the Free Software Foundation; either |
| 10 | version 2.1 of the License, or (at your option) any later version. |
| 11 | |
| 12 | CsoundQt is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU Lesser General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Lesser General Public |
| 18 | License along with Csound; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <cwindow.h> |
| 24 | #include <csound.hpp> // TODO These two are necessary for the WINDAT struct. Can they be moved? |
| 25 | |
| 26 | |
| 27 | #include "documentpage.h" |
| 28 | #include "documentview.h" |
| 29 | #include "csoundengine.h" |
| 30 | #include "liveeventframe.h" |
| 31 | #include "eventsheet.h" |
| 32 | #include "liveeventcontrol.h" |
| 33 | #include "qutecsound.h" // For playParent and renderParent functions (called from button |
| 34 | // reserved channels) and for connecting from console to log file |
| 35 | #include "opentryparser.h" |
| 36 | #include "types.h" |
| 37 | #include "dotgenerator.h" |
| 38 | #include "highlighter.h" |
| 39 | #include "widgetlayout.h" |
| 40 | #include "console.h" |
| 41 | #include "midilearndialog.h" |
| 42 | #include "qutebutton.h" |
| 43 | |
| 44 | #include <QMessageBox> |
| 45 | |
| 46 | // TODO is is possible to move the editor to a separate child class, to be able to use a cleaner class? |
| 47 | DocumentPage::DocumentPage(QWidget *parent, OpEntryParser *opcodeTree, |
| 48 | ConfigLists *configlists, MidiLearnDialog *midiLearn): |
| 49 | BaseDocument(parent, opcodeTree, configlists) |
| 50 | { |
| 51 | init(parent, opcodeTree); |
| 52 | m_view->showLineArea(true); |
| 53 | m_midiLearn = midiLearn; |
| 54 | m_colorTheme = ""; |
| 55 | regexUdo.setPattern("\\n\\s*\\bopcode\\s+(\\w+)\\s*,\\s*[a-zA-Z0\\[\\]]+\\s*,\\s*[a-zA-Z0\\[\\]]+"); |
| 56 | m_parseUdosNeeded = true; |
| 57 | foreach(WidgetLayout* wl, m_widgetLayouts) { |
| 58 | connect(wl, SIGNAL(changed()), this, SLOT(setModified())); |
| 59 | connect(wl, SIGNAL(widgetSelectedSignal(QuteWidget*)), |
| 60 | this, SLOT(passSelectedWidget(QuteWidget*))); |
| 61 | connect(wl, SIGNAL(widgetUnselectedSignal(QuteWidget*)), |
| 62 | this, SLOT(passUnselectedWidget(QuteWidget*))); |
| 63 | connect(wl,SIGNAL(showMidiLearn(QuteWidget*)),this, SLOT(showMidiLearn(QuteWidget*))); |
| 64 | connect(wl, SIGNAL(addChn_kSignal(QString)), m_view, SLOT(insertChn_k(QString)) ); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | DocumentPage::~DocumentPage() |
| 69 | { |
| 70 | // qDebug(); |
| 71 | disconnect(m_console, 0,0,0); |
| 72 | disconnect(m_view, 0,0,0); |
| 73 | // deleteAllLiveEvents(); // FIXME This is also crashing... |
| 74 | } |
| 75 | |
| 76 | void DocumentPage::setCompanionFileName(QString name) |
| 77 | { |
| 78 | companionFile = name; |
| 79 | } |
| 80 | |
| 81 | void DocumentPage::loadTextString(QString &text) |
| 82 | { |
| 83 | setTextString(text); |
| 84 | m_view->clearUndoRedoStack(); |
| 85 | } |
| 86 | |
| 87 | void DocumentPage::toggleLineArea() |
| 88 | { |
| 89 | m_view->toggleLineArea(); |
| 90 | } |
| 91 | |
| 92 | void DocumentPage::toggleParameterMode() |
| 93 | { |
| 94 | m_view->toggleParameterMode(); |
| 95 | } |
| 96 | |
| 97 | //void DocumentPage::showParametersInEditor() |
| 98 | //{ |
| 99 | // m_view->parameterShowShortcutPressed(); |
| 100 | //} |
| 101 | |
| 102 | int DocumentPage::setTextString(QString &text) |
| 103 | { |
| 104 | int ret = 0; |
| 105 | deleteAllLiveEvents(); |
| 106 | if (!fileName.endsWith(".csd") && !fileName.isEmpty()) { |
| 107 | // Put all text since not a csd file (and not default file which has no name) |
| 108 | m_view->setFullText(text, true); |
| 109 | m_view->setModified(false); |
| 110 | return ret; |
| 111 | } |
| 112 | auto t0 = std::chrono::high_resolution_clock::now(); |
| 113 | parseAndRemoveWidgetText(text); |
| 114 | auto t1 = std::chrono::high_resolution_clock::now(); |
| 115 | auto diff = std::chrono::duration<double, std::milli>(t1-t0).count(); |
| 116 | QDEBUG << "parseAndRemoveWidgetText:" << diff << "ms"; |
| 117 | /* |
| 118 | if (text.contains("<MacOptions>") && text.contains("</MacOptions>")) { |
| 119 | QString options = text.right(text.size()-text.indexOf("<MacOptions>")); |
| 120 | options.resize(options.indexOf("</MacOptions>") + 13); |
| 121 | // qDebug("<MacOptions> present. \n%s", options.toStdString().c_str()); |
| 122 | if (text.indexOf("</MacOptions>") + 13 < text.size() |
| 123 | && text[text.indexOf("</MacOptions>") + 13] == '\n') |
| 124 | text.remove(text.indexOf("</MacOptions>") + 13, 1); //remove final line break |
| 125 | if (text.indexOf("<MacOptions>") > 0 && text[text.indexOf("<MacOptions>") - 1] == '\n') |
| 126 | text.remove(text.indexOf("<MacOptions>") - 1, 1); //remove initial line break |
| 127 | text.remove(text.indexOf("<MacOptions>"), options.size()); |
| 128 | // qDebug("<MacOptions> present. %s", getMacOptions("WindowBounds").toStdString().c_str()); |
| 129 | m_macOptions = options.split('\n'); |
| 130 | } |
| 131 | if (text.contains("<MacPresets>") && text.contains("</MacPresets>")) { |
| 132 | m_macPresets = text.right(text.size()-text.indexOf("<MacPresets>")); |
| 133 | m_macPresets.resize(m_macPresets.indexOf("</MacPresets>") + 12); |
| 134 | if (text.indexOf("</MacPresets>") + 12 < text.size() && text[text.indexOf("</MacPresets>") + 12] == '\n') |
| 135 | text.remove(text.indexOf("</MacPresets>") + 12, 1); //remove final line break |
| 136 | if (text.indexOf("<MacPresets>") > 0 && text[text.indexOf("<MacPresets>") - 1] == '\n') |
| 137 | text.remove(text.indexOf("<MacPresets>") - 1, 1); //remove initial line break |
| 138 | text.remove(text.indexOf("<MacPresets>"), m_macPresets.size()); |
| 139 | // qDebug("<MacPresets> present."); |
| 140 | } |
| 141 | else { |
| 142 | m_macPresets = ""; |
| 143 | } |
| 144 | if (text.contains("<MacGUI>") && text.contains("</MacGUI>")) { |
| 145 | QString m_macGUI = text.right(text.size()-text.indexOf("<MacGUI>")); |
| 146 | m_macGUI.resize(m_macGUI.indexOf("</MacGUI>") + 9); |
| 147 | if (text.indexOf("</MacGUI>") + 9 < text.size() && text[text.indexOf("</MacGUI>") + 9] == '\n') |
| 148 | text.remove(text.indexOf("</MacGUI>") + 9, 1); //remove final line break |
| 149 | if (text.indexOf("<MacGUI>") > 0 && text[text.indexOf("<MacGUI>") - 1] == '\n') |
| 150 | text.remove(text.indexOf("<MacGUI>") - 1, 1); //remove initial line break |
| 151 | text.remove(m_macGUI); |
| 152 | if (baseRet < 1) { |
| 153 | //FIXME allow multiple |
| 154 | m_widgetLayouts[0]->loadMacWidgets(m_macGUI); |
| 155 | qDebug("<MacGUI> loaded."); |
| 156 | } |
| 157 | } |
| 158 | else { |
| 159 | m_macGUI = ""; |
| 160 | } |
| 161 | if (baseRet != 1) { // Use the old options only if the new ones are not present |
| 162 | // This here is for compatibility with MacCsound (copy output filename from |
| 163 | // <MacOptions> to <CsOptions>) |
| 164 | QString optionsText = getMacOptions("Options:"); |
| 165 | if (optionsText.contains(" -o")) { |
| 166 | QString outFile = optionsText.mid(optionsText.indexOf(" -o") + 1); |
| 167 | int index = outFile.indexOf(" -"); |
| 168 | if (index > 0) { |
| 169 | outFile = outFile.left(index); |
| 170 | } |
| 171 | optionsText.remove(outFile); |
| 172 | setMacOption("Options:", optionsText); |
| 173 | index = text.indexOf("<CsOptions>"); |
| 174 | int endindex = text.indexOf("</CsOptions>"); |
| 175 | if (index >= 0 && endindex > index) { |
| 176 | text.remove(index, endindex - index); |
| 177 | text.insert(index, "<CsOptions>\n" + outFile); |
| 178 | } |
| 179 | else { |
| 180 | index = text.indexOf("<CsInstruments>"); |
| 181 | text.insert(index, "<CsOptions>\n" + outFile + "\n</CsOptions>\n"); |
| 182 | } |
| 183 | } |
| 184 | ret = 1; |
| 185 | } |
| 186 | */ |
| 187 | // Load Live Event Panels ------------------------ |
| 188 | while (text.indexOf("<EventPanel") != -1 |
| 189 | && text.indexOf("<EventPanel") < text.indexOf("</EventPanel>")) { |
| 190 | QString liveEventsText = text.mid(text.indexOf("<EventPanel "), |
| 191 | text.indexOf("</EventPanel>") - text.indexOf("<EventPanel ") + 13 |
| 192 | + (text[text.indexOf("</EventPanel>") + 14] == '\n' ? 1:0)); |
| 193 | QDomDocument doc("doc"); |
| 194 | doc.setContent(liveEventsText); |
| 195 | QDomElement panelElement = doc.firstChildElement("EventPanel"); |
| 196 | QString liveText = panelElement.text(); |
| 197 | // qDebug() << liveText; |
| 198 | QString panelName = panelElement.attribute("name",""); |
| 199 | double tempo = panelElement.attribute("tempo","60.0").toDouble(); |
| 200 | double loop = panelElement.attribute("loop","8.0").toDouble(); |
| 201 | int posx = panelElement.attribute("x","-1").toDouble(); |
| 202 | int posy = panelElement.attribute("y","-1").toDouble(); |
| 203 | int width = panelElement.attribute("width","-1").toDouble(); |
| 204 | int height = panelElement.attribute("height","-1").toDouble(); |
| 205 | // TODO recall live event panel visibility |
| 206 | //int visibleEnabled = panelElement.attribute("visible","true") == "true"; |
| 207 | int loopStart = panelElement.attribute("loopStart","0.0").toDouble(); |
| 208 | int loopEnd = panelElement.attribute("loopEnd","0.0").toDouble(); |
| 209 | |
| 210 | LiveEventFrame *panel = createLiveEventPanel(); |
| 211 | panel->setFromText(liveText); |
| 212 | panel->setName(panelName); |
| 213 | panel->setTempo(tempo); |
| 214 | panel->setLoopLength(loop); |
| 215 | panel->setLoopRange(loopStart, loopEnd); |
| 216 | m_liveEventControl->appendPanel(panel); |
| 217 | if (posx > 5 && posy > 5) { |
| 218 | panel->move(posx, posy); |
| 219 | } |
| 220 | if (width > 100 && height > 80) { |
| 221 | panel->resize(width, height); |
| 222 | } |
| 223 | panel->hide(); |
| 224 | text.remove(liveEventsText); |
| 225 | } |
| 226 | // if (m_liveFrames.size() == 0) { |
| 227 | // LiveEventFrame *e = createLiveEventPanel(); |
| 228 | // e->setFromText(QString()); // Must set blank for undo history point |
| 229 | // } |
| 230 | // This must be last as some of the text has been removed along the way |
| 231 | m_view->setFullText(text,true); |
| 232 | m_view->setModified(false); |
| 233 | // This ensures that modifications triggered later by the maineditor |
| 234 | // do not set the modified status of the page when a file is first |
| 235 | // loaded |
| 236 | auto t2 = std::chrono::high_resolution_clock::now(); |
| 237 | QDEBUG << "finished parsing in (ms)" << |
| 238 | std::chrono::duration<double, std::milli>(t2-t1).count(); |
| 239 | // QTimer::singleShot(1000, this, [this](){this->setModified(false);}); |
| 240 | return ret; |
| 241 | } |
| 242 | |
| 243 | void DocumentPage::setEditorFocus() |
| 244 | { |
| 245 | m_view->setFocus(); |
| 246 | } |
| 247 | |
| 248 | void DocumentPage::showLineNumbers(bool show) |
| 249 | { |
| 250 | m_view->showLineArea(show); |
| 251 | } |
| 252 | |
| 253 | void DocumentPage::insertText(QString text, int section) |
| 254 | { |
| 255 | return m_view->insertText(text, section); |
| 256 | } |
| 257 | |
| 258 | void DocumentPage::setFullText(QString text) |
| 259 | { |
| 260 | return m_view->setFullText(text); |
| 261 | } |
| 262 | |
| 263 | void DocumentPage::setBasicText(QString text) |
| 264 | { |
| 265 | return m_view->setBasicText(text); |
| 266 | } |
| 267 | |
| 268 | void DocumentPage::setOrc(QString text) |
| 269 | { |
| 270 | return m_view->setOrc(text); |
| 271 | } |
| 272 | |
| 273 | void DocumentPage::setSco(QString text) |
| 274 | { |
| 275 | return m_view->setSco(text); |
| 276 | } |
| 277 | |
| 278 | void DocumentPage::setWidgetsText(QString text) |
| 279 | { |
| 280 | // TODO support multiple layouts |
| 281 | qDebug() << "DocumentPage. calling loadXmlWidgets"; |
| 282 | return m_widgetLayouts.at(0)->loadXmlWidgets(text); |
| 283 | } |
| 284 | |
| 285 | void DocumentPage::setPresetsText(QString text) |
| 286 | { |
| 287 | // TODO support multiple layouts |
| 288 | return m_widgetLayouts.at(0)->loadXmlPresets(text); |
| 289 | } |
| 290 | |
| 291 | void DocumentPage::setOptionsText(QString text) |
| 292 | { |
| 293 | m_view->setOptionsText(text); |
| 294 | } |
| 295 | |
| 296 | QString DocumentPage::getFullText() |
| 297 | { |
| 298 | QString fullText = BaseDocument::getFullText(); |
| 299 | if (saveOldFormat) { |
| 300 | QString macOptions = getMacOptionsText(); |
| 301 | if (!macOptions.isEmpty()) { |
| 302 | fullText += macOptions + "\n"; |
| 303 | } |
| 304 | QString macWidgets = getMacWidgetsText(); |
| 305 | if (!macWidgets.isEmpty()) { |
| 306 | fullText += macWidgets + "\n"; |
| 307 | } |
| 308 | QString macPresets = getMacPresetsText(); |
| 309 | if (!macPresets.isEmpty()) { |
| 310 | fullText += macPresets + "\n"; // Put old format for backward compatibility |
| 311 | } |
| 312 | } |
| 313 | QString liveEventsText = ""; |
| 314 | if (saveLiveEvents) { // Only add live events sections if file is a csd file |
| 315 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 316 | liveEventsText += m_liveFrames[i]->getPlainText(); |
| 317 | // qDebug() << panel; |
| 318 | } |
| 319 | fullText += liveEventsText; |
| 320 | } |
| 321 | if (m_lineEnding == 1) { // Windows line ending mode |
| 322 | fullText.replace("\n", "\r\n"); |
| 323 | fullText.replace("\r\r\n", "\r\n"); |
| 324 | } else { |
| 325 | fullText.replace("\r\r\n", "\r\n"); |
| 326 | fullText.replace("\r\n", "\n"); |
| 327 | } |
| 328 | return fullText; |
| 329 | } |
| 330 | |
| 331 | QString DocumentPage::getDotText() |
| 332 | { |
| 333 | if (fileName.endsWith("sco")) { |
| 334 | qDebug() << "No dot for sco files"; |
| 335 | return QString(); |
| 336 | } |
| 337 | QString orcText = getFullText(); |
| 338 | if (!fileName.endsWith("orc")) { //asume csd |
| 339 | if (orcText.contains("<CsInstruments>")) { |
| 340 | auto start = orcText.indexOf("<CsInstruments>"); |
| 341 | orcText = orcText.mid(start + 15, |
| 342 | orcText.indexOf("</CsInstruments>") - start - 15); |
| 343 | } |
| 344 | } |
| 345 | DotGenerator dot(fileName, orcText, m_opcodeTree); |
| 346 | return dot.getDotText(); |
| 347 | } |
| 348 | |
| 349 | QString DocumentPage::getSelectedText(int section) |
| 350 | { |
| 351 | QString text = m_view->getSelectedText(section); |
| 352 | return text; |
| 353 | } |
| 354 | |
| 355 | QString DocumentPage::getSelectedWidgetsText() |
| 356 | { |
| 357 | //FIXME allow multiple |
| 358 | QString text = m_widgetLayouts[0]->getSelectedWidgetsText(); |
| 359 | return text; |
| 360 | } |
| 361 | |
| 362 | QString DocumentPage::getMacWidgetsText() |
| 363 | { |
| 364 | QString t = getWidgetsText(); // TODO only for testing. remove later |
| 365 | //FIXME allow multiple |
| 366 | return m_widgetLayouts[0]->getMacWidgetsText(); |
| 367 | } |
| 368 | |
| 369 | QString DocumentPage::getMacPresetsText() |
| 370 | { |
| 371 | return m_macPresets; |
| 372 | } |
| 373 | |
| 374 | QString DocumentPage::getMacOptionsText() |
| 375 | { |
| 376 | return m_macOptions.join("\n"); |
| 377 | } |
| 378 | |
| 379 | QString DocumentPage::getMacOptions(QString option) |
| 380 | { |
| 381 | if (!option.endsWith(":")) |
| 382 | option += ":"; |
| 383 | if (!option.endsWith(" ")) |
| 384 | option += " "; |
| 385 | int index = m_macOptions.indexOf(QRegExp(option + ".*")); |
| 386 | if (index < 0) { |
| 387 | qDebug("Option %s not found!", option.toLocal8Bit().constData()); |
| 388 | return QString(""); |
| 389 | } |
| 390 | return m_macOptions[index].mid(option.size()); |
| 391 | } |
| 392 | |
| 393 | QString DocumentPage::getHtmlText() |
| 394 | { |
| 395 | QString fullText = BaseDocument::getFullText(); |
| 396 | // does windows need /r/n replacemant? then probably this.getFullText(); |
| 397 | // get the <html> </html> element: |
| 398 | QString::SectionFlags sectionflags = QString::SectionIncludeLeadingSep | |
| 399 | QString::SectionIncludeTrailingSep | QString::SectionCaseInsensitiveSeps; |
| 400 | QString element = fullText.section("<html", 1, 1, sectionflags); |
| 401 | element = element.section("</html>", 0, 0, sectionflags); |
| 402 | return element; |
| 403 | |
| 404 | } |
| 405 | |
| 406 | int DocumentPage::getViewMode() |
| 407 | { |
| 408 | return m_view->getViewMode(); |
| 409 | } |
| 410 | |
| 411 | QString DocumentPage::getLiveEventsText() |
| 412 | { |
| 413 | QString text; |
| 414 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 415 | text += m_liveFrames[i]->getPlainText(); |
| 416 | } |
| 417 | return text; |
| 418 | } |
| 419 | |
| 420 | QString DocumentPage::wordUnderCursor() |
| 421 | { |
| 422 | return m_view->wordUnderCursor(); |
| 423 | } |
| 424 | |
| 425 | QString DocumentPage::lineUnderCursor() { |
| 426 | return m_view->lineUnderCursor(); |
| 427 | } |
| 428 | |
| 429 | QRect DocumentPage::getWidgetLayoutOuterGeometry() |
| 430 | { |
| 431 | //FIXME allow multiple |
| 432 | return m_widgetLayouts[0]->getOuterGeometry(); |
| 433 | } |
| 434 | |
| 435 | void DocumentPage::setWidgetLayoutOuterGeometry(QRect r) |
| 436 | { |
| 437 | m_widgetLayouts[0]->setOuterGeometry(r); |
| 438 | } |
| 439 | |
| 440 | void DocumentPage::setChannelValue(QString channel, double value) |
| 441 | { |
| 442 | for (int i = 0; i < m_widgetLayouts.size(); i++) { |
| 443 | m_widgetLayouts[i]->newValue(QPair<QString,double>(channel, value)); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | double DocumentPage::getChannelValue(QString channel) |
| 448 | { |
| 449 | //FIXME allow multiple |
| 450 | return m_widgetLayouts[0]->getValueForChannel(channel); |
| 451 | } |
| 452 | |
| 453 | void DocumentPage::setChannelString(QString channel, QString value) |
| 454 | { |
| 455 | for (int i = 0; i < m_widgetLayouts.size(); i++) { |
| 456 | m_widgetLayouts[i]->newValue(QPair<QString,QString>(channel, value)); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | QString DocumentPage::getChannelString(QString channel) |
| 461 | { |
| 462 | //FIXME allow multiple |
| 463 | return m_widgetLayouts[0]->getStringForChannel(channel); |
| 464 | } |
| 465 | |
| 466 | void DocumentPage::setWidgetProperty(QString widgetid, QString property, QVariant value) |
| 467 | { |
| 468 | for (int i = 0; i < m_widgetLayouts.size(); i++) { |
| 469 | m_widgetLayouts[i]->setWidgetProperty(widgetid, property, value); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | QVariant DocumentPage::getWidgetProperty(QString widgetid, QString property) |
| 474 | { |
| 475 | //FIXME allow multiple |
| 476 | return m_widgetLayouts[0]->getWidgetProperty(widgetid, property); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | QStringList DocumentPage::getWidgetUuids() |
| 481 | { QStringList uuids = QStringList(); |
| 482 | for (int i = 0; i < m_widgetLayouts.size(); i++) { |
| 483 | uuids << m_widgetLayouts[i]->getUuids(); // add up all widgets from all layouts |
| 484 | } |
| 485 | return uuids; |
| 486 | } |
| 487 | |
| 488 | bool DocumentPage::destroyWidget(QString widgetid) |
| 489 | { |
| 490 | //FIXME allow multiple |
| 491 | return m_widgetLayouts[0]->destroyWidget(widgetid); |
| 492 | |
| 493 | } |
| 494 | |
| 495 | QStringList DocumentPage::listWidgetProperties(QString widgetid) |
| 496 | { |
| 497 | // widgetid can be eihter uuid (prefered) or channel |
| 498 | //FIXME allow multiple |
| 499 | return m_widgetLayouts[0]->listProperties(widgetid); |
| 500 | } |
| 501 | |
| 502 | |
| 503 | void DocumentPage::loadPreset(int preSetIndex) { |
| 504 | //FIXME allow multiple |
| 505 | return m_widgetLayouts[0]->loadPresetFromIndex(preSetIndex); |
| 506 | } |
| 507 | |
| 508 | QString DocumentPage::createNewLabel(int x, int y, QString channel) |
| 509 | { |
| 510 | //FIXME allow multiple |
| 511 | return m_widgetLayouts[0]->createNewLabel(x, y, channel); |
| 512 | } |
| 513 | |
| 514 | QString DocumentPage::createNewDisplay(int x, int y, QString channel) |
| 515 | { |
| 516 | //FIXME allow multiple |
| 517 | return m_widgetLayouts[0]->createNewDisplay(x, y, channel); |
| 518 | } |
| 519 | |
| 520 | QString DocumentPage::createNewScrollNumber(int x, int y, QString channel) |
| 521 | { |
| 522 | //FIXME allow multiple |
| 523 | return m_widgetLayouts[0]->createNewScrollNumber(x, y, channel); |
| 524 | } |
| 525 | |
| 526 | QString DocumentPage::createNewLineEdit(int x, int y, QString channel) |
| 527 | { |
| 528 | //FIXME allow multiple |
| 529 | return m_widgetLayouts[0]->createNewLineEdit(x, y, channel); |
| 530 | } |
| 531 | |
| 532 | QString DocumentPage::createNewSpinBox(int x, int y, QString channel) |
| 533 | { |
| 534 | //FIXME allow multiple |
| 535 | return m_widgetLayouts[0]->createNewSpinBox(x, y, channel); |
| 536 | } |
| 537 | |
| 538 | QString DocumentPage::createNewSlider(int x, int y, QString channel) |
| 539 | { |
| 540 | //FIXME allow multiple |
| 541 | return m_widgetLayouts[0]->createNewSlider(x, y, channel); |
| 542 | } |
| 543 | |
| 544 | QString DocumentPage::createNewButton(int x, int y, QString channel) |
| 545 | { |
| 546 | //FIXME allow multiple |
| 547 | return m_widgetLayouts[0]->createNewButton(x, y, channel); |
| 548 | } |
| 549 | |
| 550 | QString DocumentPage::createNewKnob(int x, int y, QString channel) |
| 551 | { |
| 552 | //FIXME allow multiple |
| 553 | return m_widgetLayouts[0]->createNewKnob(x, y, channel); |
| 554 | } |
| 555 | |
| 556 | QString DocumentPage::createNewCheckBox(int x, int y, QString channel) |
| 557 | { |
| 558 | //FIXME allow multiple |
| 559 | return m_widgetLayouts[0]->createNewCheckBox(x, y, channel); |
| 560 | } |
| 561 | |
| 562 | QString DocumentPage::createNewMenu(int x, int y, QString channel) |
| 563 | { |
| 564 | //FIXME allow multiple |
| 565 | return m_widgetLayouts[0]->createNewMenu(x, y, channel); |
| 566 | } |
| 567 | |
| 568 | QString DocumentPage::createNewMeter(int x, int y, QString channel) |
| 569 | { |
| 570 | //FIXME allow multiple |
| 571 | return m_widgetLayouts[0]->createNewMeter(x, y, channel); |
| 572 | } |
| 573 | |
| 574 | QString DocumentPage::createNewConsole(int x, int y, QString channel) |
| 575 | { |
| 576 | //FIXME allow multiple |
| 577 | return m_widgetLayouts[0]->createNewConsole(x, y, channel); |
| 578 | } |
| 579 | |
| 580 | QString DocumentPage::createNewGraph(int x, int y, QString channel) |
| 581 | { |
| 582 | //FIXME allow multiple |
| 583 | return m_widgetLayouts[0]->createNewGraph(x, y, channel); |
| 584 | } |
| 585 | |
| 586 | QString DocumentPage::createNewScope(int x, int y, QString channel) |
| 587 | { |
| 588 | //FIXME allow multiple |
| 589 | return m_widgetLayouts[0]->createNewScope(x, y, channel); |
| 590 | } |
| 591 | |
| 592 | |
| 593 | EventSheet* DocumentPage::getSheet(int sheetIndex) |
| 594 | { |
| 595 | if (sheetIndex == -1) { |
| 596 | sheetIndex = 0; //FIXME find sheet |
| 597 | } |
| 598 | if (sheetIndex < m_liveFrames.size() && sheetIndex >= 0) { |
| 599 | return m_liveFrames[sheetIndex]->getSheet(); |
| 600 | } |
| 601 | return nullptr; |
| 602 | } |
| 603 | |
| 604 | EventSheet* DocumentPage::getSheet(QString sheetName) |
| 605 | { |
| 606 | (void) sheetName; |
| 607 | return nullptr; |
| 608 | } |
| 609 | |
| 610 | int DocumentPage::lineCount(bool countExtras) |
| 611 | { |
| 612 | QString text; |
| 613 | if (countExtras) { |
| 614 | text = this->getBasicText(); |
| 615 | } |
| 616 | else |
| 617 | { |
| 618 | text = this->getFullText(); |
| 619 | } |
| 620 | return text.count("\n"); |
| 621 | } |
| 622 | |
| 623 | int DocumentPage::characterCount(bool countExtras) |
| 624 | { |
| 625 | QString text; |
| 626 | if (countExtras) { |
| 627 | text = this->getBasicText(); |
| 628 | } |
| 629 | else |
| 630 | { |
| 631 | text = this->getFullText(); |
| 632 | } |
| 633 | return text.size(); |
| 634 | } |
| 635 | |
| 636 | int DocumentPage::instrumentCount() |
| 637 | { |
| 638 | QString text = this->getBasicText(); |
| 639 | return text.count((QRegExp("\\n[ \\t]*instr\\s"))); |
| 640 | } |
| 641 | |
| 642 | int DocumentPage::udoCount() |
| 643 | { |
| 644 | QString text = this->getBasicText(); |
| 645 | return text.count((QRegExp("\\n[ \\t]*opcode\\s"))); |
| 646 | } |
| 647 | |
| 648 | int DocumentPage::widgetCount() |
| 649 | { |
| 650 | QString text = this->getWidgetsText(); |
| 651 | return text.count("<bsbObject"); |
| 652 | } |
| 653 | |
| 654 | QString DocumentPage::embeddedFiles() |
| 655 | { |
| 656 | QString text = m_view->getFileB(); |
| 657 | return QString::number(text.count("<CsFileB ")); |
| 658 | } |
| 659 | |
| 660 | QString DocumentPage::getFilePath() |
| 661 | { |
| 662 | return fileName.left(fileName.lastIndexOf("/")); |
| 663 | } |
| 664 | |
| 665 | QStringList DocumentPage::getScheduledEvents(unsigned long ksmps) |
| 666 | { |
| 667 | QStringList events; |
| 668 | // Called once after every Csound control pass |
| 669 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 670 | m_liveFrames[i]->getEvents(ksmps, &events); |
| 671 | } |
| 672 | // m_ksmpscount = ksmpscount; |
| 673 | return events; |
| 674 | } |
| 675 | |
| 676 | void DocumentPage::setModified(bool mod) |
| 677 | { |
| 678 | // This slot is triggered by the document children whenever they are modified |
| 679 | // It is also called from the main application when the file is saved to set as unmodified. |
| 680 | // FIXME live frame modification should also affect here |
| 681 | // qDebug() << "DocumentPage::setModified :" << mod; |
| 682 | if (mod == true) { |
| 683 | emit modified(); |
| 684 | } |
| 685 | else { |
| 686 | emit unmodified(); |
| 687 | m_view->setModified(false); |
| 688 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 689 | wl->setModified(false); |
| 690 | } |
| 691 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 692 | m_liveFrames[i]->setModified(false); |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | void DocumentPage::sendCodeToEngine(QString code) |
| 698 | { |
| 699 | m_csEngine->evaluate(code); |
| 700 | } |
| 701 | |
| 702 | bool DocumentPage::isModified() |
| 703 | { |
| 704 | if (m_view->isModified()) { |
| 705 | return true; |
| 706 | } |
| 707 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 708 | if (wl->isModified()) { |
| 709 | return true; |
| 710 | } |
| 711 | } |
| 712 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 713 | if (m_liveFrames[i]->isModified()) { |
| 714 | return true; |
| 715 | } |
| 716 | } |
| 717 | return false; |
| 718 | } |
| 719 | |
| 720 | bool DocumentPage::isRunning() |
| 721 | { |
| 722 | // TODO what to do with pause? |
| 723 | return m_csEngine->isRunning() || m_pythonRunning; |
| 724 | } |
| 725 | |
| 726 | bool DocumentPage::isRecording() |
| 727 | { |
| 728 | // TODO what to do with pause? |
| 729 | return m_csEngine->isRecording(); |
| 730 | } |
| 731 | |
| 732 | bool DocumentPage::usesFltk() |
| 733 | { |
| 734 | return m_view->getBasicText().contains("FLpanel"); |
| 735 | } |
| 736 | |
| 737 | void DocumentPage::updateCsLadspaText() |
| 738 | { |
| 739 | QString text = "<csLADSPA>\nName="; |
| 740 | text += fileName.mid(fileName.lastIndexOf("/") + 1) + "\n"; |
| 741 | text += "Maker=CsoundQt\n"; |
| 742 | QString id = QString::number(QRandomGenerator::global()->generate()); |
| 743 | text += "UniqueID=" + id + "\n"; |
| 744 | text += "Copyright=none\n"; |
| 745 | //FIXME allow multiple |
| 746 | text += m_widgetLayouts[0]->getCsladspaLines(); |
| 747 | text += "</csLADSPA>"; |
| 748 | m_view->setLadspaText(text); |
| 749 | } |
| 750 | |
| 751 | QString DocumentPage::getQml() |
| 752 | { |
| 753 | QString qml = m_widgetLayouts[0]->getQml(); |
| 754 | return qml; |
| 755 | } |
| 756 | |
| 757 | QString DocumentPage::getMidiControllerInstrument() |
| 758 | { |
| 759 | return m_widgetLayouts[0]->getMidiControllerInstrument(); |
| 760 | } |
| 761 | |
| 762 | void DocumentPage::updateCabbageText() |
| 763 | { |
| 764 | if (widgetCount()==0) { |
| 765 | QMessageBox::warning(nullptr, tr("No widgets"), tr("There are no widgets to convert!")); |
| 766 | return; |
| 767 | } |
| 768 | QString text = "<Cabbage>\n"; |
| 769 | text += m_widgetLayouts[0]->getCabbageWidgets(); |
| 770 | text += "</Cabbage>"; |
| 771 | m_view->setCabbageText(text); |
| 772 | } |
| 773 | |
| 774 | void DocumentPage::focusWidgets() |
| 775 | { |
| 776 | //FIXME allow multiple |
| 777 | //TODO is this really required? |
| 778 | m_widgetLayouts[0]->setFocus(); |
| 779 | } |
| 780 | |
| 781 | QString DocumentPage::getFileName() |
| 782 | { |
| 783 | return fileName; |
| 784 | } |
| 785 | |
| 786 | QString DocumentPage::getCompanionFileName() |
| 787 | { |
| 788 | return companionFile; |
| 789 | } |
| 790 | |
| 791 | void DocumentPage::setLineEnding(int lineEndingMode) |
| 792 | { |
| 793 | m_lineEnding = lineEndingMode; |
| 794 | } |
| 795 | |
| 796 | void DocumentPage::copy() |
| 797 | { |
| 798 | qDebug() << m_widgetLayouts[0]->hasFocus(); |
| 799 | bool liveeventfocus = false; |
| 800 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 801 | if (m_liveFrames[i]->getSheet()->hasFocus()) { |
| 802 | m_liveFrames[i]->getSheet()->copy(); |
| 803 | liveeventfocus = true; |
| 804 | } |
| 805 | } |
| 806 | if (!liveeventfocus) { |
| 807 | if (m_view->childHasFocus()) { |
| 808 | m_view->copy(); |
| 809 | } |
| 810 | else { // FIXME allow multiple layouts |
| 811 | m_widgetLayouts[0]->copy(); |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | |
| 816 | void DocumentPage::cut() |
| 817 | { |
| 818 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 819 | if (wl->hasFocus()) { |
| 820 | wl->cut(); |
| 821 | return; |
| 822 | } |
| 823 | } |
| 824 | if (m_view->childHasFocus()) { |
| 825 | m_view->cut(); |
| 826 | } |
| 827 | else { |
| 828 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 829 | if (m_liveFrames[i]->getSheet()->hasFocus()) |
| 830 | m_liveFrames[i]->getSheet()->cut(); |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | void DocumentPage::paste() |
| 836 | { |
| 837 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 838 | if (wl->hasFocus()) { |
| 839 | wl->paste(); |
| 840 | return; |
| 841 | } |
| 842 | } |
| 843 | if (m_view->childHasFocus()) { |
| 844 | m_view->paste(); |
| 845 | } |
| 846 | else { |
| 847 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 848 | if (m_liveFrames[i]->getSheet()->hasFocus()) |
| 849 | m_liveFrames[i]->getSheet()->paste(); |
| 850 | } |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | void DocumentPage::undo() |
| 855 | { |
| 856 | // qDebug()"; |
| 857 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 858 | if (wl->hasFocus()) { |
| 859 | wl->undo(); |
| 860 | wl->setFocus(Qt::OtherFocusReason); // Why is this here? |
| 861 | return; |
| 862 | } |
| 863 | } |
| 864 | if (m_view->childHasFocus()) { |
| 865 | m_view->undo(); |
| 866 | } |
| 867 | else { |
| 868 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 869 | if (m_liveFrames[i]->getSheet()->hasFocus()) |
| 870 | m_liveFrames[i]->getSheet()->undo(); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | void DocumentPage::redo() |
| 876 | { |
| 877 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 878 | if (wl->hasFocus()) { |
| 879 | wl->redo(); |
| 880 | wl->setFocus(Qt::OtherFocusReason); // Why is this here? |
| 881 | return; |
| 882 | } |
| 883 | } |
| 884 | if (m_view->childHasFocus()) |
| 885 | m_view->redo(); |
| 886 | else { |
| 887 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 888 | if (m_liveFrames[i]->getSheet()->hasFocus()) |
| 889 | m_liveFrames[i]->getSheet()->redo(); |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | void DocumentPage::gotoNextRow() |
| 895 | { |
| 896 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 897 | if (wl->hasFocus()) { |
| 898 | wl->redo(); |
| 899 | wl->setFocus(Qt::OtherFocusReason); // Why is this here? |
| 900 | return; |
| 901 | } |
| 902 | } |
| 903 | if (m_view->childHasFocus()) { |
| 904 | m_view->gotoNextLine(); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | |
| 909 | DocumentView *DocumentPage::getView() |
| 910 | { |
| 911 | Q_ASSERT(m_view != 0); |
| 912 | return m_view; |
| 913 | } |
| 914 | |
| 915 | void DocumentPage::setTextFont(QFont font) |
| 916 | { |
| 917 | m_view->setFont(font); |
| 918 | |
| 919 | } |
| 920 | |
| 921 | void DocumentPage::setTabStopWidth(int tabWidth) |
| 922 | { |
| 923 | m_view->setTabStopWidth(tabWidth); |
| 924 | } |
| 925 | |
| 926 | void DocumentPage::setTabIndents(bool indents) |
| 927 | { |
| 928 | m_view->setTabIndents(indents); |
| 929 | } |
| 930 | |
| 931 | void DocumentPage::setLineWrapMode(QTextEdit::LineWrapMode wrapLines) |
| 932 | { |
| 933 | m_view->setLineWrapMode(wrapLines); |
| 934 | } |
| 935 | |
| 936 | void DocumentPage::setColorVariables(bool colorVariables) |
| 937 | { |
| 938 | m_view->setColorVariables(colorVariables); |
| 939 | } |
| 940 | |
| 941 | void DocumentPage::setAutoComplete(bool autoComplete, int delay) |
| 942 | { |
| 943 | m_view->setAutoComplete(autoComplete, delay); |
| 944 | } |
| 945 | |
| 946 | void DocumentPage::setAutoParameterMode(bool autoParameterMode) |
| 947 | { |
| 948 | m_view->setAutoParameterMode(autoParameterMode); |
| 949 | } |
| 950 | |
| 951 | QString DocumentPage::getActiveSection() |
| 952 | { |
| 953 | return m_view->getActiveSection(); |
| 954 | } |
| 955 | |
| 956 | QString DocumentPage::getActiveText() |
| 957 | { |
| 958 | return m_view->getActiveText(); |
| 959 | } |
| 960 | |
| 961 | void DocumentPage::print(QPrinter *printer) |
| 962 | { |
| 963 | m_view->print(printer); |
| 964 | } |
| 965 | |
| 966 | void DocumentPage::findReplace() |
| 967 | { |
| 968 | m_view->findReplace(); |
| 969 | } |
| 970 | |
| 971 | void DocumentPage::findString() |
| 972 | { |
| 973 | m_view->findString(); |
| 974 | } |
| 975 | |
| 976 | void DocumentPage::getToIn() |
| 977 | { |
| 978 | m_view->getToIn(); |
| 979 | } |
| 980 | |
| 981 | void DocumentPage::inToGet() |
| 982 | { |
| 983 | m_view->inToGet(); |
| 984 | } |
| 985 | |
| 986 | void DocumentPage::showWidgetTooltips(bool visible) |
| 987 | { |
| 988 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 989 | wl->showWidgetTooltips(visible); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | void DocumentPage::setKeyRepeatMode(bool keyRepeat) |
| 994 | { |
| 995 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 996 | wl->setKeyRepeatMode(keyRepeat); |
| 997 | } |
| 998 | m_console->setKeyRepeatMode(keyRepeat); |
| 999 | } |
| 1000 | |
| 1001 | void DocumentPage::setOpenProperties(bool open) |
| 1002 | { |
| 1003 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 1004 | wl->setProperty("openProperties", open); |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | void DocumentPage::setFontOffset(double offset) |
| 1009 | { |
| 1010 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 1011 | wl->setFontOffset(offset); |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | void DocumentPage::setFontScaling(double offset) |
| 1016 | { |
| 1017 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 1018 | wl->setFontScaling(offset); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | void DocumentPage::setGraphUpdateRate(int rate) { |
| 1023 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 1024 | wl->setUpdateRate(rate); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | void DocumentPage::setConsoleFont(QFont font) |
| 1029 | { |
| 1030 | m_console->setDefaultFont(font); |
| 1031 | } |
| 1032 | |
| 1033 | void DocumentPage::setConsoleColors(QColor fontColor, QColor bgColor) |
| 1034 | { |
| 1035 | m_console->setColors(fontColor, bgColor); |
| 1036 | } |
| 1037 | |
| 1038 | void DocumentPage::setEditorColors(QColor text, QColor bg) { |
| 1039 | this->setProperty("textColor", text); |
| 1040 | this->setProperty("backgroundColor", bg); |
| 1041 | m_view->setColors(text, bg); |
| 1042 | } |
| 1043 | |
| 1044 | void DocumentPage::setScriptDirectory(QString dir) |
| 1045 | { |
| 1046 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 1047 | m_liveFrames[i]->getSheet()->setScriptDirectory(dir); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | void DocumentPage::setDebugLiveEvents(bool debug) |
| 1052 | { |
| 1053 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 1054 | m_liveFrames[i]->getSheet()->setDebug(debug); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | void DocumentPage::setConsoleBufferSize(int size) |
| 1059 | { |
| 1060 | m_csEngine->setConsoleBufferSize(size); |
| 1061 | } |
| 1062 | |
| 1063 | void DocumentPage::setWidgetEnabled(bool enabled) |
| 1064 | { |
| 1065 | // TODO disable widgetLayout if its not being used? |
| 1066 | // m_widgetLayout->setEnabled(enabled); |
| 1067 | m_csEngine->enableWidgets(enabled); |
| 1068 | } |
| 1069 | |
| 1070 | void DocumentPage::useOldFormat(bool use) |
| 1071 | { |
| 1072 | // qDebug() << use; |
| 1073 | saveOldFormat = use; |
| 1074 | } |
| 1075 | |
| 1076 | void DocumentPage::setPythonExecutable(QString pythonExec) |
| 1077 | { |
| 1078 | m_pythonExecutable = pythonExec; |
| 1079 | } |
| 1080 | |
| 1081 | |
| 1082 | void DocumentPage::showLiveEventPanels() |
| 1083 | { |
| 1084 | if (fileName.endsWith(".csd")) { |
| 1085 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 1086 | // qDebug() << "DocumentPage::showLiveEventPanels " << visible << (int) this; |
| 1087 | if (m_liveFrames[i]->isVisible()) |
| 1088 | m_liveFrames[i]->raise(); |
| 1089 | else { |
| 1090 | if (m_liveFrames[i]->getVisibleEnabled()) { |
| 1091 | m_liveFrames[i]->setWindowFlags(Qt::Window); |
| 1092 | m_liveFrames[i]->show(); |
| 1093 | m_liveFrames[i]->raise(); |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | } |
| 1100 | |
| 1101 | void DocumentPage::hideLiveEventPanels() { |
| 1102 | if (fileName.endsWith(".csd")) { |
| 1103 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 1104 | m_liveFrames[i]->setWindowFlags(Qt::Widget); // don't hide |
| 1105 | m_liveFrames[i]->hide(); |
| 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | void DocumentPage::showLiveEventControl(bool visible) { |
| 1111 | if (fileName.endsWith(".csd")) { |
| 1112 | m_liveEventControl->setVisible(visible); |
| 1113 | if (visible) { |
| 1114 | showLiveEventPanels(); |
| 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | void DocumentPage::stopAllSlot() |
| 1120 | { |
| 1121 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 1122 | m_liveFrames[i]->getSheet()->stopAllEvents(); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | void DocumentPage::newPanelSlot() |
| 1127 | { |
| 1128 | newLiveEventPanel(); |
| 1129 | } |
| 1130 | |
| 1131 | void DocumentPage::playPanelSlot(int index) |
| 1132 | { |
| 1133 | m_liveFrames[index]->getSheet()->sendAllEvents(); |
| 1134 | } |
| 1135 | |
| 1136 | void DocumentPage::loopPanelSlot(int index, bool loop) |
| 1137 | { |
| 1138 | m_liveFrames[index]->loopPanel(loop); |
| 1139 | } |
| 1140 | |
| 1141 | void DocumentPage::stopPanelSlot(int index) |
| 1142 | { |
| 1143 | (void) index; |
| 1144 | qDebug() << "Not implemented."; |
| 1145 | } |
| 1146 | |
| 1147 | void DocumentPage::setPanelVisibleSlot(int index, bool visible) |
| 1148 | { |
| 1149 | if (visible) { |
| 1150 | m_liveFrames[index]->setWindowFlags(Qt::Window); |
| 1151 | } |
| 1152 | else { |
| 1153 | m_liveFrames[index]->setWindowFlags(Qt::Widget); |
| 1154 | } |
| 1155 | m_liveFrames[index]->setVisible(visible); |
| 1156 | m_liveFrames[index]->setVisibleEnabled(visible); |
| 1157 | } |
| 1158 | |
| 1159 | void DocumentPage::setPanelSyncSlot(int index, int mode) |
| 1160 | { |
| 1161 | (void) index; |
| 1162 | (void) mode; |
| 1163 | qDebug() << "Not implemented."; |
| 1164 | } |
| 1165 | |
| 1166 | void DocumentPage::setPanelNameSlot(int index, QString name) |
| 1167 | { |
| 1168 | m_liveFrames[index]->setName(name); |
| 1169 | } |
| 1170 | |
| 1171 | void DocumentPage::setPanelTempoSlot(int index, double tempo) |
| 1172 | { |
| 1173 | m_liveFrames[index]->setTempo(tempo); |
| 1174 | } |
| 1175 | |
| 1176 | void DocumentPage::setPanelLoopLengthSlot(int index, double length) |
| 1177 | { |
| 1178 | m_liveFrames[index]->setLoopLength(length); |
| 1179 | } |
| 1180 | |
| 1181 | void DocumentPage::setPanelLoopRangeSlot(int index, double start, double end) |
| 1182 | { |
| 1183 | m_liveFrames[index]->setLoopRange(start,end); |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | void DocumentPage::registerButton(QuteButton *b) |
| 1188 | { |
| 1189 | // qDebug(); |
| 1190 | connect(b, SIGNAL(play()), static_cast<CsoundQt *>(parent()), SLOT(play())); |
| 1191 | connect(b, SIGNAL(render()), static_cast<CsoundQt *>(parent()), SLOT(render())); |
| 1192 | connect(b, SIGNAL(pause()), static_cast<CsoundQt *>(parent()), SLOT(pause())); |
| 1193 | connect(b, SIGNAL(stop()), static_cast<CsoundQt *>(parent()), SLOT(stop())); |
| 1194 | } |
| 1195 | |
| 1196 | void DocumentPage::queueMidiIn(std::vector< unsigned char > *message) |
| 1197 | { |
| 1198 | WidgetLayout *d = m_widgetLayouts[0]; |
| 1199 | unsigned int nBytes = message->size(); |
| 1200 | if (nBytes > 3 || nBytes < 1) { |
| 1201 | qDebug() << "MIDI message ignored. nBytes=" << nBytes << " status =" << (int)message->at(0); |
| 1202 | return; |
| 1203 | } |
| 1204 | if ( (((d->midiWriteCounter + 1) % QCS_MAX_MIDI_QUEUE) != d->midiReadCounter) && acceptsMidiCC) { |
| 1205 | int index = d->midiWriteCounter; |
| 1206 | for (unsigned int i = 0; i < nBytes; i++) { |
| 1207 | d->midiQueue[index][i] = (int)message->at(i); |
| 1208 | } |
| 1209 | d->midiWriteCounter = (d->midiWriteCounter + 1) % QCS_MAX_MIDI_QUEUE; |
| 1210 | } |
| 1211 | m_csEngine->queueMidiIn(message); |
| 1212 | } |
| 1213 | |
| 1214 | void DocumentPage::queueVirtualMidiIn(std::vector< unsigned char > &message) |
| 1215 | { |
| 1216 | m_csEngine->queueVirtualMidiIn(message); |
| 1217 | } |
| 1218 | |
| 1219 | void DocumentPage::init(QWidget *parent, OpEntryParser *opcodeTree) |
| 1220 | { |
| 1221 | fileName = ""; |
| 1222 | companionFile = ""; |
| 1223 | askForFile = true; |
| 1224 | readOnly = false; |
| 1225 | |
| 1226 | //TODO this should be set from CsoundQt configuration |
| 1227 | saveLiveEvents = true; |
| 1228 | |
| 1229 | m_view = new DocumentView(parent, opcodeTree); |
| 1230 | |
| 1231 | //connect(m_view, SIGNAL(evaluate(QString)), this, SLOT(evaluate(QString))); |
| 1232 | connect(m_view,SIGNAL(setHelp()), this, SLOT(setHelp())); |
| 1233 | connect(m_view, SIGNAL(closeExtraPanels()), this, SLOT(closeExtraPanels())); |
| 1234 | |
| 1235 | // For logging of Csound output to file |
| 1236 | connect(m_console, SIGNAL(logMessage(QString)), |
| 1237 | static_cast<CsoundQt *>(parent), SLOT(logMessage(QString))); |
| 1238 | |
| 1239 | // m_widgetLayout->show(); |
| 1240 | m_liveEventControl = new LiveEventControl(parent); |
| 1241 | m_liveEventControl->hide(); |
| 1242 | connect(m_liveEventControl, SIGNAL(closed()), this, SLOT(liveEventControlClosed())); |
| 1243 | connect(m_liveEventControl, SIGNAL(stopAll()), this, SLOT(stopAllSlot())); |
| 1244 | connect(m_liveEventControl, SIGNAL(newPanel()), this, SLOT(newPanelSlot())); |
| 1245 | connect(m_liveEventControl, SIGNAL(playPanel(int)), this, SLOT(playPanelSlot(int))); |
| 1246 | connect(m_liveEventControl, SIGNAL(loopPanel(int,bool)), this, SLOT(loopPanelSlot(int,bool))); |
| 1247 | connect(m_liveEventControl, SIGNAL(stopPanel(int)), this, SLOT(stopPanelSlot(int))); |
| 1248 | connect(m_liveEventControl, SIGNAL(setPanelVisible(int,bool)), |
| 1249 | this, SLOT(setPanelVisibleSlot(int,bool))); |
| 1250 | connect(m_liveEventControl, SIGNAL(setPanelSync(int,int)), this, SLOT(setPanelSyncSlot(int,int))); |
| 1251 | connect(m_liveEventControl, SIGNAL(setPanelNameSignal(int,QString)), |
| 1252 | this, SLOT(setPanelNameSlot(int,QString))); |
| 1253 | connect(m_liveEventControl, SIGNAL(setPanelTempoSignal(int,double)), |
| 1254 | this, SLOT(setPanelTempoSlot(int,double))); |
| 1255 | connect(m_liveEventControl, SIGNAL(setPanelLoopLengthSignal(int,double)), |
| 1256 | this, SLOT(setPanelLoopLengthSlot(int,double))); |
| 1257 | connect(m_liveEventControl, SIGNAL(setPanelLoopRangeSignal(int,double,double)), |
| 1258 | this, SLOT(setPanelLoopRangeSlot(int,double,double))); |
| 1259 | connect(m_liveEventControl, SIGNAL(hidePanels()), this, SLOT(hideLiveEventPanels()) ); |
| 1260 | |
| 1261 | // Connect for clearing marked lines and letting inspector know text has changed |
| 1262 | connect(m_view, SIGNAL(contentsChanged()), this, SLOT(textChanged())); |
| 1263 | |
| 1264 | |
| 1265 | connect(m_csEngine, SIGNAL(errorLines(QList<QPair<int, QString> >)), |
| 1266 | m_view, SLOT(markErrorLines(QList<QPair<int, QString> >))); |
| 1267 | connect(m_csEngine, SIGNAL(stopSignal()), |
| 1268 | this, SLOT(perfEnded())); |
| 1269 | |
| 1270 | // detachWidgets(); |
| 1271 | saveOldFormat = false; // don't save Mac widgets by default |
| 1272 | m_pythonRunning = false; |
| 1273 | } |
| 1274 | |
| 1275 | void DocumentPage::deleteAllLiveEvents() |
| 1276 | { |
| 1277 | for (int i = 0; i < m_liveFrames.size(); i++) { |
| 1278 | deleteLiveEventPanel(m_liveFrames[i]); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | WidgetLayout* DocumentPage::newWidgetLayout() |
| 1283 | { |
| 1284 | WidgetLayout* wl = BaseDocument::newWidgetLayout(); |
| 1285 | connect(wl, SIGNAL(changed()), this, SLOT(setModified())); |
| 1286 | connect(wl, SIGNAL(widgetSelectedSignal(QuteWidget*)), |
| 1287 | this, SLOT(passSelectedWidget(QuteWidget*))); |
| 1288 | connect(wl, SIGNAL(widgetUnselectedSignal(QuteWidget*)), |
| 1289 | this, SLOT(passUnselectedWidget(QuteWidget*))); |
| 1290 | // connect(wl, SIGNAL(setWidgetClipboardSignal(QString)), |
| 1291 | // this, SLOT(setWidgetClipboard(QString))); |
| 1292 | connect(wl,SIGNAL(showMidiLearn(QuteWidget *)),this, SLOT(showMidiLearn(QuteWidget *))); |
| 1293 | return wl; |
| 1294 | } |
| 1295 | |
| 1296 | int DocumentPage::play(CsoundOptions *options) |
| 1297 | { |
| 1298 | if (fileName.endsWith(".py")) { |
| 1299 | m_console->reset(); // Clear consoles |
| 1300 | return runPython(); |
| 1301 | } |
| 1302 | else { |
| 1303 | m_view->unmarkErrorLines(); // Clear error lines when running |
| 1304 | return BaseDocument::play(options); |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | void DocumentPage::stop() |
| 1309 | { |
| 1310 | BaseDocument::stop(); |
| 1311 | if (m_pythonRunning == true) { |
| 1312 | m_pythonRunning = false; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | int DocumentPage::record(int format) |
| 1317 | { |
| 1318 | #ifdef PERFTHREAD_RECORD |
| 1319 | if (fileName.startsWith(":/")) { |
| 1320 | QMessageBox::critical(static_cast<QWidget *>(parent()), |
| 1321 | tr("CsoundQt"), |
| 1322 | tr("You must save the examples to use Record."), |
| 1323 | QMessageBox::Ok); |
| 1324 | return -1; |
| 1325 | } |
| 1326 | int number = 0; |
| 1327 | QString recName = fileName + "-000.wav"; |
| 1328 | while (QFile::exists(recName)) { |
| 1329 | number++; |
| 1330 | recName = fileName + "-"; |
| 1331 | if (number < 10) |
| 1332 | recName += "0"; |
| 1333 | if (number < 100) |
| 1334 | recName += "0"; |
| 1335 | recName += QString::number(number) + ".wav"; |
| 1336 | } |
| 1337 | emit setCurrentAudioFile(recName); |
| 1338 | return m_csEngine->startRecording(format, recName); |
| 1339 | #else |
| 1340 | (void) format; |
| 1341 | QMessageBox::warning(nullptr, tr("Recording not possible"), tr("This version of CsoundQt was not built with recording support.")); |
| 1342 | return 0; |
| 1343 | #endif |
| 1344 | } |
| 1345 | |
| 1346 | void DocumentPage::perfEnded() |
| 1347 | { |
| 1348 | emit stopSignal(); |
| 1349 | } |
| 1350 | |
| 1351 | void DocumentPage::setHelp() |
| 1352 | { |
| 1353 | emit setHelpSignal(); |
| 1354 | } |
| 1355 | |
| 1356 | int DocumentPage::runPython() |
| 1357 | { |
| 1358 | QProcess p; |
| 1359 | QDir::setCurrent(fileName.mid(fileName.lastIndexOf("/") + 1)); |
| 1360 | p.start(m_pythonExecutable + " \"" + fileName + "\""); |
| 1361 | m_pythonRunning = true; |
| 1362 | while (!p.waitForFinished (100) && m_pythonRunning) { |
| 1363 | // TODO make stop button stop python too |
| 1364 | QByteArray sout = p.readAllStandardOutput(); |
| 1365 | QByteArray serr = p.readAllStandardError(); |
| 1366 | m_console->appendMessage(sout); |
| 1367 | m_console->appendMessage(serr); |
| 1368 | qApp->processEvents(); |
| 1369 | } |
| 1370 | QByteArray sout = p.readAllStandardOutput(); |
| 1371 | QByteArray serr = p.readAllStandardError(); |
| 1372 | m_console->appendMessage(sout); |
| 1373 | m_console->appendMessage(serr); |
| 1374 | emit stopSignal(); |
| 1375 | return p.exitCode(); |
| 1376 | } |
| 1377 | |
| 1378 | void DocumentPage::closeExtraPanels() |
| 1379 | { |
| 1380 | emit closeExtraPanelsSignal(); |
| 1381 | } |
| 1382 | |
| 1383 | void DocumentPage::showWidgets(bool show) |
| 1384 | { |
| 1385 | if (!show || (!fileName.endsWith(".csd") && !fileName.isEmpty())) { |
| 1386 | hideWidgets(); |
| 1387 | return; |
| 1388 | } |
| 1389 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 1390 | wl->adjustWidgetSize(); |
| 1391 | wl->setVisible(true); |
| 1392 | wl->raise(); |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | void DocumentPage::hideWidgets() |
| 1397 | { |
| 1398 | // qDebug(); |
| 1399 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 1400 | wl->setVisible(false); |
| 1401 | } |
| 1402 | } |
| 1403 | |
| 1404 | void DocumentPage::passSelectedWidget(QuteWidget *widget) // necessary only when ML is opened from edit menu and a widget is selected. |
| 1405 | { |
| 1406 | m_midiLearn->setCurrentWidget(widget); |
| 1407 | } |
| 1408 | |
| 1409 | void DocumentPage::passUnselectedWidget(QuteWidget *widget) // necessary only when ML is opened from edit menu and a widget is selected. |
| 1410 | { |
| 1411 | // TODO: Better options for unselecting widgets. |
| 1412 | (void) widget; |
| 1413 | m_midiLearn->setCurrentWidget(nullptr); |
| 1414 | } |
| 1415 | |
| 1416 | void DocumentPage::showMidiLearn(QuteWidget *widget) |
| 1417 | { |
| 1418 | //qDebug(); |
| 1419 | m_midiLearn->setCurrentWidget(widget); |
| 1420 | m_midiLearn->setModal(true); // not to leave the dialog floating around |
| 1421 | m_midiLearn->show(); |
| 1422 | } |
| 1423 | |
| 1424 | void DocumentPage::applyMacOptions(QStringList options) |
| 1425 | { |
| 1426 | int index = options.indexOf(QRegExp("WindowBounds: .*")); |
| 1427 | if (index > 0) { |
| 1428 | QString line = options[index]; |
| 1429 | QStringList values = line.split(" "); |
| 1430 | values.removeFirst(); //remove property name |
| 1431 | // FIXME allow multiple layouts |
| 1432 | QRect r(values[0].toInt(),values[1].toInt(), |
| 1433 | values[2].toInt(), values[3].toInt()); |
| 1434 | if (r.isValid()) { |
| 1435 | m_widgetLayouts[0]->setOuterGeometry(r); |
| 1436 | } |
| 1437 | } |
| 1438 | else { |
| 1439 | qDebug("no Geometry!"); |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | void DocumentPage::setMacOption(QString option, QString newValue) |
| 1444 | { |
| 1445 | if (!option.endsWith(":")) |
| 1446 | option += ":"; |
| 1447 | if (!option.endsWith(" ")) |
| 1448 | option += " "; |
| 1449 | int index = m_macOptions.indexOf(QRegExp(option + ".*")); |
| 1450 | if (index < 0) { |
| 1451 | qDebug("Option not found!"); |
| 1452 | return; |
| 1453 | } |
| 1454 | m_macOptions[index] = option + newValue; |
| 1455 | qDebug("%s", m_macOptions[index].toLocal8Bit().constData()); |
| 1456 | } |
| 1457 | |
| 1458 | void DocumentPage::setWidgetEditMode(bool active) |
| 1459 | { |
| 1460 | // qDebug(); |
| 1461 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 1462 | wl->setEditMode(active); |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | //void DocumentPage::toggleWidgetEditMode() |
| 1467 | //{ |
| 1468 | // qDebug() <<; |
| 1469 | // m_widgetLayout->toggleEditMode(); |
| 1470 | //} |
| 1471 | |
| 1472 | void DocumentPage::duplicateWidgets() |
| 1473 | { |
| 1474 | foreach (WidgetLayout *wl, m_widgetLayouts) { |
| 1475 | if (wl->hasFocus()) { |
| 1476 | wl->duplicate(); |
| 1477 | } |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | void DocumentPage::jumpToLine(int line) |
| 1482 | { |
| 1483 | // qDebug() << line; |
| 1484 | m_view->jumpToLine(line); |
| 1485 | } |
| 1486 | |
| 1487 | void DocumentPage::comment() |
| 1488 | { |
| 1489 | // qDebug(); |
| 1490 | m_view->comment(); |
| 1491 | } |
| 1492 | |
| 1493 | void DocumentPage::uncomment() |
| 1494 | { |
| 1495 | m_view->uncomment(); |
| 1496 | } |
| 1497 | |
| 1498 | void DocumentPage::indent() |
| 1499 | { |
| 1500 | m_view->indent(); |
| 1501 | } |
| 1502 | |
| 1503 | void DocumentPage::unindent() |
| 1504 | { |
| 1505 | m_view->unindent(); |
| 1506 | } |
| 1507 | |
| 1508 | void DocumentPage::killToEnd() |
| 1509 | { |
| 1510 | m_view->killToEnd(); |
| 1511 | } |
| 1512 | |
| 1513 | void DocumentPage::killLine() |
| 1514 | { |
| 1515 | m_view->killLine(); |
| 1516 | } |
| 1517 | |
| 1518 | void DocumentPage::gotoLine(int line) |
| 1519 | { |
| 1520 | m_view->jumpToLine(line); |
| 1521 | // m_view->gotoLine(line); |
| 1522 | } |
| 1523 | |
| 1524 | void DocumentPage::gotoLineDialog() |
| 1525 | { |
| 1526 | m_view->gotoLineDialog(); |
| 1527 | } |
| 1528 | |
| 1529 | void DocumentPage::goBackToPreviousPosition() { |
| 1530 | m_view->goBackToPreviousPosition(); |
| 1531 | } |
| 1532 | |
| 1533 | void DocumentPage::setViewMode(int mode) |
| 1534 | { |
| 1535 | m_view->setViewMode(mode); |
| 1536 | // this->setHighlightingTheme(m_colorTheme); |
| 1537 | } |
| 1538 | |
| 1539 | void DocumentPage::showOrc(bool show) |
| 1540 | { |
| 1541 | m_view->showOrc(show); |
| 1542 | } |
| 1543 | |
| 1544 | void DocumentPage::showScore(bool show) |
| 1545 | { |
| 1546 | m_view->showScore(show); |
| 1547 | } |
| 1548 | |
| 1549 | void DocumentPage::showOptions(bool show) |
| 1550 | { |
| 1551 | m_view->showOptions(show); |
| 1552 | } |
| 1553 | |
| 1554 | void DocumentPage::showFileB(bool show) |
| 1555 | { |
| 1556 | m_view->showFileB(show); |
| 1557 | } |
| 1558 | |
| 1559 | void DocumentPage::showOther(bool show) |
| 1560 | { |
| 1561 | m_view->showOther(show); |
| 1562 | } |
| 1563 | |
| 1564 | void DocumentPage::showOtherCsd(bool show) |
| 1565 | { |
| 1566 | m_view->showOtherCsd(show); |
| 1567 | } |
| 1568 | |
| 1569 | void DocumentPage::showWidgetEdit(bool show) |
| 1570 | { |
| 1571 | m_view->showWidgetEdit(show); |
| 1572 | } |
| 1573 | |
| 1574 | void DocumentPage::newLiveEventPanel(QString text) |
| 1575 | { |
| 1576 | LiveEventFrame *e = createLiveEventPanel(text); |
| 1577 | m_liveEventControl->appendPanel(e); |
| 1578 | e->setWindowFlags(Qt::Window); |
| 1579 | e->markLoop(0,0); |
| 1580 | // e->setVisible(false); |
| 1581 | e->show(); //Assume that since slot was called must be visible |
| 1582 | } |
| 1583 | |
| 1584 | LiveEventFrame * DocumentPage::createLiveEventPanel(QString text) |
| 1585 | { |
| 1586 | // qDebug()"; |
| 1587 | LiveEventFrame *e = new LiveEventFrame("Live Event", m_liveEventControl, Qt::Window); |
| 1588 | // e->setVisible(false); |
| 1589 | // e->setAttribute(Qt::WA_DeleteOnClose, false); |
| 1590 | e->getSheet()->setRowCount(1); |
| 1591 | e->getSheet()->setColumnCount(6); |
| 1592 | |
| 1593 | if (!text.isEmpty()) { |
| 1594 | e->setFromText(text); |
| 1595 | } |
| 1596 | m_liveFrames.append(e); |
| 1597 | // connect(e, SIGNAL(closed()), this, SLOT(liveEventFrameClosed())); |
| 1598 | connect(e, SIGNAL(newFrameSignal(QString)), this, SLOT(newLiveEventPanel(QString))); |
| 1599 | connect(e, SIGNAL(deleteFrameSignal(LiveEventFrame *)), this, SLOT(deleteLiveEventPanel(LiveEventFrame *))); |
| 1600 | connect(e, SIGNAL(renamePanel(LiveEventFrame *, QString)), |
| 1601 | this, SLOT(renamePanel(LiveEventFrame *,QString))); |
| 1602 | connect(e, SIGNAL(setLoopRangeFromPanel(LiveEventFrame *, double, double)), |
| 1603 | this, SLOT(setPanelLoopRange(LiveEventFrame *,double, double))); |
| 1604 | connect(e, SIGNAL(setTempoFromPanel(LiveEventFrame *, double)), |
| 1605 | this, SLOT(setPanelTempo(LiveEventFrame *,double))); |
| 1606 | connect(e, SIGNAL(setLoopEnabledFromPanel(LiveEventFrame *, bool)), |
| 1607 | this, SLOT(setPanelLoopEnabled(LiveEventFrame *,bool))); |
| 1608 | connect(e, SIGNAL(setLoopLengthFromPanel(LiveEventFrame *, double)), |
| 1609 | this, SLOT(setPanelLoopLength(LiveEventFrame *,double))); |
| 1610 | connect(e->getSheet(), SIGNAL(sendEvent(QString)),this,SLOT(queueEvent(QString))); |
| 1611 | connect(e->getSheet(), SIGNAL(modified()),this,SLOT(setModified())); |
| 1612 | return e; |
| 1613 | } |
| 1614 | |
| 1615 | void DocumentPage::deleteLiveEventPanel(LiveEventFrame *frame) |
| 1616 | { |
| 1617 | // qDebug() << "deleteLiveEventPanel(LiveEventFrame *frame)"; |
| 1618 | int index = m_liveFrames.indexOf(frame); |
| 1619 | if (index >= 0) { // Frames should already have been deleted by parent document view widget |
| 1620 | if (frame != 0) { |
| 1621 | disconnect(frame, 0,0,0); |
| 1622 | disconnect(frame->getSheet(), 0,0,0); |
| 1623 | m_liveFrames.removeAt(index); |
| 1624 | m_liveEventControl->removePanel(index); |
| 1625 | frame->close(); |
| 1626 | } |
| 1627 | } |
| 1628 | else { |
| 1629 | qDebug() << "DocumentPage::deleteLiveEventPanel frame not found"; |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | |
| 1634 | void DocumentPage::textChanged() |
| 1635 | { |
| 1636 | // setModified(true); |
| 1637 | m_parseUdosNeeded = true; |
| 1638 | // This signal triggers an inspector update |
| 1639 | emit currentTextUpdated(); |
| 1640 | } |
| 1641 | |
| 1642 | //void DocumentPage::liveEventFrameClosed() |
| 1643 | //{ |
| 1644 | //// qDebug() << "DocumentPage::liveEventFrameClosed()"; |
| 1645 | // LiveEventFrame *e = dynamic_cast<LiveEventFrame *>(QObject::sender()); |
| 1646 | //// if (e != 0) { // This shouldn't really be necessary but just in case |
| 1647 | // bool shown = false; |
| 1648 | // for (int i = 0; i < m_liveFrames.size(); i++) { |
| 1649 | // if (m_liveFrames[i]->isVisible() |
| 1650 | // && m_liveFrames[i] != e) // frame that called has not been called yet |
| 1651 | // shown = true; |
| 1652 | // } |
| 1653 | // emit liveEventsVisible(shown); |
| 1654 | //// } |
| 1655 | //} |
| 1656 | |
| 1657 | void DocumentPage::liveEventControlClosed() |
| 1658 | { |
| 1659 | qDebug()<< "DocumentPage::liveEventControlClosed()"; |
| 1660 | showLiveEventControl(false); |
| 1661 | } |
| 1662 | |
| 1663 | void DocumentPage::renamePanel(LiveEventFrame *panel,QString newName) |
| 1664 | { |
| 1665 | int index = m_liveFrames.indexOf(panel); |
| 1666 | if (index >= 0) { |
| 1667 | m_liveEventControl->renamePanel(index, newName); |
| 1668 | panel->setName(newName); |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | void DocumentPage::setPanelLoopRange(LiveEventFrame *panel, double start, double end) |
| 1673 | { |
| 1674 | int index = m_liveFrames.indexOf(panel); |
| 1675 | if (index >= 0) { |
| 1676 | m_liveEventControl->setPanelLoopRange(index, start, end); |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | void DocumentPage::setPanelLoopLength(LiveEventFrame *panel, double length) |
| 1681 | { |
| 1682 | int index = m_liveFrames.indexOf(panel); |
| 1683 | if (index >= 0) { |
| 1684 | m_liveEventControl->setPanelLoopLength(index, length); |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | void DocumentPage::setPanelTempo(LiveEventFrame *panel, double tempo) |
| 1689 | { |
| 1690 | int index = m_liveFrames.indexOf(panel); |
| 1691 | if (index >= 0) { |
| 1692 | m_liveEventControl->setPanelTempo(index, tempo); |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | void DocumentPage::evaluatePython(QString code) |
| 1697 | { |
| 1698 | emit evaluatePythonSignal(code); |
| 1699 | } |
| 1700 | |
| 1701 | |
| 1702 | void DocumentPage::setPanelLoopEnabled(LiveEventFrame *panel, bool enabled) |
| 1703 | { |
| 1704 | int index = m_liveFrames.indexOf(panel); |
| 1705 | if (index >= 0) { |
| 1706 | m_liveEventControl->setPanelLoopEnabled(index, enabled); |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | void DocumentPage::setHighlightingTheme(QString theme) { |
| 1711 | if(m_view == nullptr) |
| 1712 | return; |
| 1713 | m_colorTheme = theme; |
| 1714 | bool modified = isModified(); |
| 1715 | m_view->setTheme(theme); |
| 1716 | setModified(modified); |
| 1717 | auto defaultFormat = m_view->getDefaultFormat(); |
| 1718 | this->setEditorColors(defaultFormat.foreground().color(), |
| 1719 | defaultFormat.background().color()); |
| 1720 | /* |
| 1721 | m_console->setColors(defaultFormat.foreground().color(), |
| 1722 | defaultFormat.background().color()); |
| 1723 | */ |
| 1724 | } |
| 1725 | |
| 1726 | void DocumentPage::enableScoreSyntaxHighlighting(bool status) { |
| 1727 | m_view->enableScoreSyntaxHighlighting(status); |
| 1728 | } |
| 1729 | |
| 1730 | void DocumentPage::setParsedUDOs(QStringList udos) { |
| 1731 | m_view->setParsedUDOs(udos); |
| 1732 | } |
| 1733 | |
| 1734 | void DocumentPage::parseUdos(bool force) { |
| 1735 | if(!m_parseUdosNeeded && !force) |
| 1736 | return; |
| 1737 | auto text = this->getBasicText(); |
| 1738 | QRegularExpressionMatchIterator i = regexUdo.globalMatch(text); |
| 1739 | int numUdos = m_parsedUdos.size(); |
| 1740 | m_parsedUdos.clear(); |
| 1741 | while(i.hasNext()) { |
| 1742 | QRegularExpressionMatch match = i.next(); |
| 1743 | QString udoName = match.captured(1); |
| 1744 | m_parsedUdos.append(udoName); |
| 1745 | } |
| 1746 | auto highlighter = m_view->getHighlighter(); |
| 1747 | highlighter->setUDOs(m_parsedUdos); |
| 1748 | if(numUdos != m_parsedUdos.size()) { |
| 1749 | highlighter->rehighlight(); |
| 1750 | } |
| 1751 | m_parseUdosNeeded = false; |
| 1752 | } |
| 1753 | |
| 1754 | void DocumentPage::autocomplete() { |
| 1755 | m_view->autoCompleteAtCursor(); |
| 1756 | } |