Debian Codegraph @

src/qutecsound.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2008, 2009 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 "configdialog.h"
24 #include "console.h"
25 #include "dockhelp.h"
26 #include "documentpage.h"
27 #include "highlighter.h"
28 #include "inspector.h"
29 #include "opentryparser.h"
30 #include "options.h"
31 #include "qutecsound.h"
32 #include "widgetpanel.h"
33 #include "utilitiesdialog.h"
34 #include "graphicwindow.h"
35 #include "keyboardshortcuts.h"
36 #include "liveeventframe.h"
37 #include "about.h"
38 #include "eventsheet.h"
39 #include "appwizard.h"
40 #include "midihandler.h"
41 #include "midilearndialog.h"
42 #include "livecodeeditor.h"
43 #include "csoundhtmlview.h"
44 #include "risset.h"
45 #include <thread>
46
47
48 #ifdef Q_OS_WIN
49 #include <ole2.h> // for OleInitialize() FLTK bug workaround
50 #endif
51
52
53 #ifdef QCS_PYTHONQT
54 #include "pythonconsole.h"
55 #endif
56 #ifdef QCS_DEBUGGER
57 #include "debugpanel.h"
58 #endif
59
60 // One day remove these from here for nicer abstraction....
61 #include "csoundengine.h"
62 #include "documentview.h"
63 #include "widgetlayout.h"
64
65 #ifdef QCS_RTMIDI
66 #include "RtMidi.h"
67 #endif
68
69 #ifdef Q_OS_WIN32
70 static const QString SCRIPT_NAME = "csoundqt_run_script-XXXXXX.bat";
71 #else
72 static const QString SCRIPT_NAME = "csoundqt_run_script-XXXXXX.sh";
73 #endif
74
75 #define MAX_THREAD_COUNT 32 // to enable up to MAX_THREAD_COUNT documents/consoles have messageDispatchers
76
77 #define INSPECTOR_UPDATE_PERIOD_MS 3000
78
79
80 CsoundQt::CsoundQt(QStringList fileNames)
81 {
82 m_closing = false;
83 m_resetPrefs = false;
84 utilitiesDialog = NULL;
85 curCsdPage = -1;
86 configureTab = 0;
87 // initialDir = QDir::current().path();
88 initialDir = QCoreApplication::applicationDirPath();
89 setWindowTitle("CsoundQt[*]");
90 // resize(780,550);
91 m_fullScreenComponent = QString();
92 #ifdef QCS_USE_NEW_ICON
93 // setWindowIcon(QIcon(":/images/qtcs-alt.svg"));
94 setWindowIcon(QIcon(":/images/qtcs-alt.png"));
95 #else
96 setWindowIcon(QIcon(":/images/qtcs.png"));
97 #endif
98 //Does this take care of the decimal separator for different locales?
99 QLocale::setDefault(QLocale::system());
100 curPage = -1;
101 m_options = new Options(&m_configlists);
102
103 #ifdef Q_OS_MAC
104 // this->setUnifiedTitleAndToolBarOnMac(true);
105 // The unified toolbar has rendering problems if opengl is used, which happens
106 // when any QtQuick widget is in use - that is the case with the MIDI keyboard widgetu
107 #endif
108
109
110 // Create GUI panels
111
112 helpPanel = new DockHelp(this);
113 helpPanel->setAllowedAreas(Qt::RightDockWidgetArea |
114 Qt::BottomDockWidgetArea |
115 Qt::LeftDockWidgetArea);
116 helpPanel->setObjectName("helpPanel");
117
118 // QLabel *helpTitle = new QLabel("Help", helpPanel);
119 // helpTitle->setStyleSheet("qproperty-alignment: AlignCenter; padding: 3px; font-size: 9pt; ");
120 // helpPanel->setTitleBarWidget(helpTitle);
121
122 helpPanel->show();
123 addDockWidget(Qt::RightDockWidgetArea, helpPanel);
124
125 #ifdef Q_OS_WIN
126 // Call OleInitialize to enable clipboard together with FLTK libraries
127 HRESULT result = OleInitialize(NULL);
128 if (result) {
129 qDebug()<<"Problem with OleInitialization" << result;
130 }
131 #endif
132
133 widgetPanel = new WidgetPanel(this);
134 widgetPanel->setFocusPolicy(Qt::NoFocus);
135 widgetPanel->setAllowedAreas(Qt::RightDockWidgetArea |
136 Qt::BottomDockWidgetArea |
137 Qt::LeftDockWidgetArea);
138 widgetPanel->setObjectName("widgetPanel");
139 // Hide until CsoundQt has finished loading
140 widgetPanel->hide();
141 // widgetPanel->show();
142
143 addDockWidget(Qt::RightDockWidgetArea, widgetPanel);
144 tabifyDockWidget(helpPanel, widgetPanel);
145
146 m_console = new DockConsole(this);
147 m_console->setObjectName("m_console");
148 m_console->setFeatures(QDockWidget::DockWidgetMovable |
149 QDockWidget::DockWidgetClosable);
150 QLabel *consoleTitle = new QLabel("Console", m_console);
151 consoleTitle->setStyleSheet("qproperty-alignment: AlignCenter; padding: 3px; font-size: 9pt; ");
152 m_console->setTitleBarWidget(consoleTitle);
153
154 // m_console->setAllowedAreas(Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
155 // addDockWidget(Qt::BottomDockWidgetArea, m_console);
156 addDockWidget(Qt::RightDockWidgetArea, m_console);
157
158 m_inspector = new Inspector(this);
159 m_inspector->setObjectName("Inspector");
160 m_inspector->parseText(QString());
161 addDockWidget(Qt::LeftDockWidgetArea, m_inspector);
162 m_inspector->hide();
163
164 #ifdef QCS_DEBUGGER
165 m_debugPanel = new DebugPanel(this);
166 m_debugPanel->setObjectName("Debug Panel");
167 m_debugPanel->hide();
168 connect(m_debugPanel, SIGNAL(runSignal()), this, SLOT(runDebugger()));
169 connect(m_debugPanel, SIGNAL(pauseSignal()), this, SLOT(pauseDebugger()));
170 connect(m_debugPanel, SIGNAL(continueSignal()), this, SLOT(continueDebugger()));
171 connect(m_debugPanel, SIGNAL(addInstrumentBreakpoint(double, int)),
172 this, SLOT(addInstrumentBreakpoint(double, int)));
173 connect(m_debugPanel, SIGNAL(removeInstrumentBreakpoint(double)),
174 this, SLOT(removeInstrumentBreakpoint(double)));
175 connect(m_debugPanel, SIGNAL(addBreakpoint(int, int, int)),
176 this, SLOT(addBreakpoint(int, int, int)));
177 connect(m_debugPanel, SIGNAL(removeBreakpoint(int, int)),
178 this, SLOT(removeBreakpoint(int, int)));
179 addDockWidget(Qt::RightDockWidgetArea, m_debugPanel);
180 m_debugEngine = NULL;
181 #endif
182
183 #ifdef QCS_PYTHONQT
184 m_pythonConsole = new PythonConsole(this);
185 addDockWidget(Qt::LeftDockWidgetArea, m_pythonConsole);
186 m_pythonConsole->setObjectName("Python Console");
187 m_pythonConsole->show();
188 #endif
189
190 m_scratchPad = new QDockWidget(this);
191 addDockWidget(Qt::LeftDockWidgetArea, m_scratchPad);
192 m_scratchPad->setObjectName("Interactive Code Pad");
193 m_scratchPad->setWindowTitle(tr("Interactive Code Pad"));
194 m_scratchPad->hide();
195 connect(helpPanel, SIGNAL(openManualExample(QString)), this, SLOT(openManualExample(QString)));
196
197 QSettings settings("csound", "qutecsound");
198 settings.beginGroup("GUI");
199 m_options->theme = settings.value("theme", "breeze").toString();
200 helpPanel->setIconTheme(m_options->theme);
201
202 if(settings.contains("windowState")) {
203 restoreState(settings.value("windowState").toByteArray());
204 }
205 settings.endGroup();
206
207 settings.beginGroup("Options");
208 settings.beginGroup("Editor");
209 // necessary to get it before htmlview is created
210 m_options->debugPort = settings.value("debugPort", 34711).toInt();
211 m_options->highlightingTheme = settings.value("higlightingTheme", "light").toString();
212 settings.endGroup();
213
214 m_server = new QLocalServer();
215 connect(m_server, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
216
217 #if defined(QCS_QTHTML)
218 #ifdef USE_WEBENGINE // set the remote debugging port for chromium based web browser here
219 //TODO: change it when user changes
220 if (m_options->debugPort) {
221 qDebug()<<"Set port "<< m_options->debugPort << " for remote html debugging";
222 qputenv("QTWEBENGINE_REMOTE_DEBUGGING",
223 QString::number(m_options->debugPort).toLocal8Bit().data() );
224 }
225
226 #endif
227 csoundHtmlView = new CsoundHtmlView(this);
228 csoundHtmlView->setFocusPolicy(Qt::NoFocus);
229 csoundHtmlView->setAllowedAreas(Qt::RightDockWidgetArea |
230 Qt::BottomDockWidgetArea |
231 Qt::LeftDockWidgetArea);
232 csoundHtmlView->setObjectName("csoundHtmlView");
233 csoundHtmlView->setWindowTitle(tr("HTML View"));
234 csoundHtmlView->setOptions(m_options);
235 addDockWidget(Qt::LeftDockWidgetArea, csoundHtmlView);
236 csoundHtmlView->hide();
237 #endif
238
239 focusMapper = new QSignalMapper(this);
240 createActions(); // Must be before readSettings: this sets default shortcuts
241 createStatusBar();
242 createToolBars();
243 readSettings();
244 createMenus(); // creating menu must be after readSettings. probably create Status- and toolbars, too?
245 this->setToolbarIconSize(m_options->toolbarIconSize);
246
247 // this section was above before, check that it does not create problems...
248 // Later: find a way to recreate Midi Handler, if API jack/alsa or similar is changed
249 midiHandler = new MidiHandler(m_options->rtMidiApi, this);
250 m_midiLearn = new MidiLearnDialog(this);
251 m_midiLearn->setModal(false);
252 midiHandler->setMidiLearner(m_midiLearn);
253
254 // Must be after readSettings() to save last state // was: isVisible()
255 // in some reason reported always false
256 bool widgetsVisible = !widgetPanel->isHidden();
257 // To avoid showing and reshowing panels during initial load
258 showWidgetsAct->setChecked(false);
259 // Must be after readSettings() to save last state
260 bool scratchPadVisible = !m_scratchPad->isHidden();
261 if (scratchPadVisible)
262 m_scratchPad->hide(); // Hide until CsoundQt has finished loading
263 documentTabs = new QTabWidget (this);
264 documentTabs->setTabsClosable(true);
265 documentTabs->setMovable(true);
266 connect(documentTabs, SIGNAL(currentChanged(int)), this, SLOT(changePage(int)));
267 // To force changing to clicked tab before closing
268 connect(documentTabs, SIGNAL(tabCloseRequested(int)),
269 documentTabs, SLOT(setCurrentIndex(int)));
270 connect(documentTabs, SIGNAL(tabCloseRequested(int)), closeTabAct, SLOT(trigger()));
271 connect(documentTabs->tabBar(), SIGNAL(tabMoved(int, int)), this, SLOT(tabMoved(int, int)));
272
273 setCentralWidget(documentTabs);
274 documentTabs->setDocumentMode(true);
275 modIcon.addFile(":/images/modIcon2.png", QSize(), QIcon::Normal);
276 modIcon.addFile(":/images/modIcon.png", QSize(), QIcon::Disabled);
277 documentTabs->setMinimumSize(QSize(500, 500));
278
279 // set shortcuts to change between tabs,Alt +<tab no>
280 // example from: https://stackoverflow.com/questions/10160232/qt-designer-shortcut-to-another-tab
281 // Setup a signal mapper to avoid creating custom slots for each tab
282 // it is possible to switch it out from Cinfigure->Editor
283 if (m_options->tabShortcutActive) {
284 QSignalMapper *mapper = new QSignalMapper(this);
285 // Setup the shortcut for tabs 1..10
286 for (int i=0; i<10; i++) {
287 int key = (i==9) ? 0 : i+1;
288 #ifdef Q_OS_MACOS
289 QShortcut *shortcut = new QShortcut(QKeySequence(Qt::META + (Qt::Key_0 + key)), this);
290 #else
291 QShortcut *shortcut = new QShortcut(QKeySequence(Qt::ALT + (Qt::Key_0 + key)), this);
292 #endif
293 connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
294 mapper->setMapping(shortcut, i); // tab 0 -> Alt+1, tab 1 -> Alt + 2 etc tab 9 -> Alt + 0
295 }
296 // Wire the signal mapper to the tab widget index change slot
297 connect(mapper, SIGNAL(mapped(int)), documentTabs, SLOT(setCurrentIndex(int)));
298 #ifdef Q_OS_MACOS
299 QShortcut *tabLeft = new QShortcut(QKeySequence(Qt::META + Qt::Key_Left), this);
300 QShortcut *tabRight = new QShortcut(QKeySequence(Qt::META + Qt::Key_Right), this);
301 #else
302 QShortcut *tabLeft = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_Left), this);
303 QShortcut *tabRight = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_Right), this);
304 #endif
305 connect(tabLeft, SIGNAL(activated()), this, SLOT(pageLeft()));
306 connect(tabRight, SIGNAL(activated()), this, SLOT(pageRight()));
307 }
308
309 fillFileMenu(); // Must be placed after readSettings to include recent Files
310 fillFavoriteMenu(); // Must be placed after readSettings to know directory
311 fillScriptsMenu(); // Must be placed after readSettings to know directory
312 risset = new Risset(m_options->pythonExecutable);
313 /*
314 #if defined(Q_OS_LINUX)
315 m_rissetDataPath.setPath(QDir::home().filePath(".local/share/risset"));
316 #elif defined(Q_OS_MACOS)
317 m_rissetDataPath.setPath(QDir::home().filePath("Library/Application Support/risset"));
318 #elif defined(Q_OS_WIN)
319 m_rissetDataPath.setPath(QDir(QProcessEnvironment::systemEnvironment().value("LOCALAPPDATA")).filePath("risset"));
320 #endif
321 */
322 m_opcodeTree = new OpEntryParser(":/opcodes.xml");
323 if(risset->isInstalled) {
324 QString rissetOpcodesXml = risset->rissetOpcodesXml;
325 if(!QFile::exists(rissetOpcodesXml)) {
326 QDEBUG << "opcodes.xml not found, searched: " << rissetOpcodesXml;
327 QDEBUG << "Calling risset to generate opcodes.xml";
328 auto error = risset->generateOpcodesXml();
329 if(error != RissetError::Ok) {
330 QDEBUG << "Could not generate opcodes.xml";
331 rissetOpcodesXml = "";
332 }
333 }
334 if(!rissetOpcodesXml.isEmpty() && QFile::exists(rissetOpcodesXml)) {
335 QDEBUG << "Parsing risset's opcodes.xml:" << rissetOpcodesXml;
336 m_opcodeTree->parseOpcodesXml(rissetOpcodesXml);
337 m_opcodeTree->sortOpcodes();
338 risset->markOpcodeTree(m_opcodeTree);
339 } else {
340 QDEBUG << "Risset's opcodes.xml not found: " << rissetOpcodesXml;
341 }
342 }
343
344 m_opcodeTree->setUdos(m_inspector->getUdosMap());
345 LiveCodeEditor *liveeditor = new LiveCodeEditor(m_scratchPad, m_opcodeTree);
346 liveeditor->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
347 connect(liveeditor, SIGNAL(evaluate(QString)), this, SLOT(evaluate(QString)));
348 connect(liveeditor, SIGNAL(enableCsdMode(bool)),
349 scratchPadCsdModeAct, SLOT(setChecked(bool)));
350 // connect(scratchPadCsdModeAct, SIGNAL(toggled(bool)),
351 // liveeditor, SLOT(setCsdMode(bool)));
352 m_scratchPad->setWidget(liveeditor);
353 m_scratchPad->setFocusProxy(liveeditor->getDocumentView());
354 scratchPadCsdModeAct->setChecked(true);
355
356 // Open files passed in the command line. Here to make sure they are the active tab.
357 foreach (QString fileName, fileNames) {
358 if (QFile::exists(fileName)) {
359 loadFile(fileName, m_options->autoPlay);
360 }
361 else {
362 qDebug() << "CsoundQt::CsoundQt could not open file:" << fileName;
363 }
364 }
365
366 if (documentPages.size() == 0 ) { // No files yet open. Open default
367 QDEBUG << "No open files, opening default";
368 newFile();
369 }
370
371 // try to find directory for manual, if not set
372 QString docDir = QString(); //m_options->csdocdir;
373 QString index = docDir + QString("/index.html");
374 QStringList possibleDirectories;
375 #ifdef Q_OS_LINUX
376 possibleDirectories << "/usr/share/doc/csound-manual/html/"
377 << "/usr/share/doc/csound-doc/html/"
378 << QCoreApplication::applicationDirPath() + "/../share/doc/csound-manual/html/" // for transportable apps like AppImage and perhas others
379 << QCoreApplication::applicationDirPath() + "/../share/doc/csound-doc/html/" ;
380 #endif
381 #ifdef Q_OS_WIN
382 QString programFilesPath = QDir::fromNativeSeparators(getenv("PROGRAMFILES"));
383 QString programFilesPathx86 = QDir::fromNativeSeparators(getenv("PROGRAMFILES(X86)"));
384 possibleDirectories << initialDir +"/doc/manual/" << programFilesPath + "/Csound6/doc/manual/" << programFilesPathx86 + "/Csound6/doc/manual/" << programFilesPath + "/Csound6_x64/doc/manual/" << programFilesPath + "/csound/doc/manual/";
385 #endif
386 #ifdef Q_OS_MACOS
387 possibleDirectories << initialDir + QString("/../Frameworks/CsoundLib64.framework/Resources/Manual/") << "/Library/Frameworks/CsoundLib64.framework/Resources/Manual/";
388 #endif
389 if (m_options->csdocdir.isEmpty() ||
390 !QFile::exists(m_options->csdocdir+"/index.html") ) {
391 foreach (QString dir, possibleDirectories) {
392 qDebug() << "Looking manual in: " << dir;
393 if (QFile::exists(dir+"/index.html")) {
394 docDir = dir;
395 qDebug()<<"Found manual in: "<<docDir;
396 break;
397 }
398 }
399 } else {
400 docDir = m_options->csdocdir;
401 }
402 helpPanel->docDir = docDir;
403 helpPanel->loadFile(docDir + "/index.html");
404
405 applySettings();
406 // createQuickRefPdf();
407
408 #ifdef Q_OS_MACOS // workaround to set resotre window size for Mac. Does not work within readSettings()
409 QSettings settings2("csound", "qutecsound");
410 QSize size = settings2.value("GUI/size", QSize(800, 600)).toSize();
411 resize(size);
412 #endif
413
414 //openLogFile();
415
416 // FIXME is there still need for no atexit?
417 int init = csoundInitialize(0);
418 if (init < 0) {
419 qDebug("CsoundEngine::CsoundEngine() Error initializing Csound!\n"
420 "CsoundQt will probably crash if you try to run Csound.");
421 }
422 // To finish settling dock widgets and other stuff before messing with
423 // them (does it actually work?)
424 qApp->processEvents();
425
426 // This is a bad idea, breaks lots of subtle things, like background color
427 // on files loaded from command line
428 #ifndef Q_OS_MACOS // a workaround for showing close buttons on close NB! disable later
429 auto palette = qApp->palette();
430 // the palette is dark (dark "theme") if the background is darker than the text
431 isDarkPalette = palette.text().color().lightness() > palette.window().color().lightness();
432
433 auto originalStyleSheet = qApp->styleSheet();
434 QFile file;
435 if (isDarkPalette) {
436 QDEBUG << "Using dark palette";
437 file.setFileName(":/appstyle-dark.css");
438 }
439 else {
440 QDEBUG << "Using light palette";
441 file.setFileName(":/appstyle-white.css");
442 }
443 file.open(QFile::ReadOnly);
444 QString styleSheet = QLatin1String(file.readAll());
445 // originalStyleSheet += styleSheet;
446 // qApp->setStyleSheet(originalStyleSheet);
447 qApp->setStyleSheet(styleSheet);
448
449 #endif
450
451 m_closing = false;
452 updateInspector(); //Starts update inspector thread
453
454 // Starts updating things like a list of udos for the current page, etc.
455 updateCurrentPageTask();
456
457 showWidgetsAct->setChecked(widgetsVisible);
458 if (!m_options->widgetsIndependent) {
459 // FIXME: for some reason this produces a move event for widgetlayout with pos (0,0)
460 widgetPanel->setVisible(widgetsVisible);
461 }
462
463 if (scratchPadVisible) { // Reshow scratch panel if necessary
464 m_scratchPad->show();
465 }
466 // Initialize buttons to current state of panels
467 showConsoleAct->setChecked(!m_console->isHidden());
468 showHelpAct->setChecked(!helpPanel->isHidden());
469 showInspectorAct->setChecked(!m_inspector->isHidden());
470 #ifdef QCS_PYTHONQT
471 showPythonConsoleAct->setChecked(!m_pythonConsole->isHidden());
472 #endif
473 showScratchPadAct->setChecked(!m_scratchPad->isHidden());
474
475 //qDebug()<<"Max thread count: "<< QThreadPool::globalInstance()->maxThreadCount();
476 QThreadPool::globalInstance()->setMaxThreadCount(MAX_THREAD_COUNT);
477
478 // Open files saved from last session
479 if (!lastFiles.isEmpty()) {
480 // close the first, default page.
481 //qDebug() << " First page: " << documentPages[0]->getFileName() << lastFiles.count();
482 if (documentPages[0]->getFileName().isEmpty() && lastFiles.count()>0) { // first empty page
483 deleteTab(0);
484 }
485 foreach (QString lastFile, lastFiles) {
486 if (lastFile!="" && !lastFile.startsWith("untitled")) {
487 loadFile(lastFile);
488 }
489 }
490 }
491
492 // restore last index after opening the documents
493 if (lastTabIndex < documentPages.size() &&
494 documentTabs->currentIndex() != lastTabIndex) {
495 changePage(lastTabIndex);
496 documentTabs->setCurrentIndex(lastTabIndex);
497 }
498 else {
499 changePage(documentTabs->currentIndex());
500 }
501
502 // Make sure that we do have an open file
503 if(documentPages.size() < 1)
504 newFile();
505
506 /*
507 #ifdef Q_OS_LINUX
508 // ---- this is workaround for problem reported by Renè that on first run ival = 16.0/3
509 // gets rounded... Did not find the real reasound
510 // Csound must be started and stopped once, then it works:
511 int oldPage = documentTabs->currentIndex();
512 QString tmp1 = lastUsedDir;
513 QString tmp2 = lastFileDir;
514 makeNewPage(QDir::tempPath()+"/tmp.csd", QCS_DEFAULT_TEMPLATE);
515 save();
516 play(true, -1); // problem, if pulse/alsa in settings but jack has been started
517 QThread::msleep(100); // wait a tiny bit
518 stop();
519 deleteTab(curPage);
520 documentTabs->setCurrentIndex(oldPage);
521 lastUsedDir = tmp1;
522 lastFileDir = tmp2;
523 #endif
524 */
525 }
526
527
528 CsoundQt::~CsoundQt()
529 {
530 qDebug() << "CsoundQt::~CsoundQt()";
531 // This function is not called... see closeEvent()
532 }
533
534 void CsoundQt::utilitiesMessageCallback(CSOUND *csound,
535 int /*attr*/,
536 const char *fmt,
537 va_list args)
538 {
539 DockConsole *console = (DockConsole *) csoundGetHostData(csound);
540 QString msg;
541 msg = msg.vsprintf(fmt, args);
542 // qDebug() << msg;
543 console->appendMessage(msg);
544 }
545
546 void CsoundQt::changePage(int index)
547 {
548 // Previous page has already been destroyed here (if it was closed).
549 // Remember this is called when opening, closing or switching tabs (including loading).
550 // First thing to do is blank the HTML page to prevent misfired API calls.
551 if (index < 0) { // No tabs left
552 qDebug() << "CsoundQt::changePage index < 0";
553 return;
554 }
555 if (documentPages.size() > curPage
556 && documentPages.size() > 0
557 && documentPages[curPage]) {
558 #ifdef QCS_DEBUGGER
559 if (documentPages[curPage]->getEngine()->m_debugging) {
560 stop(); // TODO How to better handle this rather than forcing stop?
561 }
562 #endif
563 disconnect(showLiveEventsAct, 0,0,0);
564 disconnect(documentPages[curPage], SIGNAL(stopSignal()),0,0);
565 auto page = documentPages[curPage];
566 page->hideLiveEventPanels();
567 page->showLiveEventControl(false);
568 page->hideWidgets();
569 if (!m_options->widgetsIndependent) {
570 QRect panelGeometry = widgetPanel->geometry();
571 if (!widgetPanel->isFloating()) {
572 panelGeometry.setX(-1);
573 panelGeometry.setY(-1);
574 }
575 widgetPanel->takeWidgetLayout(panelGeometry);
576 } else {
577 page->setWidgetLayoutOuterGeometry(QRect());
578 }
579 }
580 curPage = index;
581 if (curPage >= 0 && curPage < documentPages.size() && documentPages[curPage] != NULL) {
582 auto page = documentPages[curPage];
583 setCurrentFile(page->getFileName());
584 connectActions();
585 page->showLiveEventControl(showLiveEventsAct->isChecked());
586 // documentPages[curPage]->passWidgetClipboard(m_widgetClipboard);
587 if (!m_options->widgetsIndependent) {
588 WidgetLayout *w = page->getWidgetLayout();
589 widgetPanel->addWidgetLayout(w);
590 setWidgetPanelGeometry();
591 } else {
592 WidgetLayout *w = page->getWidgetLayout();
593 w->adjustWidgetSize();
594 }
595 if (!page->getFileName().endsWith(".csd") && !page->getFileName().isEmpty()) {
596 widgetPanel->hide();
597 }
598 else {
599 if (!m_options->widgetsIndependent) {
600 page->showWidgets();
601 widgetPanel->setVisible(showWidgetsAct->isChecked());
602 }
603 else {
604 page->showWidgets(showWidgetsAct->isChecked());
605 }
606 }
607 m_console->setWidget(page->getConsole());
608 runAct->setChecked(page->isRunning());
609 recAct->setChecked(page->isRecording());
610 splitViewAct->setChecked(page->getViewMode() > 1);
611 if (page->getFileName().endsWith(".csd")) {
612 curCsdPage = curPage;
613 // force parsing
614 page->parseUdos(true);
615 }
616 }
617 #if defined(QCS_QTHTML)
618 if (!documentPages.isEmpty()) {
619 updateHtmlView();
620 }
621 #endif
622 m_inspectorNeedsUpdate = true;
623
624 // set acceptsMidiCC for pages - either all true, or only currrentPage true
625 for (int i=0; i<documentPages.size(); i++ ) {
626 if ( m_options->midiCcToCurrentPageOnly ) {
627 if (i==curPage) {
628 documentPages[i]->acceptsMidiCC = true;
629 } else {
630 documentPages[i]->acceptsMidiCC = false;
631 }
632 } else {
633 documentPages[i]->acceptsMidiCC = true;
634 }
635 }
636 }
637
638 void CsoundQt::pageLeft()
639 {
640 if (curPage >= 1) {
641 //changePage(curPage-1);
642 documentTabs->setCurrentIndex(curPage-1);
643
644 }
645 }
646
647 void CsoundQt::pageRight()
648 {
649 if (curPage < documentPages.count()-1) {
650 //changePage(curPage+1);
651 documentTabs->setCurrentIndex(curPage+1);
652
653 }
654 }
655
656 void CsoundQt::setWidgetTooltipsVisible(bool visible)
657 {
658 documentPages[curPage]->showWidgetTooltips(visible);
659 }
660
661 void CsoundQt::closeExtraPanels()
662 {
663 if (m_console->isVisible()) {
664 m_console->hide();
665 showConsoleAct->setChecked(false);
666 } else if (helpPanel->isVisible()) {
667 helpPanel->hide();
668 showHelpAct->setChecked(false);
669 }
670 }
671
672 void CsoundQt::openExample()
673 {
674 QObject *sender = QObject::sender();
675 if (sender == 0)
676 return;
677 QAction *action = static_cast<QAction *>(sender);
678 loadFile(action->data().toString());
679 // saveAs();
680 }
681
682 void CsoundQt::openTemplate()
683 {
684 QObject *sender = QObject::sender();
685 if (sender == 0)
686 return;
687 QAction *action = static_cast<QAction *>(sender);
688
689 QString dir = lastUsedDir;
690 QString templateName = action->data().toString();
691 dir += templateName.mid(templateName.lastIndexOf("/") + 1);
692 QString fileName = QFileDialog::getSaveFileName(this, tr("Save Template As"), dir,
693 tr("Known Files (*.csd *.html);;Csound Files (*.csd);;Html files (*.html);;All Files (*)",
694 "Rename and save the template"));
695 if (!fileName.isEmpty()) {
696
697
698 if (QFile::exists(fileName))
699 {
700 QFile::remove(fileName);
701 }
702 bool result = QFile::copy(templateName, fileName); // copy or overwrite
703 if (!result) {
704 qDebug() << "Could not copy the template to " << fileName;
705 return;
706 }
707 loadFile(fileName);
708 } else {
709 qDebug() << "No file selected";
710 }
711
712 }
713
714 void CsoundQt::logMessage(QString msg)
715 {
716 if (logFile.isOpen()) {
717 logFile.write(msg.toLatin1());
718 }
719 }
720
721 void CsoundQt::statusBarMessage(QString message)
722 {
723 statusBar()->showMessage(message.replace("<br />", " "));
724 }
725
726 void CsoundQt::closeEvent(QCloseEvent *event)
727 {
728 qDebug() ;
729 m_closing = true;
730 // this->showNormal(); // Don't store full screen size in preferences
731 qApp->processEvents();
732 storeSettings();
733 #ifdef USE_QT_GT_53
734 if (!m_virtualKeyboardPointer.isNull() && m_virtualKeyboard->isVisible()) {
735 showVirtualKeyboard(false);
736 }
737 if (!m_tableEditorPointer.isNull() && m_tableEditor->isVisible()) {
738 showTableEditor(false);
739 }
740 #endif
741 // These two give faster shutdown times as the panels don't have to be
742 // called up as the tabs close
743 showWidgetsAct->setChecked(false);
744 showLiveEventsAct->setChecked(false);
745 // Using this block this causes HTML5 performance to leave a zombie,
746 // not using it causes a crash on exit.
747 while (!documentPages.isEmpty()) {
748 if (!closeTab(true)) { // Don't ask for closing app
749 event->ignore();
750 return;
751 }
752 }
753 foreach (QString tempFile, tempScriptFiles) {
754 QDir().remove(tempFile);
755 }
756 if (logFile.isOpen()) {
757 logFile.close();
758 }
759 showUtilities(false); // Close utilities dialog if open
760 delete helpPanel;
761 // delete closeTabButton;
762 delete m_options;
763 m_closing = true;
764 widgetPanel->close();
765 m_inspector->close();
766 m_console->close();
767 documentTabs->close();
768 m_console->close();
769 delete m_opcodeTree;
770 m_opcodeTree = nullptr;
771 close();
772 }
773
774 void CsoundQt::newFile()
775 {
776 if (loadFile(":/default.csd") < 0) {
777 return;
778 }
779 documentPages[curPage]->loadTextString(m_options->csdTemplate);
780 documentPages[curPage]->setFileName("");
781 setWindowModified(false);
782 // documentTabs->setTabIcon(curPage, modIcon);
783 documentTabs->setTabText(curPage, "default.csd");
784 // documentPages[curPage]->setTabStopWidth(m_options->tabWidth);
785 connectActions();
786 }
787
788 void CsoundQt::open()
789 {
790 QStringList fileNames;
791 bool widgetsVisible = widgetPanel->isVisible();
792 if (widgetsVisible && widgetPanel->isFloating())
793 widgetPanel->hide(); // Necessary for Mac, as widget Panel covers open dialog
794 bool helpVisible = helpPanel->isVisible();
795 if (helpVisible && helpPanel->isFloating())
796 helpPanel->hide(); // Necessary for Mac, as widget Panel covers open dialog
797 bool inspectorVisible = m_inspector->isVisible();
798 if (inspectorVisible && m_inspector->isFloating())
799 m_inspector->hide(); // Necessary for Mac, as widget Panel covers open dialog
800 fileNames = QFileDialog::getOpenFileNames(this, tr("Open File"), lastUsedDir ,
801 tr("Known Files (*.csd *.orc *.sco *.py *.inc *.udo *.html);;Csound Files (*.csd *.orc *.sco *.inc *.udo *.CSD *.ORC *.SCO *.INC *.UDO);;Python Files (*.py);;HTML files (*.html);;All Files (*)",
802 "Be careful to respect spacing parenthesis and usage of punctuation"));
803 // if (widgetsVisible) {
804 // if (!m_options->widgetsIndependent) {
805 // // widgetPanel->show();
806 // }
807 // }
808 if (helpVisible)
809 helpPanel->show();
810 if (inspectorVisible)
811 m_inspector->show();
812 foreach (QString fileName, fileNames) {
813 if (!fileName.isEmpty()) {
814 loadFile(fileName, m_options->autoPlay);
815 }
816 }
817 }
818
819 void CsoundQt::reload()
820 {
821 if (documentPages[curPage]->isModified()) {
822 QString fileName = documentPages[curPage]->getFileName();
823 deleteTab();
824 loadFile(fileName);
825 // auto doc = documentPages[curPage];
826
827 } else {
828 QMessageBox::information(nullptr, "Reload", "File was not modified");
829 }
830 }
831
832 void CsoundQt::openFromAction()
833 {
834 QString fileName = static_cast<QAction *>(sender())->data().toString();
835 openFromAction(fileName);
836 }
837
838 void CsoundQt::openFromAction(QString fileName)
839 {
840 if (!fileName.isEmpty()) {
841 if ( (fileName.endsWith(".sco") || fileName.endsWith(".orc"))
842 && m_options->autoJoin) {
843
844 }
845 else {
846 loadCompanionFile(fileName);
847 loadFile(fileName);
848 }
849 }
850 }
851
852 void CsoundQt::runScriptFromAction()
853 {
854 QString fileName = static_cast<QAction *>(sender())->data().toString();
855 runScript(fileName);
856 }
857
858 void CsoundQt::runScript(QString fileName)
859 {
860 if (!fileName.isEmpty()) {
861 #ifdef QCS_PYTHONQT
862 m_pythonConsole->runScript(fileName);
863 #endif
864 }
865 }
866
867 void CsoundQt::createCodeGraph()
868 {
869 QString command = m_options->dot + " -V";
870 #ifdef Q_OS_WIN32
871 // add quotes surrounding dot command if it has spaces in it
872 if (m_options->dot.contains(" "))
873 command.replace(m_options->dot, "\"" + m_options->dot + "\"");
874 // replace linux/mac style directory separators with windows style separators
875 command.replace("/", "\\");
876 #endif
877
878 int ret = system(command.toLatin1());
879 if (ret != 0) {
880 QMessageBox::warning(this, tr("CsoundQt"),
881 tr("Dot executable not found.\n"
882 "Please install graphviz from\n"
883 "www.graphviz.org"));
884 return;
885 }
886 QString dotText = documentPages[curPage]->getDotText();
887 if (dotText.isEmpty()) {
888 qDebug() << "Empty dot text.";
889 return;
890 }
891 qDebug() << dotText;
892 QTemporaryFile file(QDir::tempPath() + QDir::separator() + "CsoundQt-GraphXXXXXX.dot");
893 QTemporaryFile pngFile(QDir::tempPath() + QDir::separator() + "CsoundQt-GraphXXXXXX.png");
894 if (!file.open() || !pngFile.open()) {
895 QMessageBox::warning(this, tr("CsoundQt"),
896 tr("Cannot create temp dot/png file."));
897 return;
898 }
899
900 QTextStream out(&file);
901 out << dotText;
902 file.close();
903 file.open();
904
905 command = "\"" + m_options->dot + "\"" + " -Tpng -o \"" + pngFile.fileName() + "\" \"" + file.fileName() + "\"";
906
907 #ifdef Q_OS_WIN32
908 // remove quotes surrounding dot command if it doesn't have spaces in it
909 if (!m_options->dot.contains(" "))
910 command.replace("\"" + m_options->dot + "\"", m_options->dot);
911 // replace linux/mac style directory separators with windows style separators
912 command.replace("/", "\\");
913 command.prepend("\"");
914 command.append("\"");
915 #endif
916 // qDebug() << command;
917 ret = system(command.toLatin1());
918 if (ret != 0) {
919 qDebug() << "CsoundQt::createCodeGraph() Error running dot";
920 }
921 m_graphic = new GraphicWindow(this);
922 m_graphic->show();
923 m_graphic->openPng(pngFile.fileName());
924 connect(m_graphic, SIGNAL(destroyed()), this, SLOT(closeGraph()));
925 }
926
927 void CsoundQt::closeGraph()
928 {
929 qDebug("CsoundQt::closeGraph()");
930 }
931
932 bool CsoundQt::save()
933 {
934 QString fileName = documentPages[curPage]->getFileName();
935 if (fileName.isEmpty() || fileName.startsWith(":/examples/", Qt::CaseInsensitive)) {
936 return saveAs();
937 }
938 else if (documentPages[curPage]->readOnly){
939 if (saveAs()) {
940 documentPages[curPage]->readOnly = false;
941 return true;
942 }
943 else {
944 return false;
945 }
946 }
947 else {
948 return saveFile(fileName);
949 }
950 }
951
952 void CsoundQt::copy()
953 {
954 if (helpPanel->hasFocus()) {
955 helpPanel->copy();
956 }
957 else if (m_console->widgetHasFocus()) {
958 m_console->copy();
959 }
960 else {
961 documentPages[curPage]->copy();
962 }
963 }
964
965 void CsoundQt::cut()
966 {
967 documentPages[curPage]->cut();
968 }
969
970 void CsoundQt::paste()
971 {
972 documentPages[curPage]->paste();
973 }
974
975 void CsoundQt::undo()
976 {
977 // qDebug() << "CsoundQt::undo()";
978 documentPages[curPage]->undo();
979 }
980
981 void CsoundQt::redo()
982 {
983 documentPages[curPage]->redo();
984 }
985
986 void CsoundQt::evaluateSection()
987 {
988 QString text;
989 if (static_cast<LiveCodeEditor *>(m_scratchPad->widget())->getDocumentView()->hasFocus()) {
990 text = static_cast<LiveCodeEditor *>(m_scratchPad->widget())->getDocumentView()->getActiveText();
991 }
992 else {
993 text = documentPages[curPage]->getActiveSection();
994 }
995 evaluateString(text);
996 }
997
998 void CsoundQt::evaluate(QString code)
999 {
1000 QString evalCode;
1001 if (code.isEmpty()) { //evaluate current selection in current document
1002 if (static_cast<LiveCodeEditor *>(m_scratchPad->widget())->getDocumentView()->hasFocus()) {
1003 evalCode = static_cast<LiveCodeEditor *>(m_scratchPad->widget())->getDocumentView()->getActiveText();
1004 }
1005 else {
1006 evalCode = documentPages[curPage]->getActiveText();
1007 if (evalCode.count("\n") <= 1) {
1008 documentPages[curPage]->gotoNextRow();
1009 }
1010 }
1011 }
1012 else {
1013 evalCode = code;
1014 }
1015 if (evalCode.size() > 1) { // evalCode can be \n and that crashes csound...
1016 evaluateString(evalCode);
1017 }
1018 }
1019
1020
1021 void CsoundQt::evaluateCsound(QString code)
1022 {
1023 documentPages[curPage]->sendCodeToEngine(code);
1024 }
1025
1026 void CsoundQt::breakpointReached()
1027 {
1028 #ifdef QCS_DEBUGGER
1029 Q_ASSERT(m_debugEngine);
1030 m_debugPanel->setVariableList(m_debugEngine->getVaribleList());
1031 m_debugPanel->setInstrumentList(m_debugEngine->getInstrumentList());
1032 documentPages[curPage]->getView()->m_mainEditor->setCurrentDebugLine(m_debugEngine->getCurrentLine());
1033 #endif
1034 }
1035
1036 void CsoundQt::evaluatePython(QString code)
1037 {
1038 #ifdef QCS_PYTHONQT
1039 m_pythonConsole->evaluate(code);
1040 #else
1041 (void) code;
1042 showNoPythonQtWarning();
1043 #endif
1044 }
1045
1046 void CsoundQt::evaluateString(QString evalCode)
1047 {
1048 TREE *testTree = NULL;
1049 if (scratchPadCsdModeAct->isChecked()) {
1050 // first check if it is a scoreline, then if it is csound code, if that also that fails, try with python
1051 if (QRegExp("[if]\\s*-*[0-9]+\\s+[0-9]+\\s+[0-9]+.*\\n").indexIn(evalCode) >= 0) {
1052 sendEvent(evalCode);
1053 return;
1054 }
1055 CSOUND *csound = getEngine(curPage)->getCsound();
1056 if (csound!=NULL) {
1057 testTree = csoundParseOrc(csound,evalCode.toLocal8Bit()); // return not NULL, if the code is valid
1058 if (testTree == NULL) {
1059 qDebug() << "Not Csound code or cannot compile";
1060 }
1061 }
1062 if (testTree) { // when the code is csound code, but with errors, it will be sent to python interpreter too
1063 evaluateCsound(evalCode);
1064 return;
1065 }
1066 } else {
1067 evaluatePython(evalCode);
1068 }
1069 }
1070
1071 void CsoundQt::setScratchPadMode(bool csdMode)
1072 {
1073 static_cast<LiveCodeEditor *>(m_scratchPad->widget())->setCsdMode(csdMode);
1074 }
1075
1076 void CsoundQt::setWidgetEditMode(bool active)
1077 {
1078 for (int i = 0; i < documentPages.size(); i++) {
1079 documentPages[i]->setWidgetEditMode(active);
1080 }
1081 }
1082
1083 void CsoundQt::duplicate()
1084 {
1085 qDebug() << "CsoundQt::duplicate()";
1086 documentPages[curPage]->duplicateWidgets();
1087 }
1088
1089 void CsoundQt::testAudioSetup()
1090 {
1091 qDebug() << "CsoundQt::testAudioSetup";
1092 loadFile(":/AudioMidiTest.csd");
1093 widgetPanel->setVisible(true);
1094 widgetPanel->setFocus();
1095 play();
1096 }
1097
1098 void CsoundQt::checkSyntaxMenuAction()
1099 {
1100 bool prev = m_options->checkSyntaxOnly;
1101 m_options->checkSyntaxOnly = true;
1102 play();
1103 m_options->checkSyntaxOnly = prev;
1104 }
1105
1106 void CsoundQt::tabMoved(int to, int from) // arguments should be from, but probably the other (counter-)moving tab is reported here, not the one that is dragged
1107 {
1108 qDebug() << "Tab moved from " << from << " to: " << to;
1109 if (to<0 || to>=documentPages.count() || from<0 || from>=documentPages.count() ) {
1110 qDebug() << "Tab index out of range";
1111 return;
1112 }
1113 std::swap( documentPages[to], documentPages[from] );
1114 curPage = to;
1115 changePage(to);
1116 }
1117
1118 void CsoundQt::openExamplesFolder()
1119 {
1120 QUrl examplePath = QUrl::fromLocalFile(QFileInfo(getExamplePath("")).absoluteFilePath());
1121 qDebug() << "Trying to open Examples folder" << examplePath;
1122 QDesktopServices::openUrl(examplePath);
1123 }
1124
1125 void CsoundQt::setLineAndColumn(int line, int column)
1126 {
1127 QString labelText = QString("%1 : %2, %3 : ").arg(tr("Line")).arg(line).arg(tr("Column"));
1128 if (column>80) {
1129 QString color = "red"; //isDarkPalette ? "#FF4C4C" : "red";
1130 labelText += QString("<span style='color:%1;'><b>%2</b></span>").arg(color).arg(column);
1131 } else {
1132 labelText += QString::number(column);
1133 }
1134 lineAndColumnLabel->setText(labelText);
1135 }
1136
1137 QString CsoundQt::getSaveFileName()
1138 {
1139 bool widgetsVisible = widgetPanel->isVisible();
1140 if (widgetsVisible && widgetPanel->isFloating())
1141 widgetPanel->hide(); // Necessary for Mac, as widget Panel covers open dialog
1142 bool helpVisible = helpPanel->isVisible();
1143 if (helpVisible && helpPanel->isFloating())
1144 helpPanel->hide(); // Necessary for Mac, as widget Panel covers open dialog
1145 bool inspectorVisible = m_inspector->isVisible();
1146 if (inspectorVisible && m_inspector->isFloating())
1147 m_inspector->hide(); // Necessary for Mac, as widget Panel covers open dialog
1148 QString dir = lastUsedDir;
1149 QString name = documentPages[curPage]->getFileName();
1150 dir += name.mid(name.lastIndexOf("/") + 1);
1151 QString fileName = QFileDialog::getSaveFileName(
1152 this, tr("Save File As"), dir,
1153 tr("Known Files (*.csd *.orc *.sco *.py *.udo *.html);;"
1154 "Csound Files (*.csd *.orc *.sco *.udo *.inc *.CSD *.ORC"
1155 "*.SCO *.UDO *.INC);;Python Files (*.py);;"
1156 "Html files (*.html);;All Files (*)",
1157 "Be careful to respect spacing parenthesis and usage of punctuation"));
1158 if (widgetsVisible) {
1159 if (!m_options->widgetsIndependent) {
1160 widgetPanel->show(); // Necessary for Mac, as widget Panel covers open dialog
1161 }
1162 }
1163 if (helpVisible)
1164 helpPanel->show(); // Necessary for Mac, as widget Panel covers open dialog
1165 if (inspectorVisible)
1166 m_inspector->show(); // Necessary for Mac, as widget Panel covers open dialog
1167 if (fileName.isEmpty())
1168 return QString("");
1169 if (isOpen(fileName) != -1 && isOpen(fileName) != curPage) {
1170 QMessageBox::critical(this, tr("CsoundQt"),
1171 tr("The file is already open in another tab.\nFile not saved!"),
1172 QMessageBox::Ok | QMessageBox::Default);
1173 return QString("");
1174 }
1175 // if (!fileName.endsWith(".csd",Qt::CaseInsensitive) && !fileName.endsWith(".orc",Qt::CaseInsensitive)
1176 // && !fileName.endsWith(".sco",Qt::CaseInsensitive) && !fileName.endsWith(".txt",Qt::CaseInsensitive)
1177 // && !fileName.endsWith(".udo",Qt::CaseInsensitive))
1178 // fileName += ".csd";
1179 if (fileName.isEmpty()) {
1180 fileName = name;
1181 }
1182 if (!fileName.contains(".")) {
1183 fileName += ".csd";
1184 }
1185 return fileName;
1186 }
1187
1188 void CsoundQt::createQuickRefPdf()
1189 {
1190 QString tempFileName(QDir::tempPath() + QDir::separator() +
1191 "QuteCsound Quick Reference.pdf");
1192 QString internalFileName = ":/doc/QuteCsound Quick Reference (0.4)-";
1193 internalFileName += m_configlists.languageCodes[m_options->language];
1194 internalFileName += ".pdf";
1195 if (!QFile::exists(internalFileName)) {
1196 internalFileName = ":/doc/QuteCsound Quick Reference (0.4).pdf";
1197 }
1198 // qDebug() << "CsoundQt::createQuickRefPdf() Opening " << internalFileName;
1199 QFile file(internalFileName);
1200 file.open(QIODevice::ReadOnly);
1201 QFile quickRefFile(tempFileName);
1202 quickRefFile.open(QFile::WriteOnly);
1203 QDataStream quickRefIn(&quickRefFile);
1204 quickRefIn << file.readAll();
1205 quickRefFileName = tempFileName;
1206 }
1207
1208 void CsoundQt::deleteTab(int index)
1209 {
1210 if (index == -1) {
1211 index = curPage;
1212 }
1213 disconnect(showLiveEventsAct, 0,0,0);
1214 DocumentPage *d = documentPages[index];
1215 d->stop();
1216 d->showLiveEventControl(false);
1217 d->hideLiveEventPanels();
1218 midiHandler->removeListener(d);
1219 if (!m_options->widgetsIndependent) {
1220 QRect panelGeometry = widgetPanel->geometry();
1221 if (!widgetPanel->isFloating()) {
1222 panelGeometry.setX(-1);
1223 panelGeometry.setY(-1);
1224 }
1225 widgetPanel->takeWidgetLayout(panelGeometry);
1226 }
1227 documentPages.remove(index);
1228 documentTabs->removeTab(index);
1229 delete d;
1230 if (curPage >= documentPages.size()) {
1231 curPage = documentPages.size() - 1;
1232 }
1233 if (curPage < 0)
1234 curPage = 0; // deleting the document page decreases curPage, so must check
1235 }
1236
1237 void CsoundQt::openLogFile()
1238 {
1239 if (logFile.isOpen()) {
1240 logFile.close();
1241 }
1242 logFile.setFileName(m_options->logFile);
1243 if (m_options->logFile.isEmpty())
1244 return;
1245 if (logFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
1246 logFile.readAll();
1247 QString text = "--**-- " + QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss")
1248 + " CsoundQt Logging Started: "
1249 + "\n";
1250 logFile.write(text.toLatin1());
1251 }
1252 else {
1253 qDebug() << "CsoundQt::openLogFile() Error. Could not open log file! NO logging. " << logFile.fileName();
1254 }
1255 }
1256
1257 void CsoundQt::showNewFormatWarning()
1258 {
1259 QMessageBox::warning(this, tr("New widget format"),
1260 tr("This version of CsoundQt implements a new format for storing"
1261 " widgets, which enables many of the new widget features you "
1262 "will find now.\n"
1263 "The old format is still read and saved, so you will be able "
1264 "to open files in older versions but some of the features will "
1265 "not be passed to older versions.\n"),
1266 QMessageBox::Ok);
1267 }
1268
1269 void CsoundQt::setupEnvironment()
1270 {
1271 if (m_options->sadirActive){
1272 int ret = csoundSetGlobalEnv("SADIR", m_options->sadir.toLocal8Bit().constData());
1273 if (ret != 0) {
1274 qDebug() << "CsoundEngine::runCsound() Error setting SADIR";
1275 }
1276 }
1277 else {
1278 csoundSetGlobalEnv("SADIR", "");
1279 }
1280 if (m_options->ssdirActive){
1281 int ret = csoundSetGlobalEnv("SSDIR", m_options->ssdir.toLocal8Bit().constData());
1282 if (ret != 0) {
1283 qDebug() << "CsoundEngine::runCsound() Error setting SSDIR";
1284 }
1285 }
1286 else {
1287 csoundSetGlobalEnv("SSDIR", "");
1288 }
1289 if (m_options->sfdirActive){
1290 int ret = csoundSetGlobalEnv("SFDIR", m_options->sfdir.toLocal8Bit().constData());
1291 if (ret != 0) {
1292 qDebug() << "CsoundEngine::runCsound() Error setting SFDIR";
1293 }
1294 }
1295 else {
1296 csoundSetGlobalEnv("SFDIR", "");
1297 }
1298 if (m_options->incdirActive){
1299 int ret = csoundSetGlobalEnv("INCDIR", m_options->incdir.toLocal8Bit().constData());
1300 if (ret != 0) {
1301 qDebug() << "CsoundEngine::runCsound() Error setting INCDIR";
1302 }
1303 }
1304 else {
1305 csoundSetGlobalEnv("INCDIR", "");
1306 }
1307 // set rawWavePath for stk opcodes
1308 QString rawWavePath = m_options->rawWaveActive ? m_options->rawWave : QString(getenv("RAWWAVE_PATH"));
1309 if (rawWavePath.isNull()) {
1310 rawWavePath=QString(""); // NULL string may crash csoundInitilaize
1311 }
1312 if ( csoundSetGlobalEnv("RAWWAVE_PATH", rawWavePath.toLocal8Bit().constData()) ) {
1313 qDebug() << "CsoundEngine::runCsound() Error setting RAWWAVE_PATH";
1314 }
1315 #ifdef Q_OS_UNIX
1316 // make sure the the environment variable is set for stk opcodes
1317 setenv("RAWWAVE_PATH",rawWavePath.toLocal8Bit(),1);
1318 #endif
1319 #ifdef Q_OS_WIN
1320 QString envString = "RAWWAVE_PATH="+rawWavePath;
1321 _putenv(envString.toLocal8Bit());
1322 #endif
1323 // csoundGetEnv must be called after Compile or Precompile,
1324 // But I need to set OPCODEDIR before compile.... So I can't know keep the old OPCODEDIR
1325 if (m_options->opcodedirActive) {
1326 csoundSetGlobalEnv("OPCODEDIR", m_options->opcodedir.toLatin1().constData());
1327 }
1328 if (m_options->opcodedir64Active) {
1329 csoundSetGlobalEnv("OPCODEDIR64", m_options->opcodedir64.toLatin1().constData());
1330 }
1331 if (m_options->opcode6dir64Active) {
1332 csoundSetGlobalEnv("OPCODE6DIR64", m_options->opcode6dir64.toLatin1().constData());
1333 }
1334 #ifdef Q_OS_WIN32
1335 // if opcodes are in the same directory or in ./plugins64, then set OPCODE6DIR64 to the bundled plugins
1336 // no need to support 32-opcodes any more, set only OPCODE6DIR64
1337 QString opcodedir;
1338 if (QFile::exists(initialDir+"/rtpa.dll" )) {
1339 opcodedir = initialDir;
1340 } else if (QFile::exists(initialDir+"/plugins64/rtpa.dll" )) {
1341 opcodedir = initialDir+"/plugins64/";
1342 } else {
1343 opcodedir = QString();
1344 }
1345 if (!opcodedir.isEmpty()) {
1346 qDebug() << "Setting OPCODE6DIR64 to: " << opcodedir;
1347 csoundSetGlobalEnv("OPCODE6DIR64", opcodedir.toLocal8Bit().constData());
1348 }
1349 #endif
1350 #ifdef Q_OS_MACOS
1351 // Use bundled opcodes if available
1352 #ifdef USE_DOUBLE
1353 QString opcodedir = initialDir + "/../Frameworks/CsoundLib64.framework/Resources/Opcodes64";
1354 #else
1355 QString opcodedir = initialDir + "/../Frameworks/CsoundLib.framework/Resources/Opcodes";
1356 #endif
1357 if (QFile::exists(opcodedir)) {
1358 #ifdef USE_DOUBLE
1359 csoundSetGlobalEnv("OPCODE6DIR64", opcodedir.toLocal8Bit().constData());
1360 #else
1361 csoundSetGlobalEnv("OPCODE6DIR", opcodedir.toLocal8Bit().constData());
1362 #endif
1363 }
1364 #endif
1365 }
1366
1367 void CsoundQt::onNewConnection()
1368 {
1369 qDebug()<<"NEW connection";
1370 QLocalSocket *client = m_server->nextPendingConnection();
1371 connect(client, SIGNAL(disconnected()), client, SLOT(deleteLater()));
1372 connect(client, SIGNAL(readyRead()), this, SLOT(onReadyRead()) );
1373 }
1374
1375 void CsoundQt::onReadyRead()
1376 {
1377 QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender());
1378 if (!socket || !socket->bytesAvailable())
1379 return;
1380 QByteArray ba = socket->readAll();
1381 if (ba.isEmpty())
1382 return;
1383 else {
1384 QStringList messageParts = QString(ba).split("***");
1385 if (messageParts[0].contains("open")) {
1386 messageParts.removeAt(0); // other parts should be filenames
1387 foreach (QString fileName, messageParts) {
1388 qDebug() << "Call from other instance. Opening "<<fileName;
1389 loadFile(fileName);
1390 //to bring window to front:
1391 this->raise();
1392 this->activateWindow();
1393 this->showNormal();
1394 }
1395 }
1396 }
1397 }
1398
1399 void CsoundQt::disableInternalRtMidi()
1400 {
1401 #ifdef QCS_RTMIDI
1402 midiHandler->closeMidiInPort();
1403 midiHandler->closeMidiOutPort();
1404 #endif
1405 }
1406
1407 void CsoundQt::focusToTab(int tab) {
1408 QDockWidget *panel = nullptr;
1409 QAction * action = nullptr;
1410 qDebug()<<tab;
1411 switch (tab) {
1412 case 1:
1413 qDebug()<<"Raise widgets";
1414 if(m_options->widgetsIndependent) {
1415 QDEBUG << "Widget panel is an independent window";
1416 auto doc = this->documentPages[this->curPage];
1417 auto wl = doc->getWidgetLayout();
1418 if(wl->isVisible()) {
1419 wl->setVisible(false);
1420 showWidgetsAct->setChecked(false);
1421 } else {
1422 // not visible
1423 wl->setVisible(true);
1424 showWidgetsAct->setChecked(true);
1425 }
1426 return;
1427 } else {
1428 panel = widgetPanel;
1429 action = showWidgetsAct;
1430 break;
1431 }
1432 case 2:
1433 qDebug()<<"Raise help";
1434 panel = helpPanel;
1435 action = showHelpAct;
1436 break;
1437 case 3:
1438 qDebug()<<"Raise console";
1439 panel = m_console;
1440 action = showConsoleAct;
1441 break;
1442 case 4:
1443 qDebug()<<"Raise html panel";
1444 #ifdef QCS_QTHTML
1445 panel = csoundHtmlView;
1446 action = showHtml5Act;
1447 #endif
1448 break;
1449 case 5:
1450 qDebug()<<"Raise inspector";
1451 panel = m_inspector;
1452 action = showInspectorAct;
1453 break;
1454 // 6 is Live events that is independent window
1455
1456 case 7:
1457 qDebug()<<"Raise Python Console";
1458 #ifdef QCS_PYTHONQT
1459 panel = m_pythonConsole;
1460 action = showPythonConsoleAct;
1461 #endif
1462 break;
1463
1464 case 8:
1465 qDebug()<<"Raise Code Pad";
1466 panel = m_scratchPad;
1467 action = showScratchPadAct;
1468 break;
1469 default:
1470 qDebug() << "focusToTab: unknoun tab" << tab;
1471 return;
1472 }
1473
1474 if(!panel)
1475 return;
1476
1477 if (panel->isFloating() && panel->isVisible()) {
1478 // if as separate window, close it shortcut activated again
1479 QDEBUG << "panel is floating, hiding";
1480 panel->setVisible(false);
1481 action->setChecked(false);
1482 return;
1483 }
1484 if (!panel->isVisible()) {
1485 panel->show();
1486 action->setChecked(true);
1487 }
1488 panel->raise();
1489 }
1490
1491 void CsoundQt::ambiguosShortcut()
1492 {
1493 QMessageBox::warning(this, tr("Shortcuts changed"),
1494 tr("Ambiguous shortcut. In version 0.9.5 some shortcuts changed, please configure "
1495 "the shourtcuts or set to defaults "
1496 "(Edit/Configure shortcuts/Restore Defaults) "));
1497
1498 }
1499
1500 bool CsoundQt::saveAs()
1501 {
1502 QString fileName = getSaveFileName();
1503 if (!fileName.isEmpty() && saveFile(fileName)) {
1504 return true;
1505 }
1506 return false;
1507 }
1508
1509 void CsoundQt::createApp()
1510 {
1511 QString opcodeDir;
1512 if (!documentPages[curPage]->getFileName().endsWith(".csd")) {
1513 QMessageBox::critical(this, tr("Error"),
1514 tr("You can only create an app with a csd file."));
1515 return;
1516 }
1517 if (documentPages[curPage]->isModified() ||
1518 documentPages[curPage]->getFileName().startsWith(":/")) {
1519 auto but = QMessageBox::question(
1520 this, tr("Save"),
1521 tr("Do you want to save before creating app?"),
1522 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
1523 if (but == QMessageBox::Yes) {
1524 bool ret = save();
1525 if (!ret) {
1526 qDebug() << "CsoundQt::createApp() Error saving file";
1527 return;
1528 }
1529 } else {
1530 QMessageBox::critical(this, tr("Abort"),
1531 tr("You must save the csd before creating the App!"));
1532 return;
1533 }
1534 }
1535
1536 if (m_options->opcodedirActive) {
1537 // FIXME allow for OPCODEDIR64 if built for doubles
1538 opcodeDir = m_options->opcodedir.toLocal8Bit();
1539 }
1540 else {
1541 #ifdef USE_DOUBLE
1542 #ifdef Q_OS_LINUX
1543 #endif
1544 #ifdef Q_OS_SOLARIS
1545 #endif
1546 #ifdef Q_OS_WIN32
1547 #endif
1548 #ifdef Q_OS_MACOS
1549 opcodeDir = "/Library/Frameworks/CsoundLib64.framework/Resources/Opcodes";
1550 // opcodeDir = initialDir + "/CsoundQt.app/Contents/Frameworks/CsoundLib64.framework/Resources/Opcodes";
1551 #endif
1552 #else
1553
1554 #ifdef Q_OS_LINUX
1555 #endif
1556 #ifdef Q_OS_SOLARS
1557 #endif
1558 #ifdef Q_OS_WIN32
1559 #endif
1560 #ifdef Q_OS_MACOS
1561 #ifdef USE_DOUBLE
1562 opcodeDir = "/Library/Frameworks/CsoundLib.framework/Resources/Opcodes";
1563 #else
1564 opcodeDir = "/Library/Frameworks/CsoundLib64.framework/Resources/Opcodes";
1565 #endif
1566 // opcodeDir = initialDir + "/CsoundQt.app/Contents/Frameworks/CsoundLib.framework/Resources/Opcodes";
1567 #endif
1568
1569
1570 #endif
1571 }
1572 QString fullPath = documentPages[curPage]->getFileName();
1573 AppWizard wizard(this, opcodeDir, fullPath, m_options->sdkDir);
1574 AppProperties existingProperties = documentPages[curPage]->getAppProperties();
1575 if (existingProperties.used) {
1576 wizard.setField("appName", QVariant(existingProperties.appName));
1577 wizard.setField("targetDir", QVariant(existingProperties.targetDir));
1578 wizard.setField("author", QVariant(existingProperties.author));
1579 wizard.setField("version", QVariant(existingProperties.version));
1580 wizard.setField("email", QVariant(existingProperties.email));
1581 wizard.setField("website", QVariant(existingProperties.website));
1582 wizard.setField("instructions", QVariant(existingProperties.instructions));
1583 wizard.setField("autorun", QVariant(existingProperties.autorun));
1584 wizard.setField("showRun", QVariant(existingProperties.showRun));
1585 wizard.setField("saveState", QVariant(existingProperties.saveState));
1586 wizard.setField("runMode", QVariant(existingProperties.runMode));
1587 wizard.setField("newParser", QVariant(existingProperties.newParser));
1588 wizard.setField("useSdk", QVariant(existingProperties.useSdk ? 1 : 0));
1589 wizard.setField("useCustomPaths", QVariant(existingProperties.useCustomPaths));
1590 wizard.setField("libDir", QVariant(existingProperties.libDir));
1591 wizard.setField("opcodeDir", QVariant(existingProperties.opcodeDir));
1592 } else { // Put in default values
1593 QString appDir = fullPath.left(fullPath.lastIndexOf(QDir::separator()) );
1594 if (appDir.startsWith(":/")) { // For embedded examples
1595 appDir = QDir::homePath();
1596 }
1597 QString appName = fullPath.mid(fullPath.lastIndexOf(QDir::separator()) + 1);
1598 appName = appName.remove(".csd");
1599 wizard.setField("appName", appName);
1600 wizard.setField("targetDir", appDir);
1601 if (m_options->sdkDir.isEmpty()) { // No sdk,
1602 wizard.setField("customPaths", true);
1603 #if defined(Q_OS_LINUX) || defined(Q_OS_SOLARIS)
1604 wizard.setField("libDir", "/usr/lib");
1605 if (opcodeDir.isEmpty()) {
1606 wizard.setField("opcodeDir", "/usr/lib/csound/plugins");
1607 }
1608 #endif
1609 #ifdef Q_OS_WIN32
1610 wizard.setField("libDir", "");
1611 if (opcodeDir.isEmpty()) {
1612 wizard.setField("opcodeDir", "");
1613 }
1614 #endif
1615 #ifdef Q_OS_MACOS
1616 wizard.setField("libDir", "/Library/Frameworks");
1617 #endif
1618 }
1619 }
1620 wizard.exec();
1621 if (wizard.result() == QDialog::Accepted) {
1622 AppProperties properties;
1623 properties.used = true;
1624 properties.appName = wizard.field("appName").toString();
1625 properties.targetDir = wizard.field("targetDir").toString();
1626 properties.author = wizard.field("author").toString();
1627 properties.version = wizard.field("version").toString();
1628 properties.date = QDateTime::currentDateTime().toString("MMMM d yyyy");
1629 properties.email = wizard.field("email").toString();
1630 properties.website = wizard.field("website").toString();
1631 properties.instructions = wizard.field("instructions").toString();
1632 properties.autorun = wizard.field("autorun").toBool();
1633 properties.showRun = wizard.field("showRun").toBool();
1634 properties.saveState = wizard.field("saveState").toBool();
1635 properties.runMode = wizard.field("runMode").toInt();
1636 properties.newParser = wizard.field("newParser").toBool();
1637 properties.useSdk = wizard.field("useSdk").toBool();
1638 properties.useCustomPaths = wizard.field("useCustomPaths").toBool();
1639 properties.libDir = wizard.field("libDir").toString();
1640 properties.opcodeDir = wizard.field("opcodeDir").toString();
1641
1642 documentPages[curPage]->setAppProperties(properties);
1643 bool ret = save(); // Must save to apply properties to file on disk.
1644 if (!ret) {
1645 qDebug() << "CsoundQt::createApp() Error saving file";
1646 return;
1647 }
1648 wizard.makeApp();
1649 }
1650 }
1651
1652 bool CsoundQt::saveNoWidgets()
1653 {
1654 QString fileName = getSaveFileName();
1655 if (fileName != "")
1656 return saveFile(fileName, false);
1657 else
1658 return false;
1659 }
1660
1661 void CsoundQt::info()
1662 {
1663 QString text = tr("Full Path:") + " " + documentPages[curPage]->getFileName() + "\n\n";
1664 text += tr("Number of lines (Csound Text):") + " " +
1665 QString::number(documentPages[curPage]->lineCount(true)) + "\n";
1666 text += tr("Number of characters (Csound Text):") + " " +
1667 QString::number(documentPages[curPage]->characterCount(true)) + "\n";
1668 text += tr("Number of lines (total):") + " " +
1669 QString::number(documentPages[curPage]->lineCount()) + "\n";
1670 text += tr("Number of characters (total):") + " " +
1671 QString::number(documentPages[curPage]->characterCount()) + "\n";
1672 text += tr("Number of instruments:") + " " +
1673 QString::number(documentPages[curPage]->instrumentCount()) + "\n";
1674 text += tr("Number of UDOs:") + " " +
1675 QString::number(documentPages[curPage]->udoCount()) + "\n";
1676 text += tr("Number of Widgets:") + " " +
1677 QString::number(documentPages[curPage]->widgetCount()) + "\n";
1678 text += tr("Embedded Files:") + " " +
1679 documentPages[curPage]->embeddedFiles() + "\n";
1680 QMessageBox::information(this, tr("File Information"),
1681 text,
1682 QMessageBox::Ok,
1683 QMessageBox::Ok);
1684 }
1685
1686 bool CsoundQt::closeTab(bool forceCloseApp, int index)
1687 {
1688 if (index == -1) {
1689 index = curPage;
1690 }
1691 // qDebug("CsoundQt::closeTab() curPage = %i documentPages.size()=%i", curPage, documentPages.size());
1692 if (documentPages.size() > 0 && documentPages[index]->isModified()) {
1693 QString message = tr("The document ")
1694 + (documentPages[index]->getFileName() != ""
1695 ? documentPages[index]->getFileName(): "untitled.csd")
1696 + tr("\nhas been modified.\nDo you want to save the changes before closing?");
1697 int ret = QMessageBox::warning(this, tr("CsoundQt"),
1698 message,
1699 QMessageBox::Yes | QMessageBox::Default,
1700 QMessageBox::No,
1701 QMessageBox::Cancel | QMessageBox::Escape);
1702 if (ret == QMessageBox::Cancel)
1703 return false;
1704 else if (ret == QMessageBox::Yes) {
1705 if (!save())
1706 return false;
1707 }
1708 }
1709 if (!forceCloseApp) {
1710 if (documentPages.size() <= 1) {
1711 if (QMessageBox::warning(this, tr("CsoundQt"),
1712 tr("Do you want to exit CsoundQt?"),
1713 QMessageBox::Yes | QMessageBox::Default,
1714 QMessageBox::No) == QMessageBox::Yes)
1715 {
1716 close();
1717 return false;
1718 }
1719 else {
1720 newFile();
1721 curPage = 0;
1722 }
1723 }
1724 }
1725 deleteTab(index);
1726 changePage(curPage);
1727 // storeSettings(); // do not store here, since all tabs are closed on exit
1728 return true;
1729 }
1730
1731 void CsoundQt::print()
1732 {
1733 QPrinter printer;
1734 QPrintDialog *dialog = new QPrintDialog(&printer, this);
1735 dialog->setWindowTitle(tr("Print Document"));
1736 // if (editor->textCursor().hasSelection())
1737 // dialog->addEnabledOption(QAbstractPrintDialog::PrintSelection);
1738 if (dialog->exec() != QDialog::Accepted)
1739 return;
1740 documentPages[curPage]->print(&printer);
1741 }
1742
1743 void CsoundQt::findReplace()
1744 {
1745 if(this->helpPanel->hasFocus()) {
1746 // TODO : call the help panel find
1747 this->helpPanel->toggleFindBarVisible(true);
1748 return;
1749 }
1750 documentPages[curPage]->findReplace();
1751 }
1752
1753 void CsoundQt::findString()
1754 {
1755 documentPages[curPage]->findString();
1756 }
1757
1758 bool CsoundQt::join(bool ask)
1759 {
1760 QDialog dialog(this);
1761 dialog.resize(700, 350);
1762 dialog.setModal(true);
1763 QPushButton *okButton = new QPushButton(tr("Ok"));
1764 QPushButton *cancelButton = new QPushButton(tr("Cancel"));
1765
1766 connect(okButton, SIGNAL(released()), &dialog, SLOT(accept()));
1767 connect(cancelButton, SIGNAL(released()), &dialog, SLOT(reject()));
1768
1769 QGridLayout *layout = new QGridLayout(&dialog);
1770 QListWidget *list1 = new QListWidget(&dialog);
1771 QListWidget *list2 = new QListWidget(&dialog);
1772 layout->addWidget(list1, 0, 0);
1773 layout->addWidget(list2, 0, 1);
1774 layout->addWidget(okButton, 1,0);
1775 layout->addWidget(cancelButton, 1,1);
1776 // layout->resize(400, 200);
1777
1778 for (int i = 0; i < documentPages.size(); i++) {
1779 QString name = documentPages[i]->getFileName();
1780 if (name.endsWith(".orc"))
1781 list1->addItem(name);
1782 else if (name.endsWith(".sco"))
1783 list2->addItem(name);
1784 }
1785 QString name = documentPages[curPage]->getFileName();
1786 QList<QListWidgetItem *> itemList = list1->findItems(name, Qt::MatchExactly);
1787 if (itemList.size() == 0) {
1788 itemList = list1->findItems(name.replace(".sco", ".orc"),Qt::MatchExactly);
1789 }
1790 if (itemList.size() > 0) {
1791 list1->setCurrentItem(itemList[0]);
1792 }
1793 QList<QListWidgetItem *> itemList2 = list2->findItems(name.replace(".orc", ".sco"),
1794 Qt::MatchExactly);
1795 if (itemList2.size() == 0) {
1796 itemList2 = list1->findItems(name,Qt::MatchExactly);
1797 }
1798 if (itemList2.size() > 0)
1799 list2->setCurrentItem(itemList2[0]);
1800 if (itemList.size() == 0 || itemList.size() == 0) {
1801 if (!ask) {
1802 QMessageBox::warning(this, tr("Join"),
1803 tr("Please open the orc and sco files in CsoundQt first!"));
1804 }
1805 return false;
1806 }
1807 if (!ask || dialog.exec() == QDialog::Accepted) {
1808 QString orcText = "";
1809 QString scoText = "";
1810 for (int i = 0; i < documentPages.size(); i++) {
1811 QString name = documentPages[i]->getFileName();
1812 if (name == list1->currentItem()->text())
1813 orcText = documentPages[i]->getFullText();
1814 else if (name == list2->currentItem()->text())
1815 scoText = documentPages[i]->getFullText();
1816 }
1817 QString text = "<CsoundSynthesizer>\n<CsOptions>\n</CsOptions>\n<CsInstruments>\n";
1818 text += orcText;
1819 text += "</CsInstruments>\n<CsScore>\n";
1820 text += scoText;
1821 text += "</CsScore>\n</CsoundSynthesizer>\n";
1822 newFile();
1823 documentPages[curPage]->loadTextString(text);
1824 return true;
1825 }
1826 return false;
1827 }
1828
1829 void CsoundQt::showUtilities(bool show)
1830 {
1831 if (!show) {
1832 if (utilitiesDialog != nullptr && utilitiesDialog->close()) {
1833 utilitiesDialog = nullptr;
1834 }
1835 }
1836 else {
1837 utilitiesDialog = new UtilitiesDialog(this, m_options/*, _configlists*/);
1838 connect(utilitiesDialog, SIGNAL(Close(bool)), showUtilitiesAct, SLOT(setChecked(bool)));
1839 connect(utilitiesDialog, SIGNAL(runUtility(QString)), this, SLOT(runUtility(QString)));
1840 utilitiesDialog->setModal(false);
1841 utilitiesDialog->show();
1842 }
1843 }
1844
1845 void CsoundQt::inToGet()
1846 {
1847 documentPages[curPage]->inToGet();
1848 }
1849
1850 void CsoundQt::insertMidiControlInstrument()
1851 {
1852
1853 QString instrument = documentPages[curPage]->getMidiControllerInstrument();
1854 qDebug() << instrument;
1855 int ret = QMessageBox::information(nullptr, tr("Insert"),
1856 tr("This function generates a Csound instrument from the MIDI bindings of your widgets (if thre is any) and inserts to the text editor at the current cursor position\n"
1857 "It can be useful if you want to run the csd outside of CsoundQt with your MIDI controller.\n" "Rembember to add -Ma or similar MIDI options to the CsOptions."), QMessageBox::Cancel |QMessageBox::Ok);
1858 if (ret==QMessageBox::Ok) {
1859 insertText("\n" + instrument + "\n");
1860 }
1861
1862 }
1863
1864 void CsoundQt::getToIn()
1865 {
1866 documentPages[curPage]->getToIn();
1867 }
1868
1869 void CsoundQt::updateCsladspaText()
1870 {
1871 documentPages[curPage]->updateCsLadspaText();
1872 }
1873
1874 void CsoundQt::updateCabbageText()
1875 {
1876 documentPages[curPage]->updateCabbageText();
1877 // check if necessary options for Cabbage
1878 QString optionsText=documentPages[curPage]->getOptionsText().trimmed();
1879 if (!(optionsText.contains("-d") && optionsText.contains("-n"))) {
1880 int answer = QMessageBox::question(this, tr("Insert Cabbage options?"),
1881 tr("There seems to be no Cabbage specific options in <CsOptions>.\n Do you want to insert it?\nNB! Comment your old options out, if necessary!"), QMessageBox::Yes|QMessageBox::No );
1882 if (answer==QMessageBox::Yes) {
1883 if (!optionsText.simplified().isEmpty()) {
1884 optionsText += "\n"; // add newline if there is some text
1885 }
1886 optionsText += "-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5";
1887 documentPages[curPage]->setOptionsText(optionsText);
1888 }
1889 }
1890 QString scoreText = documentPages[curPage]->getSco();
1891 if (scoreText.simplified().isEmpty()) {
1892 int answer = QMessageBox::question(this, tr("Insert scorelines for Cabbage?"),
1893 tr("The score is empty. Cabbage needs some lines "
1894 "to work.\n Do you want to insert it?"),
1895 QMessageBox::Yes|QMessageBox::No );
1896 if (answer==QMessageBox::Yes) {
1897 documentPages[curPage]->setSco("f 0 3600\n"
1898 ";i 1 0 3600 ; don't forget to start your instrument if you are using it as an effect!");
1899 }
1900 }
1901 }
1902
1903 void CsoundQt::saveWidgetsToQml()
1904 {
1905 QString qml = documentPages[curPage]->getQml();
1906
1907 //QString dir = lastUsedDir;
1908 QString name = documentPages[curPage]->getFileName();
1909 name.replace(".csd", ".qml");
1910 //dir += name.mid(name.lastIndexOf("/") + 1);
1911 //TODO: get dir from name - extract path
1912 QString fileName = QFileDialog::getSaveFileName(
1913 this, tr("Save Qml File"), name,
1914 tr("QML Files (*.qml *.QML);;All Files (*)",
1915 "Export Widgets to QML"));
1916 if ( !fileName.isEmpty()) { // save to file
1917 QFile file(fileName);
1918
1919 if(file.open(QFile::WriteOnly | QFile::Text)) {
1920 QTextStream stream(&file);
1921 stream << qml;
1922 file.close();
1923 }
1924 }
1925 }
1926
1927 void CsoundQt::setCurrentAudioFile(const QString fileName)
1928 {
1929 currentAudioFile = fileName;
1930 }
1931
1932 void CsoundQt::play(bool realtime, int index)
1933 {
1934 qDebug() << "CsoundQt::play...";
1935 // TODO make csound pause if it is already running
1936 int oldPage = curPage;
1937 if (index == -1) {
1938 index = curPage;
1939 }
1940 if (index < 0 && index >= documentPages.size()) {
1941 qDebug() << "CsoundQt::play index out of range " << index;
1942 return;
1943 }
1944 curPage = index;
1945 auto page = documentPages[curPage];
1946
1947 QFileInfo fileInfo(QFileInfo(page->getFileName()).path());
1948
1949 if (page->getFileName().isEmpty()) {
1950 int answer;
1951 if(!m_options->askIfTemporary)
1952 answer= QMessageBox::Ok;
1953 else
1954 answer = QMessageBox::question(this, tr("Run as temporary file?"),
1955 tr("press <b>OK</b>, if you don't care about this file in "
1956 "future.\n Press <b>Save</b>, if you want to save it with "
1957 "given name.\n You can always save the file with <b>Save As</b> "
1958 "also later, if you use the temporary file."),
1959 QMessageBox::Ok|QMessageBox::Save|QMessageBox::Cancel );
1960 bool saved = false;
1961 if (answer==QMessageBox::Save) {
1962 saved = saveAs();
1963 } else if (answer==QMessageBox::Ok) {
1964 auto tempPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
1965 if (!tempPath.isEmpty() && saveFile(tempPath + "/csoundqt-temp.csd")) {
1966 saved = true;
1967 } else {
1968 QMessageBox::critical(this,tr("Save error"), tr("Could not save temporary file"));
1969 }
1970 }
1971 if (!saved) {
1972 if (curPage == oldPage) {
1973 runAct->setChecked(false);
1974 }
1975 curPage = oldPage;
1976 return;
1977 }
1978 }
1979 //else if (page->isModified()) {
1980 else if (m_options->saveChanges && fileInfo.isWritable() && !page->getFileName().startsWith(":/")) { // is modified returns sometimes wrongly false. save anyway when asked TODO: degub DocumentPage::isModified()
1981 if (!save()) {
1982 if (curPage == oldPage) {
1983 runAct->setChecked(false);
1984 }
1985 curPage = oldPage;
1986 return;
1987 }
1988 }
1989 QString fileName = page->getFileName();
1990 QString fileName2;
1991 QString msg = "__**__ " + QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss");
1992 msg += " Play: " + fileName + "\n";
1993 logMessage(msg);
1994 m_options->csdPath = "";
1995 if (fileName.contains('/')) {
1996 //FIXME is it necessary to set the csdPath here?
1997 // m_options->csdPath =
1998 // documentPages[curPage]->fileName.left(documentPages[curPage]->fileName.lastIndexOf('/'));
1999 QDir::setCurrent(fileName.left(fileName.lastIndexOf('/')));
2000 }
2001 #ifdef QCS_PYTHONQT
2002 if (fileName.endsWith(".py",Qt::CaseInsensitive)) {
2003 m_pythonConsole->runScript(fileName);
2004 runAct->setChecked(false);
2005 curPage = documentTabs->currentIndex();
2006 return;
2007 }
2008 #endif
2009 if (fileName.endsWith(".html",Qt::CaseInsensitive)) {
2010 QMessageBox::warning(this,
2011 tr("CsoundQt"),
2012 tr("Csound in html files should be started from html code."),
2013 QMessageBox::Ok);
2014 runAct->setChecked(false);
2015 curPage = documentTabs->currentIndex();
2016 return;
2017 }
2018 if (!fileName.endsWith(".csd",Qt::CaseInsensitive)
2019 && !fileName.endsWith(".py",Qt::CaseInsensitive)) {
2020 if (page->askForFile)
2021 getCompanionFileName();
2022 // FIXME run orc file when sco companion is currently active
2023 if (fileName.endsWith(".sco",Qt::CaseInsensitive)) {
2024 //Must switch filename order when open file is a sco file
2025 fileName2 = fileName;
2026 fileName = page->getCompanionFileName();
2027 } else if (fileName.endsWith(".orc",Qt::CaseInsensitive) &&
2028 page->getCompanionFileName().isEmpty()) {
2029 //TODO: create empty score file
2030 }
2031 else
2032 fileName2 = page->getCompanionFileName();
2033 }
2034 QString runFileName1, runFileName2;
2035 QTemporaryFile csdFile, csdFile2; // TODO add support for orc/sco pairs
2036 runFileName1 = fileName;
2037 if(fileName.startsWith(":/", Qt::CaseInsensitive) || !m_options->saveChanges || !fileInfo.isWritable() ) {
2038 QDEBUG << "***** Using temporary file for filename" << fileName;
2039 QString tmpFileName = QDir::tempPath();
2040 if (!tmpFileName.endsWith("/") && !tmpFileName.endsWith("\\")) {
2041 tmpFileName += QDir::separator();
2042 }
2043 if (fileName.endsWith(".csd",Qt::CaseInsensitive)) {
2044 tmpFileName += QString("csound-tmpXXXXXXXX.csd");
2045 csdFile.setFileTemplate(tmpFileName);
2046 if (!csdFile.open()) {
2047 qDebug() << "Error creating temporary file " << tmpFileName;
2048 QMessageBox::critical(this, tr("CsoundQt"), tr("Error creating temporary file."),
2049 QMessageBox::Ok);
2050 return;
2051 }
2052 // If example, just copy, since readonly anyway, otherwise get contents from editor.
2053 // Necessary since examples may contain <CsFileB> section with data.
2054 if (!fileName.startsWith(":/examples/", Qt::CaseInsensitive) ) {
2055 csdFile.write(page->getBasicText().toLatin1());
2056 } else {
2057 auto fullText = page->getView()->getFullText();
2058 if(!fullText.contains("<CsFileB")) {
2059 csdFile.write(fullText.toLatin1());
2060 } else {
2061 qDebug() << "File has embedded elements via <CsFileB> tag";
2062 QFile file(fileName);
2063 if(!file.open(QFile::ReadOnly)) {
2064 qDebug() << "Could not open file " << fileName;
2065 return;
2066 }
2067 int result = csdFile.write(file.readAll());
2068 file.close();
2069 if (result<=0) {
2070 qDebug()<< "*** ERROR: Failed to copy to example to temporary "
2071 "location ***";
2072 return;
2073 }
2074 }
2075 }
2076 csdFile.flush();
2077 runFileName1 = csdFile.fileName();
2078 }
2079 }
2080 runFileName2 = page->getCompanionFileName();
2081 m_options->docName = fileName;
2082 m_options->fileName1 = runFileName1;
2083 m_options->fileName2 = runFileName2;
2084 m_options->rt = realtime;
2085 if (!m_options->simultaneousRun) {
2086 stopAllOthers();
2087 #if defined(QCS_QTHTML)
2088 csoundHtmlView->stop();
2089 #endif
2090 }
2091 if (curPage == oldPage) {
2092 runAct->setChecked(true); // In case the call comes from a button
2093 }
2094 if (page->usesFltk() && m_options->terminalFLTK) {
2095 runInTerm();
2096 curPage = oldPage;
2097 return;
2098 }
2099 int ret = page->play(m_options);
2100 if (ret == -1) {
2101 QMessageBox::critical(this, "CsoundQt", tr("Internal error running Csound."),
2102 QMessageBox::Ok);
2103 } else if (ret == -2) {
2104 // Error creating temporary file
2105 runAct->setChecked(false);
2106 qDebug() << "CsoundQt::play - Error creating temporary file";
2107 } else if (ret == -3) {
2108 // Csound compilation failed
2109 runAct->setChecked(false);
2110 } else if (ret == 0) {
2111 // No problem:
2112 // set playing icon on tab
2113 documentTabs->setTabIcon(index, QIcon(QString(":/themes/%1/media-play.png").arg(m_options->theme )));
2114
2115 // enable widgets
2116 if(m_options->checkSyntaxOnly) {
2117 return;
2118 }
2119 if (m_options->enableWidgets && m_options->showWidgetsOnRun && fileName.endsWith(".csd")) {
2120 if(page->usesFltk()) {
2121 // Don't bring up widget panel if there's an FLTK panel
2122 qDebug() << "Page uses FLTK, CsoundQt's widgets will not be shown";
2123 } else {
2124 if (!m_options->widgetsIndependent) {
2125 if (widgetPanel->isFloating()) {
2126 widgetPanel->setVisible(true);
2127 showWidgetsAct->setChecked(true);
2128 }
2129 }
2130 else {
2131 page->widgetsVisible(true);
2132 showWidgetsAct->setChecked(true);
2133 }
2134 widgetPanel->setFocus(Qt::OtherFocusReason);
2135 page->showLiveEventControl(showLiveEventsAct->isChecked());
2136 page->focusWidgets();
2137 }
2138 }
2139 } else {
2140 qDebug() << "play: Return value not understood!";
2141 return;
2142 }
2143 #if defined(QCS_QTHTML)
2144 if (!documentPages.isEmpty() && !documentPages[curPage]->getHtmlText().isEmpty()) {
2145 if ( !m_options->saveChanges ) { // otherwise the htmlview gets updated on save
2146 updateHtmlView();
2147 qDebug()<<"update html on run";
2148 }
2149 DocumentPage *documentPage = documentPages[curPage];
2150 if (!documentPage->getHtmlText().isEmpty()) {
2151 CsoundEngine *engine = documentPage->getEngine();
2152 csoundHtmlView->setCsoundEngine(engine);
2153 }
2154 }
2155 #endif
2156 curPage = oldPage;
2157 }
2158
2159 void CsoundQt::runInTerm(bool realtime)
2160 {
2161 QString fileName = documentPages[curPage]->getFileName();
2162 QTemporaryFile tempFile(QDir::tempPath() + QDir::separator() + "CsoundQtExample-XXXXXX.csd");
2163 tempFile.setAutoRemove(false);
2164 if (fileName.startsWith(":/")) {
2165 if (!tempFile.open()) {
2166 QMessageBox::critical(this, tr("Error running terminal"),
2167 tr("Error creating temp file"));
2168 runAct->setChecked(false);
2169 return;
2170 }
2171 QString csdText = documentPages[curPage]->getBasicText();
2172 fileName = tempFile.fileName();
2173 tempFile.write(csdText.toLatin1());
2174 tempFile.flush();
2175 if (!tempScriptFiles.contains(fileName))
2176 tempScriptFiles << fileName;
2177 }
2178 QString executable = fileName.endsWith(".py") ? m_options->pythonExecutable : "";
2179 QString script = generateScript(realtime, fileName, executable);
2180 QTemporaryFile scriptFile(QDir::tempPath() + QDir::separator() + SCRIPT_NAME);
2181 scriptFile.setAutoRemove(false);
2182 if (!scriptFile.open()) {
2183 runAct->setChecked(false);
2184 QMessageBox::critical(this, tr("Error running terminal"),
2185 tr("Error generating the script to be run at the terminal"));
2186 return;
2187 }
2188 QTextStream out(&scriptFile);
2189 out << script;
2190 scriptFile.close();
2191 scriptFile.setPermissions(QFile::ExeOwner| QFile::WriteOwner| QFile::ReadOwner);
2192 QString scriptFileName = scriptFile.fileName();
2193 QStringList args;
2194 QString termexe = m_options->terminal;
2195 // QString options;
2196 #ifdef Q_OS_LINUX
2197 args << "-e" << scriptFileName;
2198 // options = "-e " + scriptFileName;
2199 #endif
2200 #ifdef Q_OS_SOLARIS
2201 args << "-e" << scriptFileName;
2202 // options = "-e " + scriptFileName;
2203 #endif
2204 #ifdef Q_OS_MACOS
2205 args << "-a" << m_options->terminal << scriptFileName;
2206 termexe = "open";
2207 // options = scriptFileName;
2208 #endif
2209 #ifdef Q_OS_WIN32
2210 args << scriptFileName;
2211 // options = scriptFileName;
2212 // qDebug() << "m_options->terminal == " << m_options->terminal;
2213 #endif
2214 if(startProcess(termexe, args)) {
2215 QMessageBox::critical(this, tr("Error running terminal"),
2216 tr("Could not run terminal program: '%1'\nArgs: %2\n"
2217 "Check environment tab in preferences.").arg(termexe, args.join(" ")));
2218 }
2219 runAct->setChecked(false);
2220 if (!tempScriptFiles.contains(scriptFileName))
2221 tempScriptFiles << scriptFileName;
2222 }
2223
2224 void CsoundQt::pause(int index)
2225 {
2226 int docIndex = index;
2227 if (docIndex == -1) {
2228 docIndex = curPage;
2229 }
2230 if (docIndex >= 0 && docIndex < documentPages.size()) {
2231 documentPages[docIndex]->pause();
2232 if (documentPages[docIndex]->getEngine()->isPaused() ) {
2233 documentTabs->setTabIcon(docIndex, QIcon(QString(":/themes/%1/media-pause.png").arg(m_options->theme )));
2234 } else {
2235 documentTabs->setTabIcon(docIndex, QIcon(QString(":/themes/%1/media-play.png").arg(m_options->theme )));
2236 }
2237 }
2238 }
2239
2240 void CsoundQt::stop(int index)
2241 {
2242 // Must guarantee that csound has stopped when it returns
2243 int docIndex = index;
2244 if (docIndex == -1) {
2245 docIndex = curPage;
2246 }
2247 if (curPage >= documentPages.size()) {
2248 return; // A bit of a hack to avoid crashing when documents are deleted very quickly...
2249 }
2250 Q_ASSERT(docIndex >= 0);
2251 if (docIndex >= documentPages.size()) {
2252 qDebug() << "CsoundQt::stop : document index" << docIndex
2253 << "out of range (max=" << documentPages.size() << ")";
2254 markStopped();
2255 return;
2256 }
2257 if (documentPages[docIndex]->isRunning()) {
2258 documentPages[docIndex]->stop();
2259 documentTabs->setTabIcon(docIndex, QIcon());
2260
2261 #ifdef Q_OS_WIN
2262 // necessary since sometimes fltk plugin closes the OLE/COM connection on csoundCleanup
2263 HRESULT result = OleInitialize(NULL);
2264 if (result) {
2265 qDebug()<<"Problem with OleInitialization" << result;
2266 }
2267 #endif
2268
2269 }
2270 documentTabs->setTabIcon(docIndex, QIcon());
2271 markStopped();
2272 }
2273
2274 void CsoundQt::stopAll()
2275 {
2276 for (int i = 0; i < documentPages.size(); i++) {
2277 documentPages[i]->stop();
2278 documentTabs->setTabIcon(i, QIcon());
2279 }
2280 markStopped();
2281 }
2282
2283 void CsoundQt::stopAllOthers()
2284 {
2285 for (int i = 0; i < documentPages.size(); i++) {
2286 if (i != curPage) {
2287 DocumentPage *documentPage = documentPages[i];
2288 documentPage->stop();
2289 documentTabs->setTabIcon(i, QIcon());
2290 }
2291 }
2292 // markStopped();
2293 }
2294
2295 void CsoundQt::markStopped()
2296 {
2297 DocumentPage * senderPage = dynamic_cast<DocumentPage *>(sender());
2298 if (senderPage) {
2299 int index = documentPages.indexOf(senderPage);
2300 //qDebug() << "Stop was sent from: " << index;
2301 documentTabs->setTabIcon(index, QIcon());
2302 }
2303 documentTabs->setTabIcon(curPage, QIcon());
2304 runAct->setChecked(false);
2305 recAct->setChecked(false);
2306 #ifdef QCS_DEBUGGER
2307 m_debugPanel->stopDebug();
2308 #endif
2309 }
2310
2311 void CsoundQt::perfEnded()
2312 {
2313 runAct->setChecked(false);
2314 }
2315
2316 void CsoundQt::record(bool rec) {
2317 record(rec, curPage);
2318 }
2319
2320 void CsoundQt::record(bool rec, int index=-1)
2321 {
2322 if (index==-1) index=curPage;
2323 if (rec) {
2324 if (!documentPages[index]->isRunning()) {
2325 play();
2326 }
2327 int ret = documentPages[index]->record(m_options->sampleFormat);
2328 documentTabs->setTabIcon(index, QIcon(QString(":/themes/%1/media-record.png").arg(m_options->theme )));
2329 if (ret != 0) {
2330 recAct->setChecked(false);
2331 documentTabs->setTabIcon(index, QIcon());
2332 }
2333 }
2334 else {
2335 documentPages[index]->stopRecording();
2336 QMessageBox::information(nullptr, tr("Record"), tr("Recorded to audiofile ") + this->currentAudioFile);
2337 // documentTabs->setTabIcon(curPage, QIcon());
2338 }
2339 }
2340
2341
2342 void CsoundQt::sendEvent(QString eventLine, double delay)
2343 {
2344 sendEvent(curCsdPage, eventLine, delay);
2345 }
2346
2347 void CsoundQt::sendEvent(int index, QString eventLine, double delay)
2348 {
2349 int docIndex = index;
2350 if (docIndex == -1) {
2351 docIndex = curPage;
2352 }
2353 if (docIndex >= 0 && docIndex < documentPages.size()) {
2354 documentPages[docIndex]->queueEvent(eventLine, delay);
2355 }
2356 }
2357
2358 void CsoundQt::render()
2359 {
2360 if (m_options->fileAskFilename) {
2361 QString defaultFile;
2362 if (m_options->fileOutputFilenameActive) {
2363 defaultFile = m_options->fileOutputFilename;
2364 }
2365 else {
2366 defaultFile = lastFileDir;
2367 }
2368 QFileDialog dialog(this,tr("Output Filename"),defaultFile);
2369 dialog.setAcceptMode(QFileDialog::AcceptSave);
2370 // dialog.setConfirmOverwrite(false);
2371 auto extensions = m_configlists.fileTypeExtensions[m_options->fileFileType];
2372 QString filter = QString(m_configlists.fileTypeLongNames[m_options->fileFileType] +
2373 " Files (" + extensions + ")");
2374 dialog.selectNameFilter(filter);
2375 if (dialog.exec() == QDialog::Accepted) {
2376 QString extension = extensions.left(extensions.indexOf(";"));
2377 // Remove the '*' from the extension
2378 extension.remove(0,1);
2379 m_options->fileOutputFilename = dialog.selectedFiles()[0];
2380 if (!m_options->fileOutputFilename.endsWith(".wav")
2381 && !m_options->fileOutputFilename.endsWith(".aif")
2382 && !m_options->fileOutputFilename.endsWith(extension) ) {
2383 m_options->fileOutputFilename += extension;
2384 }
2385 auto outfile = m_options->fileOutputFilename;
2386 if (QFile::exists(outfile)) {
2387 int ret = QMessageBox::warning(this, tr("CsoundQt"),
2388 tr("The file %1 already exists.\n Do you want to overwrite it?")
2389 .arg(outfile),
2390 QMessageBox::Save|QMessageBox::Cancel, QMessageBox::Save);
2391 if (ret == QMessageBox::Cancel)
2392 return;
2393 }
2394 lastFileDir = dialog.directory().path();
2395 }
2396 else {
2397 return;
2398 }
2399 }
2400 QString outName = m_options->fileOutputFilename;
2401 #ifdef Q_OS_WIN32
2402 outName = outName.replace('\\', '/');
2403 #endif
2404 if (outName.isEmpty()) {
2405 outName = "test.wav";
2406 }
2407 setCurrentAudioFile(outName);
2408 play(false);
2409 }
2410
2411 void CsoundQt::openExternalEditor()
2412 {
2413 QString name = "";
2414 if (m_options->sfdirActive) {
2415 name = m_options->sfdir + (m_options->sfdir.endsWith("/") ? "" : "/");
2416 }
2417 name += currentAudioFile;
2418 QString optionsText = documentPages[curPage]->getOptionsText();
2419 if (currentAudioFile == "") {
2420 if (!optionsText.contains(QRegExp("\\W-o"))) {
2421 name += "test.wav";
2422 }
2423 else {
2424 optionsText = optionsText.mid(optionsText.indexOf(QRegExp("\\W-o")) + 3);
2425 optionsText = optionsText.left(optionsText.indexOf("\n")).trimmed();
2426 optionsText = optionsText.left(optionsText.indexOf("-")).trimmed();
2427 if (!optionsText.startsWith("dac"))
2428 name += optionsText;
2429 }
2430 }
2431 if (!QFile::exists(name)) {
2432 QMessageBox::critical(this, tr("Render not available"),
2433 tr("Could not find rendered file. Please render before calling"
2434 " external editor."));
2435 }
2436 if (!m_options->waveeditor.isEmpty()) {
2437 // name = "\"" + name + "\"";
2438 QDEBUG << "Opening rendered audiofile: " << name;
2439 execute(m_options->waveeditor, name);
2440 }
2441 else {
2442 QDesktopServices::openUrl(QUrl::fromLocalFile (name));
2443 }
2444 }
2445
2446 void CsoundQt::openExternalPlayer()
2447 {
2448 QString name = "";
2449 if (m_options->sfdirActive) {
2450 name = m_options->sfdir + (m_options->sfdir.endsWith("/") ? "" : "/");
2451 }
2452 name += currentAudioFile;
2453 QString optionsText = documentPages[curPage]->getOptionsText();
2454 if (currentAudioFile == "") {
2455 if (!optionsText.contains(QRegExp("\\W-o"))) {
2456 name += "test.wav";
2457 }
2458 else {
2459 optionsText = optionsText.mid(optionsText.indexOf(QRegExp("\\W-o")) + 3);
2460 optionsText = optionsText.left(optionsText.indexOf("\n")).trimmed();
2461 optionsText = optionsText.left(optionsText.indexOf(QRegExp("-"))).trimmed();
2462 if (!optionsText.startsWith("dac"))
2463 name += optionsText;
2464 }
2465 }
2466 if (!QFile::exists(name)) {
2467 QMessageBox::critical(this, tr("Render not available"),
2468 tr("Could not find rendered file. Please render before calling"
2469 " external player."));
2470 }
2471 if (!m_options->waveplayer.isEmpty()) {
2472 name = "\"" + name + "\"";
2473 execute(m_options->waveplayer, name);
2474 }
2475 else {
2476 QDesktopServices::openUrl(QUrl::fromLocalFile (name));
2477 }
2478 }
2479
2480 void CsoundQt::setEditorFocus()
2481 {
2482 documentPages[curPage]->setEditorFocus();
2483 this->raise();
2484 }
2485
2486
2487 /**
2488 * @brief CsoundQt::helpForEntry open help for given entry
2489 * @param entry - The entry to find help for (normally an opcode)
2490 * @param external - If true, open in an external browser (default=false)
2491 */
2492 void CsoundQt::helpForEntry(QString entry, bool external) {
2493 QDEBUG << "searching help for" << entry;
2494 if (entry.startsWith('#')) { // For #define and friends
2495 entry.remove(0,1);
2496 }
2497 QString dir = m_options->csdocdir.isEmpty() ? helpPanel->docDir : m_options->csdocdir ;
2498 if (entry.startsWith("http://")) {
2499 openExternalBrowser(QUrl(entry));
2500 return;
2501 }
2502 QString errmsg;
2503
2504 if(risset->isInstalled && risset->opcodeToPlugin.contains(entry)) {
2505 // Check external help sources
2506 QDEBUG << "Found an opcode from an external plugin: " << entry;
2507 auto pluginName = risset->opcodeToPlugin[entry];
2508 if(!risset->pluginInstalled[pluginName]) {
2509 QDEBUG << "The opcode " << entry << "is defined in the plugin " << pluginName << ", but this plugin is not installed";
2510 QMessageBox::information(this, "Risset",
2511 QString("The plugin '%1' containing the opcode '%2' is not installed "
2512 "You can install it via risset: 'risset install %1'").arg(pluginName, entry));
2513 }
2514 QString fileName = risset->htmlManpage(entry);
2515 if(!fileName.isEmpty()) {
2516 openHtmlHelp(fileName, entry, external);
2517 }
2518 else {
2519 QDEBUG << "Did not find html page for opcode" << entry;
2520 auto reply = QMessageBox::question(this, "Risset",
2521 "Risset documentation not found. Do you want to fetch it? "
2522 " (it may take a few seconds)",
2523 QMessageBox::Yes|QMessageBox::No);
2524 if(reply == QMessageBox::Yes) {
2525 risset->generateDocumentation([=](int exitCode) {
2526 if(exitCode==0) {
2527 QMessageBox::information(this, "Risset", "Fetched documentation");
2528 helpForEntry(entry, external);
2529 }
2530 else {
2531 qDebug() << "Generate documentation exit code: " << exitCode;
2532 QMessageBox::warning(this, "Risset",
2533 "Failed to fetch documentation");
2534 }
2535 });
2536 }
2537 return;
2538 }
2539 }
2540 else if (dir.isEmpty()) {
2541 QMessageBox::critical(this, tr("Error"),
2542 tr("HTML Documentation directory not set!\n"
2543 "Please go to Edit->Options->Environment and select directory\n"));
2544 return;
2545 }
2546 else if(entry.startsWith("--") || entry.startsWith("-+")) {
2547 openHtmlHelp(dir+"/CommandFlagsCategory.html", "", external);
2548 }
2549 else {
2550 helpPanel->docDir = dir;
2551 QString fileName;
2552 if (entry == "0dbfs")
2553 fileName = dir + "/Zerodbfs.html";
2554 else if (entry.contains("CsOptions"))
2555 fileName = dir + "/CommandUnifile.html";
2556 else if (entry.startsWith("chn_"))
2557 fileName = dir + "/chn.html";
2558 else if(QFile::exists(dir + "/" + entry + ".html")) {
2559 fileName = dir + "/" + entry + ".html";
2560 }
2561 else
2562 return;
2563 openHtmlHelp(fileName, entry, external);
2564 }
2565 }
2566
2567
2568 void CsoundQt::openHtmlHelp(QString fileName, QString entry, bool external) {
2569 if(external) {
2570 openExternalBrowser(fileName);
2571 } else {
2572 helpPanel->loadFile(fileName, entry);
2573 helpPanel->show();
2574 helpPanel->raise();
2575 helpPanel->focusText();
2576 }
2577 }
2578
2579
2580 void CsoundQt::setHelpEntry()
2581 {
2582 QString line = documentPages[curPage]->lineUnderCursor();
2583 auto match = QRegularExpression("-[-\\+][a-zA-Z-_]+").match(line);
2584 if(match.hasMatch()) {
2585 auto capt = match.captured();
2586 if(m_longOptions.contains(capt)) {
2587 return helpForEntry(capt);
2588 }
2589 }
2590 QString word = documentPages[curPage]->wordUnderCursor();
2591 return helpForEntry(word);
2592 }
2593
2594
2595 void CsoundQt::setFullScreen(bool full)
2596 {
2597 if (full) {
2598 checkFullScreen();
2599 this->showFullScreen();
2600 m_fullScreenComponent = "mainwindow";
2601 }
2602 else {
2603 checkFullScreen(); // if something is still fullscreen by error, reset it;
2604 this->showNormal();
2605 m_fullScreenComponent = "";
2606 }
2607 }
2608
2609 void CsoundQt::checkFullScreen() // checks if some component is already fullscreen and resets it
2610 {
2611 //qDebug()<< " fullScreenComponent: " << m_fullScreenComponent << "state bytes: " << m_preFullScreenState.size();
2612 if ( !m_fullScreenComponent.isEmpty() ) {
2613 if (m_fullScreenComponent == "mainwindow" ) {
2614 viewFullScreenAct->setChecked(false);
2615 } else if (m_fullScreenComponent == "help" ) {
2616 viewHelpFullScreenAct->setChecked(false);
2617 } else if (m_fullScreenComponent == "widgets") {
2618 viewWidgetsFullScreenAct->setChecked(false);
2619 } else if ( m_fullScreenComponent == "editor" ) {
2620 } else if ( m_fullScreenComponent == "html" ) {
2621 viewHtmlFullScreenAct->setChecked(false);
2622 }
2623 }
2624 }
2625
2626 void CsoundQt::setEditorFullScreen(bool full)
2627 {
2628 if (full) {
2629 checkFullScreen();
2630 m_preFullScreenState = this->saveState();
2631 QList<QDockWidget *> dockWidgets = findChildren<QDockWidget *>();
2632 foreach (QDockWidget *dockWidget, dockWidgets) {
2633 dockWidget->hide();
2634 }
2635 this->showFullScreen();
2636 m_fullScreenComponent = "editor";
2637 }
2638 else {
2639 this->restoreState(m_preFullScreenState);
2640 this->showNormal(); // to restore titlebar etc
2641 m_fullScreenComponent = "";
2642 }
2643 }
2644
2645
2646 void CsoundQt::setHtmlFullScreen(bool full)
2647 {
2648 #ifdef QCS_QTHTML
2649 if (full) {
2650 checkFullScreen();
2651 m_preFullScreenState = this->saveState();
2652 this->csoundHtmlView->setFloating(true);
2653 #ifndef Q_OS_WIN // this was Q_OS_MACOS before - try now showMaximized for all expect Windows
2654 this->csoundHtmlView->showMaximized();
2655 #else
2656 this->csoundHtmlView->showFullScreen();
2657 #endif
2658 m_fullScreenComponent = "html";
2659 }
2660 else {
2661 this->restoreState(m_preFullScreenState);
2662 this->csoundHtmlView->setFloating(false);
2663 //this->showNormal();
2664 m_fullScreenComponent = "";
2665 }
2666 #endif
2667 }
2668
2669 void CsoundQt::setHelpFullScreen(bool full)
2670 {
2671 if (full) {
2672 checkFullScreen();
2673 m_preFullScreenState = this->saveState();
2674 this->helpPanel->setFloating(true);
2675 #ifndef Q_OS_WIN
2676 this->helpPanel->showMaximized();
2677 #else
2678 this->helpPanel->showFullScreen();
2679 #endif
2680 m_fullScreenComponent = "help";
2681 }
2682 else {
2683 this->restoreState(m_preFullScreenState);
2684 //this->showNormal();
2685 m_fullScreenComponent = "";
2686 }
2687 }
2688
2689 void CsoundQt::setWidgetsFullScreen(bool full)
2690 {
2691 if (full) {
2692 checkFullScreen();
2693 m_preFullScreenState = this->saveState();
2694 if (m_options->widgetsIndependent) {
2695 auto doc = getCurrentDocumentPage();
2696 if(doc == nullptr)
2697 return;
2698 auto wl = doc->getWidgetLayout();
2699 wl->setVisible(true);
2700 #ifndef Q_OS_WIN
2701 wl->showMaximized();
2702 #else
2703 wl->showFullScreen();
2704 #endif
2705 } else {
2706 this->widgetPanel->setFloating(true);
2707 #ifndef Q_OS_WIN
2708 this->widgetPanel->showMaximized();
2709 #else
2710 this->widgetPanel->showFullScreen();
2711 #endif
2712 }
2713 m_fullScreenComponent = "widgets";
2714 }
2715 else {
2716 if(m_options->widgetsIndependent) {
2717 auto doc = getCurrentDocumentPage();
2718 if(doc == nullptr)
2719 return;
2720 doc->getWidgetLayout()->showNormal();
2721 m_fullScreenComponent = "";
2722 } else {
2723 this->restoreState(m_preFullScreenState);
2724 //this->showNormal();
2725 m_fullScreenComponent = "";
2726 }
2727
2728 }
2729 }
2730
2731
2732 void CsoundQt::showDebugger(bool show)
2733 {
2734 #ifdef QCS_DEBUGGER
2735 m_debugPanel->setVisible(show);
2736 #else
2737 (void) show;
2738 #endif
2739 }
2740
2741 void CsoundQt::showVirtualKeyboard(bool show)
2742 {
2743 #ifdef USE_QT_GT_53
2744 if (show) {
2745 // create here to be able to be able to delete in on close and catch destroyed()
2746 // to uncheck action button
2747 m_virtualKeyboard = new QQuickWidget(this);
2748 m_virtualKeyboard->setAttribute(Qt::WA_DeleteOnClose);
2749 m_virtualKeyboardPointer = m_virtualKeyboard; // guarded pointer to check if object is alive
2750 m_virtualKeyboard->setWindowTitle(tr("CsoundQt Virtual Keyboard"));
2751 m_virtualKeyboard->setWindowFlags(Qt::Window);
2752 m_virtualKeyboard->setSource(QUrl("qrc:/QML/VirtualKeyboard.qml"));
2753 QObject *rootObject = m_virtualKeyboard->rootObject();
2754 m_virtualKeyboard->setFocus();
2755 connect(rootObject, SIGNAL(genNote(QVariant, QVariant, QVariant, QVariant)),
2756 this, SLOT(virtualMidiIn(QVariant, QVariant, QVariant, QVariant)));
2757 connect(rootObject, SIGNAL(newCCvalue(int,int,int)), this, SLOT(virtualCCIn(int, int, int)));
2758 m_virtualKeyboard->setVisible(true);
2759 connect(m_virtualKeyboard, SIGNAL(destroyed(QObject*)),
2760 this, SLOT(virtualKeyboardActOff(QObject*)));
2761 } else if (!m_virtualKeyboardPointer.isNull()) { // check if object still existing (i.e not on exit)
2762 m_virtualKeyboard->setVisible(false);
2763 m_virtualKeyboard->close();
2764 }
2765 #else
2766 QMessageBox::warning(this, tr("Qt5 Required"), tr("Qt version > 5.2 is required for the virtual keyboard."));
2767 #endif
2768 }
2769
2770 void CsoundQt::showTableEditor(bool show)
2771 {
2772 #ifdef USE_QT_GT_53
2773 if (show) {
2774 m_tableEditor = new QQuickWidget(this); // create here to be able to
2775 m_tableEditor->setAttribute(Qt::WA_DeleteOnClose); // ... be able to delete in on close and catch destroyed() to uncheck action button
2776 m_tableEditorPointer = m_tableEditor; // guarded pointer to check if object is alive
2777 m_tableEditor->setWindowTitle(tr("CsoundQt table editor"));
2778 m_tableEditor->setWindowFlags(Qt::Window);
2779 m_tableEditor->setSource(QUrl("qrc:/QML/TableEditor.qml"));
2780 m_tableEditor->setResizeMode(QQuickWidget::SizeRootObjectToView);
2781 QObject *rootObject = m_tableEditor->rootObject();
2782 m_tableEditor->setFocus();
2783 connect(rootObject, SIGNAL(newSyntax(QString)), this, SLOT(handleTableSyntax(QString)));
2784 // see if selected text contains a ftgen definition, then set in the editor
2785 QString selectedText = getSelectedText();
2786 if (selectedText.contains("ftgen") && selectedText.split(",")[3].simplified()=="7") {
2787 qDebug()<<"This is a ftgen 7 definition: " << selectedText;
2788 QObject *syntaxField = rootObject->findChild<QObject*>("syntaxField");
2789 syntaxField->setProperty("text",QVariant(selectedText.simplified())); // display teh text in QML window
2790 QMetaObject::invokeMethod(rootObject, "syntax2graph",
2791 Q_ARG(QVariant, selectedText.simplified() ),
2792 Q_ARG(QVariant, 0)); // if 0, finds max from the table parameters
2793 }
2794
2795 m_tableEditor->setVisible(true);
2796 connect(m_tableEditor, SIGNAL(destroyed(QObject*)), this, SLOT(tableEditorActOff(QObject*)));
2797 } else if (!m_tableEditorPointer.isNull()) { // check if object still existing (i.e not on exit)
2798 m_tableEditor->setVisible(false);
2799 m_tableEditor->close();
2800 }
2801 #else
2802 QMessageBox::warning(this, tr("Qt5 Required"), tr("Qt version > 5.2 is required for the virtual keyboard."));
2803 #endif
2804
2805 }
2806
2807 void CsoundQt::virtualKeyboardActOff(QObject *parent)
2808 {
2809 (void) parent;
2810 #ifdef USE_QT_GT_53
2811 //qDebug()<<"VirtualKeyboard destroyed";
2812 if (!m_virtualKeyboardPointer.isNull()) {
2813 // check if object still existing (i.e application not exiting)
2814 if (showVirtualKeyboardAct->isChecked()) {
2815 showVirtualKeyboardAct->setChecked(false);
2816 }
2817 }
2818 #endif
2819 }
2820
2821 void CsoundQt::tableEditorActOff(QObject *parent)
2822 {
2823 (void) parent;
2824 #ifdef USE_QT_GT_53
2825 //qDebug()<<"VirtualKeyboard destroyed";
2826 if (!m_tableEditorPointer.isNull()) { // check if object still existing (i.e application not exiting)
2827 if (showTableEditorAct->isChecked()) {
2828 showTableEditorAct->setChecked(false);
2829 }
2830 }
2831 #endif
2832 }
2833
2834
2835 void CsoundQt::showHtml5Gui(bool show)
2836 {
2837 #if defined(QCS_QTHTML)
2838 csoundHtmlView->setVisible(show);
2839 #endif
2840 }
2841
2842 void CsoundQt::splitView(bool split)
2843 {
2844 if (split) {
2845 int mode = showOrcAct->isChecked() ? 2 : 0 ;
2846 mode |= showScoreAct->isChecked() ? 4 : 0 ;
2847 mode |= showOptionsAct->isChecked() ? 8 : 0 ;
2848 mode |= showFileBAct->isChecked() ? 16 : 0 ;
2849 mode |= showOtherAct->isChecked() ? 32 : 0 ;
2850 mode |= showOtherCsdAct->isChecked() ? 64 : 0 ;
2851 mode |= showWidgetEditAct->isChecked() ? 128 : 0 ;
2852 if (mode == 0) {
2853 mode = 2+4;
2854 }
2855 documentPages[curPage]->setViewMode(mode);
2856 }
2857 else {
2858 documentPages[curPage]->setViewMode(0);
2859 }
2860 }
2861
2862 void CsoundQt::showMidiLearn()
2863 {
2864 m_midiLearn->show();
2865 }
2866
2867 void CsoundQt::virtualMidiIn(QVariant on, QVariant note, QVariant channel, QVariant velocity)
2868 {
2869 std::vector<unsigned char> message;
2870 unsigned char status = (8 << 4) | on.toInt() << 4 | (channel.toInt() -1);
2871 message.push_back(status);
2872 message.push_back(note.toInt());
2873 message.push_back(velocity.toInt());
2874 documentPages[curPage]->queueVirtualMidiIn(message);
2875 }
2876
2877 void CsoundQt::virtualCCIn(int channel, int cc, int value)
2878 {
2879 //qDebug()<<"CC event: "<<channel<< cc<<value;
2880 std::vector<unsigned char> message;
2881 unsigned char status = (11 << 4 | (channel - 1));
2882 message.push_back(status);
2883 message.push_back(cc);
2884 message.push_back(value);
2885 documentPages[curPage]->queueVirtualMidiIn(message);
2886 }
2887
2888 void CsoundQt::handleTableSyntax(QString syntax)
2889 {
2890 qDebug() << syntax;
2891 insertText(syntax+"\n");
2892 }
2893
2894 void CsoundQt::openManualExample(QString fileName)
2895 {
2896 #ifdef Q_OS_WIN // on windows poper path is not forwarded. Add it if necessary.
2897 if (!fileName.startsWith(helpPanel->docDir)) {
2898 fileName = helpPanel->docDir + fileName;
2899 }
2900 #endif
2901 loadFile(fileName);
2902 }
2903
2904 void CsoundQt::openExternalBrowser(QUrl url)
2905 {
2906 QString test = url.toString();
2907 if (!m_options->browser.isEmpty() && QFile::exists(m_options->browser)) {
2908 //execute(m_options->browser, "\"" + url.toString() + "\"");
2909 startProcess(m_options->browser, QStringList(url.toString()));
2910 // execute(m_options->browser, url.toString()); // remove quotes, otherwise wrong with changed QProcess
2911 }
2912 else {
2913 // QMessageBox::critical(this, tr("Error"),
2914 // tr("Could not open external browser:\n%1\n"
2915 // "Please check preferences.").arg(m_options->browser));
2916 qDebug() << "No browser found from option, trying default system browser";
2917 QDesktopServices::openUrl(url);
2918 }
2919 //QDesktopServices::openUrl(url); // this opens it twice
2920 }
2921
2922 void CsoundQt::increaseFontSize()
2923 {
2924 changeFontSize(1);
2925 }
2926
2927 void CsoundQt::decreaseFontSize()
2928 {
2929 changeFontSize(-1);
2930 }
2931
2932 void CsoundQt::changeFontSize(int change)
2933 {
2934 if (helpPanel->hasFocus() ) {
2935 // QDEBUG << "change helpPanel size" << change;
2936 helpPanel->changeFontSize(change);
2937 } else {
2938 m_options->fontPointSize += change; // this may affect the pad's font size as well...
2939 // QDEBUG << "main Editor size" << m_options->fontPointSize;
2940 for (int i = 0; i < documentPages.size(); i++) {
2941 documentPages[i]->setTextFont(QFont(m_options->font, (int) m_options->fontPointSize));
2942 }
2943 // apply the same size to code pad (maybe should be separate but so far it has used the same size.
2944 DocumentView *pad = static_cast<LiveCodeEditor*>(m_scratchPad->widget())->getDocumentView();
2945 pad->setFont(QFont(m_options->font, (int) m_options->fontPointSize));
2946 }
2947 // console live changing not supported now, possible only through Configuration Dialog
2948 }
2949
2950 void CsoundQt::openPdfFile(QString name)
2951 {
2952 if (!m_options->pdfviewer.isEmpty()) {
2953 #ifndef Q_OS_MACOS
2954 if (!QFile::exists(m_options->pdfviewer)) {
2955 QMessageBox::critical(this,
2956 tr("Error"),
2957 tr("PDF viewer not found!\n"
2958 "Please go to Edit->Options->Environment and select directory\n"));
2959 }
2960 #endif
2961 QString arg = "\"" + name + "\"";
2962 execute(m_options->pdfviewer, arg);
2963 }
2964 else {
2965 QDesktopServices::openUrl(QUrl::fromLocalFile (name));
2966 }
2967 }
2968
2969 void CsoundQt::openFLOSSManual()
2970 {
2971 openExternalBrowser(QUrl("http://en.flossmanuals.net/csound/"));
2972 }
2973
2974 void CsoundQt::openQuickRef()
2975 {
2976 openPdfFile(quickRefFileName);
2977 }
2978
2979 void CsoundQt::openOnlineDocumentation()
2980 {
2981 openExternalBrowser(QUrl("http://csoundqt.github.io/pages/documentation.html"));
2982 }
2983
2984
2985 void CsoundQt::showManualOnline()
2986 {
2987 openExternalBrowser(QUrl("http://csound.com/manual/index.html"));
2988 }
2989
2990 void CsoundQt::resetPreferences()
2991 {
2992 int ret = QMessageBox::question (this, tr("Reset Preferences"),
2993 tr("Are you sure you want to revert CsoundQt's "
2994 "preferences\nto their initial default values? "),
2995 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok);
2996 if (ret == QMessageBox::Ok) {
2997 m_resetPrefs = true;
2998 storeSettings();
2999 QMessageBox::information(this, tr("Reset Preferences"),
3000 tr("Preferences have been reset.\nYou must restart CsoundQt."),
3001 QMessageBox::Ok, QMessageBox::Ok);
3002 }
3003 }
3004
3005 void CsoundQt::reportBug()
3006 {
3007 openExternalBrowser(QUrl("https://github.com/CsoundQt/CsoundQt/issues/new"));
3008 }
3009
3010 void CsoundQt::reportCsoundBug()
3011 {
3012 openExternalBrowser(QUrl("https://github.com/csound/csound/issues/new"));
3013 }
3014
3015 void CsoundQt::openShortcutDialog()
3016 {
3017 KeyboardShortcuts dialog(this, m_keyActions);
3018 connect(&dialog, SIGNAL(restoreDefaultShortcuts()), this, SLOT(setDefaultKeyboardShortcuts()));
3019 dialog.exec();
3020 if(dialog.needsSave()) {
3021 writeSettings(QStringList(), 0);
3022 }
3023 }
3024
3025 void CsoundQt::downloadManual()
3026 {
3027 // NB! must be updated when new manual comes out!
3028 openExternalBrowser(QUrl("https://github.com/csound/manual/releases/download/6.18.0/Csound6.18.0_manual_html.zip"));
3029 QMessageBox::information(this, tr("Set manual path"),
3030 tr("Unzip the manual to any location and set that path"
3031 " in Configure/Enviromnent/Html doc directory"));
3032 }
3033
3034 void CsoundQt::about()
3035 {
3036 About *msgBox = new About(this);
3037 msgBox->setWindowFlags(msgBox->windowFlags() | Qt::FramelessWindowHint);
3038
3039 QString text ="<h2>";
3040 text += tr("Authors: Andres Cabrera, Tarmo Johannes, Eduardo Moguillansky and others") + "</h2><h2>";
3041 text += tr("Version %1").arg(QCS_VERSION) + "</h2>";
3042 text += "<h3>" + tr("Released under the LGPLv2 or GPLv3") + "</h3>";
3043 text += tr("Using Csound version: <strong>%1</strong>, precision: <strong>%2</strong><br/>").arg(
3044 QString::number(csoundGetVersion()),
3045 csoundGetSizeOfMYFLT() == 8 ? "double (64-bit)" : "float (32-bit)");
3046 if(risset->isInstalled) {
3047 text += "<hr>";
3048 text += "<h3>Risset</h3>";
3049 text += tr("Risset package manager found, version: <strong>%1</strong><br/>").arg(risset->rissetVersion);
3050 text += tr("Plugins installed:<br/>");
3051 if(!risset->installedPlugins.isEmpty()) {
3052 text += "<ul>";
3053 for(auto pluginName : risset->installedPlugins) {
3054 auto opcodesInPlugin = risset->pluginOpcodes[pluginName];
3055 auto opcodesStr = opcodesInPlugin.join(", ");
3056
3057 text += QString("<li><strong>%1</strong>: %2</li>").arg(pluginName, opcodesStr);
3058 }
3059 text += "</ul>";
3060 } else {
3061 text += "No plugins installed<br/>";
3062 }
3063
3064 } else {
3065 text += tr("Risset package manager not found. See <center><a href=\"https://github.com/csound-plugins/risset\">github.com/csound-plugins/risset</a></center>");
3066 }
3067 text += "<hr>";
3068
3069 #ifdef QCS_PYTHONQT
3070 text += tr("Built with PythonQt support.")+ "<br />";
3071 #endif
3072 #ifdef USE_WEBENGINE
3073 text += tr("Html5 support based on QtWebEngine")+"<br />";
3074 #endif
3075 #ifdef USE_WEBKIT
3076 text += tr("Html5 support based on QtWebkit")+"<br />";
3077 #endif
3078 text += "<br />";
3079 text += tr("Spanish translation: Andrés Cabrera and Guillermo Senna") + "<br />";
3080 text += tr("French translation: Fran&ccedil;ois Pinot") + "<br />";
3081 text += tr("German translation: Joachim Heintz") + "<br />";
3082 text += tr("Portuguese translation: Victor Lazzarini") + "<br />";
3083 text += tr("Italian translation: Francesco") + "<br />";
3084 text += tr("Turkish translation: Ali Isciler") + "<br />";
3085 text += tr("Finnish translation: Niko Humalam&auml;ki") + "<br />";
3086 text += tr("Russian translation: Gleb Rogozinski") + "<br />";
3087 text += tr("Persian translation: Amin Khoshsabk") + "<br />";
3088 text += tr("Korean translation: Jieun Jun") + "<br />";
3089 text += QString("<center><a href=\"http://csoundqt.github.io\">csoundqt.github.io</a></center>");
3090 text += QString("<center><a href=\"mailto:[email protected]\">[email protected]</a><br /> <a href=\"mailto:[email protected]\">[email protected]</a> </center><br />");
3091 text += tr("If you find CsoundQt useful, please consider donating to the project:");
3092 text += "<center><a href=\"http://sourceforge.net/donate/index.php?group_id=227265\">Support this project!</a></center><br>";
3093
3094 text += tr("Please file bug reports and feature suggestions in the ");
3095 text += "<a href=\"https://github.com/CsoundQt/CsoundQt/issues\">";
3096 text += tr("CsoundQt tracker") + "</a>.<br><br />";
3097
3098 text +=tr("Mailing Lists:");
3099 text += "<br /><a href=\"http://lists.sourceforge.net/lists/listinfo/qutecsound-users\">Join/Read CsoundQt Mailing List</a><br />";
3100 text += "<a href=\"http://lists.sourceforge.net/lists/listinfo/qutecsound-devel\">Join/Read CsoundQt Developer List</a><br />";
3101 text += "<a href=\"https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND\">Join/Read Csound Mailing List</a><br />";
3102 text += "<a href=\"https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND-DEV\"> Join/Read Csound Developer List</a><br />";
3103
3104 text += "<br />"+ tr("Other Resources:") + "<br />";
3105 text += "<a href=\"http://csound.github.io\">Csound official homepage</a><br />";
3106 text += "<a href=\"http://www.csoundjournal.com/\">Csound Journal</a><br />";
3107 text += "<a href=\"http://csound.noisepages.com/\">The Csound Blog</a><br />";
3108 text += "<br />" + tr("Supported by:") +"<br />";
3109 text += "<a href=\"http://www.incontri.hmtm-hannover.de/\">Incontri - HMTM Hannover</a><br />";
3110 text += "<a href=\"http://sourceforge.net/project/project_donations.php?group_id=227265\">";
3111 text += tr("And other generous users.") + "</a><br />";
3112
3113 msgBox->getTextEdit()->setOpenLinks(false);
3114 msgBox->setHtmlText(text);
3115 connect(msgBox->getTextEdit(), SIGNAL(anchorClicked(QUrl)), this, SLOT(openExternalBrowser(QUrl)));
3116 msgBox->exec();
3117 delete msgBox;
3118 }
3119
3120 void CsoundQt::donate()
3121 {
3122 openExternalBrowser(QUrl("http://sourceforge.net/donate/index.php?group_id=227265"));
3123 }
3124
3125 void CsoundQt::documentWasModified(bool status)
3126 {
3127 if(status) {
3128 setWindowModified(true);
3129 documentTabs->setTabIcon(curPage, modIcon);
3130 }
3131 else {
3132 setWindowModified(false);
3133 documentTabs->setTabIcon(curPage, QIcon());
3134 }
3135 }
3136
3137 void CsoundQt::configure()
3138 {
3139 ConfigDialog dialog(this, m_options, &m_configlists);
3140 dialog.setCurrentTab(configureTab);
3141 // dialog.newParserCheckBox->setEnabled(csoundGetVersion() > 5125);
3142 dialog.multicoreCheckBox->setEnabled(csoundGetVersion() > 5125);
3143 dialog.numThreadsSpinBox->setEnabled(csoundGetVersion() > 5125);
3144 connect(dialog.applyButton, SIGNAL(released()),
3145 this, SLOT(applySettings()));
3146 connect(&dialog, SIGNAL(disableInternalRtMidi()),
3147 this, SLOT(disableInternalRtMidi()) );
3148 connect(dialog.testAudioSetupButton, SIGNAL(released()),
3149 this, SLOT(testAudioSetup()));
3150 if (dialog.exec() == QDialog::Accepted) {
3151 applySettings();
3152 storeSettings();
3153 }
3154 configureTab = dialog.currentTab();
3155 }
3156
3157 void CsoundQt::applySettings()
3158 {
3159 // This is called at initialization, when clicking "apply" in the settings dialog
3160 // and when closing it with "OK"
3161 for (int i = 0; i < documentPages.size(); i++) {
3162 setCurrentOptionsForPage(documentPages[i]);
3163 }
3164 auto toolButtonStyle = (m_options->iconText ? Qt::ToolButtonTextUnderIcon :
3165 Qt::ToolButtonIconOnly);
3166
3167 // setUnifiedTitleAndToolBarOnMac(m_options->iconText);
3168 // fileToolBar->setToolButtonStyle(toolButtonStyle);
3169 // editToolBar->setToolButtonStyle(toolButtonStyle);
3170 controlToolBar->setToolButtonStyle(toolButtonStyle);
3171 configureToolBar->setToolButtonStyle(toolButtonStyle);
3172 // fileToolBar->setVisible(m_options->showToolbar);
3173 // editToolBar->setVisible(m_options->showToolbar);
3174 controlToolBar->setVisible(m_options->showToolbar);
3175 configureToolBar->setVisible(m_options->showToolbar);
3176 controlToolBar->setMovable(!(m_options->lockToolbar));
3177 configureToolBar->setMovable(!(m_options->lockToolbar));
3178
3179 QString currentOptions = (m_options->useAPI ? tr("API") : tr("Console")) + " ";
3180 // if (m_options->useAPI) {
3181 // currentOptions += (m_options->thread ? tr("Thread") : tr("NoThread")) + " ";
3182 // }
3183
3184 // Display a summary of options on the status bar
3185 currentOptions += (m_options->saveWidgets ? tr("SaveWidgets") : tr("DontSaveWidgets")) + " ";
3186 QString playOptions = " (Audio:" + m_options->rtAudioModule + " ";
3187 playOptions += "MIDI:" + m_options->rtMidiModule + ")";
3188 playOptions += " (" + (m_options->rtUseOptions ? tr("UseCsoundQtOptions"):
3189 tr("DiscardCsoundQtOptions"));
3190 playOptions += " " + (m_options->rtOverrideOptions? tr("OverrideCsOptions"): tr("")) + ") ";
3191 playOptions += currentOptions;
3192 QString renderOptions =
3193 " ("
3194 + (m_options->fileUseOptions? tr("UseCsoundQtOptions"): tr("DiscardCsoundQtOptions"))
3195 + " ";
3196 renderOptions += "" + (m_options->fileOverrideOptions? tr("OverrideCsOptions"): tr("")) + ") ";
3197 renderOptions += currentOptions;
3198 runAct->setStatusTip(tr("Play") + playOptions);
3199 renderAct->setStatusTip(tr("Render to file") + renderOptions);
3200
3201 if (! m_options->useCsoundMidi) {
3202 QString interfaceNotFoundMessage;
3203 // find midi interface by name; if not found, set to None
3204 // returns 9999 if not found
3205 m_options->midiInterface = midiHandler->findMidiInPortByName(m_options->midiInterfaceName);
3206 midiHandler->setMidiInterface(m_options->midiInterface);
3207 // close port, if 9999
3208 if (m_options->midiInterface==9999 && !m_options->midiInterfaceName.contains("None")) {
3209 qDebug()<<"MIDI In interface "<< m_options->midiInterfaceName << " not found!";
3210 interfaceNotFoundMessage = tr("MIDI In interface ") +
3211 m_options->midiInterfaceName +
3212 tr(" not found!\n Switching to None.\n");
3213 }
3214
3215 m_options->midiOutInterface = midiHandler->findMidiOutPortByName(m_options->midiOutInterfaceName);
3216 midiHandler->setMidiOutInterface(m_options->midiOutInterface);
3217 if (m_options->midiOutInterface == 9999 && !m_options->midiOutInterfaceName.contains("None")) {
3218 qDebug()<<"MIDI Out interface "<< m_options->midiOutInterfaceName << " not found!";
3219 interfaceNotFoundMessage += tr("MIDI Out interface ") +
3220 m_options->midiOutInterfaceName +
3221 tr(" not found!\n Switching to None.");
3222 }
3223 // if (!interfaceNotFoundMessage.isEmpty()) { // probably messagebox alwais is a bit too disturbing. Keep it quiet.
3224 // QMessageBox::warning(this, tr("MIDI interface not found"),
3225 // interfaceNotFoundMessage);
3226 // }
3227 }
3228
3229 fillFavoriteMenu();
3230 fillScriptsMenu();
3231 DocumentView *pad = static_cast<LiveCodeEditor*>(m_scratchPad->widget())->getDocumentView();
3232 pad->setFont(QFont(m_options->font, (int) m_options->fontPointSize));
3233 if (csoundGetVersion() < 5140) {
3234 m_options->newParser = -1; // Don't use new parser flags
3235 }
3236 setupEnvironment();
3237
3238 // set editorBgColor also for inspector, codepad and python console.
3239 // Maybe the latter should use the same color as console?
3240 // auto bgColor= m_options->editorBgColor.name();
3241 // m_inspector->setStyleSheet(QString("QTreeWidget { background-color: %1; }").arg(bgColor));
3242 // m_scratchPad->setStyleSheet(QString("QTextEdit { background-color: %1; }").arg(bgColor));
3243 this->setToolbarIconSize(m_options->toolbarIconSize);
3244 #ifdef QCS_PYTHONQT
3245 m_pythonConsole->setStyleSheet(QString("QTextEdit { background-color: %1; }").arg(m_options->editorBgColor.name()));
3246 #endif
3247 //storeSettings(); // save always when something new is changed
3248
3249 this->helpPanel->setIconTheme(m_options->theme);
3250 }
3251
3252 void CsoundQt::setCurrentOptionsForPage(DocumentPage *p)
3253 {
3254 p->setColorVariables(m_options->colorVariables);
3255 p->setTabStopWidth(m_options->tabWidth);
3256 p->setTabIndents(m_options->tabIndents);
3257 p->setLineWrapMode(m_options->wrapLines ? QTextEdit::WidgetWidth : QTextEdit::NoWrap);
3258 p->setAutoComplete(m_options->autoComplete, m_options->autoCompleteDelay);
3259 p->setAutoParameterMode(m_options->autoParameterMode);
3260 p->setWidgetEnabled(m_options->enableWidgets);
3261 p->showWidgetTooltips(m_options->showTooltips);
3262 p->setKeyRepeatMode(m_options->keyRepeat);
3263 p->setOpenProperties(m_options->openProperties);
3264 p->setFontOffset(m_options->fontOffset);
3265 p->setFontScaling(m_options->fontScaling);
3266 p->setGraphUpdateRate(m_options->graphUpdateRate);
3267 p->setDebugLiveEvents(m_options->debugLiveEvents);
3268 p->setTextFont(QFont(m_options->font,
3269 (int) m_options->fontPointSize));
3270 p->setLineEnding(m_options->lineEnding);
3271 p->setConsoleFont(QFont(m_options->consoleFont,
3272 (int) m_options->consoleFontPointSize));
3273 p->setConsoleColors(m_options->consoleFontColor,
3274 m_options->consoleBgColor);
3275 p->setScriptDirectory(m_options->pythonDir);
3276 p->setPythonExecutable(m_options->pythonExecutable);
3277 p->useOldFormat(m_options->oldFormat);
3278 p->setConsoleBufferSize(m_options->consoleBufferSize);
3279 p->showLineNumbers(m_options->showLineNumberArea);
3280 p->setHighlightingTheme(m_options->highlightingTheme);
3281 p->enableScoreSyntaxHighlighting(m_options->highlightScore);
3282
3283 int flags = m_options->noBuffer ? QCS_NO_COPY_BUFFER : 0;
3284 flags |= m_options->noPython ? QCS_NO_PYTHON_CALLBACK : 0;
3285 flags |= m_options->noMessages ? QCS_NO_CONSOLE_MESSAGES : 0;
3286 flags |= m_options->noEvents ? QCS_NO_RT_EVENTS : 0;
3287 p->setFlags(flags);
3288
3289 }
3290
3291 void CsoundQt::runUtility(QString flags)
3292 {
3293 qDebug("CsoundQt::runUtility");
3294 if (m_options->useAPI) {
3295 #ifdef MACOSX_PRE_SNOW
3296 //Remember menu bar to set it after FLTK grabs it
3297 menuBarHandle = GetMenuBar();
3298 #endif
3299 // m_console->reset();
3300 static char *argv[33];
3301 QString name = "";
3302 QString fileFlags = flags.mid(flags.indexOf("\""));
3303 flags.remove(fileFlags);
3304 QStringList indFlags= flags.split(" ", SKIP_EMPTY_PARTS);
3305 QStringList files = fileFlags.split("\"", SKIP_EMPTY_PARTS);
3306 if (indFlags.size() < 2) {
3307 qDebug("CsoundQt::runUtility: Error: empty flags");
3308 return;
3309 }
3310 if (indFlags[0] == "-U") {
3311 indFlags.removeAt(0);
3312 name = indFlags[0];
3313 indFlags.removeAt(0);
3314 }
3315 else {
3316 qDebug("CsoundQt::runUtility: Error: unexpected flag!");
3317 return;
3318 }
3319 int index = 0;
3320 foreach (QString flag, indFlags) {
3321 argv[index] = (char *) calloc(flag.size()+1, sizeof(char));
3322 strcpy(argv[index], flag.toLocal8Bit());
3323 index++;
3324 }
3325 argv[index] = (char *) calloc(files[0].size()+1, sizeof(char));
3326 strcpy(argv[index++], files[0].toLocal8Bit());
3327 argv[index] = (char *) calloc(files[2].size()+1, sizeof(char));
3328 strcpy(argv[index++],files[2].toLocal8Bit());
3329 int argc = index;
3330 CSOUND *csoundU;
3331 csoundU=csoundCreate(0);
3332 csoundSetHostData(csoundU, (void *) m_console);
3333 csoundSetMessageCallback(csoundU, &CsoundQt::utilitiesMessageCallback);
3334 // Utilities always run in the same thread as CsoundQt
3335 csoundRunUtility(csoundU, name.toLocal8Bit(), argc, argv);
3336 csoundDestroy(csoundU);
3337 for (int i = 0; i < argc; i++) {
3338 free(argv[i]);
3339 }
3340 #ifdef MACOSX_PRE_SNOW
3341 // Put menu bar back
3342 SetMenuBar(menuBarHandle);
3343 #endif
3344 }
3345 else {
3346 QString script;
3347 #ifdef Q_OS_WIN32
3348 script = "";
3349 #ifdef USE_DOUBLE
3350 if (m_options->opcodedir64Active)
3351 script += "set OPCODEDIR64=" + m_options->opcodedir64 + "\n";
3352 if (m_options->opcode6dir64Active)
3353 script += "set OPCODE6DIR64=" + m_options->opcode6dir64 + "\n";
3354 #else
3355 if (m_options->opcodedirActive)
3356 script += "set OPCODEDIR=" + m_options->opcodedir + "\n";
3357 #endif
3358 // Only OPCODEDIR left here as it must be present before csound initializes
3359
3360 script += "cd " + QFileInfo(documentPages[curPage]->getFileName()).absolutePath() + "\n";
3361 script += "csound " + flags + "\n";
3362 #else
3363 script = "#!/bin/sh\n";
3364 #ifdef USE_DOUBLE
3365 if (m_options->opcodedir64Active)
3366 script += "set OPCODEDIR64=" + m_options->opcodedir64 + "\n";
3367 if (m_options->opcode6dir64Active)
3368 script += "set OPCODE6DIR64=" + m_options->opcode6dir64 + "\n";
3369 #else
3370 if (m_options->opcodedirActive)
3371 script += "export OPCODEDIR=" + m_options->opcodedir + "\n";
3372 #endif
3373 // Only OPCODEDIR left here as it must be present before csound initializes
3374
3375 script += "cd " + QFileInfo(documentPages[curPage]->getFileName()).absolutePath() + "\n";
3376 #ifdef Q_OS_MACOS
3377 script += "/usr/local/bin/csound " + flags + "\n";
3378 #else
3379 script += "csound " + flags + "\n";
3380 #endif
3381 script += "echo \"\nPress return to continue\"\n";
3382 script += "dummy_var=\"\"\n";
3383 script += "read dummy_var\n";
3384 script += "rm $0\n";
3385 #endif
3386 QFile file(SCRIPT_NAME);
3387 if (!file.open(QIODevice::WriteOnly))
3388 return;
3389
3390 QTextStream out(&file);
3391 out << script;
3392 file.flush();
3393 file.close();
3394 file.setPermissions (QFile::ExeOwner| QFile::WriteOwner| QFile::ReadOwner);
3395
3396 QString options;
3397 #ifdef Q_OS_LINUX
3398 options = "-e " + SCRIPT_NAME;
3399 #endif
3400 #ifdef Q_OS_SOLARIS
3401 options = "-e " + SCRIPT_NAME;
3402 #endif
3403 #ifdef Q_OS_MACOS
3404 options = SCRIPT_NAME;
3405 #endif
3406 #ifdef Q_OS_WIN32
3407 options = SCRIPT_NAME;
3408 #endif
3409 execute(m_options->terminal, options);
3410 }
3411 }
3412
3413
3414 void CsoundQt::updateCurrentPageTask() {
3415 if (m_closing || curPage >= documentPages.size() ) {
3416 return; // And don't call this again from the timer
3417 }
3418 Q_ASSERT(documentPages.size() > curPage);
3419 auto currentPage = documentPages[curPage];
3420 if ( !currentPage->getFileName().toLower().endsWith(".udo") ) { // otherwise this marks an unedited .udo file as edited
3421 currentPage->parseUdos();
3422 }
3423 QTimer::singleShot(INSPECTOR_UPDATE_PERIOD_MS, this, SLOT(updateCurrentPageTask()));
3424 }
3425
3426
3427 void CsoundQt::updateInspector()
3428 {
3429 if (m_closing || curPage >= documentPages.size()) {
3430 return; // And don't call this again from the timer
3431 }
3432 Q_ASSERT(documentPages.size() > curPage);
3433 if (!m_inspectorNeedsUpdate) {
3434 QTimer::singleShot(INSPECTOR_UPDATE_PERIOD_MS, this, SLOT(updateInspector()));
3435 return; // Retrigger timer, but do no update
3436 }
3437 if (!documentPages[curPage]->getFileName().endsWith(".py")) {
3438 m_inspector->parseText(documentPages[curPage]->getBasicText());
3439 }
3440 else {
3441 m_inspector->parsePythonText(documentPages[curPage]->getBasicText());
3442 // m_inspector->parsePythonText(documentPages[curPage]->getFullText());
3443 }
3444 m_inspectorNeedsUpdate = false;
3445 QTimer::singleShot(INSPECTOR_UPDATE_PERIOD_MS, this, SLOT(updateInspector()));
3446 }
3447
3448 void CsoundQt::markInspectorUpdate()
3449 {
3450 // qDebug() << "CsoundQt::markInspectorUpdate()";
3451 m_inspectorNeedsUpdate = true;
3452 }
3453
3454 void CsoundQt::setDefaultKeyboardShortcuts()
3455 {
3456 // m_keyActions.append(createCodeGraphAct);
3457 newAct->setShortcut(tr("Ctrl+N"));
3458 openAct->setShortcut(tr("Ctrl+O"));
3459 reloadAct->setShortcut(tr("Alt+R"));
3460 saveAct->setShortcut(tr("Ctrl+S"));
3461 saveAsAct->setShortcut(tr("Shift+Ctrl+S"));
3462 createAppAct->setShortcut(tr(""));
3463 closeTabAct->setShortcut(tr("Ctrl+W"));
3464
3465 printAct->setShortcut(tr("Ctrl+P"));
3466 exitAct->setShortcut(tr("Ctrl+Q"));
3467
3468 undoAct->setShortcut(tr("Ctrl+Z"));
3469 redoAct->setShortcut(tr("Shift+Ctrl+Z"));
3470
3471 cutAct->setShortcut(tr("Ctrl+X"));
3472 copyAct->setShortcut(tr("Ctrl+C"));
3473 pasteAct->setShortcut(tr("Ctrl+V"));
3474 duplicateAct->setShortcut(tr("Ctrl+D"));
3475 joinAct->setShortcut(tr(""));
3476 inToGetAct->setShortcut(tr(""));
3477 getToInAct->setShortcut(tr(""));
3478 midiControlAct->setShortcut(tr(""));
3479 csladspaAct->setShortcut(tr(""));
3480 findAct->setShortcut(tr("Ctrl+F"));
3481 findAgainAct->setShortcut(tr("Ctrl+G"));
3482 configureAct->setShortcut(tr("Ctrl+,"));
3483 editAct->setShortcut(tr("CTRL+E"));
3484 runAct->setShortcut(tr("CTRL+R"));
3485 runTermAct->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_T));
3486 pauseAct->setShortcut(tr("Ctrl+Shift+M"));
3487
3488 stopAct->setShortcut(tr("Ctrl+."));
3489 stopAllAct->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_Period));
3490
3491 recAct->setShortcut(tr("Ctrl+Space"));
3492 renderAct->setShortcut(tr("Alt+F"));
3493 externalPlayerAct->setShortcut(tr(""));
3494 externalEditorAct->setShortcut(tr(""));
3495 focusEditorAct->setShortcut(tr("Ctrl+0"));
3496 raiseHelpAct->setShortcut(tr("Ctrl+2"));
3497 raiseWidgetsAct->setShortcut(tr("Ctrl+1"));
3498 showGenAct->setShortcut(tr(""));
3499 showOverviewAct->setShortcut(tr(""));
3500 raiseConsoleAct->setShortcut(tr("Ctrl+3"));
3501 autocompleteAct->setShortcut(tr("Ctrl+M"));
3502 #ifdef Q_OS_MACOS
3503 viewFullScreenAct->setShortcut(tr("Ctrl+Shift+F"));
3504 #else
3505 viewFullScreenAct->setShortcut(tr("F11"));
3506 #endif
3507
3508 viewEditorFullScreenAct->setShortcut(tr("Alt+Ctrl+0"));
3509 #ifdef QCS_QTHTML
3510 viewHtmlFullScreenAct->setShortcut(tr("Alt+Ctrl+4")); // was H
3511 #endif
3512 viewHelpFullScreenAct->setShortcut(tr("Alt+Ctrl+2")); // was vice versa
3513 viewWidgetsFullScreenAct->setShortcut(tr("Alt+Ctrl+1"));
3514 #ifdef QCS_DEBUGGER
3515 showDebugAct->setShortcut(tr("F5"));
3516 #endif
3517 showVirtualKeyboardAct->setShortcut(tr("Ctrl+Shift+V"));
3518 showTableEditorAct->setShortcut(tr(""));
3519 splitViewAct->setShortcut(tr("Ctrl+Shift+A"));
3520 midiLearnAct->setShortcut(tr("Ctrl+Shift+M"));
3521 createCodeGraphAct->setShortcut(tr("")); // was Ctr +4 save it for html view
3522 raiseInspectorAct->setShortcut(tr("Ctrl+5"));
3523 showLiveEventsAct->setShortcut(tr("Ctrl+6"));
3524
3525 #ifdef QCS_QTHTML
3526 raiseHtml5Act->setShortcut(tr("Ctrl+4")); // Alt-4 was before for Code graph
3527 #endif
3528 openDocumentationAct->setShortcut(tr("F1"));
3529 showUtilitiesAct->setShortcut(tr("Ctrl+9"));
3530
3531 setHelpEntryAct->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_F1));
3532 externalBrowserAct->setShortcut(tr("Shift+Alt+F1"));
3533 showInspectorAct->setShortcut(tr("F5"));
3534
3535 browseBackAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
3536 browseForwardAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
3537 openQuickRefAct->setShortcut(tr(""));
3538 commentAct->setShortcut(tr("Ctrl+/"));
3539 // uncommentAct->setShortcut(tr("Shift+Ctrl+/"));
3540 indentAct->setShortcut(tr("Ctrl+I"));
3541 unindentAct->setShortcut(tr("Shift+Ctrl+I"));
3542 evaluateAct->setShortcut(tr("Shift+Ctrl+E"));
3543 evaluateSectionAct->setShortcut(tr("Shift+Ctrl+W"));
3544 scratchPadCsdModeAct->setShortcut(tr("Shift+Alt+S"));
3545 raisePythonConsoleAct->setShortcut(tr("Ctrl+7"));
3546 raiseScratchPadAct->setShortcut(tr("Ctrl+8"));
3547 killLineAct->setShortcut(tr("Ctrl+K"));
3548 killToEndAct->setShortcut(tr("Shift+Alt+K"));
3549 gotoLineAct->setShortcut(tr("Ctrl+L"));
3550 goBackAct->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Left));
3551 showOrcAct->setShortcut(tr("Shift+Alt+1"));
3552 showScoreAct->setShortcut(tr("Shift+Alt+2"));
3553 showOptionsAct->setShortcut(tr("Shift+Alt+3"));
3554 showFileBAct->setShortcut(tr("Shift+Alt+4"));
3555 showOtherAct->setShortcut(tr("Shift+Alt+5"));
3556 showOtherCsdAct->setShortcut(tr("Shift+Alt+6"));
3557 showWidgetEditAct->setShortcut(tr("Shift+Alt+7"));
3558 lineNumbersAct->setShortcut(tr("Shift+Alt+L"));
3559 parameterModeAct->setShortcut(tr("Shift+Alt+P"));
3560 cabbageAct->setShortcut(tr("Shift+Ctrl+C"));
3561 // showParametersAct->setShortcut(tr("Alt+P"));
3562
3563 checkSyntaxAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U));
3564
3565 storeSettings();
3566 }
3567
3568 void CsoundQt::showNoPythonQtWarning()
3569 {
3570 QMessageBox::warning(this, tr("No PythonQt support"),
3571 tr("This version of CsoundQt has been compiled without PythonQt support.\n"
3572 "Extended Python features are not available"));
3573 qDebug() << "CsoundQt::showNoPythonQtWarning()";
3574 }
3575
3576 void CsoundQt::showOrc(bool show)
3577 {
3578 documentPages[curPage]->showOrc(show);
3579 }
3580
3581 void CsoundQt::showScore(bool show)
3582 {
3583 documentPages[curPage]->showScore(show);
3584 }
3585
3586 void CsoundQt::showOptions(bool show)
3587 {
3588 documentPages[curPage]->showOptions(show);
3589 }
3590
3591 void CsoundQt::showFileB(bool show)
3592 {
3593 documentPages[curPage]->showFileB(show);
3594 }
3595
3596 void CsoundQt::showOther(bool show)
3597 {
3598 documentPages[curPage]->showOther(show);
3599 }
3600
3601 void CsoundQt::showOtherCsd(bool show)
3602 {
3603 documentPages[curPage]->showOtherCsd(show);
3604 }
3605
3606 void CsoundQt::showWidgetEdit(bool show)
3607 {
3608 documentPages[curPage]->showWidgetEdit(show);
3609 }
3610
3611 void CsoundQt::toggleLineArea()
3612 {
3613 documentPages[curPage]->toggleLineArea();
3614 }
3615
3616 void CsoundQt::toggleParameterMode()
3617 {
3618 documentPages[curPage]->toggleParameterMode();
3619 }
3620
3621 void CsoundQt::autocomplete()
3622 {
3623 DocumentPage* page = documentPages[curPage];
3624 page->autocomplete();
3625 }
3626
3627 #ifdef QCS_DEBUGGER
3628
3629 void CsoundQt::runDebugger()
3630 {
3631 m_debugEngine = documentPages[curPage]->getEngine();
3632 m_debugEngine->setDebug();
3633
3634 m_debugPanel->setDebugFilename(documentPages[curPage]->getFileName());
3635 connect(m_debugEngine, SIGNAL(breakpointReached()),
3636 this, SLOT(breakpointReached()));
3637 connect(m_debugPanel, SIGNAL(stopSignal()),
3638 this, SLOT(stopDebugger()));
3639 m_debugEngine->setStartingBreakpoints(m_debugPanel->getBreakpoints());
3640
3641 documentPages[curPage]->getView()->m_mainEditor->setCurrentDebugLine(-1);
3642 play();
3643 }
3644
3645 void CsoundQt::stopDebugger()
3646 {
3647 if (m_debugEngine) {
3648 disconnect(m_debugEngine, SIGNAL(breakpointReached()), 0, 0);
3649 disconnect(m_debugPanel, SIGNAL(stopSignal()), 0, 0);
3650 m_debugEngine->stopDebug();
3651 m_debugEngine = 0;
3652 documentPages[curPage]->getView()->m_mainEditor->setCurrentDebugLine(-1);
3653 }
3654 markStopped();
3655 }
3656
3657 void CsoundQt::pauseDebugger()
3658 {
3659 if(m_debugEngine) {
3660 m_debugEngine->pauseDebug();
3661 }
3662 }
3663
3664 void CsoundQt::continueDebugger()
3665 {
3666 if(m_debugEngine) {
3667 m_debugEngine->continueDebug();
3668 documentPages[curPage]->getView()->m_mainEditor->setCurrentDebugLine(-1);
3669 }
3670 }
3671
3672 void CsoundQt::addBreakpoint(int line, int instr, int skip)
3673 {
3674 if (instr == 0) {
3675 documentPages[curPage]->getView()->m_mainEditor->markDebugLine(line);
3676 }
3677 if(m_debugEngine) {
3678 m_debugEngine->addBreakpoint(line, instr, skip);
3679 }
3680 }
3681
3682 void CsoundQt::addInstrumentBreakpoint(double instr, int skip)
3683 {
3684 if(m_debugEngine) {
3685 m_debugEngine->addInstrumentBreakpoint(instr, skip);
3686 }
3687 }
3688
3689 void CsoundQt::removeBreakpoint(int line, int instr)
3690 {
3691 if (instr == 0) {
3692 documentPages[curPage]->getView()->m_mainEditor->unmarkDebugLine(line);
3693 }
3694 if(m_debugEngine) {
3695 m_debugEngine->removeBreakpoint(line, instr);
3696 }
3697 }
3698
3699 void CsoundQt::removeInstrumentBreakpoint(double instr)
3700 {
3701 if(m_debugEngine) {
3702 m_debugEngine->removeInstrumentBreakpoint(instr);
3703 }
3704 }
3705
3706 #endif
3707
3708 //void CsoundQt::showParametersInEditor()
3709 //{
3710 // documentPages[curPage]->showParametersInEditor();
3711 //}
3712
3713 void CsoundQt::createActions()
3714 {
3715 // Actions that are not connected here depend on the active document, so they are
3716 // connected with connectActions() and are changed when the document changes.
3717 QString theme = m_options->theme;
3718 QString prefix = ":/themes/" + theme + "/";
3719 newAct = new QAction(QIcon(prefix + "edit-new.png"), tr("&New"), this);
3720 newAct->setStatusTip(tr("Create a new file"));
3721 newAct->setIconText(tr("New"));
3722 newAct->setShortcutContext(Qt::ApplicationShortcut);
3723 connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
3724
3725 openAct = new QAction(QIcon(prefix + "folder.png"), tr("&Open..."), this);
3726 openAct->setStatusTip(tr("Open an existing file"));
3727 openAct->setIconText(tr("Open"));
3728 openAct->setShortcutContext(Qt::ApplicationShortcut);
3729 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
3730
3731 reloadAct = new QAction(QIcon(prefix + "reload.png"), tr("Reload"), this);
3732 reloadAct->setStatusTip(tr("Reload file from disk, discarding changes"));
3733 // reloadAct->setIconText(tr("Reload"));
3734 reloadAct->setShortcutContext(Qt::ApplicationShortcut);
3735 connect(reloadAct, SIGNAL(triggered()), this, SLOT(reload()));
3736
3737 saveAct = new QAction(QIcon(prefix + "floppy.png"), tr("&Save"), this);
3738 saveAct->setStatusTip(tr("Save the document to disk"));
3739 saveAct->setIconText(tr("Save"));
3740 saveAct->setShortcutContext(Qt::ApplicationShortcut);
3741 connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
3742
3743 saveAsAct = new QAction(tr("Save &As..."), this);
3744 saveAsAct->setStatusTip(tr("Save the document under a new name"));
3745 saveAsAct->setIconText(tr("Save as"));
3746 saveAsAct->setShortcutContext(Qt::ApplicationShortcut);
3747 connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
3748
3749 createAppAct = new QAction(tr("Create App..."), this);
3750 createAppAct->setStatusTip(tr("Create Standalone application"));
3751 createAppAct->setShortcutContext(Qt::ApplicationShortcut);
3752 connect(createAppAct, SIGNAL(triggered()), this, SLOT(createApp()));
3753
3754 saveNoWidgetsAct = new QAction(tr("Export without widgets"), this);
3755 saveNoWidgetsAct->setStatusTip(tr("Save to new file without including widget sections"));
3756 // saveNoWidgetsAct->setIconText(tr("Save as"));
3757 saveNoWidgetsAct->setShortcutContext(Qt::ApplicationShortcut);
3758 connect(saveNoWidgetsAct, SIGNAL(triggered()), this, SLOT(saveNoWidgets()));
3759
3760 closeTabAct = new QAction(tr("Close current tab"), this);
3761 closeTabAct->setStatusTip(tr("Close current tab"));
3762 // closeTabAct->setIconText(tr("Close"));
3763 closeTabAct->setIcon(QIcon(prefix + "edit-close.png"));
3764 closeTabAct->setShortcutContext(Qt::ApplicationShortcut);
3765 connect(closeTabAct, SIGNAL(triggered()), this, SLOT(closeTab()));
3766
3767 printAct = new QAction(tr("Print"), this);
3768 printAct->setStatusTip(tr("Print current document"));
3769 // printAct->setIconText(tr("Print"));
3770 // closeTabAct->setIcon(QIcon(prefix + "gtk-close.png"));
3771 printAct->setShortcutContext(Qt::ApplicationShortcut);
3772 connect(printAct, SIGNAL(triggered()), this, SLOT(print()));
3773
3774 // for (int i = 0; i < QCS_MAX_RECENT_FILES; i++) {
3775 // QAction *newAction = new QAction(this);
3776 // openRecentAct.append(newAction);
3777 // connect(newAction, SIGNAL(triggered()), this, SLOT(openFromAction()));
3778 // }
3779
3780 infoAct = new QAction(tr("File Information"), this);
3781 infoAct->setStatusTip(tr("Show information for the current file"));
3782 // exitAct->setIconText(tr("Exit"));
3783 infoAct->setShortcutContext(Qt::ApplicationShortcut);
3784 connect(infoAct, SIGNAL(triggered()), this, SLOT(info()));
3785
3786 exitAct = new QAction(tr("E&xit"), this);
3787 exitAct->setStatusTip(tr("Exit the application"));
3788 // exitAct->setIconText(tr("Exit"));
3789 exitAct->setShortcutContext(Qt::ApplicationShortcut);
3790 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
3791
3792 createCodeGraphAct = new QAction(tr("View Code &Graph"), this);
3793 createCodeGraphAct->setStatusTip(tr("View Code Graph"));
3794 // createCodeGraphAct->setIconText("Exit");
3795 createCodeGraphAct->setShortcutContext(Qt::ApplicationShortcut);
3796 connect(createCodeGraphAct, SIGNAL(triggered()), this, SLOT(createCodeGraph()));
3797
3798 undoAct = new QAction(QIcon(prefix + "edit-undo.png"), tr("Undo"), this);
3799 undoAct->setStatusTip(tr("Undo last action"));
3800 undoAct->setIconText(tr("Undo"));
3801 undoAct->setShortcutContext(Qt::ApplicationShortcut);
3802 connect(undoAct, SIGNAL(triggered()), this, SLOT(undo()));
3803
3804 redoAct = new QAction(QIcon(prefix + "edit-redo.png"), tr("Redo"), this);
3805 redoAct->setStatusTip(tr("Redo last action"));
3806 redoAct->setIconText(tr("Redo"));
3807 redoAct->setShortcutContext(Qt::ApplicationShortcut);
3808 connect(redoAct, SIGNAL(triggered()), this, SLOT(redo()));
3809
3810 cutAct = new QAction(QIcon(prefix + "edit-cut.png"), tr("Cu&t"), this);
3811 cutAct->setStatusTip(tr("Cut the current selection's contents to the "
3812 "clipboard"));
3813 cutAct->setIconText(tr("Cut"));
3814 cutAct->setShortcutContext(Qt::ApplicationShortcut);
3815 connect(cutAct, SIGNAL(triggered()), this, SLOT(cut()));
3816
3817 copyAct = new QAction(QIcon(prefix + "edit-copy.png"), tr("&Copy"), this);
3818 copyAct->setStatusTip(tr("Copy the current selection's contents to the "
3819 "clipboard"));
3820 copyAct->setIconText(tr("Copy"));
3821 copyAct->setShortcutContext(Qt::ApplicationShortcut);
3822 connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
3823
3824 pasteAct = new QAction(QIcon(prefix + "edit-paste.png"), tr("&Paste"), this);
3825 pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
3826 "selection"));
3827 pasteAct->setIconText(tr("Paste"));
3828 pasteAct->setShortcutContext(Qt::ApplicationShortcut);
3829 connect(pasteAct, SIGNAL(triggered()), this, SLOT(paste()));
3830
3831 joinAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("&Join orc/sco"), this);
3832 joinAct->setStatusTip(tr("Join orc/sco files in a single csd file"));
3833 // joinAct->setIconText(tr("Join"));
3834 joinAct->setShortcutContext(Qt::ApplicationShortcut);
3835 connect(joinAct, SIGNAL(triggered()), this, SLOT(join()));
3836
3837 evaluateAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("Evaluate selection"), this);
3838 evaluateAct->setStatusTip(tr("Evaluate selection in Python Console"));
3839 evaluateAct->setShortcutContext(Qt::ApplicationShortcut);
3840 connect(evaluateAct, SIGNAL(triggered()), this, SLOT(evaluate()));
3841
3842 evaluateSectionAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("Evaluate section"), this);
3843 evaluateSectionAct->setStatusTip(tr("Evaluate current section in Python Console"));
3844 evaluateSectionAct->setShortcutContext(Qt::ApplicationShortcut);
3845 connect(evaluateSectionAct, SIGNAL(triggered()), this, SLOT(evaluateSection()));
3846
3847 scratchPadCsdModeAct = new QAction(tr("Code Pad in Csound Mode"), this);
3848 scratchPadCsdModeAct->setStatusTip(tr("Toggle the mode for the scratch pad between python and csound"));
3849 scratchPadCsdModeAct->setShortcutContext(Qt::ApplicationShortcut);
3850 scratchPadCsdModeAct->setCheckable(true);
3851 connect(scratchPadCsdModeAct, SIGNAL(toggled(bool)), this, SLOT(setScratchPadMode(bool)));
3852
3853 inToGetAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("Invalue->Chnget"), this);
3854 inToGetAct->setStatusTip(tr("Convert invalue/outvalue to chnget/chnset"));
3855 inToGetAct->setShortcutContext(Qt::ApplicationShortcut);
3856 connect(inToGetAct, SIGNAL(triggered()), this, SLOT(inToGet()));
3857
3858 getToInAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("Chnget->Invalue"), this);
3859 getToInAct->setStatusTip(tr("Convert chnget/chnset to invalue/outvalue"));
3860 getToInAct->setShortcutContext(Qt::ApplicationShortcut);
3861 connect(getToInAct, SIGNAL(triggered()), this, SLOT(getToIn()));
3862
3863 midiControlAct = new QAction(tr("Insert MidiControl instrument"), this);
3864 midiControlAct->setStatusTip(tr("Generate instrument according to MIDI bindings of widgets"));
3865 midiControlAct->setShortcutContext(Qt::ApplicationShortcut);
3866 connect(midiControlAct, SIGNAL(triggered()), this, SLOT(insertMidiControlInstrument()));
3867
3868 csladspaAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("Insert/Update CsLADSPA text"), this);
3869 csladspaAct->setStatusTip(tr("Insert/Update CsLADSPA section to csd file"));
3870 csladspaAct->setShortcutContext(Qt::ApplicationShortcut);
3871 connect(csladspaAct, SIGNAL(triggered()), this, SLOT(updateCsladspaText()));
3872
3873 cabbageAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("Insert/Update Cabbage text"), this);
3874 cabbageAct->setStatusTip(tr("Insert/Update Cabbage section to csd file"));
3875 cabbageAct->setShortcutContext(Qt::ApplicationShortcut);
3876 connect(cabbageAct, SIGNAL(triggered()), this, SLOT(updateCabbageText()));
3877
3878 qmlAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("Export widgets to QML"), this);
3879 qmlAct->setStatusTip(tr("Export widgets in QML format"));
3880 qmlAct->setShortcutContext(Qt::ApplicationShortcut);
3881 connect(qmlAct, SIGNAL(triggered()), this, SLOT(saveWidgetsToQml()));
3882
3883 findAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("&Find and Replace"), this);
3884 findAct->setStatusTip(tr("Find and replace strings in file"));
3885 // findAct->setIconText(tr("Find"));
3886 findAct->setShortcutContext(Qt::ApplicationShortcut);
3887 connect(findAct, SIGNAL(triggered()), this, SLOT(findReplace()));
3888
3889 findAgainAct = new QAction(/*QIcon(prefix + "gtk-paste.png"),*/ tr("Find again"), this);
3890 findAgainAct->setStatusTip(tr("Find next appearance of string"));
3891 // findAct->setIconText(tr("Find"));
3892 findAgainAct->setShortcutContext(Qt::ApplicationShortcut);
3893 connect(findAgainAct, SIGNAL(triggered()), this, SLOT(findString()));
3894
3895 configureAct = new QAction(QIcon(prefix + "settings.png"), tr("Configuration"), this);
3896 configureAct->setStatusTip(tr("Open configuration dialog"));
3897 configureAct->setIconText(tr("Configure"));
3898 configureAct->setShortcutContext(Qt::ApplicationShortcut);
3899 connect(configureAct, SIGNAL(triggered()), this, SLOT(configure()));
3900
3901 editAct = new QAction(/*QIcon(prefix + "gtk-media-play-ltr.png"),*/ tr("Widget Edit Mode"), this);
3902 editAct->setStatusTip(tr("Activate Edit Mode for Widget Panel"));
3903 // editAct->setIconText("Play");
3904 editAct->setCheckable(true);
3905 editAct->setShortcutContext(Qt::ApplicationShortcut);
3906 connect(editAct, SIGNAL(triggered(bool)), this, SLOT(setWidgetEditMode(bool)));
3907
3908 runAct = new QAction(QIcon(prefix + "media-play.png"), tr("Run Csound"), this);
3909 runAct->setStatusTip(tr("Run current file"));
3910 runAct->setIconText(tr("Run"));
3911 runAct->setCheckable(true);
3912 runAct->setShortcutContext(Qt::ApplicationShortcut);
3913 connect(runAct, SIGNAL(triggered()), this, SLOT(play()));
3914
3915 runTermAct = new QAction(QIcon(prefix + "terminal.png"), tr("Run in Terminal"), this);
3916 runTermAct->setStatusTip(tr("Run in external shell"));
3917 runTermAct->setIconText(tr("Run in Term"));
3918 runTermAct->setShortcutContext(Qt::ApplicationShortcut);
3919 connect(runTermAct, SIGNAL(triggered()), this, SLOT(runInTerm()));
3920
3921 stopAct = new QAction(QIcon(prefix + "media-stop.png"), tr("Stop"), this);
3922 stopAct->setStatusTip(tr("Stop"));
3923 stopAct->setIconText(tr("Stop"));
3924 stopAct->setShortcutContext(Qt::ApplicationShortcut);
3925 connect(stopAct, SIGNAL(triggered()), this, SLOT(stop()));
3926
3927 pauseAct = new QAction(QIcon(prefix + "media-pause.png"), tr("Pause"), this);
3928 pauseAct->setStatusTip(tr("Pause"));
3929 pauseAct->setIconText(tr("Pause"));
3930 pauseAct->setShortcutContext(Qt::ApplicationShortcut);
3931 connect(pauseAct, SIGNAL(triggered()), this, SLOT(pause()));
3932
3933 stopAllAct = new QAction(QIcon(prefix + "media-stop.png"), tr("Stop All"), this);
3934 stopAllAct->setStatusTip(tr("Stop all running documents"));
3935 stopAllAct->setIconText(tr("Stop All"));
3936 stopAllAct->setShortcutContext(Qt::ApplicationShortcut);
3937 connect(stopAllAct, SIGNAL(triggered()), this, SLOT(stopAll()));
3938
3939 recAct = new QAction(QIcon(prefix + "media-record.png"), tr("Record"), this);
3940 recAct->setStatusTip(tr("Record"));
3941 recAct->setIconText(tr("Record"));
3942 recAct->setCheckable(true);
3943 recAct->setShortcutContext(Qt::ApplicationShortcut);
3944 recAct->setChecked(false);
3945 connect(recAct, SIGNAL(toggled(bool)), this, SLOT(record(bool)));
3946
3947 // renderAct = new QAction(QIcon(prefix + "render.png"), tr("Render to file"), this);
3948 renderAct = new QAction(QIcon(prefix + "render.svg"), tr("Render to file"), this);
3949 renderAct->setStatusTip(tr("Render to file"));
3950 renderAct->setIconText(tr("Render"));
3951 renderAct->setShortcutContext(Qt::ApplicationShortcut);
3952 connect(renderAct, SIGNAL(triggered()), this, SLOT(render()));
3953
3954 testAudioSetupAct = new QAction(QIcon(prefix+"hearing.svg"),
3955 tr("Test Audio Setup"), this);
3956 connect(testAudioSetupAct, SIGNAL(triggered(bool)), this, SLOT(testAudioSetup()));
3957
3958 checkSyntaxAct = new QAction(QIcon(prefix + "scratchpad.png"), tr("Check Syntax"), this);
3959 checkSyntaxAct->setShortcutContext(Qt::ApplicationShortcut);
3960 connect(checkSyntaxAct, SIGNAL(triggered()), this, SLOT(checkSyntaxMenuAction()));
3961
3962 externalPlayerAct = new QAction(QIcon(prefix + "playfile.png"), tr("Play Rendered Audiofile"), this);
3963 externalPlayerAct->setStatusTip(tr("Play rendered audiofile in external application"));
3964 externalPlayerAct->setIconText(tr("Ext. Player"));
3965 externalPlayerAct->setShortcutContext(Qt::ApplicationShortcut);
3966 connect(externalPlayerAct, SIGNAL(triggered()), this, SLOT(openExternalPlayer()));
3967
3968 externalEditorAct = new QAction(QIcon(prefix + "editfile.png"), tr("Edit Rendered Audiofile"), this);
3969 externalEditorAct->setStatusTip(tr("Edit rendered audiofile in External Editor"));
3970 externalEditorAct->setIconText(tr("Ext. Editor"));
3971 externalEditorAct->setShortcutContext(Qt::ApplicationShortcut);
3972 connect(externalEditorAct, SIGNAL(triggered()), this, SLOT(openExternalEditor()));
3973
3974 showWidgetsAct = new QAction(QIcon(prefix + "widgets.png"),
3975 tr("Widgets"), this);
3976 showWidgetsAct->setCheckable(true);
3977 //showWidgetsAct->setChecked(true);
3978 showWidgetsAct->setStatusTip(tr("Show Realtime Widgets"));
3979 showWidgetsAct->setIconText(tr("Widgets"));
3980 showWidgetsAct->setShortcutContext(Qt::ApplicationShortcut);
3981
3982 raiseWidgetsAct = new QAction(this);
3983 raiseWidgetsAct->setText(tr("Show/Raise Widgets Panel"));
3984 raiseWidgetsAct->setShortcutContext(Qt::ApplicationShortcut);
3985 connect(raiseWidgetsAct, SIGNAL(triggered()), focusMapper, SLOT(map()));
3986 focusMapper->setMapping(raiseWidgetsAct, 1);
3987 this->addAction(raiseWidgetsAct);
3988
3989 showInspectorAct = new QAction(QIcon(prefix + "edit-find.png"), tr("Inspector"), this);
3990 showInspectorAct->setCheckable(true);
3991 showInspectorAct->setStatusTip(tr("Show Inspector"));
3992 showInspectorAct->setIconText(tr("Inspector"));
3993 showInspectorAct->setShortcutContext(Qt::ApplicationShortcut);
3994 connect(showInspectorAct, SIGNAL(triggered(bool)), m_inspector, SLOT(setVisible(bool)));
3995 connect(m_inspector, SIGNAL(Close(bool)), showInspectorAct, SLOT(setChecked(bool)));
3996
3997 raiseInspectorAct = new QAction(this);
3998 raiseInspectorAct->setText(tr("Show/Raise Inspector Panel"));
3999 raiseInspectorAct->setShortcutContext(Qt::ApplicationShortcut);
4000 connect(raiseInspectorAct, SIGNAL(triggered()), focusMapper, SLOT(map()));
4001 focusMapper->setMapping(raiseInspectorAct, 5);
4002 this->addAction(raiseInspectorAct);
4003
4004 focusEditorAct = new QAction(tr("Focus Text Editor", "Give keyboard focus to the text editor"), this);
4005 focusEditorAct->setStatusTip(tr("Give keyboard focus to the text editor"));
4006 focusEditorAct->setIconText(tr("Editor"));
4007 focusEditorAct->setShortcutContext(Qt::ApplicationShortcut);
4008 connect(focusEditorAct, SIGNAL(triggered()), this, SLOT(setEditorFocus()));
4009
4010 showHelpAct = new QAction(QIcon(prefix + "info.png"), tr("Help Panel"), this);
4011 showHelpAct->setCheckable(true);
4012 showHelpAct->setChecked(true);
4013 showHelpAct->setStatusTip(tr("Show the Csound Manual Panel"));
4014 showHelpAct->setIconText(tr("Manual"));
4015 showHelpAct->setShortcutContext(Qt::ApplicationShortcut);
4016 // connect(showHelpAct, SIGNAL(toggled(bool)), helpPanel, SLOT(setVisible(bool)));
4017 connect(showHelpAct, SIGNAL(toggled(bool)), helpPanel, SLOT(setVisibleAndRaise(bool)));
4018 connect(helpPanel, SIGNAL(Close(bool)), showHelpAct, SLOT(setChecked(bool)));
4019 connect(helpPanel, SIGNAL(requestExternalBrowser(QUrl)), this, SLOT(openExternalBrowser(QUrl)) );
4020
4021 raiseHelpAct = new QAction(this);
4022 raiseHelpAct->setText(tr("Show/Raise help panel"));
4023 raiseHelpAct->setShortcutContext(Qt::ApplicationShortcut);
4024 connect(raiseHelpAct, SIGNAL(triggered()), focusMapper, SLOT(map()));
4025 focusMapper->setMapping(raiseHelpAct, 2);
4026 connect(focusMapper, SIGNAL(mapped(int)), this, SLOT(focusToTab(int)));
4027 this->addAction(raiseHelpAct);
4028
4029 showLiveEventsAct = new QAction(QIcon(prefix + "note.png"), tr("Live Events"), this);
4030 showLiveEventsAct->setCheckable(true);
4031 // showLiveEventsAct->setChecked(true); // Unnecessary because it is set by options
4032 showLiveEventsAct->setStatusTip(tr("Show Live Events Panels"));
4033 showLiveEventsAct->setIconText(tr("Live Events"));
4034 showLiveEventsAct->setShortcutContext(Qt::ApplicationShortcut);
4035
4036 showPythonConsoleAct = new QAction(QIcon(prefix + "pyroom.png"), tr("Python Console"), this);
4037 showPythonConsoleAct->setCheckable(true);
4038 // showPythonConsoleAct->setChecked(true); // Unnecessary because it is set by options
4039 showPythonConsoleAct->setStatusTip(tr("Show Python Console"));
4040 showPythonConsoleAct->setIconText(tr("Python"));
4041 showPythonConsoleAct->setShortcutContext(Qt::ApplicationShortcut);
4042 #ifdef QCS_PYTHONQT
4043 connect(showPythonConsoleAct, SIGNAL(triggered(bool)), m_pythonConsole, SLOT(setVisible(bool)));
4044 connect(m_pythonConsole, SIGNAL(Close(bool)), showPythonConsoleAct, SLOT(setChecked(bool)));
4045 #else
4046 connect(showPythonConsoleAct, SIGNAL(triggered()), this, SLOT(showNoPythonQtWarning()));
4047 #endif
4048
4049 raisePythonConsoleAct = new QAction(this);
4050 raisePythonConsoleAct->setText(tr("Show/Raise Python Console"));
4051 raisePythonConsoleAct->setShortcutContext(Qt::ApplicationShortcut);
4052 connect(raisePythonConsoleAct, SIGNAL(triggered()), focusMapper, SLOT(map()));
4053 focusMapper->setMapping(raisePythonConsoleAct, 7);
4054 this->addAction(raisePythonConsoleAct);
4055
4056 showScratchPadAct = new QAction(QIcon(prefix + "scratchpad.png"), tr("CodePad"), this);
4057 showScratchPadAct->setCheckable(true);
4058 // showPythonConsoleAct->setChecked(true); // Unnecessary because it is set by options
4059 showScratchPadAct->setStatusTip(tr("Show Code Pad"));
4060 showScratchPadAct->setIconText(tr("CodePad"));
4061 showScratchPadAct->setShortcutContext(Qt::ApplicationShortcut);
4062 connect(showScratchPadAct, SIGNAL(triggered(bool)), m_scratchPad, SLOT(setVisible(bool)));
4063 connect(m_scratchPad, SIGNAL(visibilityChanged(bool)), showScratchPadAct, SLOT(setChecked(bool)));
4064
4065 raiseScratchPadAct = new QAction(this);
4066 raiseScratchPadAct->setText(tr("Show/Raise Code Pad"));
4067 raiseScratchPadAct->setShortcutContext(Qt::ApplicationShortcut);
4068 connect(raiseScratchPadAct, SIGNAL(triggered()), focusMapper, SLOT(map()));
4069 focusMapper->setMapping(raiseScratchPadAct, 8);
4070 this->addAction(raiseScratchPadAct);
4071
4072 showManualAct = new QAction(/*QIcon(prefix + "gtk-info.png"), */tr("Csound Manual"), this);
4073 showManualAct->setStatusTip(tr("Show the Csound manual in the help panel"));
4074 showManualAct->setShortcutContext(Qt::ApplicationShortcut);
4075 connect(showManualAct, SIGNAL(triggered()), helpPanel, SLOT(showManual()));
4076
4077 showManualOnlineAct = new QAction(tr("Csound Manual Online"), this);
4078 showManualOnlineAct->setStatusTip(tr("Show the Csound manual online"));
4079 showManualOnlineAct->setShortcutContext(Qt::ApplicationShortcut);
4080 connect(showManualOnlineAct, SIGNAL(triggered()), this, SLOT(showManualOnline()));
4081
4082 downloadManualAct = new QAction(/*QIcon(prefix + "gtk-info.png"), */tr("Download Csound Manual"), this);
4083 downloadManualAct->setStatusTip(tr("Download latest Csound manual"));
4084 downloadManualAct->setShortcutContext(Qt::ApplicationShortcut);
4085 connect(downloadManualAct, SIGNAL(triggered()), this, SLOT(downloadManual()));
4086
4087
4088 showGenAct = new QAction(/*QIcon(prefix + "gtk-info.png"), */tr("GEN Routines"), this);
4089 showGenAct->setStatusTip(tr("Show the GEN Routines Manual page"));
4090 showGenAct->setShortcutContext(Qt::ApplicationShortcut);
4091 connect(showGenAct, SIGNAL(triggered()), helpPanel, SLOT(showGen()));
4092
4093 showOverviewAct = new QAction(/*QIcon(prefix + "gtk-info.png"), */tr("Opcode Overview"), this);
4094 showOverviewAct->setStatusTip(tr("Show opcode overview"));
4095 showOverviewAct->setShortcutContext(Qt::ApplicationShortcut);
4096 connect(showOverviewAct, SIGNAL(triggered()), helpPanel, SLOT(showOverview()));
4097
4098 showOpcodeQuickRefAct = new QAction(/*QIcon(prefix + "gtk-info.png"), */tr("Opcode Quick Reference"), this);
4099 showOpcodeQuickRefAct->setStatusTip(tr("Show opcode quick reference page"));
4100 showOpcodeQuickRefAct->setShortcutContext(Qt::ApplicationShortcut);
4101 connect(showOpcodeQuickRefAct, SIGNAL(triggered()), helpPanel, SLOT(showOpcodeQuickRef()));
4102
4103 showConsoleAct = new QAction(QIcon(prefix + "terminal.png"), tr("Output Console"), this);
4104 showConsoleAct->setCheckable(true);
4105 showConsoleAct->setChecked(true);
4106 showConsoleAct->setStatusTip(tr("Show Csound's message console"));
4107 showConsoleAct->setIconText(tr("Console"));
4108 showConsoleAct->setShortcutContext(Qt::ApplicationShortcut);
4109 connect(showConsoleAct, SIGNAL(toggled(bool)), m_console, SLOT(setVisible(bool)));
4110 connect(m_console, SIGNAL(Close(bool)), showConsoleAct, SLOT(setChecked(bool)));
4111
4112 raiseConsoleAct = new QAction(this);
4113 raiseConsoleAct->setText(tr("Show/Raise Console"));
4114 raiseConsoleAct->setShortcutContext(Qt::ApplicationShortcut);
4115 connect(raiseConsoleAct, SIGNAL(triggered()), focusMapper, SLOT(map()));
4116 focusMapper->setMapping(raiseConsoleAct, 3);
4117 this->addAction(raiseConsoleAct);
4118
4119 viewFullScreenAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("View Fullscreen"), this);
4120 viewFullScreenAct->setCheckable(true);
4121 viewFullScreenAct->setChecked(false);
4122 viewFullScreenAct->setStatusTip(tr("Have CsoundQt occupy all available screen space"));
4123 viewFullScreenAct->setShortcutContext(Qt::ApplicationShortcut);
4124 connect(viewFullScreenAct, SIGNAL(toggled(bool)), this, SLOT(setFullScreen(bool)));
4125
4126 viewEditorFullScreenAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("View Editor Fullscreen"), this);
4127 viewEditorFullScreenAct->setCheckable(true);
4128 viewEditorFullScreenAct->setChecked(false);
4129 viewEditorFullScreenAct->setStatusTip(tr("Have the editor occupy all available screen space"));
4130 viewEditorFullScreenAct->setShortcutContext(Qt::ApplicationShortcut);
4131 connect(viewEditorFullScreenAct, SIGNAL(toggled(bool)), this, SLOT(setEditorFullScreen(bool)));
4132
4133 #ifdef QCS_QTHTML
4134 viewHtmlFullScreenAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("View HTML Fullscreen"), this);
4135 viewHtmlFullScreenAct->setCheckable(true);
4136 viewHtmlFullScreenAct->setChecked(false);
4137 viewHtmlFullScreenAct->setStatusTip(tr("Have the HTML page occupy all available screen space"));
4138 viewHtmlFullScreenAct->setShortcutContext(Qt::ApplicationShortcut);
4139 connect(viewHtmlFullScreenAct, SIGNAL(toggled(bool)), this, SLOT(setHtmlFullScreen(bool)));
4140 #endif
4141 viewHelpFullScreenAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("View Help Fullscreen"), this);
4142 viewHelpFullScreenAct->setCheckable(true);
4143 viewHelpFullScreenAct->setChecked(false);
4144 viewHelpFullScreenAct->setStatusTip(tr("Have the help page occupy all available screen space"));
4145 viewHelpFullScreenAct->setShortcutContext(Qt::ApplicationShortcut);
4146 connect(viewHelpFullScreenAct, SIGNAL(toggled(bool)), this, SLOT(setHelpFullScreen(bool)));
4147
4148 viewWidgetsFullScreenAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("View Widgets Fullscreen"), this);
4149 viewWidgetsFullScreenAct->setCheckable(true);
4150 viewWidgetsFullScreenAct->setChecked(false);
4151 viewWidgetsFullScreenAct->setStatusTip(tr("Have the widgets panel occupy all available screen space"));
4152 viewWidgetsFullScreenAct->setShortcutContext(Qt::ApplicationShortcut);
4153 connect(viewWidgetsFullScreenAct, SIGNAL(toggled(bool)), this, SLOT(setWidgetsFullScreen(bool)));
4154
4155 #ifdef QCS_DEBUGGER
4156 showDebugAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Show debugger"), this);
4157 showDebugAct->setCheckable(true);
4158 showDebugAct->setChecked(false);
4159 showDebugAct->setStatusTip(tr("Show the Csound debugger"));
4160 showDebugAct->setShortcutContext(Qt::ApplicationShortcut);
4161 connect(showDebugAct, SIGNAL(toggled(bool)), this, SLOT(showDebugger(bool)));
4162 #endif
4163 showVirtualKeyboardAct = new QAction(QIcon(prefix + "midi-keyboard.png"), tr("Show Virtual Keyboard"), this);
4164 showVirtualKeyboardAct->setCheckable(true);
4165 showVirtualKeyboardAct->setChecked(false);
4166 showVirtualKeyboardAct->setStatusTip(tr("Show the Virtual MIDI Keyboard"));
4167 showVirtualKeyboardAct->setIconText(tr("Keyboard"));
4168 showVirtualKeyboardAct->setShortcutContext(Qt::ApplicationShortcut);
4169 connect(showVirtualKeyboardAct, SIGNAL(toggled(bool)), this, SLOT(showVirtualKeyboard(bool)));
4170
4171 showTableEditorAct = new QAction(tr("Show Table editor"), this);
4172 showTableEditorAct->setCheckable(true); // TODO: make it clickable, ie not checkable
4173 showTableEditorAct->setChecked(false);
4174 showTableEditorAct->setStatusTip(tr("Show Table editor"));
4175 showTableEditorAct->setIconText(tr("Table editor"));
4176 showTableEditorAct->setShortcutContext(Qt::ApplicationShortcut);
4177 connect(showTableEditorAct, SIGNAL(toggled(bool)), this, SLOT(showTableEditor(bool)));
4178
4179
4180 #if defined(QCS_QTHTML)
4181 showHtml5Act = new QAction(QIcon(":/images/html5.png"), tr("HTML View"), this);
4182 showHtml5Act->setIconText(tr("HTML"));
4183 showHtml5Act->setCheckable(true);
4184 showHtml5Act->setChecked(true);
4185 showHtml5Act->setStatusTip(tr("Show the HTML view"));
4186 showHtml5Act->setShortcutContext(Qt::ApplicationShortcut);
4187 connect(showHtml5Act, SIGNAL(toggled(bool)), this, SLOT(showHtml5Gui(bool)));
4188 //connect(csoundHtmlView, SIGNAL(Close(bool)), showHtml5Act, SLOT(setChecked(bool)));
4189
4190 raiseHtml5Act = new QAction(this);
4191 raiseHtml5Act->setText(tr("Show/Raise HtmlView"));
4192 raiseHtml5Act->setShortcutContext(Qt::ApplicationShortcut);
4193 connect(raiseHtml5Act, SIGNAL(triggered()), focusMapper, SLOT(map()));
4194 focusMapper->setMapping(raiseHtml5Act, 4);
4195 this->addAction(raiseHtml5Act);
4196 #endif
4197 splitViewAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Split View"), this);
4198 splitViewAct->setCheckable(true);
4199 splitViewAct->setChecked(false);
4200 splitViewAct->setStatusTip(tr("Toggle between full csd and split text display"));
4201 splitViewAct->setShortcutContext(Qt::ApplicationShortcut);
4202 connect(splitViewAct, SIGNAL(toggled(bool)), this, SLOT(splitView(bool)));
4203
4204 midiLearnAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("MIDI Learn"), this);
4205 midiLearnAct->setStatusTip(tr("Show MIDI Learn Window for widgets"));
4206 midiLearnAct->setShortcutContext(Qt::ApplicationShortcut);
4207 connect(midiLearnAct, SIGNAL(triggered()), this, SLOT(showMidiLearn()));
4208
4209 showOrcAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Show Orchestra"), this);
4210 showOrcAct->setCheckable(true);
4211 showOrcAct->setChecked(true);
4212 showOrcAct->setEnabled(false);
4213 showOrcAct->setStatusTip(tr("Show orchestra panel in split view"));
4214 showOrcAct->setShortcutContext(Qt::ApplicationShortcut);
4215 connect(showOrcAct, SIGNAL(toggled(bool)), this, SLOT(showOrc(bool)));
4216 connect(splitViewAct, SIGNAL(toggled(bool)), showOrcAct, SLOT(setEnabled(bool)));
4217
4218 showScoreAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Show Score"), this);
4219 showScoreAct->setCheckable(true);
4220 showScoreAct->setChecked(true);
4221 showScoreAct->setEnabled(false);
4222 showScoreAct->setStatusTip(tr("Show orchestra panel in split view"));
4223 showScoreAct->setShortcutContext(Qt::ApplicationShortcut);
4224 connect(showScoreAct, SIGNAL(toggled(bool)), this, SLOT(showScore(bool)));
4225 connect(splitViewAct, SIGNAL(toggled(bool)), showScoreAct, SLOT(setEnabled(bool)));
4226
4227 showOptionsAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Show CsOptions"), this);
4228 showOptionsAct->setCheckable(true);
4229 showOptionsAct->setChecked(true);
4230 showOptionsAct->setEnabled(false);
4231 showOptionsAct->setStatusTip(tr("Show CsOptions section panel in split view"));
4232 showOptionsAct->setShortcutContext(Qt::ApplicationShortcut);
4233 connect(showOptionsAct, SIGNAL(toggled(bool)), this, SLOT(showOptions(bool)));
4234 connect(splitViewAct, SIGNAL(toggled(bool)), showOptionsAct, SLOT(setEnabled(bool)));
4235
4236 showFileBAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Show Embedded files"), this);
4237 showFileBAct->setCheckable(true);
4238 showFileBAct->setChecked(false);
4239 showFileBAct->setEnabled(false);
4240 showFileBAct->setStatusTip(tr("Show Embedded files panel in split view"));
4241 showFileBAct->setShortcutContext(Qt::ApplicationShortcut);
4242 connect(showFileBAct, SIGNAL(toggled(bool)), this, SLOT(showFileB(bool)));
4243 connect(splitViewAct, SIGNAL(toggled(bool)), showFileBAct, SLOT(setEnabled(bool)));
4244
4245 showOtherAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Show Information Text"), this);
4246 showOtherAct->setCheckable(true);
4247 showOtherAct->setChecked(false);
4248 showOtherAct->setEnabled(false);
4249 showOtherAct->setStatusTip(tr("Show information text panel in split view"));
4250 showOtherAct->setShortcutContext(Qt::ApplicationShortcut);
4251 connect(showOtherAct, SIGNAL(toggled(bool)), this, SLOT(showOther(bool)));
4252 connect(splitViewAct, SIGNAL(toggled(bool)), showOtherAct, SLOT(setEnabled(bool)));
4253
4254 showOtherCsdAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Show Extra Tags"), this);
4255 showOtherCsdAct->setCheckable(true);
4256 showOtherCsdAct->setChecked(false);
4257 showOtherCsdAct->setEnabled(false);
4258 showOtherCsdAct->setStatusTip(tr("Show extra tags panel in split view"));
4259 showOtherCsdAct->setShortcutContext(Qt::ApplicationShortcut);
4260 connect(showOtherCsdAct, SIGNAL(toggled(bool)), this, SLOT(showOtherCsd(bool)));
4261 connect(splitViewAct, SIGNAL(toggled(bool)), showOtherCsdAct, SLOT(setEnabled(bool)));
4262
4263 showWidgetEditAct = new QAction(/*QIcon(prefix + "gksu-root-terminal.png"),*/ tr("Show Widgets Text"), this);
4264 showWidgetEditAct->setCheckable(true);
4265 showWidgetEditAct->setChecked(false);
4266 showWidgetEditAct->setEnabled(false);
4267 showWidgetEditAct->setStatusTip(tr("Show Widgets text panel in split view"));
4268 showWidgetEditAct->setShortcutContext(Qt::ApplicationShortcut);
4269 connect(showWidgetEditAct, SIGNAL(toggled(bool)), this, SLOT(showWidgetEdit(bool)));
4270 connect(splitViewAct, SIGNAL(toggled(bool)), showWidgetEditAct, SLOT(setEnabled(bool)));
4271
4272 setHelpEntryAct = new QAction(QIcon(prefix + "info.png"), tr("Opcode Entry"), this);
4273 setHelpEntryAct->setStatusTip(tr("Show Opcode Entry in help panel"));
4274 setHelpEntryAct->setIconText(tr("Manual for opcode"));
4275 setHelpEntryAct->setShortcutContext(Qt::ApplicationShortcut);
4276 connect(setHelpEntryAct, SIGNAL(triggered()), this, SLOT(setHelpEntry()));
4277
4278 browseBackAct = new QAction(tr("Help Back"), this);
4279 browseBackAct->setStatusTip(tr("Go back in help page"));
4280 browseBackAct->setShortcutContext(Qt::ApplicationShortcut);
4281 connect(browseBackAct, SIGNAL(triggered()), helpPanel, SLOT(browseBack()));
4282
4283 browseForwardAct = new QAction(tr("Help Forward"), this);
4284 browseForwardAct->setStatusTip(tr("Go forward in help page"));
4285 browseForwardAct->setShortcutContext(Qt::ApplicationShortcut);
4286 connect(browseForwardAct, SIGNAL(triggered()), helpPanel, SLOT(browseForward()));
4287
4288 externalBrowserAct = new QAction(/*QIcon(prefix + "gtk-info.png"), */ tr("Opcode Entry in External Browser"), this);
4289 externalBrowserAct->setStatusTip(tr("Show Opcode Entry in external browser"));
4290 externalBrowserAct->setShortcutContext(Qt::ApplicationShortcut);
4291
4292 connect(externalBrowserAct, &QAction::triggered, this,
4293 [this](){this->helpForEntry(documentPages[curPage]->wordUnderCursor(), true);});
4294
4295 openDocumentationAct = new QAction(/*QIcon(prefix + "gtk-info.png"), */ tr("CsoundQt Documentation (online)"), this);
4296 openDocumentationAct->setStatusTip(tr("open CsoundQt Documentation in browser"));
4297 openDocumentationAct->setShortcutContext(Qt::ApplicationShortcut);
4298 connect(openDocumentationAct, SIGNAL(triggered()), this, SLOT(openOnlineDocumentation()));
4299
4300 openQuickRefAct = new QAction(/*QIcon(prefix + "gtk-info.png"), */ tr("Quick Reference Guide"), this);
4301 openQuickRefAct->setStatusTip(tr("Open Quick Reference Guide in PDF viewer"));
4302 openQuickRefAct->setShortcutContext(Qt::ApplicationShortcut);
4303 connect(openQuickRefAct, SIGNAL(triggered()), this, SLOT(openQuickRef()));
4304
4305 showUtilitiesAct = new QAction(QIcon(prefix + "devel.png"), tr("Utilities"), this);
4306 showUtilitiesAct->setCheckable(true);
4307 showUtilitiesAct->setChecked(false);
4308 showUtilitiesAct->setStatusTip(tr("Show the Csound Utilities dialog"));
4309 showUtilitiesAct->setIconText(tr("Utilities"));
4310 showUtilitiesAct->setShortcutContext(Qt::ApplicationShortcut);
4311 connect(showUtilitiesAct, SIGNAL(triggered(bool)), this, SLOT(showUtilities(bool)));
4312
4313 setShortcutsAct = new QAction(tr("Keyboard Shortcuts"), this);
4314 setShortcutsAct->setStatusTip(tr("Set Keyboard Shortcuts"));
4315 setShortcutsAct->setIconText(tr("Set Shortcuts"));
4316 setShortcutsAct->setShortcutContext(Qt::ApplicationShortcut);
4317 connect(setShortcutsAct, SIGNAL(triggered()), this, SLOT(openShortcutDialog()));
4318
4319 commentAct = new QAction(tr("Comment/Uncomment"), this);
4320 commentAct->setStatusTip(tr("Comment/Uncomment selection"));
4321 commentAct->setShortcutContext(Qt::ApplicationShortcut);
4322 // commentAct->setIconText(tr("Comment"));
4323 // connect(commentAct, SIGNAL(triggered()), this, SLOT(controlD()));
4324
4325 // uncommentAct = new QAction(tr("Uncomment"), this);
4326 // uncommentAct->setStatusTip(tr("Uncomment selection"));
4327 // uncommentAct->setShortcutContext(Qt::ApplicationShortcut);
4328 // uncommentAct->setIconText(tr("Uncomment"));
4329 // connect(uncommentAct, SIGNAL(triggered()), this, SLOT(uncomment()));
4330
4331 indentAct = new QAction(tr("Indent"), this);
4332 indentAct->setStatusTip(tr("Indent selection"));
4333 indentAct->setShortcutContext(Qt::ApplicationShortcut);
4334 // indentAct->setIconText(tr("Indent"));
4335 // connect(indentAct, SIGNAL(triggered()), this, SLOT(indent()));
4336
4337 unindentAct = new QAction(tr("Unindent"), this);
4338 unindentAct->setStatusTip(tr("Unindent selection"));
4339 unindentAct->setShortcutContext(Qt::ApplicationShortcut);
4340 // unindentAct->setIconText(tr("Unindent"));
4341 // connect(unindentAct, SIGNAL(triggered()), this, SLOT(unindent()));
4342
4343 killLineAct = new QAction(tr("Kill Line"), this);
4344 killLineAct->setStatusTip(tr("Completely delete current line"));
4345 killLineAct->setShortcutContext(Qt::ApplicationShortcut);
4346
4347 killToEndAct = new QAction(tr("Kill to End of Line"), this);
4348 killToEndAct->setStatusTip(tr("Delete everything from cursor to the end of the current line"));
4349 killToEndAct->setShortcutContext(Qt::ApplicationShortcut);
4350
4351 gotoLineAct = new QAction(tr("Goto Line"), this);
4352 gotoLineAct->setStatusTip(tr("Go to a given line"));
4353 gotoLineAct->setShortcutContext(Qt::ApplicationShortcut);
4354 connect(gotoLineAct, SIGNAL(triggered()), this, SLOT(gotoLineDialog()));
4355
4356 goBackAct = new QAction(tr("Go Back"), this);
4357 goBackAct->setStatusTip(tr("Go back to previous position"));
4358 goBackAct->setShortcutContext(Qt::ApplicationShortcut);
4359 connect(goBackAct, &QAction::triggered, [this]() { this->getCurrentDocumentPage()->goBackToPreviousPosition(); });
4360
4361 aboutAct = new QAction(tr("&About CsoundQt"), this);
4362 aboutAct->setStatusTip(tr("Show the application's About box"));
4363 // aboutAct->setIconText(tr("About"));
4364 aboutAct->setShortcutContext(Qt::ApplicationShortcut);
4365 connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
4366
4367 donateAct = new QAction(tr("Donate to CsoundQt"), this);
4368 donateAct->setStatusTip(tr("Donate to support development of CsoundQt"));
4369 // aboutAct->setIconText(tr("About"));
4370 donateAct->setShortcutContext(Qt::ApplicationShortcut);
4371 connect(donateAct, SIGNAL(triggered()), this, SLOT(donate()));
4372
4373 // aboutQtAct = new QAction(tr("About &Qt"), this);
4374 // aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
4375 //// aboutQtAct->setIconText(tr("About Qt"));
4376 // aboutQtAct->setShortcutContext(Qt::ApplicationShortcut);
4377 // connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
4378
4379 resetPreferencesAct = new QAction(tr("Reset Preferences"), this);
4380 resetPreferencesAct->setStatusTip(tr("Reset CsoundQt's preferences to their original default state"));
4381 resetPreferencesAct->setShortcutContext(Qt::ApplicationShortcut);
4382 connect(resetPreferencesAct, SIGNAL(triggered()), this, SLOT(resetPreferences()));
4383
4384 reportBugAct = new QAction(tr("Report a CsoundQt Bug"), this);
4385 reportBugAct->setStatusTip(tr("Report a CsoundQt bug that is clearly related to the front-end"));
4386 reportBugAct->setShortcutContext(Qt::ApplicationShortcut);
4387 connect(reportBugAct, SIGNAL(triggered()), this, SLOT(reportBug()));
4388
4389 reportCsoundBugAct = new QAction(tr("Report a Csound Bug"), this);
4390 reportCsoundBugAct->setStatusTip(tr("Report a bug that is caused by the core Csound - when the same problem occurs also with \"Run in Terminal\""));
4391 reportCsoundBugAct->setShortcutContext(Qt::ApplicationShortcut);
4392 connect(reportCsoundBugAct, SIGNAL(triggered()), this, SLOT(reportCsoundBug()));
4393
4394 duplicateAct = new QAction(tr("Duplicate Widgets"), this);
4395 duplicateAct->setShortcutContext(Qt::ApplicationShortcut);
4396 connect(duplicateAct, SIGNAL(triggered()), this, SLOT(duplicate()));
4397
4398 lineNumbersAct = new QAction(tr("Show/hide line number area"),this);
4399 lineNumbersAct->setShortcutContext(Qt::ApplicationShortcut);
4400 connect(lineNumbersAct,SIGNAL(triggered()), this, SLOT(toggleLineArea()));
4401
4402 parameterModeAct = new QAction(tr("Toggle parameter mode"),this);
4403 connect(parameterModeAct,SIGNAL(triggered()), this, SLOT(toggleParameterMode()));
4404
4405 autocompleteAct = new QAction(tr("Autocomplete"), this);
4406 autocompleteAct->setShortcutContext(Qt::ApplicationShortcut);
4407 connect(autocompleteAct, SIGNAL(triggered()), this, SLOT(autocomplete()));
4408
4409 // showParametersAct = new QAction(tr("Show available parameters"),this);
4410 // connect(showParametersAct,SIGNAL(triggered()), this, SLOT(showParametersInEditor()));
4411
4412 // font size ZoomIn, ZoomOut
4413 QAction *increaseFontAction = new QAction(this);
4414 QAction *decreaseFontAction = new QAction(this);
4415 increaseFontAction->setShortcut(QKeySequence::ZoomIn);
4416 decreaseFontAction->setShortcut(QKeySequence::ZoomOut);
4417 connect(increaseFontAction, &QAction::triggered, this, &CsoundQt::increaseFontSize );
4418 connect(decreaseFontAction, &QAction::triggered, this, &CsoundQt::decreaseFontSize);
4419 addAction(increaseFontAction);
4420 addAction(decreaseFontAction);
4421
4422 setKeyboardShortcutsList();
4423 setDefaultKeyboardShortcuts();
4424 }
4425
4426 void CsoundQt::setKeyboardShortcutsList()
4427 {
4428 m_keyActions.append(newAct);
4429 m_keyActions.append(openAct);
4430 m_keyActions.append(reloadAct);
4431 m_keyActions.append(saveAct);
4432 m_keyActions.append(saveAsAct);
4433 m_keyActions.append(createAppAct);
4434 m_keyActions.append(closeTabAct);
4435 m_keyActions.append(printAct);
4436 m_keyActions.append(exitAct);
4437 m_keyActions.append(createCodeGraphAct);
4438 m_keyActions.append(undoAct);
4439 m_keyActions.append(redoAct);
4440 m_keyActions.append(cutAct);
4441 m_keyActions.append(copyAct);
4442 m_keyActions.append(pasteAct);
4443 m_keyActions.append(duplicateAct);
4444 m_keyActions.append(joinAct);
4445 m_keyActions.append(inToGetAct);
4446 m_keyActions.append(getToInAct);
4447 m_keyActions.append(csladspaAct);
4448 m_keyActions.append(cabbageAct);
4449 m_keyActions.append(findAct);
4450 m_keyActions.append(findAgainAct);
4451 m_keyActions.append(configureAct);
4452 m_keyActions.append(editAct);
4453 m_keyActions.append(runAct);
4454 m_keyActions.append(runTermAct);
4455 m_keyActions.append(stopAct);
4456 m_keyActions.append(pauseAct);
4457 m_keyActions.append(stopAllAct);
4458 m_keyActions.append(recAct);
4459 m_keyActions.append(renderAct);
4460 m_keyActions.append(commentAct);
4461 m_keyActions.append(indentAct);
4462 m_keyActions.append(unindentAct);
4463 m_keyActions.append(externalPlayerAct);
4464 m_keyActions.append(externalEditorAct);
4465 m_keyActions.append(focusEditorAct);
4466 m_keyActions.append(raiseWidgetsAct);
4467 m_keyActions.append(showInspectorAct);
4468 m_keyActions.append(raiseHelpAct);
4469 m_keyActions.append(showGenAct);
4470 m_keyActions.append(showOverviewAct);
4471 m_keyActions.append(raiseConsoleAct);
4472 m_keyActions.append(raiseInspectorAct);
4473 m_keyActions.append(showLiveEventsAct);
4474 m_keyActions.append(raisePythonConsoleAct);
4475 m_keyActions.append(raiseScratchPadAct);
4476 m_keyActions.append(showUtilitiesAct);
4477 m_keyActions.append(showVirtualKeyboardAct);
4478 m_keyActions.append(showTableEditorAct);
4479 m_keyActions.append(checkSyntaxAct);
4480 m_keyActions.append(autocompleteAct);
4481 #if defined(QCS_QTHTML)
4482 m_keyActions.append(raiseHtml5Act);
4483 #endif
4484 m_keyActions.append(setHelpEntryAct);
4485 m_keyActions.append(browseBackAct);
4486 m_keyActions.append(browseForwardAct);
4487 m_keyActions.append(externalBrowserAct);
4488 m_keyActions.append(openQuickRefAct);
4489 m_keyActions.append(openDocumentationAct);
4490 // m_keyActions.append(showOpcodeQuickRefAct);
4491 m_keyActions.append(infoAct);
4492 m_keyActions.append(viewFullScreenAct);
4493 m_keyActions.append(viewEditorFullScreenAct);
4494 #if defined(QCS_QTHTML)
4495 m_keyActions.append(viewHtmlFullScreenAct);
4496 #endif
4497 m_keyActions.append(viewHelpFullScreenAct);
4498 m_keyActions.append(viewWidgetsFullScreenAct);
4499 #ifdef QCS_DEBUGGER
4500 m_keyActions.append(showDebugAct);
4501 #endif
4502 m_keyActions.append(splitViewAct);
4503 m_keyActions.append(midiLearnAct);
4504 m_keyActions.append(killLineAct);
4505 m_keyActions.append(killToEndAct);
4506 m_keyActions.append(gotoLineAct);
4507 m_keyActions.append(goBackAct);
4508 m_keyActions.append(evaluateAct);
4509 m_keyActions.append(evaluateSectionAct);
4510 m_keyActions.append(scratchPadCsdModeAct);
4511 m_keyActions.append(showOrcAct);
4512 m_keyActions.append(showScoreAct);
4513 m_keyActions.append(showOptionsAct);
4514 m_keyActions.append(showFileBAct);
4515 m_keyActions.append(showOtherAct);
4516 m_keyActions.append(showOtherCsdAct);
4517 m_keyActions.append(showWidgetEditAct);
4518 m_keyActions.append(lineNumbersAct);
4519 m_keyActions.append(parameterModeAct);
4520 // m_keyActions.append(showParametersAct);
4521 }
4522
4523 void CsoundQt::connectActions()
4524 {
4525 DocumentPage * doc = documentPages[curPage];
4526
4527 disconnect(commentAct, 0, 0, 0);
4528 // disconnect(uncommentAct, 0, 0, 0);
4529 disconnect(indentAct, 0, 0, 0);
4530 disconnect(unindentAct, 0, 0, 0);
4531 disconnect(killLineAct, 0, 0, 0);
4532 disconnect(killToEndAct, 0, 0, 0);
4533 // disconnect(gotoLineAct, 0, 0, 0);
4534 // disconnect(findAct, 0, 0, 0);
4535 // disconnect(findAgainAct, 0, 0, 0);
4536 connect(commentAct, SIGNAL(triggered()), doc, SLOT(comment()));
4537 // connect(uncommentAct, SIGNAL(triggered()), doc, SLOT(uncomment()));
4538 connect(indentAct, SIGNAL(triggered()), doc, SLOT(indent()));
4539 connect(unindentAct, SIGNAL(triggered()), doc, SLOT(unindent()));
4540 connect(killLineAct, SIGNAL(triggered()), doc, SLOT(killLine()));
4541 connect(killToEndAct, SIGNAL(triggered()), doc, SLOT(killToEnd()));
4542
4543 // line and column number connection
4544 connect(doc->getView(), SIGNAL(newLineAndColumn(int, int)), this, SLOT(setLineAndColumn(int,int)));
4545
4546 // connect(gotoLineAct, SIGNAL(triggered()), doc, SLOT(gotoLineDialog()));
4547 // disconnect(doc, SIGNAL(copyAvailable(bool)), 0, 0);
4548 // disconnect(doc, SIGNAL(copyAvailable(bool)), 0, 0);
4549 //TODO put these back
4550 // connect(doc, SIGNAL(copyAvailable(bool)),
4551 // cutAct, SLOT(setEnabled(bool)));
4552 // connect(doc, SIGNAL(copyAvailable(bool)),
4553 // copyAct, SLOT(setEnabled(bool)));
4554
4555 // disconnect(doc, SIGNAL(textChanged()), 0, 0);
4556 // disconnect(doc, SIGNAL(cursorPositionChanged()), 0, 0);
4557
4558 // disconnect(widgetPanel, SIGNAL(widgetsChanged(QString)),0,0);
4559 // connect(widgetPanel, SIGNAL(widgetsChanged(QString)),
4560 // doc, SLOT(setMacWidgetsText(QString)) );
4561
4562 // Connect inspector actions to document
4563 disconnect(m_inspector, 0, 0, 0);
4564 connect(m_inspector, SIGNAL(jumpToLine(int)),
4565 doc, SLOT(jumpToLine(int)));
4566 disconnect(m_inspector, 0, 0, 0);
4567 connect(m_inspector, SIGNAL(jumpToLine(int)),
4568 doc, SLOT(jumpToLine(int)));
4569 connect(m_inspector, SIGNAL(Close(bool)), showInspectorAct, SLOT(setChecked(bool)));
4570
4571 disconnect(showLiveEventsAct, 0,0,0);
4572 connect(showLiveEventsAct, SIGNAL(toggled(bool)), doc, SLOT(showLiveEventControl(bool)));
4573 disconnect(doc, 0,0,0);
4574 connect(doc, SIGNAL(liveEventsVisible(bool)), showLiveEventsAct, SLOT(setChecked(bool)));
4575 connect(doc, SIGNAL(stopSignal()), this, SLOT(markStopped()));
4576 connect(doc, SIGNAL(setHelpSignal()), this, SLOT(setHelpEntry()));
4577 connect(doc, SIGNAL(closeExtraPanelsSignal()), this, SLOT(closeExtraPanels()));
4578 connect(doc, SIGNAL(currentTextUpdated()), this, SLOT(markInspectorUpdate()));
4579
4580 connect(doc->getView(), SIGNAL(opcodeSyntaxSignal(QString)),
4581 this, SLOT(statusBarMessage(QString)));
4582
4583 connect(doc, SIGNAL(modified()), this, SLOT(documentWasModified()));
4584 connect(doc, &DocumentPage::unmodified, [this](){this->documentWasModified(false);});
4585
4586 // connect(documentPages[curPage], SIGNAL(setWidgetClipboardSignal(QString)),
4587 // this, SLOT(setWidgetClipboard(QString)));
4588 connect(doc, SIGNAL(setCurrentAudioFile(QString)),
4589 this, SLOT(setCurrentAudioFile(QString)));
4590 connect(doc, SIGNAL(evaluatePythonSignal(QString)),
4591 this, SLOT(evaluateString(QString)));
4592
4593 disconnect(showWidgetsAct, 0,0,0);
4594 if (m_options->widgetsIndependent) {
4595 connect(showWidgetsAct, SIGNAL(triggered(bool)), doc, SLOT(showWidgets(bool)));
4596 auto wl = doc->getWidgetLayout();
4597 connect(wl, SIGNAL(windowStatus(bool)), showWidgetsAct, SLOT(setChecked(bool)));
4598 // connect(widgetPanel, SIGNAL(Close(bool)), showWidgetsAct, SLOT(setChecked(bool)));
4599 }
4600 else {
4601 // connect(showWidgetsAct, SIGNAL(triggered(bool)), widgetPanel, SLOT(setVisible(bool)));
4602 connect(showWidgetsAct, SIGNAL(triggered(bool)), widgetPanel, SLOT(showAndRaise(bool)));
4603
4604 connect(widgetPanel, SIGNAL( Close(bool)), showWidgetsAct, SLOT(setChecked(bool)));
4605 }
4606 }
4607
4608 QString CsoundQt::getExamplePath(QString dir)
4609 {
4610 QString examplePath;
4611
4612 if (!m_options->examplePath.isEmpty() && QDir(m_options->examplePath + dir).exists()) {
4613 examplePath = m_options->examplePath + dir;
4614 return examplePath;
4615 }
4616
4617 #ifdef Q_OS_WIN32
4618 examplePath = qApp->applicationDirPath() + "/Examples/" + dir;
4619 if (!QDir(examplePath).exists()) {
4620 QString programFilesPath= QDir::fromNativeSeparators(getenv("PROGRAMFILES"));
4621 examplePath = programFilesPath + "/Csound6/bin/Examples/" + dir; // NB! with csound6.0.6 no Floss/mCcurdy/Stria examples there. Copy manually
4622 //qDebug()<<"Windows examplepath: "<<examplePath;
4623 }
4624 #endif
4625 #ifdef Q_OS_MAC
4626 examplePath = qApp->applicationDirPath() + "/../Resources/Examples/" + dir;
4627 qDebug() << examplePath;
4628 #endif
4629 #ifdef Q_OS_LINUX
4630 examplePath = QString(); //qApp->applicationDirPath() + "/Examples/" + dir;
4631 QStringList possiblePaths;
4632 possiblePaths << qApp->applicationDirPath() + "/Examples/"
4633 << qApp->applicationDirPath() + "/../src/Examples/"
4634 << qApp->applicationDirPath() + "/../../csoundqt/src/Examples/"
4635 << qApp->applicationDirPath() + "/../../CsoundQt/src/Examples/"
4636 << qApp->applicationDirPath() + "/../share/csoundqt/Examples/"
4637 << "/../../qutecsound/src/Examples/"
4638 << "~/.local/share/qutecsound/Examples/" << "/usr/share/qutecsound/Examples/"
4639 << "~/.local/share/csoundqt/Examples/"
4640 << "/usr/share/csoundqt/Examples/";
4641
4642 foreach (QString path, possiblePaths) {
4643 path += dir;
4644 if (QDir(path).exists()) {
4645 examplePath = path;
4646 break;
4647 }
4648 }
4649 if (examplePath.isEmpty()) {
4650 qDebug() << "Path to extended examples not found!";
4651 } else {
4652 qDebug() << "ExamplePath: " << examplePath;
4653 }
4654
4655 #endif
4656 #ifdef Q_OS_SOLARIS
4657 examplePath = qApp->applicationDirPath() + "/Examples/" + dir;
4658 if (!QDir(examplePath).exists()) {
4659 examplePath = "/usr/share/qutecsound/Examples/" + dir;
4660 }
4661 if (!QDir(examplePath).exists()) {
4662 examplePath = qApp->applicationDirPath() + "/../src/Examples/" + dir;
4663 }
4664 #endif
4665 return examplePath;
4666 }
4667
4668
4669
4670 void CsoundQt::createMenus()
4671 {
4672 fileMenu = menuBar()->addMenu(tr("File"));
4673 fileMenu->addAction(newAct);
4674 fileMenu->addAction(openAct);
4675 fileMenu->addAction(saveAct);
4676 fileMenu->addAction(saveAsAct);
4677 fileMenu->addAction(saveNoWidgetsAct);
4678 fileMenu->addAction(qmlAct);
4679 // fileMenu->addAction(createAppAct);
4680 fileMenu->addAction(reloadAct);
4681 fileMenu->addAction(closeTabAct);
4682 fileMenu->addAction(printAct);
4683 fileMenu->addAction(infoAct);
4684 fileMenu->addSeparator();
4685 recentMenu = fileMenu->addMenu(tr("Recent files"));
4686 templateMenu = fileMenu->addMenu(tr("Templates"));
4687 fileMenu->addSeparator();
4688 fileMenu->addAction(exitAct);
4689
4690 editMenu = menuBar()->addMenu(tr("Edit"));
4691 editMenu->addAction(undoAct);
4692 editMenu->addAction(redoAct);
4693 editMenu->addSeparator();
4694 editMenu->addAction(cutAct);
4695 editMenu->addAction(copyAct);
4696 editMenu->addAction(pasteAct);
4697 editMenu->addAction(autocompleteAct);
4698 editMenu->addAction(evaluateAct);
4699 editMenu->addAction(evaluateSectionAct);
4700 editMenu->addAction(scratchPadCsdModeAct);
4701
4702 editMenu->addSeparator();
4703 editMenu->addAction(findAct);
4704 editMenu->addAction(findAgainAct);
4705 editMenu->addAction(gotoLineAct);
4706 // editMenu->addAction(goBackAct);
4707 editMenu->addSeparator();
4708 editMenu->addAction(commentAct);
4709 // editMenu->addAction(uncommentAct);
4710 editMenu->addAction(indentAct);
4711 editMenu->addAction(unindentAct);
4712 // editMenu->addAction(killLineAct);
4713 // editMenu->addAction(killToEndAct);
4714 editMenu->addAction(lineNumbersAct);
4715 editMenu->addAction(parameterModeAct);
4716 editMenu->addSeparator();
4717 editMenu->addAction(joinAct);
4718 editMenu->addAction(inToGetAct);
4719 editMenu->addAction(getToInAct);
4720 editMenu->addAction(midiControlAct);
4721 // editMenu->addAction(csladspaAct);
4722 editMenu->addAction(cabbageAct);
4723 editMenu->addSeparator();
4724 editMenu->addAction(editAct);
4725 editMenu->addSeparator();
4726 editMenu->addAction(configureAct);
4727 editMenu->addAction(setShortcutsAct);
4728
4729 controlMenu = menuBar()->addMenu(tr("Control"));
4730 controlMenu->addAction(runAct);
4731 controlMenu->addAction(runTermAct);
4732 controlMenu->addAction(pauseAct);
4733 controlMenu->addAction(renderAct);
4734 controlMenu->addAction(recAct);
4735 controlMenu->addAction(stopAct);
4736 controlMenu->addAction(stopAllAct);
4737 controlMenu->addSeparator();
4738 controlMenu->addAction(externalEditorAct);
4739 controlMenu->addAction(externalPlayerAct);
4740 controlMenu->addAction(checkSyntaxAct);
4741 controlMenu->addSeparator();
4742 controlMenu->addAction(testAudioSetupAct);
4743
4744
4745 viewMenu = menuBar()->addMenu(tr("View"));
4746 viewMenu->addAction(focusEditorAct);
4747 viewMenu->addAction(showWidgetsAct);
4748 viewMenu->addAction(showHelpAct);
4749 viewMenu->addAction(showConsoleAct);
4750 viewMenu->addAction(showUtilitiesAct);
4751 viewMenu->addAction(createCodeGraphAct);
4752 viewMenu->addAction(showInspectorAct);
4753 viewMenu->addAction(showLiveEventsAct);
4754 #ifdef QCS_PYTHONQT
4755 viewMenu->addAction(showPythonConsoleAct);
4756 #endif
4757 viewMenu->addAction(showScratchPadAct);
4758 #if defined(QCS_QTHTML)
4759 viewMenu->addAction(showHtml5Act);
4760 #endif
4761 viewMenu->addAction(showUtilitiesAct);
4762 #ifdef QCS_DEBUGGER
4763 viewMenu->addAction(showDebugAct);
4764 #endif
4765 viewMenu->addAction(midiLearnAct);
4766 viewMenu->addAction(showVirtualKeyboardAct);
4767 viewMenu->addAction(showTableEditorAct);
4768 viewMenu->addSeparator();
4769 viewMenu->addAction(viewFullScreenAct);
4770 viewMenu->addAction(viewEditorFullScreenAct);
4771 #if defined(QCS_QTHTML)
4772 viewMenu->addAction(viewHtmlFullScreenAct);
4773 #endif
4774 viewMenu->addAction(viewHelpFullScreenAct);
4775 viewMenu->addAction(viewWidgetsFullScreenAct);
4776 viewMenu->addSeparator();
4777 viewMenu->addAction(splitViewAct);
4778 viewMenu->addSeparator();
4779 viewMenu->addAction(showOrcAct);
4780 viewMenu->addAction(showScoreAct);
4781 viewMenu->addAction(showOptionsAct);
4782 viewMenu->addAction(showFileBAct);
4783 viewMenu->addAction(showOtherAct);
4784 viewMenu->addAction(showOtherCsdAct);
4785 viewMenu->addAction(showWidgetEditAct);
4786
4787 fillExampleMenu();
4788
4789
4790 favoriteMenu = menuBar()->addMenu(tr("Favorites"));
4791 #ifdef QCS_PYTHONQT
4792 scriptsMenu = menuBar()->addMenu(tr("Scripts"));
4793 scriptsMenu->hide();
4794 #endif
4795
4796 menuBar()->addSeparator();
4797
4798 helpMenu = menuBar()->addMenu(tr("Help"));
4799 helpMenu->addAction(openDocumentationAct);
4800 helpMenu->addAction(setHelpEntryAct);
4801 helpMenu->addAction(externalBrowserAct);
4802 // helpMenu->addSeparator();
4803 // helpMenu->addAction(browseBackAct);
4804 // helpMenu->addAction(browseForwardAct);
4805 helpMenu->addSeparator();
4806 helpMenu->addAction(showManualAct);
4807 helpMenu->addAction(showManualOnlineAct);
4808 helpMenu->addAction(downloadManualAct);
4809 helpMenu->addAction(showOverviewAct);
4810 // helpMenu->addAction(showOpcodeQuickRefAct);
4811 helpMenu->addAction(showGenAct);
4812 // helpMenu->addAction(openQuickRefAct);
4813 helpMenu->addSeparator();
4814 helpMenu->addAction(resetPreferencesAct);
4815 helpMenu->addSeparator();
4816 helpMenu->addAction(reportBugAct);
4817 helpMenu->addAction(reportCsoundBugAct);
4818 helpMenu->addSeparator();
4819 helpMenu->addAction(aboutAct);
4820 // helpMenu->addAction(donateAct);
4821 // uhelpMenu->addAction(aboutQtAct);
4822
4823 }
4824
4825
4826 void CsoundQt::fillExampleMenu()
4827 {
4828 QString examplePath = getExamplePath("");
4829 qDebug() << examplePath;
4830 if (examplePath.isEmpty() ) {
4831 qDebug() << "examplePath not set";
4832 return;
4833 }
4834
4835 QMenu *examplesMenu = menuBar()->addMenu(tr("Examples"));
4836
4837 QDir dir(examplePath);
4838 if (dir.count() > 0) {
4839 fillExampleSubmenu(dir.absolutePath(), examplesMenu, 0);
4840 }
4841
4842 if (!examplePath.isEmpty()) {
4843 examplesMenu->addSeparator();
4844 openExamplesFolderAct = new QAction(tr("Open Examples Folder"), this);
4845 openExamplesFolderAct->setStatusTip(tr("Save the document under a new name"));
4846 openExamplesFolderAct->setShortcutContext(Qt::ApplicationShortcut);
4847 connect(openExamplesFolderAct, SIGNAL(triggered()), this, SLOT(openExamplesFolder()));
4848 examplesMenu->addAction(openExamplesFolderAct);
4849 }
4850
4851
4852 }
4853
4854 void CsoundQt::fillExampleSubmenu(QDir dir, QMenu *m, int depth)
4855 {
4856 QString test = dir.dirName();
4857 //qDebug() << "dirName: " << test;
4858 if (depth > m_options->menuDepth) {
4859 return;
4860 }
4861
4862 // add extra entry for FLOSS manual
4863 if (dir.dirName().startsWith("FLOSS")) {
4864 m->addAction(tr("Read FLOSS Manual Online"),this, SLOT(openFLOSSManual()));
4865 m->addSeparator();
4866 }
4867
4868 QStringList filters;
4869 filters << "*.csd" << "*.pdf" << "*.html";
4870 dir.setNameFilters(filters);
4871 QStringList files = dir.entryList(QDir::Files,QDir::Name);
4872 QStringList dirs = dir.entryList(QDir::AllDirs,QDir::Name);
4873 for (int i = 0; i < dirs.size() && i < 256; i++) {
4874 QDir newDir(dir.absolutePath() + "/" + dirs[i]);
4875 newDir.setNameFilters(filters);
4876 QStringList newFiles = dir.entryList(QDir::Files,QDir::Name);
4877 QStringList newDirs = dir.entryList(QDir::AllDirs,QDir::Name);
4878 if (newFiles.size() > 0 || newDirs.size() > 0) {
4879 if (dirs[i] != "." && dirs[i] != ".." && dirs[i]!="SourceMaterials") {
4880 QMenu *menu = m->addMenu(dirs[i]);
4881 fillExampleSubmenu(newDir.absolutePath(), menu, depth + 1);
4882 }
4883 }
4884 }
4885 for (int i = 0; i < files.size() && i < 256; i++) {
4886 QAction *newAction = m->addAction(files[i],
4887 this, SLOT(openExample()));
4888 newAction->setData(dir.absoluteFilePath(files[i]));
4889 }
4890 }
4891
4892
4893 void CsoundQt::fillFileMenu()
4894 {
4895 recentMenu->clear();
4896 for (int i = 0; i < recentFiles.size(); i++) {
4897 if (i < recentFiles.size() && recentFiles[i] != "") {
4898 QAction *a = recentMenu->addAction(recentFiles[i], this, SLOT(openFromAction()));
4899 a->setData(recentFiles[i]);
4900 }
4901 }
4902 templateMenu->clear();
4903 QString templatePath = m_options->templateDir;
4904 if (templatePath.isEmpty() || !QDir(templatePath).exists()) {
4905 #ifdef Q_OS_WIN32
4906 templatePath = qApp->applicationDirPath() + "/templates/";
4907 #endif
4908 #ifdef Q_OS_MAC
4909 templatePath = qApp->applicationDirPath() + "/../templates/";
4910 qDebug() << templatePath;
4911 #endif
4912 #ifdef Q_OS_LINUX
4913 templatePath = qApp->applicationDirPath() + "/templates/";
4914 if (!QDir(templatePath).exists()) {
4915 templatePath = qApp->applicationDirPath() + "/../templates/";
4916 }
4917 if (!QDir(templatePath).exists()) { // for out of tree builds
4918 templatePath = qApp->applicationDirPath() + "/../../csoundqt/templates/";
4919 }
4920 if (!QDir(templatePath).exists()) { // for out of tree builds
4921 templatePath = qApp->applicationDirPath() + "/../../qutecsound/templates/";
4922 }
4923 if (!QDir(templatePath).exists()) {
4924 templatePath = "/usr/share/csoundqt/templates/";
4925 }
4926 #endif
4927 #ifdef Q_OS_SOLARIS
4928 templatePath = qApp->applicationDirPath() + "/templates/";
4929 if (!QDir(templatePath).exists()) {
4930 templatePath = "/usr/share/qutecsound/templates/";
4931 }
4932 if (!QDir(templatePath).exists()) {
4933 templatePath = qApp->applicationDirPath() + "/../src/templates/";
4934 }
4935 #endif
4936 }
4937 QStringList filters;
4938 filters << "*.csd"<<"*.html";
4939 QStringList templateFiles = QDir(templatePath).entryList(filters,QDir::Files);
4940 foreach (QString fileName, templateFiles) {
4941 QAction *newAction = templateMenu->addAction(fileName, this,
4942 SLOT(openTemplate()));
4943 newAction->setData(templatePath + QDir::separator() + fileName);
4944 }
4945 }
4946
4947 void CsoundQt::fillFavoriteMenu()
4948 {
4949 favoriteMenu->clear();
4950 if (!m_options->favoriteDir.isEmpty()) {
4951 QDir dir(m_options->favoriteDir);
4952 fillFavoriteSubMenu(dir.absolutePath(), favoriteMenu, 0);
4953 }
4954 else {
4955 favoriteMenu->addAction(tr("Set the Favourites folder in the Configuration Window"),
4956 this, SLOT(configure()));
4957 }
4958 }
4959
4960 void CsoundQt::fillFavoriteSubMenu(QDir dir, QMenu *m, int depth)
4961 {
4962 QStringList filters;
4963 filters << "*.csd" << "*.orc" << "*.sco" << "*.udo" << "*.inc" << "*.py";
4964 dir.setNameFilters(filters);
4965 QStringList files = dir.entryList(QDir::Files,QDir::Name);
4966 QStringList dirs = dir.entryList(QDir::AllDirs,QDir::Name);
4967 if (depth > m_options->menuDepth)
4968 return;
4969 for (int i = 0; i < dirs.size() && i < 64; i++) {
4970 QDir newDir(dir.absolutePath() + "/" + dirs[i]);
4971 newDir.setNameFilters(filters);
4972 QStringList newFiles = dir.entryList(QDir::Files,QDir::Name);
4973 QStringList newDirs = dir.entryList(QDir::AllDirs,QDir::Name);
4974 if (newFiles.size() > 0 || newDirs.size() > 0) {
4975 if (dirs[i] != "." && dirs[i] != "..") {
4976 QMenu *menu = m->addMenu(dirs[i]);
4977 fillFavoriteSubMenu(newDir.absolutePath(), menu, depth + 1);
4978 }
4979 }
4980 }
4981 for (int i = 0; i < files.size() && i < 64; i++) {
4982 QAction *newAction = m->addAction(files[i],
4983 this, SLOT(openFromAction()));
4984 newAction->setData(dir.absoluteFilePath(files[i]));
4985 }
4986 }
4987
4988 void CsoundQt::fillScriptsMenu()
4989 {
4990 #ifdef QCS_PYTHONQT
4991 scriptsMenu->clear();
4992 QString dirName = m_options->pythonDir.isEmpty() ? DEFAULT_SCRIPT_DIR : m_options->pythonDir;
4993 QDir dir(dirName);
4994 if (dir.count() > 0) {
4995 fillScriptsSubMenu(dir.absolutePath(), scriptsMenu, 0);
4996 scriptsMenu->addSeparator();
4997 QMenu *editMenu = scriptsMenu->addMenu("Edit");
4998 fillEditScriptsSubMenu(dir.absolutePath(), editMenu, 0);
4999 }
5000 #endif
5001 }
5002
5003 void CsoundQt::fillScriptsSubMenu(QDir dir, QMenu *m, int depth)
5004 {
5005 QStringList filters;
5006 filters << "*.py";
5007 dir.setNameFilters(filters);
5008 QStringList files = dir.entryList(QDir::Files,QDir::Name);
5009 QStringList dirs = dir.entryList(QDir::AllDirs,QDir::Name);
5010 if (depth > m_options->menuDepth)
5011 return;
5012 for (int i = 0; i < dirs.size() && i < 64; i++) {
5013 QDir newDir(dir.absolutePath() + "/" + dirs[i]);
5014 newDir.setNameFilters(filters);
5015 QStringList newFiles = dir.entryList(QDir::Files,QDir::Name);
5016 QStringList newDirs = dir.entryList(QDir::AllDirs,QDir::Name);
5017 if (newFiles.size() > 0 || newDirs.size() > 0) {
5018 if (dirs[i] != "." && dirs[i] != "..") {
5019 QMenu *menu = m->addMenu(dirs[i]);
5020 fillScriptsSubMenu(newDir.absolutePath(), menu, depth + 1);
5021 }
5022 }
5023 }
5024 for (int i = 0; i < files.size() && i < 64; i++) {
5025 QAction *newAction = m->addAction(files[i],
5026 this, SLOT(runScriptFromAction()));
5027 newAction->setData(dir.absoluteFilePath(files[i]));
5028 }
5029 }
5030
5031 void CsoundQt::fillEditScriptsSubMenu(QDir dir, QMenu *m, int depth)
5032 {
5033 QStringList filters;
5034 filters << "*.py";
5035 dir.setNameFilters(filters);
5036 QStringList files = dir.entryList(QDir::Files,QDir::Name);
5037 QStringList dirs = dir.entryList(QDir::AllDirs,QDir::Name);
5038 if (depth > m_options->menuDepth)
5039 return;
5040 for (int i = 0; i < dirs.size() && i < 64; i++) {
5041 QDir newDir(dir.absolutePath() + "/" + dirs[i]);
5042 newDir.setNameFilters(filters);
5043 QStringList newFiles = dir.entryList(QDir::Files,QDir::Name);
5044 QStringList newDirs = dir.entryList(QDir::AllDirs,QDir::Name);
5045 if (newFiles.size() > 0 || newDirs.size() > 0) {
5046 if (dirs[i] != "." && dirs[i] != "..") {
5047 QMenu *menu = m->addMenu(dirs[i]);
5048 fillEditScriptsSubMenu(newDir.absolutePath(), menu, depth + 1);
5049 }
5050 }
5051 }
5052 for (int i = 0; i < files.size() && i < 64; i++) {
5053 QAction *newAction = m->addAction(files[i],
5054 this, SLOT(openFromAction()));
5055 newAction->setData(dir.absoluteFilePath(files[i]));
5056 }
5057 }
5058
5059 //#include "flowlayout.h"
5060
5061 void CsoundQt::createToolBars()
5062 {
5063 // fileToolBar = addToolBar(tr("File"));
5064 // fileToolBar->setObjectName("fileToolBar");
5065 // fileToolBar->addAction(newAct);
5066 // fileToolBar->addAction(openAct);
5067 // fileToolBar->addAction(saveAct);
5068
5069 // editToolBar = addToolBar(tr("Edit"));
5070 // editToolBar->setObjectName("editToolBar");
5071 // editToolBar->addAction(undoAct);
5072 // editToolBar->addAction(redoAct);
5073 // editToolBar->addAction(cutAct);
5074 // editToolBar->addAction(copyAct);
5075 // editToolBar->addAction(pasteAct);
5076
5077 // QDockWidget *toolWidget = new QDockWidget(tr("Tools"), this);
5078 // QWidget *w = new QWidget(toolWidget);
5079 // FlowLayout * flowlayout = new FlowLayout(w);
5080 // toolWidget->setWidget(w);
5081 // w->setLayout(flowlayout);
5082 // QVector<QAction *> actions;
5083 // actions << runAct << pauseAct << stopAct << recAct << runTermAct << renderAct;
5084 // foreach (QAction * act, actions) {
5085 // QToolButton *b = new QToolButton(w);
5086 // b->setDefaultAction(act);
5087 // flowlayout->addWidget(b);
5088 // }
5089 // addDockWidget(Qt::AllDockWidgetAreas, toolWidget);
5090 // toolWidget->show();
5091 const int iconSize = this->m_options->toolbarIconSize;
5092 controlToolBar = addToolBar(tr("Control"));
5093 controlToolBar->setObjectName("controlToolBar");
5094 controlToolBar->addAction(runAct);
5095 controlToolBar->addAction(pauseAct);
5096 controlToolBar->addAction(stopAct);
5097 controlToolBar->addAction(recAct);
5098 controlToolBar->addSeparator();
5099 controlToolBar->addAction(runTermAct);
5100 controlToolBar->addAction(renderAct);
5101 // controlToolBar->addAction(externalEditorAct);
5102 // controlToolBar->addAction(externalPlayerAct);
5103 controlToolBar->addAction(configureAct);
5104 controlToolBar->setIconSize(QSize(iconSize, iconSize));
5105 controlToolBar->setFloatable(false);
5106
5107 configureToolBar = addToolBar(tr("Panels"));
5108 configureToolBar->setObjectName("panelToolBar");
5109 #if defined(QCS_QTHTML)
5110 // configureToolBar->addAction(showHtml5Act);
5111 #endif
5112 configureToolBar->addAction(showWidgetsAct);
5113 configureToolBar->addAction(showHelpAct);
5114 configureToolBar->addAction(showConsoleAct);
5115 configureToolBar->addAction(showInspectorAct);
5116 // configureToolBar->addAction(showLiveEventsAct);
5117 configureToolBar->addAction(showVirtualKeyboardAct);
5118 //configureToolBar->addAction(showTableEditorAct);
5119
5120 #ifdef QCS_PYTHONQT
5121 configureToolBar->addAction(showPythonConsoleAct);
5122 #endif
5123 // configureToolBar->addAction(showScratchPadAct);
5124 configureToolBar->addAction(showUtilitiesAct);
5125 configureToolBar->setFloatable(false);
5126
5127 Qt::ToolButtonStyle toolButtonStyle = (m_options->iconText?
5128 Qt::ToolButtonTextUnderIcon: Qt::ToolButtonIconOnly);
5129 // fileToolBar->setToolButtonStyle(toolButtonStyle);
5130 // editToolBar->setToolButtonStyle(toolButtonStyle);
5131 controlToolBar->setToolButtonStyle(toolButtonStyle);
5132 configureToolBar->setToolButtonStyle(toolButtonStyle);
5133 configureToolBar->setIconSize(QSize(iconSize, iconSize));
5134 // test Mac
5135 #ifdef Q_OS_MAC
5136
5137 if (m_options->theme=="breeze-dark") {
5138 QColor textColor = QGuiApplication::palette().color(QPalette::Text);
5139 qDebug() << "Textcolor: " << textColor;
5140 QString styleString = QString("color: %1").arg(textColor.name());
5141 controlToolBar->setStyleSheet(styleString);
5142 configureToolBar->setStyleSheet(styleString);
5143 }
5144 #endif
5145 }
5146
5147 void CsoundQt::setToolbarIconSize(int size) {
5148 controlToolBar->setIconSize(QSize(size, size));
5149 controlToolBar->setStyleSheet("QToolBar { padding: 0 3px }");
5150 configureToolBar->setIconSize(QSize(size, size));
5151 }
5152
5153 void CsoundQt::createStatusBar()
5154 {
5155 auto statusbar = statusBar();
5156 statusbar->showMessage(tr("Ready"));
5157
5158 lineAndColumnLabel = new QLabel();
5159 setLineAndColumn(0,0);
5160 statusbar->addPermanentWidget(lineAndColumnLabel);
5161 }
5162
5163 void CsoundQt::readSettings()
5164 {
5165 QSettings settings("csound", "qutecsound");
5166 int settingsVersion = settings.value("settingsVersion", 4).toInt();
5167 // Version 1 to remove "-d" from additional command line flags
5168 // Version 2 to save default keyboard shortcuts (weren't saved previously)
5169 // Version 2 to add "*" to jack client name
5170 // version 4 to signal that many shotcuts have been changed
5171 if (settingsVersion>0 && settingsVersion<4) {
5172 QMessageBox::warning(this, tr("Settings changed"),
5173 tr("In this version the shortcuts for showing panels changed. "
5174 "See ... for more information. Please Use "
5175 "'Edit/Keyboard shortcuts/Restore Defaults' to activate it."));
5176 }
5177
5178 settings.beginGroup("GUI");
5179 m_options->theme = settings.value("theme", "breeze").toString();
5180 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
5181 QSize size = settings.value("size", QSize(600, 500)).toSize();
5182 resize(size); // does not work here for MacOS Mojave
5183 move(pos);
5184 if (settings.contains("dockstate")) {
5185 restoreState(settings.value("dockstate").toByteArray());
5186 }
5187 lastUsedDir = settings.value("lastuseddir", "").toString();
5188 lastFileDir = settings.value("lastfiledir", "").toString();
5189 // showLiveEventsAct->setChecked(settings.value("liveEventsActive", true).toBool());
5190 m_options->language = m_configlists.languageCodes.indexOf(settings.value("language", QLocale::system().name()).toString());
5191 if (m_options->language < 0)
5192 m_options->language = 0;
5193 recentFiles.clear();
5194 recentFiles = settings.value("recentFiles").toStringList();
5195 setDefaultKeyboardShortcuts();
5196 QHash<QString, QVariant> actionList = settings.value("shortcuts").toHash();
5197
5198 if (actionList.count() != 0) {
5199 QHashIterator<QString, QVariant> i(actionList);
5200 while (i.hasNext()) {
5201 i.next();
5202 QString shortcut = i.value().toString();
5203 foreach (QAction *act, m_keyActions) {
5204 if (act->text().remove("&") == i.key()) {
5205 act->setShortcut(shortcut);
5206 break;
5207 }
5208 }
5209 }
5210 }
5211 // else { // No shortcuts are stored
5212 // setDefaultKeyboardShortcuts();
5213 // }
5214 settings.endGroup();
5215 settings.beginGroup("Options");
5216 settings.beginGroup("Editor");
5217 #ifdef Q_OS_MACOS
5218 m_options->font = settings.value("font", "Menlo").toString();
5219 m_options->fontPointSize = settings.value("fontsize", 12).toDouble();
5220 m_options->consoleFont = settings.value("consolefont", "Menlo").toString();
5221 m_options->consoleFontPointSize = settings.value("consolefontsize", 10).toDouble();
5222 #endif
5223 #ifdef Q_OS_WIN
5224 m_options->font = settings.value("font", "Consolas").toString();
5225 m_options->fontPointSize = settings.value("fontsize", 11).toDouble();
5226 m_options->consoleFont = settings.value("consolefont", "Consolas").toString();
5227 m_options->consoleFontPointSize = settings.value("consolefontsize", 10).toDouble();
5228 #endif
5229 #ifdef Q_OS_LINUX
5230 m_options->font = settings.value("font", "Liberation Mono").toString();
5231 m_options->fontPointSize = settings.value("fontsize", 11).toDouble();
5232 m_options->consoleFont = settings.value("consolefont", "Liberation Mono").toString();
5233 m_options->consoleFontPointSize = settings.value("consolefontsize", 10).toDouble();
5234 #endif
5235 m_options->showLineNumberArea = settings.value("showLineNumberArea", true).toBool();
5236
5237 #ifdef Q_OS_WIN
5238 m_options->lineEnding = settings.value("lineEnding", 1).toInt();
5239 #else
5240 m_options->lineEnding = settings.value("lineEnding", 0).toInt();
5241 #endif
5242
5243 //m_options->consoleFont = settings.value("consolefont", "Courier").toString(); // platform specific
5244 //m_options->consoleFontPointSize = settings.value("consolefontsize", 10).toDouble();
5245
5246 m_options->consoleFontColor = settings.value("consoleFontColor",
5247 QVariant(QColor(Qt::black))).value<QColor>();
5248 m_options->consoleBgColor = settings.value("consoleBgColor",
5249 QVariant(QColor(Qt::white))).value<QColor>();
5250 // m_options->editorBgColor = settings.value("editorBgColor",
5251 // QVariant(QColor(Qt::white))).value<QColor>();
5252
5253 m_options->tabWidth = settings.value("tabWidth", 24).toInt();
5254 m_options->tabIndents = settings.value("tabIndents", false).toBool();
5255 // m_options->colorVariables = settings.value("colorvariables", true).toBool();
5256 m_options->highlightingTheme = settings.value("highlightingTheme", "light").toString();
5257 m_options->colorVariables = m_options->highlightingTheme != "none";
5258 m_options->autoPlay = settings.value("autoplay", false).toBool();
5259 m_options->autoJoin = settings.value("autoJoin", true).toBool();
5260 m_options->menuDepth = settings.value("menuDepth", 3).toInt();
5261 m_options->saveChanges = settings.value("savechanges", true).toBool();
5262 m_options->askIfTemporary = settings.value("askIfTemporary", false).toBool();
5263 m_options->rememberFile = settings.value("rememberfile", true).toBool();
5264 m_options->saveWidgets = settings.value("savewidgets", true).toBool();
5265 m_options->midiCcToCurrentPageOnly = settings.value("midiCcToActivePageOnly", false).toBool();
5266 m_options->widgetsIndependent = settings.value("widgetsIndependent", false).toBool();
5267 m_options->iconText = settings.value("iconText", false).toBool();
5268 m_options->showToolbar = settings.value("showToolbar", true).toBool();
5269 m_options->lockToolbar = settings.value("lockToolbar", true).toBool();
5270 m_options->toolbarIconSize = settings.value("toolbarIconSize", 20).toInt();
5271 m_options->wrapLines = settings.value("wrapLines", true).toBool();
5272 m_options->autoComplete = settings.value("autoComplete", true).toBool();
5273 m_options->autoCompleteDelay = settings.value("autoCompleteDelay", 150).toInt();
5274 m_options->autoParameterMode = settings.value("autoParameterMode", true).toBool();
5275 m_options->enableWidgets = settings.value("enableWidgets", true).toBool();
5276 m_options->showWidgetsOnRun = settings.value("showWidgetsOnRun", true).toBool();
5277 m_options->showTooltips = settings.value("showTooltips", true).toBool();
5278 m_options->enableFLTK = settings.value("enableFLTK", true).toBool();
5279 m_options->terminalFLTK = settings.value("terminalFLTK", true).toBool();
5280 m_options->oldFormat = settings.value("oldFormat", false).toBool();
5281 m_options->openProperties = settings.value("openProperties", true).toBool();
5282 m_options->fontOffset = settings.value("fontOffset", 0.0).toDouble();
5283 m_options->fontScaling = settings.value("fontScaling", 1.0).toDouble();
5284 m_options->graphUpdateRate = settings.value("graphUpdateRate", 30).toInt();
5285 lastFiles = settings.value("lastfiles", QStringList()).toStringList();
5286 lastTabIndex = settings.value("lasttabindex", "").toInt();
5287 m_options->debugPort = settings.value("debugPort",34711).toInt();
5288 m_options->tabShortcutActive = settings.value("tabShortcutActive", true).toBool();
5289 m_options->highlightScore = settings.value("highlightScore", false).toBool();
5290
5291
5292 settings.endGroup();
5293 settings.beginGroup("Run");
5294 m_options->useAPI = settings.value("useAPI", true).toBool();
5295 m_options->keyRepeat = settings.value("keyRepeat", false).toBool();
5296 m_options->debugLiveEvents = settings.value("debugLiveEvents", false).toBool();
5297 m_options->consoleBufferSize = settings.value("consoleBufferSize", 1024).toInt();
5298 m_options->checkSyntaxBeforeRun = settings.value("checkSyntaxBeforeRun", false).toBool();
5299 m_options->midiInterface = settings.value("midiInterface", 9999).toInt();
5300 m_options->midiInterfaceName = settings.value("midiInterfaceName", "None").toString();
5301 m_options->midiOutInterface = settings.value("midiOutInterface", 9999).toInt();
5302 m_options->midiOutInterfaceName = settings.value("midiOutInterfaceName", "None").toString();
5303 m_options->noBuffer = settings.value("noBuffer", false).toBool();
5304 m_options->noPython = settings.value("noPython", false).toBool();
5305 m_options->noMessages = settings.value("noMessages", false).toBool();
5306 m_options->noEvents = settings.value("noEvents", false).toBool();
5307
5308
5309 //experimental: enable setting internal RtMidi API in settings file. See RtMidi.h
5310 #ifdef QCS_RTMIDI
5311 QString rtMidiApiString = settings.value("rtMidiApi","UNSPECIFIED").toString();
5312 if (rtMidiApiString.toUpper()=="LINUX_ALSA" )
5313 m_options->rtMidiApi = RtMidi::LINUX_ALSA;
5314 else if (rtMidiApiString.toUpper()=="UNIX_JACK" )
5315 m_options->rtMidiApi = RtMidi::UNIX_JACK;
5316 else if (rtMidiApiString.toUpper()=="MACOSX_CORE" )
5317 m_options->rtMidiApi = RtMidi::MACOSX_CORE;
5318 else if (rtMidiApiString.toUpper()=="WINDOWS_MM" )
5319 m_options->rtMidiApi = RtMidi::WINDOWS_MM;
5320 else
5321 m_options->rtMidiApi = RtMidi::UNSPECIFIED;
5322 #endif
5323
5324 m_options->bufferSize = settings.value("bufferSize", 1024).toInt();
5325 m_options->bufferSizeActive = settings.value("bufferSizeActive", false).toBool();
5326 m_options->HwBufferSize = settings.value("HwBufferSize", 1024).toInt();
5327 m_options->HwBufferSizeActive = settings.value("HwBufferSizeActive", false).toBool();
5328 m_options->dither = settings.value("dither", false).toBool();
5329 m_options->newParser = settings.value("newParser", false).toBool();
5330 m_options->multicore = settings.value("multicore", false).toBool();
5331 m_options->numThreads = settings.value("numThreads", 1).toInt();
5332 m_options->additionalFlags = settings.value("additionalFlags", "").toString();
5333 m_options->useSystemSamplerate = settings.value("useSystemSamplerate", false).toBool();
5334 m_options->samplerate = settings.value("overrideSamplerate", 0).toInt();
5335 m_options->overrideNumChannels = settings.value("overrideNumChannels", false).toBool();
5336 m_options->numChannels = settings.value("numChannels", 2).toInt();
5337 m_options->numInputChannels = settings.value("numInputChannels", 2).toInt();
5338
5339 m_options->useLimiter = settings.value("useLimiter", csoundGetVersion()>=6160).toBool();
5340 m_options->limitValue = settings.value("limitValue", 1.0).toDouble();
5341
5342 m_options->realtimeFlag = settings.value("realtimeFlag", false).toBool();
5343 m_options->sampleAccurateFlag = settings.value("sampleAccurateFlag", false).toBool();
5344 if (settingsVersion < 1)
5345 m_options->additionalFlags.remove("-d"); // remove old -d preference, as it is fixed now.
5346 m_options->additionalFlagsActive = settings.value("additionalFlagsActive", false).toBool();
5347 m_options->fileUseOptions = settings.value("fileUseOptions", true).toBool();
5348 m_options->fileOverrideOptions = settings.value("fileOverrideOptions", false).toBool();
5349 m_options->fileAskFilename = settings.value("fileAskFilename", false).toBool();
5350 m_options->filePlayFinished = settings.value("filePlayFinished", false).toBool();
5351 m_options->fileFileType = settings.value("fileFileType", 0).toInt();
5352 m_options->fileSampleFormat = settings.value("fileSampleFormat", 1).toInt();
5353 m_options->fileInputFilenameActive = settings.value("fileInputFilenameActive", false).toBool();
5354 m_options->fileInputFilename = settings.value("fileInputFilename", "").toString();
5355 m_options->fileOutputFilenameActive = settings.value("fileOutputFilenameActive", false).toBool();
5356 m_options->fileOutputFilename = settings.value("fileOutputFilename", "").toString();
5357 m_options->rtUseOptions = settings.value("rtUseOptions", true).toBool();
5358 m_options->rtOverrideOptions = settings.value("rtOverrideOptions", false).toBool();
5359 m_options->rtAudioModule = settings.value("rtAudioModule", "pa_cb").toString();
5360 if (m_options->rtAudioModule.isEmpty()) { m_options->rtAudioModule = "pa_cb"; }
5361 m_options->rtInputDevice = settings.value("rtInputDevice", "adc").toString();
5362 m_options->rtOutputDevice = settings.value("rtOutputDevice", "dac").toString();
5363 m_options->rtJackName = settings.value("rtJackName", "").toString();
5364 if (settingsVersion < 2) {
5365 if (!m_options->rtJackName.endsWith("*"))
5366 m_options->rtJackName.append("*");
5367 }
5368 m_options->rtMidiModule = settings.value("rtMidiModule", "portmidi").toString();
5369 if (m_options->rtMidiModule.isEmpty()) { m_options->rtMidiModule = "portmidi"; }
5370 m_options->rtMidiInputDevice = settings.value("rtMidiInputDevice", "0").toString();
5371 m_options->rtMidiOutputDevice = settings.value("rtMidiOutputDevice", "").toString();
5372 m_options->useCsoundMidi = settings.value("useCsoundMidi", false).toBool();
5373 m_options->simultaneousRun = settings.value("simultaneousRun", "").toBool();
5374 m_options->sampleFormat = settings.value("sampleFormat", 0).toInt();
5375 settings.endGroup();
5376 settings.beginGroup("Environment");
5377 #ifdef Q_OS_MAC
5378 m_options->csdocdir = settings.value("csdocdir", DEFAULT_HTML_DIR).toString();
5379 #else
5380 m_options->csdocdir = settings.value("csdocdir", "").toString();
5381 #endif
5382 m_options->opcodedir = settings.value("opcodedir","").toString();
5383 m_options->opcodedirActive = settings.value("opcodedirActive",false).toBool();
5384 m_options->opcodedir64 = settings.value("opcodedir64","").toString();
5385 m_options->opcodedir64Active = settings.value("opcodedir64Active",false).toBool();
5386 m_options->opcode6dir64 = settings.value("opcode6dir64","").toString();
5387 m_options->opcode6dir64Active = settings.value("opcode6dir64Active",false).toBool();
5388 m_options->sadir = settings.value("sadir","").toString();
5389 m_options->sadirActive = settings.value("sadirActive","").toBool();
5390 m_options->ssdir = settings.value("ssdir","").toString();
5391 m_options->ssdirActive = settings.value("ssdirActive","").toBool();
5392 m_options->sfdir = settings.value("sfdir","").toString();
5393 m_options->sfdirActive = settings.value("sfdirActive","").toBool();
5394 m_options->incdir = settings.value("incdir","").toString();
5395 m_options->incdirActive = settings.value("incdirActive","").toBool();
5396 m_options->rawWave = settings.value("rawWave","").toString();
5397 m_options->rawWaveActive = settings.value("rawWaveActive","").toBool();
5398 m_options->defaultCsd = settings.value("defaultCsd","").toString();
5399 m_options->defaultCsdActive = settings.value("defaultCsdActive","").toBool();
5400 m_options->favoriteDir = settings.value("favoriteDir","").toString();
5401 m_options->examplePath = settings.value("examplePath", "").toString();
5402 m_options->pythonDir = settings.value("pythonDir","").toString();
5403 m_options->pythonExecutable = settings.value("pythonExecutable","python").toString();
5404 m_options->csoundExecutable = settings.value("csoundExecutable","csound").toString();
5405 m_options->logFile = settings.value("logFile",DEFAULT_LOG_FILE).toString();
5406 m_options->sdkDir = settings.value("sdkDir","").toString();
5407 m_options->templateDir = settings.value("templateDir","").toString();
5408 m_options->opcodexmldir = settings.value("opcodexmldir", "").toString();
5409 m_options->opcodexmldirActive = settings.value("opcodexmldirActive","").toBool();
5410 settings.endGroup();
5411 settings.beginGroup("External");
5412 m_options->terminal = settings.value("terminal", DEFAULT_TERM_EXECUTABLE).toString();
5413 m_options->browser = settings.value("browser", DEFAULT_BROWSER_EXECUTABLE).toString();
5414 m_options->dot = settings.value("dot", DEFAULT_DOT_EXECUTABLE).toString();
5415 m_options->waveeditor = settings.value("waveeditor",
5416 DEFAULT_WAVEEDITOR_EXECUTABLE
5417 ).toString();
5418 m_options->waveplayer = settings.value("waveplayer",
5419 DEFAULT_WAVEPLAYER_EXECUTABLE
5420 ).toString();
5421 m_options->pdfviewer = settings.value("pdfviewer",
5422 DEFAULT_PDFVIEWER_EXECUTABLE
5423 ).toString();
5424 #ifdef Q_OS_MACOS
5425 if (QOperatingSystemVersion::current() > QOperatingSystemVersion::MacOSMojave ) { // fix path change to /System/Applications on MacOS Catalina
5426
5427 QList <QString *> apps;
5428 apps << &m_options->terminal << &m_options->browser << &m_options->waveplayer << &m_options->pdfviewer;
5429 // not sure about &m_options->waveeditor (Audacity) - where is this installed on Catalina
5430 // no correctrion for waveeditor now
5431
5432 foreach (QString * app, apps) {
5433 if (app->startsWith("/Applications")) {
5434 app->prepend("/System");
5435 }
5436 }
5437
5438 if (m_options->browser.contains("Safary")) { // fix for typo in 0.9.8.1
5439 m_options->browser.replace("Safary", "Safari");
5440 }
5441 }
5442 #endif
5443 settings.endGroup();
5444 settings.beginGroup("Template");
5445 m_options->csdTemplate = settings.value("csdTemplate", QCS_DEFAULT_TEMPLATE).toString();
5446 settings.endGroup();
5447 settings.endGroup();
5448 if (settingsVersion < 3 && settingsVersion > 0) {
5449 showNewFormatWarning();
5450 m_options->csdTemplate = QCS_DEFAULT_TEMPLATE;
5451 }
5452 }
5453
5454 void CsoundQt::storeSettings()
5455 {
5456 qDebug();
5457 QStringList files;
5458 if (m_options->rememberFile) {
5459 for (int i = 0; i < documentPages.size(); i++ ) {
5460 files.append(documentPages[i]->getFileName());
5461 }
5462 }
5463 // sometimes settings are stored in startup when there is no pages open
5464 if (documentPages.size() > 0) {
5465 writeSettings(files, documentTabs->currentIndex());
5466 } else {
5467 qDebug() << "No files open. Will not store settings (for any case - testing)";
5468 }
5469 }
5470
5471 void CsoundQt::writeSettings(QStringList openFiles, int lastIndex)
5472 {
5473 QSettings settings("csound", "qutecsound");
5474 QDEBUG << "writing settings to csound/qutecsound";
5475
5476 settings.setValue("settingsVersion", 4);
5477
5478 QHash<QString, QVariant> shortcuts;
5479 foreach (QAction *act, m_keyActions) {
5480 shortcuts[act->text().remove("&")] = QVariant(act->shortcut().toString());
5481 }
5482
5483 if(m_resetPrefs) {
5484 settings.beginGroup("GUI");
5485 settings.setValue("shortcuts", QVariant(shortcuts));
5486 settings.endGroup();
5487 settings.beginGroup("Options");
5488 for(auto groupName: {"Editor", "Run", "Environment", "External"}) {
5489 settings.beginGroup(groupName);
5490 settings.remove(""); // removes all settings in the section
5491 settings.endGroup();
5492 }
5493 settings.beginGroup("Template");
5494 settings.setValue("csdTemplate", m_options->csdTemplate);
5495 settings.endGroup();
5496 settings.endGroup();; // options
5497 m_resetPrefs = false;
5498
5499 } else {
5500 settings.beginGroup("GUI");
5501 settings.setValue("shortcuts", QVariant(shortcuts));
5502 settings.setValue("pos", pos());
5503 settings.setValue("size", size());
5504 settings.setValue("dockstate", saveState());
5505 settings.setValue("lastuseddir", lastUsedDir);
5506 settings.setValue("lastfiledir", lastFileDir);
5507 settings.setValue("language", m_configlists.languageCodes[m_options->language]);
5508 // settings.setValue("liveEventsActive", showLiveEventsAct->isChecked());
5509 settings.setValue("recentFiles", recentFiles);
5510 settings.setValue("theme", m_options->theme);
5511 settings.setValue("windowState", saveState());
5512 settings.setValue("windowGeometry", saveGeometry());
5513 settings.endGroup();
5514
5515 settings.beginGroup("Options");
5516 settings.beginGroup("Editor");
5517 settings.setValue("font", m_options->font );
5518 settings.setValue("fontsize", m_options->fontPointSize);
5519 settings.setValue("showLineNumberArea", m_options->showLineNumberArea);
5520 settings.setValue("lineEnding", m_options->lineEnding);
5521 settings.setValue("consolefont", m_options->consoleFont );
5522 settings.setValue("consolefontsize", m_options->consoleFontPointSize);
5523 settings.setValue("consoleFontColor", QVariant(m_options->consoleFontColor));
5524 settings.setValue("consoleBgColor", QVariant(m_options->consoleBgColor));
5525 // settings.setValue("editorBgColor", QVariant(m_options->editorBgColor));
5526 settings.setValue("tabWidth", m_options->tabWidth );
5527 settings.setValue("tabIndents", m_options->tabIndents);
5528 settings.setValue("colorvariables", m_options->colorVariables);
5529 settings.setValue("highlightingTheme", m_options->highlightingTheme);
5530 settings.setValue("autoplay", m_options->autoPlay);
5531 settings.setValue("autoJoin", m_options->autoJoin);
5532 settings.setValue("menuDepth", m_options->menuDepth);
5533 settings.setValue("savechanges", m_options->saveChanges);
5534 settings.setValue("askIfTemporary", m_options->askIfTemporary);
5535 settings.setValue("rememberfile", m_options->rememberFile);
5536 settings.setValue("savewidgets", m_options->saveWidgets);
5537 settings.setValue("midiCcToActivePageOnly", m_options->midiCcToCurrentPageOnly);
5538 settings.setValue("widgetsIndependent", m_options->widgetsIndependent);
5539 settings.setValue("iconText", m_options->iconText);
5540 settings.setValue("showToolbar", m_options->showToolbar);
5541 settings.setValue("lockToolbar", m_options->lockToolbar);
5542 settings.setValue("toolbarIconSize", m_options->toolbarIconSize);
5543 settings.setValue("wrapLines", m_options->wrapLines);
5544 settings.setValue("autoComplete", m_options->autoComplete);
5545 settings.setValue("autoCompleteDelay", m_options->autoCompleteDelay);
5546 settings.setValue("autoParameterMode", m_options->autoParameterMode);
5547 settings.setValue("enableWidgets", m_options->enableWidgets);
5548 settings.setValue("showWidgetsOnRun", m_options->showWidgetsOnRun);
5549 settings.setValue("graphUpdateRate", m_options->graphUpdateRate);
5550 settings.setValue("showTooltips", m_options->showTooltips);
5551 settings.setValue("enableFLTK", m_options->enableFLTK);
5552 settings.setValue("terminalFLTK", m_options->terminalFLTK);
5553 settings.setValue("oldFormat", m_options->oldFormat);
5554 settings.setValue("openProperties", m_options->openProperties);
5555 settings.setValue("fontOffset", m_options->fontOffset);
5556 settings.setValue("fontScaling", m_options->fontScaling);
5557 settings.setValue("debugPort", m_options->debugPort);
5558 settings.setValue("tabShortcutActive", m_options->tabShortcutActive);
5559 settings.setValue("highlightScore", m_options->highlightScore);
5560
5561 settings.setValue("lastfiles", openFiles);
5562 settings.setValue("lasttabindex", lastIndex);
5563 // if(openFiles.size() > 0 && lastIndex != 0) {
5564 if(openFiles.size() > 0) {
5565 settings.setValue("lastfiles", openFiles);
5566 if(lastIndex > 0) {
5567 settings.setValue("lasttabindex", lastIndex);
5568 }
5569 }
5570 settings.endGroup(); // Options/Editor
5571
5572 settings.beginGroup("Run");
5573 settings.setValue("useAPI", m_options->useAPI);
5574 settings.setValue("keyRepeat", m_options->keyRepeat);
5575 settings.setValue("debugLiveEvents", m_options->debugLiveEvents);
5576 settings.setValue("consoleBufferSize", m_options->consoleBufferSize);
5577 settings.setValue("midiInterface", m_options->midiInterface);
5578 settings.setValue("midiInterfaceName", m_options->midiInterfaceName);
5579 settings.setValue("midiOutInterface", m_options->midiOutInterface);
5580 settings.setValue("midiOutInterfaceName", m_options->midiOutInterfaceName);
5581 settings.setValue("noBuffer", m_options->noBuffer);
5582 settings.setValue("noPython", m_options->noPython);
5583 settings.setValue("noMessages", m_options->noMessages);
5584 settings.setValue("noEvents", m_options->noEvents);
5585 settings.setValue("bufferSize", m_options->bufferSize);
5586 settings.setValue("bufferSizeActive", m_options->bufferSizeActive);
5587 settings.setValue("HwBufferSize",m_options->HwBufferSize);
5588 settings.setValue("HwBufferSizeActive", m_options->HwBufferSizeActive);
5589 settings.setValue("dither", m_options->dither);
5590 settings.setValue("realtimeFlag", m_options->realtimeFlag);
5591 settings.setValue("sampleAccurateFlag", m_options->sampleAccurateFlag);
5592 settings.setValue("newParser", m_options->newParser);
5593 settings.setValue("multicore", m_options->multicore);
5594 settings.setValue("numThreads", m_options->numThreads);
5595 settings.setValue("useSystemSamplerate", m_options->useSystemSamplerate);
5596 settings.setValue("overrideSamplerate", m_options->samplerate);
5597 settings.setValue("overrideNumChannels", m_options->overrideNumChannels);
5598 settings.setValue("numChannels", m_options->numChannels);
5599 settings.setValue("numInputChannels", m_options->numInputChannels);
5600 settings.setValue("useLimiter", m_options->useLimiter);
5601 settings.setValue("limitValue", m_options->limitValue);
5602 settings.setValue("additionalFlags", m_options->additionalFlags);
5603 settings.setValue("additionalFlagsActive", m_options->additionalFlagsActive);
5604 settings.setValue("fileUseOptions", m_options->fileUseOptions);
5605 settings.setValue("fileOverrideOptions", m_options->fileOverrideOptions);
5606 settings.setValue("fileAskFilename", m_options->fileAskFilename);
5607 settings.setValue("filePlayFinished", m_options->filePlayFinished);
5608 settings.setValue("fileFileType", m_options->fileFileType);
5609 settings.setValue("fileSampleFormat", m_options->fileSampleFormat);
5610 settings.setValue("fileInputFilenameActive", m_options->fileInputFilenameActive);
5611 settings.setValue("fileInputFilename", m_options->fileInputFilename);
5612 settings.setValue("fileOutputFilenameActive", m_options->fileOutputFilenameActive);
5613 settings.setValue("fileOutputFilename", m_options->fileOutputFilename);
5614 settings.setValue("rtUseOptions", m_options->rtUseOptions);
5615 settings.setValue("rtOverrideOptions", m_options->rtOverrideOptions);
5616 settings.setValue("rtAudioModule", m_options->rtAudioModule);
5617 settings.setValue("rtInputDevice", m_options->rtInputDevice);
5618 settings.setValue("rtOutputDevice", m_options->rtOutputDevice);
5619 settings.setValue("rtJackName", m_options->rtJackName);
5620 settings.setValue("rtMidiModule", m_options->rtMidiModule);
5621 settings.setValue("rtMidiInputDevice", m_options->rtMidiInputDevice);
5622 settings.setValue("rtMidiOutputDevice", m_options->rtMidiOutputDevice);
5623 settings.setValue("useCsoundMidi", m_options->useCsoundMidi);
5624 settings.setValue("simultaneousRun", m_options->simultaneousRun);
5625 settings.setValue("sampleFormat", m_options->sampleFormat);
5626 settings.setValue("checkSyntaxBeforeRun", m_options->checkSyntaxBeforeRun);
5627 settings.endGroup(); // Options/Run
5628
5629 settings.beginGroup("Environment");
5630 settings.setValue("csdocdir", m_options->csdocdir);
5631 settings.setValue("opcodedir",m_options->opcodedir);
5632 settings.setValue("opcodedirActive",m_options->opcodedirActive);
5633 settings.setValue("opcodedir64",m_options->opcodedir64);
5634 settings.setValue("opcodedir64Active",m_options->opcodedir64Active);
5635 settings.setValue("opcode6dir64",m_options->opcode6dir64);
5636 settings.setValue("opcode6dir64Active",m_options->opcode6dir64Active);
5637 settings.setValue("sadir",m_options->sadir);
5638 settings.setValue("sadirActive",m_options->sadirActive);
5639 settings.setValue("ssdir",m_options->ssdir);
5640 settings.setValue("ssdirActive",m_options->ssdirActive);
5641 settings.setValue("sfdir",m_options->sfdir);
5642 settings.setValue("sfdirActive",m_options->sfdirActive);
5643 settings.setValue("incdir",m_options->incdir);
5644 settings.setValue("incdirActive",m_options->incdirActive);
5645 settings.setValue("rawWave",m_options->rawWave);
5646 settings.setValue("rawWaveActive",m_options->rawWaveActive);
5647 settings.setValue("defaultCsd",m_options->defaultCsd);
5648 settings.setValue("defaultCsdActive",m_options->defaultCsdActive);
5649 settings.setValue("favoriteDir",m_options->favoriteDir);
5650 settings.setValue("examplePath", m_options->examplePath);
5651 settings.setValue("pythonDir",m_options->pythonDir);
5652 settings.setValue("pythonExecutable",m_options->pythonExecutable);
5653 settings.setValue("csoundExecutable", m_options->csoundExecutable);
5654 settings.setValue("logFile",m_options->logFile);
5655 settings.setValue("sdkDir",m_options->sdkDir);
5656 settings.setValue("templateDir",m_options->templateDir);
5657 settings.setValue("opcodexmldir", m_options->opcodexmldir); // TEST can be that this is the reason for crash MacOS - dir set wrong from corrupted plist file
5658 settings.setValue("opcodexmldirActive",m_options->opcodexmldirActive);
5659 settings.endGroup(); // options/environment
5660
5661 settings.beginGroup("External");
5662 settings.setValue("terminal", m_options->terminal);
5663 settings.setValue("browser", m_options->browser);
5664 settings.setValue("dot", m_options->dot);
5665 settings.setValue("waveeditor", m_options->waveeditor);
5666 settings.setValue("waveplayer", m_options->waveplayer);
5667 settings.setValue("pdfviewer", m_options->pdfviewer);
5668 settings.endGroup(); // options/external
5669
5670 settings.beginGroup("Template");
5671 settings.setValue("csdTemplate", m_options->csdTemplate);
5672 settings.endGroup(); // options/template
5673
5674 settings.endGroup(); // options
5675
5676 }
5677 settings.sync();
5678 return;
5679
5680 }
5681
5682 void CsoundQt::clearSettings()
5683 {
5684 QSettings settings("csound", "qutecsound");
5685 settings.remove("");
5686 settings.beginGroup("GUI");
5687 settings.beginGroup("Shortcuts");
5688 settings.remove("");
5689 settings.endGroup();
5690 settings.endGroup();
5691 settings.beginGroup("Options");
5692 settings.remove("");
5693 settings.beginGroup("Editor");
5694 settings.remove("");
5695 settings.endGroup();
5696 settings.beginGroup("Run");
5697 settings.remove("");
5698 settings.endGroup();
5699 settings.beginGroup("Environment");
5700 settings.remove("");
5701 settings.endGroup();
5702 settings.beginGroup("External");
5703 settings.remove("");
5704 settings.endGroup();
5705 settings.endGroup();
5706
5707 settings.sync();
5708 }
5709
5710 int CsoundQt::startProcess(QString executable, const QStringList &args) {
5711 QString path = documentPages[curPage]->getFilePath();
5712 if (path.startsWith(":/examples/", Qt::CaseInsensitive)) {
5713 // example or other embedded file
5714 path = QDir::tempPath(); // copy of example is saved there
5715 }
5716 auto p = new QProcess();
5717 p->setProgram(executable);
5718 p->setArguments(args);
5719 p->setWorkingDirectory(path);
5720 p->start();
5721 qDebug() << "Launched external program with id:" << p->processId() << ", executable: " << executable << ", args: " << args;
5722 return !p->waitForStarted() ? 1 : 0;
5723 }
5724
5725 int CsoundQt::execute(QString executable, QString options)
5726 {
5727 int ret = 0;
5728
5729 #ifdef Q_OS_MAC
5730 QString commandLine = "open -a \"" + executable + "\" " + options;
5731 #endif
5732 #ifdef Q_OS_LINUX
5733 // QString commandLine = "\"" + executable + "\" " + options;
5734 QString commandLine = executable + " " + options;
5735 #endif
5736 #ifdef Q_OS_HAIKU
5737 QString commandLine = "\"" + executable + "\" " + options;
5738 #endif
5739 #ifdef Q_OS_SOLARIS
5740 QString commandLine = "\"" + executable + "\" " + options;
5741 #endif
5742 #ifdef Q_OS_WIN32
5743 QString commandLine = "\"" + executable + "\" " + (executable.startsWith("cmd")? " /k " : " ") + options;
5744 auto command_line = commandLine.toUtf8();
5745 qDebug() << "command_line: " << command_line;
5746 std::thread system_thread([command_line]{std::system(command_line);});
5747 system_thread.detach();
5748 #else
5749 QString path = documentPages[curPage]->getFilePath();
5750 if (path.startsWith(":/examples/", Qt::CaseInsensitive)) {
5751 // example or other embedded file
5752 path = QDir::tempPath(); // copy of example is saved there
5753 }
5754 qDebug() << "CsoundQt::execute " << commandLine;
5755 auto p = new QProcess();
5756 p->setProgram(executable);
5757 auto args = options.split(" ");
5758 p->setArguments(args);
5759 p->setWorkingDirectory(path);
5760 p->start();
5761 qDebug() << "Launched external program with id:" << p->processId();
5762 ret = !p->waitForStarted() ? 1 : 0;
5763 #endif
5764 return ret;
5765 }
5766
5767 int CsoundQt::loadFileFromSystem(QString fileName)
5768 {
5769 return loadFile(fileName,m_options->autoPlay);
5770 }
5771
5772 void changeNewLines(QByteArray &line) {
5773 while(line.contains("\r\n")) {
5774 line.replace("\r\n", "\n");
5775 }
5776 while (line.contains("\r")) {
5777 line.replace("\r", "\n");
5778 }
5779 }
5780
5781 void fillCompanionSco(QString &fileName, QString &text) {
5782 auto companionFileName = fileName.replace(".orc", ".sco");
5783 if (!QFile::exists(companionFileName))
5784 return;
5785 text.prepend("<CsoundSynthesizer>\n<CsOptions>\n</CsOptions>\n<CsInstruments>\n");
5786 text.append("\n</CsInstruments>\n<CsScore>\n");
5787 QFile companionFile(companionFileName);
5788 if (!companionFile.open(QFile::ReadOnly))
5789 return;
5790 while (!companionFile.atEnd()) {
5791 QByteArray line = companionFile.readLine();
5792 changeNewLines(line);
5793 QTextDecoder decoder(QTextCodec::codecForLocale());
5794 text = text + decoder.toUnicode(line);
5795 if (!line.endsWith("\n"))
5796 text.append("\n");
5797 }
5798 text.append("</CsScore>\n</CsoundSynthesizer>\n");
5799 }
5800
5801 void fillCompanionOrc(QString &fileName, QString &text) {
5802 auto companionFileName = fileName.replace(".sco", ".orc");
5803 if (!QFile::exists(companionFileName))
5804 return;
5805 QFile companionFlle(companionFileName);
5806 QString orcText = "";
5807 if (!companionFlle.open(QFile::ReadOnly))
5808 return;
5809 while (!companionFlle.atEnd()) {
5810 QByteArray line = companionFlle.readLine();
5811 changeNewLines(line);
5812 QTextDecoder decoder(QTextCodec::codecForLocale());
5813 orcText = orcText + decoder.toUnicode(line);
5814 if (!line.endsWith("\n"))
5815 orcText += "\n";
5816 }
5817 text.prepend("\n</CsInstruments>\n<CsScore>\n");
5818 text.prepend(orcText);
5819 text.prepend("<CsoundSynthesizer>\n<CsOptions>\n</CsOptions>\n<CsInstruments>\n");
5820 text += "</CsScore>\n</CsoundSynthesizer>\n";
5821 }
5822
5823 int CsoundQt::loadFile(QString fileName, bool runNow)
5824 {
5825 if (fileName.endsWith(".pdf")) {
5826 openPdfFile(fileName);
5827 return 0;
5828 }
5829 int index = isOpen(fileName);
5830 if (index != -1) {
5831 QDEBUG << "File " << fileName << "already open, switching to index " << index;
5832 documentTabs->setCurrentIndex(index);
5833 changePage(index);
5834 return index;
5835 }
5836 // QDEBUG << "loading file" << fileName;
5837 QFile file(fileName);
5838 if (!file.open(QFile::ReadOnly)) {
5839 QMessageBox::warning(this, tr("CsoundQt"),
5840 tr("Cannot read file %1:\n%2.")
5841 .arg(fileName)
5842 .arg(file.errorString()));
5843 return -1;
5844 }
5845 QApplication::setOverrideCursor(Qt::WaitCursor);
5846
5847 QString text;
5848 QStringList lines;
5849 bool inEncFile = false;
5850 while (!file.atEnd()) {
5851 QByteArray line = file.readLine();
5852 if (line.contains("<CsFileB ")) {
5853 inEncFile = true;
5854 }
5855 if (!inEncFile) {
5856 changeNewLines(line);
5857 QTextDecoder decoder(QTextCodec::codecForLocale());
5858 // text = text + decoder.toUnicode(line);
5859 if (!line.endsWith("\n"))
5860 text += "\n";
5861 lines << text + decoder.toUnicode(line);
5862 }
5863 else {
5864 // text += line;
5865 lines << line;
5866 if (line.contains("</CsFileB>" && !line.contains("<CsFileB " )) ) {
5867 inEncFile = false;
5868 }
5869 }
5870 }
5871 text = lines.join("");
5872 if (m_options->autoJoin) {
5873 // QString companionFileName = fileName;
5874 if (fileName.endsWith(".orc"))
5875 fillCompanionSco(fileName, text);
5876 else if (fileName.endsWith(".sco"))
5877 fillCompanionOrc(fileName, text);
5878 }
5879
5880 if (fileName == ":/default.csd") {
5881 fileName = QString("");
5882 }
5883
5884 if (!makeNewPage(fileName, text)) {
5885 QApplication::restoreOverrideCursor();
5886 return -1;
5887 }
5888
5889 if (!m_options->autoJoin &&
5890 (fileName.endsWith(".sco") ||
5891 fileName.endsWith(".orc")) ) {
5892 // load companion, when the new page is made, otherwise isOpen works uncorrect
5893 loadCompanionFile(fileName);
5894 }
5895
5896 if (m_options->autoJoin &&
5897 (fileName.endsWith(".sco") || fileName.endsWith(".orc"))) {
5898 fileName.chop(4);
5899 fileName += ".csd";
5900 documentPages[curPage]->setFileName(fileName); // Must update internal name
5901 setCurrentFile(fileName);
5902 if (!QFile::exists(fileName))
5903 save();
5904 else
5905 saveAs();
5906 } else {
5907 documentPages[curPage]->setModified(false);
5908 setWindowModified(false);
5909 documentTabs->setTabIcon(curPage, QIcon());
5910 }
5911
5912 if (fileName.startsWith(m_options->csdocdir) && !m_options->csdocdir.isEmpty()) {
5913 documentPages[curPage]->readOnly = true;
5914 }
5915 QApplication::restoreOverrideCursor();
5916
5917 // FIXME put back
5918 // widgetPanel->clearHistory();
5919 if (runNow) {
5920 play();
5921 }
5922 //QDEBUG << "loadFile" << fileName << "finished, curPage:" << curPage;
5923 return curPage;
5924 }
5925
5926 bool CsoundQt::makeNewPage(QString fileName, QString text)
5927 {
5928 if (documentPages.size() >= MAX_THREAD_COUNT) {
5929 QMessageBox::warning(this, tr("Document number limit"),
5930 tr("Please close a document before opening another."));
5931 return false;
5932 }
5933 auto t0 = std::chrono::high_resolution_clock::now();
5934 DocumentPage *newPage = new DocumentPage(this, m_opcodeTree, &m_configlists, m_midiLearn);
5935 int insertPoint = curPage + 1;
5936 curPage += 1;
5937 if (documentPages.size() == 0) {
5938 insertPoint = 0;
5939 curPage = 0;
5940 }
5941 documentPages.insert(insertPoint, newPage);
5942 // documentPages[curPage]->setOpcodeNameList(m_opcodeTree->opcodeNameList());
5943 documentPages[curPage]->showLiveEventControl(false);
5944 setCurrentOptionsForPage(documentPages[curPage]);
5945
5946 // Must set before sending text to set highlighting mode
5947 documentPages[curPage]->setFileName(fileName);
5948
5949 #ifdef QCS_PYTHONQT
5950 documentPages[curPage]->getEngine()->setPythonConsole(m_pythonConsole);
5951 #endif
5952
5953 connectActions();
5954 // connect(documentPages[curPage], SIGNAL(currentTextUpdated()), this, SLOT(markInspectorUpdate()));
5955 // connect(documentPages[curPage], SIGNAL(modified()), this, SLOT(documentWasModified()));
5956 // // connect(documentPages[curPage], SIGNAL(setWidgetClipboardSignal(QString)),
5957 // // this, SLOT(setWidgetClipboard(QString)));
5958 // connect(documentPages[curPage], SIGNAL(setCurrentAudioFile(QString)),
5959 // this, SLOT(setCurrentAudioFile(QString)));
5960 // connect(documentPages[curPage], SIGNAL(evaluatePythonSignal(QString)),
5961 // this, SLOT(evaluatePython(QString)));
5962 auto page = documentPages[curPage];
5963 page->loadTextString(text);
5964 if (m_options->widgetsIndependent) {
5965 // documentPages[curPage]->setWidgetLayoutOuterGeometry(documentPages[curPage]->getWidgetLayoutOuterGeometry());
5966 page->getWidgetLayout()->setGeometry(page->getWidgetLayoutOuterGeometry());
5967 }
5968 // setWidgetPanelGeometry();
5969
5970 if (!fileName.startsWith(":/")) { // Don't store internal examples in recents menu
5971 lastUsedDir = fileName;
5972 lastUsedDir.resize(fileName.lastIndexOf(QRegExp("[/]")) + 1);
5973 }
5974 if (recentFiles.count(fileName) == 0 && fileName!="" && !fileName.startsWith(":/")) {
5975 recentFiles.prepend(fileName);
5976 if (recentFiles.size() > QCS_MAX_RECENT_FILES)
5977 recentFiles.removeLast();
5978 fillFileMenu();
5979 }
5980 documentTabs->insertTab(curPage, page->getView(),"");
5981 documentTabs->setCurrentIndex(curPage);
5982
5983 midiHandler->addListener(page);
5984 page->getEngine()->setMidiHandler(midiHandler);
5985
5986 setCurrentOptionsForPage(page); // Redundant but does the trick of setting the font properly now that stylesheets are being used...
5987 auto t1 = std::chrono::high_resolution_clock::now();
5988 auto elapsed = std::chrono::duration<double, std::milli>(t1-t0).count();
5989 QDEBUG << "makeNewPage finished in (ms)" << elapsed;
5990 return true;
5991 }
5992
5993 bool CsoundQt::loadCompanionFile(const QString &fileName)
5994 {
5995 QString companionFileName = fileName;
5996 if (fileName.endsWith(".orc")) {
5997 companionFileName.replace(".orc", ".sco");
5998 }
5999 else if (fileName.endsWith(".sco")) {
6000 companionFileName.replace(".sco", ".orc");
6001 }
6002 else {
6003 return false;
6004 }
6005 if (QFile::exists(companionFileName)) {
6006 return (loadFile(companionFileName) != -1);
6007 }
6008 return false;
6009 }
6010
6011 bool CsoundQt::saveFile(const QString &fileName, bool saveWidgets)
6012 {
6013 // qDebug("CsoundQt::saveFile");
6014 // update htmlview on Save
6015 #if defined(QCS_QTHTML)
6016 if (!documentPages.isEmpty() && !documentPages[curPage]->getHtmlText().isEmpty()) {
6017 qDebug()<<"Update html on save";
6018 updateHtmlView();
6019 }
6020 #endif
6021 QString text;
6022 QApplication::setOverrideCursor(Qt::WaitCursor);
6023 if (!m_options->widgetsIndependent) { // Update outer geometry information for writing
6024 QWidget *s = widgetPanel->widget();
6025 // widgetPanel->applySize(); //Store size of outer panel as size of widget
6026 if (s != 0) {
6027 QRect panelGeometry = widgetPanel->geometry();
6028 if (!widgetPanel->isFloating()) {
6029 panelGeometry.setX(-1);
6030 panelGeometry.setY(-1);
6031 }
6032 documentPages[curPage]->setWidgetLayoutOuterGeometry(panelGeometry);
6033 } else {
6034 documentPages[curPage]->setWidgetLayoutOuterGeometry(QRect());
6035 }
6036 }
6037 if (m_options->saveWidgets && saveWidgets)
6038 text = documentPages[curPage]->getFullText();
6039 else
6040 text = documentPages[curPage]->getBasicText();
6041 QApplication::restoreOverrideCursor();
6042
6043 if (fileName != documentPages[curPage]->getFileName()) {
6044 documentPages[curPage]->setFileName(fileName);
6045 setCurrentFile(fileName);
6046 }
6047 lastUsedDir = fileName;
6048 lastUsedDir.resize(fileName.lastIndexOf("/") + 1);
6049 if (recentFiles.count(fileName) == 0) {
6050 recentFiles.prepend(fileName);
6051 recentFiles.removeLast();
6052 fillFileMenu();
6053 }
6054 QFile file(fileName);
6055 if (!file.open(QFile::WriteOnly)) {
6056 QMessageBox::warning(this, tr("Application"),
6057 tr("Cannot write file %1:\n%2.")
6058 .arg(fileName)
6059 .arg(file.errorString()));
6060 return false;
6061 }
6062
6063 QTextStream out(&file);
6064 out << text;
6065 documentPages[curPage]->setModified(false);
6066 setWindowModified(false);
6067 documentTabs->setTabIcon(curPage, QIcon());
6068 return true;
6069 }
6070
6071 void CsoundQt::setCurrentFile(const QString &fileName)
6072 {
6073 QString shownName;
6074 if (fileName.isEmpty())
6075 shownName = "untitled.csd";
6076 else
6077 shownName = strippedName(fileName);
6078
6079 setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("CsoundQt")));
6080 documentTabs->setTabText(curPage, shownName);
6081 // updateWidgets();
6082 }
6083
6084 QString CsoundQt::strippedName(const QString &fullFileName)
6085 {
6086 return QFileInfo(fullFileName).fileName();
6087 }
6088
6089 QString CsoundQt::generateScript(bool realtime, QString tempFileName, QString executable)
6090 {
6091 #ifndef Q_OS_WIN32
6092 QString script = "#!/bin/sh\n";
6093 #else
6094 QString script = "";
6095 #endif
6096 QString cmdLine = "";
6097 // Only OPCODEDIR left here as it must be present before csound initializes
6098 // The problem is that it can't be passed when using the API...
6099 #ifdef USE_DOUBLE
6100 if (m_options->opcodedir64Active)
6101 script += "export OPCODEDIR64=" + m_options->opcodedir64 + "\n";
6102 if (m_options->opcode6dir64Active)
6103 script += "export OPCODE6DIR64=" + m_options->opcode6dir64 + "\n";
6104 #else
6105 if (m_options->opcodedirActive)
6106 script += "export OPCODEDIR=" + m_options->opcodedir + "\n";
6107 #endif
6108
6109 #ifndef Q_OS_WIN32
6110 script += "cd " + QFileInfo(documentPages[curPage]->getFileName()).absolutePath() + "\n";
6111 #else
6112 QString script_cd = "@pushd " + QFileInfo(documentPages[curPage]->getFileName()).absolutePath() + "\n";
6113 script_cd.replace("/", "\\");
6114 script += script_cd;
6115 #endif
6116
6117 if (executable.isEmpty()) {
6118
6119 //test if csound is present in the same folder as CsoundQt, then Csound is bundled. Try to copy it to temporary location and run it from there
6120 // TODO: condition on csound.exe for windows, don't copy but set
6121 #ifdef Q_OS_WIN32
6122 QString csoundExecutable = "/csound.exe";
6123 #else
6124 QString csoundExecutable = "/csound";
6125 #endif
6126 if (QFile::exists(initialDir+csoundExecutable) && !initialDir.startsWith("/usr")) { // if starts with /usr then probably normal install on Linux
6127 qDebug() << "Using bundled Csound to run in terminal";
6128 cmdLine = "\"" + initialDir+csoundExecutable + "\" ";
6129 } else {
6130 cmdLine = m_options->csoundExecutable+ " ";
6131 }
6132 qDebug()<<"Command line: " << cmdLine;
6133 m_options->rt = (realtime && m_options->rtUseOptions)
6134 || (!realtime && m_options->fileUseOptions);
6135 cmdLine += m_options->generateCmdLineFlags() + " ";
6136 }
6137 else {
6138 cmdLine = executable + " ";
6139 }
6140
6141 if (tempFileName == ""){
6142 QString fileName = documentPages[curPage]->getFileName();
6143 if (documentPages[curPage]->getCompanionFileName() != "") {
6144 QString companionFile = documentPages[curPage]->getCompanionFileName();
6145 if (fileName.endsWith(".orc"))
6146 cmdLine += "\"" + fileName
6147 + "\" \""+ companionFile + "\" ";
6148 else
6149 cmdLine += "\"" + companionFile
6150 + "\" \""+ fileName + "\" ";
6151 }
6152 else if (fileName.endsWith(".csd",Qt::CaseInsensitive)) {
6153 cmdLine += "\"" + fileName + "\" ";
6154 }
6155 }
6156 else {
6157 cmdLine += "\"" + tempFileName + "\" ";
6158 }
6159 // m_options->rt = (realtime and m_options->rtUseOptions)
6160 // or (!realtime and m_options->fileUseOptions);
6161 // cmdLine += m_options->generateCmdLineFlags();
6162 script += "echo \"" + cmdLine + "\"\n";
6163 script += cmdLine + "\n";
6164
6165 #ifndef Q_OS_WIN32
6166 script += "echo \"\nPress return to continue\"\n";
6167 script += "dummy_var=\"\"\n";
6168 script += "read dummy_var\n";
6169 script += "rm $0\n";
6170 #else
6171 script += "@echo.\n";
6172 script += "@pause\n";
6173 script += "@exit\n";
6174 #endif
6175 return script;
6176 }
6177
6178 void CsoundQt::getCompanionFileName()
6179 {
6180 QString fileName = "";
6181 QDialog dialog(this);
6182 dialog.resize(400, 200);
6183 dialog.setModal(true);
6184 QPushButton *button = new QPushButton(tr("Ok"));
6185
6186 connect(button, SIGNAL(released()), &dialog, SLOT(accept()));
6187
6188 QSplitter *splitter = new QSplitter(&dialog);
6189 QListWidget *list = new QListWidget(&dialog);
6190 QCheckBox *checkbox = new QCheckBox(tr("Do not ask again"), &dialog);
6191 splitter->addWidget(list);
6192 splitter->addWidget(checkbox);
6193 splitter->addWidget(button);
6194 splitter->resize(400, 200);
6195 splitter->setOrientation(Qt::Vertical);
6196 QString extensionComplement = "";
6197 if (documentPages[curPage]->getFileName().endsWith(".orc"))
6198 extensionComplement = ".sco";
6199 else if (documentPages[curPage]->getFileName().endsWith(".sco"))
6200 extensionComplement = ".orc";
6201 else if (documentPages[curPage]->getFileName().endsWith(".udo"))
6202 extensionComplement = ".csd";
6203 else if (documentPages[curPage]->getFileName().endsWith(".inc"))
6204 extensionComplement = ".csd";
6205
6206 for (int i = 0; i < documentPages.size(); i++) {
6207 QString name = documentPages[i]->getFileName();
6208 if (name.endsWith(extensionComplement))
6209 list->addItem(name);
6210 }
6211 QList<QListWidgetItem *> itemList = list->findItems(
6212 documentPages[curPage]->getCompanionFileName(),
6213 Qt::MatchExactly);
6214 if (itemList.size() > 0)
6215 list->setCurrentItem(itemList[0]);
6216 dialog.exec();
6217 QListWidgetItem *item = list->currentItem();
6218 if (!item) {
6219 qDebug() << "Empty list. Create empty score file";
6220 QString companion = "";
6221 if (documentPages[curPage]->getFileName().endsWith(".orc")) {
6222 // create an empty score file to run the orchestra scorelessly
6223 companion = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/empty.sco";
6224 QFile f(companion); // does it create it here
6225 f.open(QIODevice::ReadWrite | QIODevice::Text);
6226 f.close();
6227 qDebug() << "Created empty score file as companion: " << companion;
6228 }
6229 documentPages[curPage]->setCompanionFileName(companion);
6230 return;
6231 }
6232 QString itemText = item->text();
6233 if (checkbox->isChecked())
6234 documentPages[curPage]->askForFile = false;
6235 documentPages[curPage]->setCompanionFileName(itemText);
6236 for (int i = 0; i < documentPages.size(); i++) {
6237 if (documentPages[i]->getFileName() == documentPages[curPage]->getCompanionFileName()
6238 && !documentPages[i]->getFileName().endsWith(".csd")) {
6239 documentPages[i]->setCompanionFileName(documentPages[curPage]->getFileName());
6240 documentPages[i]->askForFile = documentPages[curPage]->askForFile;
6241 break;
6242 }
6243 }
6244 }
6245
6246 void CsoundQt::setWidgetPanelGeometry()
6247 {
6248 QRect geometry = documentPages[curPage]->getWidgetLayoutOuterGeometry();
6249 if (geometry.width() <= 0 || geometry.width() > 4096) {
6250 geometry.setWidth(400);
6251 qDebug() << "Warning: width invalid.";
6252 }
6253 if (geometry.height() <= 0 || geometry.height() > 4096) {
6254 geometry.setHeight(300);
6255 qDebug() << "Warning: height invalid.";
6256 }
6257 if (geometry.x() < 0 || geometry.x() > 4096) {
6258 geometry.setX(20);
6259 qDebug() << "Warning: X position invalid.";
6260 }
6261 if (geometry.y() < 0 || geometry.y() > 4096) {
6262 geometry.setY(0);
6263 qDebug() << "Warning: Y position invalid.";
6264 }
6265 // qDebug() << "geom " << widgetPanel->geometry() << " frame " << widgetPanel->frameGeometry();
6266 widgetPanel->setGeometry(geometry);
6267 }
6268
6269 int CsoundQt::isOpen(QString fileName)
6270 {
6271 int open = -1;
6272 int i = 0;
6273 for (i = 0; i < documentPages.size(); i++) {
6274 if (documentPages[i]->getFileName() == fileName) {
6275 open = i;
6276 break;
6277 }
6278 }
6279 return open;
6280 }
6281
6282
6283 QString CsoundQt::setDocument(int index)
6284 {
6285 QString name = QString();
6286 if (index < documentTabs->count() && index >= 0) {
6287 documentTabs->setCurrentIndex(index);
6288 name = documentPages[index]->getFileName();
6289 }
6290 return name;
6291 }
6292
6293 void CsoundQt::insertText(QString text, int index, int section)
6294 {
6295 if (index == -1) {
6296 index = curPage;
6297 }
6298 if (section == -1) {
6299 if (index < documentTabs->count() && index >= 0) {
6300 documentPages[index]->insertText(text);
6301 }
6302 }
6303 else {
6304 qDebug() << "Not implemented for sections";
6305 }
6306 }
6307
6308 void CsoundQt::setCsd(QString text, int index)
6309 {
6310 if (index == -1) {
6311 index = curPage;
6312 }
6313 if (index < documentTabs->count() && index >= 0) {
6314 documentPages[index]->setBasicText(text);
6315 }
6316 }
6317
6318 void CsoundQt::setFullText(QString text, int index)
6319 {
6320 if (index == -1) {
6321 index = curPage;
6322 }
6323 if (index < documentTabs->count() && index >= 0) {
6324 documentPages[index]->setFullText(text);
6325 }
6326 }
6327
6328 void CsoundQt::setOrc(QString text, int index)
6329 {
6330 if (index == -1) {
6331 index = curPage;
6332 }
6333 if (index < documentTabs->count() && index >= 0) {
6334 documentPages[index]->setOrc(text);
6335 }
6336 }
6337
6338 void CsoundQt::setSco(QString text, int index)
6339 {
6340 if (index == -1) {
6341 index = curPage;
6342 }
6343 if (index < documentTabs->count() && index >= 0) {
6344 documentPages[index]->setSco(text);
6345 }
6346 }
6347
6348 void CsoundQt::setWidgetsText(QString text, int index)
6349 {
6350 if (index == -1) {
6351 index = curPage;
6352 }
6353 if (index < documentTabs->count() && index >= 0) {
6354 documentPages[index]->setWidgetsText(text);
6355 }
6356 }
6357
6358 void CsoundQt::setPresetsText(QString text, int index)
6359 {
6360 if (index == -1) {
6361 index = curPage;
6362 }
6363 if (index < documentTabs->count() && index >= 0) {
6364 documentPages[index]->setPresetsText(text);
6365 }
6366 }
6367
6368 void CsoundQt::setOptionsText(QString text, int index)
6369 {
6370 if (index == -1) {
6371 index = curPage;
6372 }
6373 if (index < documentTabs->count() && index >= 0) {
6374 documentPages[index]->setOptionsText(text);
6375 }
6376 }
6377
6378 int CsoundQt::getDocument(QString name)
6379 {
6380 int index = curPage;
6381 if (!name.isEmpty()) {
6382 index = -1;
6383 for (int i = 0; i < documentPages.size(); i++) {
6384 QString fileName = documentPages[i]->getFileName();
6385 QString relName = fileName.mid(fileName.lastIndexOf("/")+1);
6386 if (name == fileName || name == relName ) {
6387 index = i;
6388 break;
6389 }
6390 }
6391 }
6392 return index;
6393 }
6394
6395 QString CsoundQt::getTheme()
6396 {
6397 return m_options->theme;
6398 }
6399
6400 QString CsoundQt::getSelectedText(int index, int section)
6401 {
6402 QString text = QString();
6403 if (index == -1) {
6404 index = curPage;
6405 }
6406 if (index < documentTabs->count() && index >= 0) {
6407 text = documentPages[index]->getSelectedText(section);
6408 }
6409 return text;
6410 }
6411
6412 QString CsoundQt::getCsd(int index)
6413 {
6414 QString text = QString();
6415 if (index == -1) {
6416 index = curPage;
6417 }
6418 if (index < documentTabs->count() && index >= 0) {
6419 text = documentPages[index]->getBasicText();
6420 }
6421 return text;
6422 }
6423
6424 QString CsoundQt::getFullText(int index)
6425 {
6426 QString text = QString();
6427 if (index == -1) {
6428 index = curPage;
6429 }
6430 if (index < documentTabs->count() && index >= 0) {
6431 text = documentPages[index]->getFullText();
6432 }
6433 return text;
6434 }
6435
6436 QString CsoundQt::getOrc(int index)
6437 {
6438 QString text = QString();
6439 if (index == -1) {
6440 index = curPage;
6441 }
6442 if (index < documentTabs->count() && index >= 0) {
6443 text = documentPages[index]->getOrc();
6444 }
6445 return text;
6446 }
6447
6448 QString CsoundQt::getSco(int index)
6449 {
6450 QString text = QString();
6451 if (index == -1) {
6452 index = curPage;
6453 }
6454 if (index < documentTabs->count() && index >= 0) {
6455 text = documentPages[index]->getSco();
6456 }
6457 return text;
6458 }
6459
6460 QString CsoundQt::getWidgetsText(int index)
6461 {
6462 QString text = QString();
6463 if (index == -1) {
6464 index = curPage;
6465 }
6466 if (index < documentTabs->count() && index >= 0) {
6467 text = documentPages[index]->getWidgetsText();
6468 }
6469 return text;
6470 }
6471
6472 QString CsoundQt::getSelectedWidgetsText(int index)
6473 {
6474 QString text = QString();
6475 if (index == -1) {
6476 index = curPage;
6477 }
6478 if (index < documentTabs->count() && index >= 0) {
6479 text = documentPages[index]->getSelectedWidgetsText();
6480 }
6481 return text;
6482 }
6483
6484 QString CsoundQt::getPresetsText(int index)
6485 {
6486 QString text = QString();
6487 if (index == -1) {
6488 index = curPage;
6489 }
6490 if (index < documentTabs->count() && index >= 0) {
6491 text = documentPages[index]->getPresetsText();
6492 }
6493 return text;
6494 }
6495
6496 QString CsoundQt::getOptionsText(int index)
6497 {
6498 QString text = QString();
6499 if (index == -1) {
6500 index = curPage;
6501 }
6502 if (index < documentTabs->count() && index >= 0) {
6503 text = documentPages[index]->getOptionsText();
6504 }
6505 return text;
6506 }
6507
6508 QString CsoundQt::getFileName(int index)
6509 {
6510 QString text = QString();
6511 if (index == -1) {
6512 index = curPage;
6513 }
6514 if (index < documentTabs->count() && index >= 0) {
6515 text = documentPages[index]->getFileName();
6516 }
6517 return text;
6518 }
6519
6520 QString CsoundQt::getFilePath(int index)
6521 {
6522 QString text = QString();
6523 if (index == -1) {
6524 index = curPage;
6525 }
6526 if (index < documentTabs->count() && index >= 0) {
6527 text = documentPages[index]->getFilePath();
6528 }
6529 return text;
6530 }
6531
6532
6533
6534 void CsoundQt::setChannelValue(QString channel, double value, int index)
6535 {
6536
6537 if (index == -1) {
6538 index = curPage;
6539 }
6540 if (index < documentTabs->count() && index >= 0) {
6541 documentPages[index]->setChannelValue(channel, value);
6542 }
6543 }
6544
6545 double CsoundQt::getChannelValue(QString channel, int index)
6546 {
6547 double value = 0.0;
6548 if (index == -1) {
6549 index = curPage;
6550 }
6551 if (index < documentTabs->count() && index >= 0) {
6552 value = documentPages[index]->getChannelValue(channel);
6553 }
6554 return value;
6555 }
6556
6557 void CsoundQt::setChannelString(QString channel, QString value, int index)
6558 {
6559 if (index == -1) {
6560 index = curPage;
6561 }
6562 if (index < documentTabs->count() && index >= 0) {
6563 documentPages[index]->setChannelString(channel, value);
6564 }
6565 }
6566
6567 QString CsoundQt::getChannelString(QString channel, int index)
6568 {
6569 QString value = "";
6570 if (index == -1) {
6571 index = curPage;
6572 }
6573 if (index < documentTabs->count() && index >= 0) {
6574 value = documentPages[index]->getChannelString(channel);
6575 }
6576 return value;
6577 }
6578
6579 void CsoundQt::setWidgetProperty(QString widgetid, QString property, QVariant value, int index)
6580 {
6581 if (index == -1) {
6582 index = curPage;
6583 }
6584 if (index < documentTabs->count() && index >= 0) {
6585 documentPages[index]->setWidgetProperty(widgetid, property, value);
6586 }
6587 }
6588
6589 QVariant CsoundQt::getWidgetProperty(QString widgetid, QString property, int index)
6590 {
6591 QVariant value;
6592 if (index == -1) {
6593 index = curPage;
6594 }
6595 if (index < documentTabs->count() && index >= 0) {
6596 value = documentPages[index]->getWidgetProperty(widgetid, property);
6597 }
6598 return value;
6599 }
6600
6601
6602 QString CsoundQt::createNewLabel(int x , int y , QString channel, int index)
6603 {
6604 if (index == -1) {
6605 index = curPage;
6606 }
6607 if (index < documentTabs->count() && index >= 0) {
6608 return documentPages[index]->createNewLabel(x,y,channel);
6609 }
6610 return QString();
6611 }
6612
6613 QString CsoundQt::createNewDisplay(int x , int y , QString channel, int index)
6614 {
6615 if (index == -1) {
6616 index = curPage;
6617 }
6618 if (index < documentTabs->count() && index >= 0) {
6619 return documentPages[index]->createNewDisplay(x,y,channel);
6620 }
6621 return QString();
6622 }
6623
6624 QString CsoundQt::createNewScrollNumber(int x , int y , QString channel, int index)
6625 {
6626 if (index == -1) {
6627 index = curPage;
6628 }
6629 if (index < documentTabs->count() && index >= 0) {
6630 return documentPages[index]->createNewScrollNumber(x,y,channel);
6631 }
6632 return QString();
6633 }
6634
6635 QString CsoundQt::createNewLineEdit(int x , int y , QString channel, int index)
6636 {
6637 if (index == -1) {
6638 index = curPage;
6639 }
6640 if (index < documentTabs->count() && index >= 0) {
6641 return documentPages[index]->createNewLineEdit(x,y,channel);
6642 }
6643 return QString();
6644 }
6645
6646 QString CsoundQt::createNewSpinBox(int x , int y , QString channel, int index)
6647 {
6648 if (index == -1) {
6649 index = curPage;
6650 }
6651 if (index < documentTabs->count() && index >= 0) {
6652 return documentPages[index]->createNewSpinBox(x,y,channel);
6653 }
6654 return QString();
6655 }
6656
6657 QString CsoundQt::createNewSlider(int x, int y, QString channel, int index)
6658 {
6659 if (index == -1) {
6660 index = curPage;
6661 }
6662 if (index < documentTabs->count() && index >= 0) {
6663 return documentPages[index]->createNewSlider(x,y, channel);
6664 }
6665 return QString();
6666 }
6667
6668 QString CsoundQt::createNewButton(int x , int y , QString channel, int index)
6669 {
6670 if (index == -1) {
6671 index = curPage;
6672 }
6673 if (index < documentTabs->count() && index >= 0) {
6674 return documentPages[index]->createNewButton(x,y,channel);
6675 }
6676 return QString();
6677 }
6678
6679 QString CsoundQt::createNewKnob(int x , int y , QString channel, int index)
6680 {
6681 if (index == -1) {
6682 index = curPage;
6683 }
6684 if (index < documentTabs->count() && index >= 0) {
6685 return documentPages[index]->createNewKnob(x,y,channel);
6686 }
6687 return QString();
6688 }
6689
6690 QString CsoundQt::createNewCheckBox(int x , int y , QString channel, int index)
6691 {
6692 if (index == -1) {
6693 index = curPage;
6694 }
6695 if (index < documentTabs->count() && index >= 0) {
6696 return documentPages[index]->createNewCheckBox(x,y,channel);
6697 }
6698 return QString();
6699 }
6700
6701 QString CsoundQt::createNewMenu(int x , int y , QString channel, int index)
6702 {
6703 if (index == -1) {
6704 index = curPage;
6705 }
6706 if (index < documentTabs->count() && index >= 0) {
6707 return documentPages[index]->createNewMenu(x,y,channel);
6708 }
6709 return QString();
6710 }
6711
6712 QString CsoundQt::createNewMeter(int x , int y , QString channel, int index)
6713 {
6714 if (index == -1) {
6715 index = curPage;
6716 }
6717 if (index < documentTabs->count() && index >= 0) {
6718 return documentPages[index]->createNewMeter(x,y,channel);
6719 }
6720 return QString();
6721 }
6722
6723 QString CsoundQt::createNewConsole(int x , int y , QString channel, int index)
6724 {
6725 if (index == -1) {
6726 index = curPage;
6727 }
6728 if (index < documentTabs->count() && index >= 0) {
6729 return documentPages[index]->createNewConsole(x,y,channel);
6730 }
6731 return QString();
6732 }
6733
6734 QString CsoundQt::createNewGraph(int x , int y , QString channel, int index)
6735 {
6736 if (index == -1) {
6737 index = curPage;
6738 }
6739 if (index < documentTabs->count() && index >= 0) {
6740 return documentPages[index]->createNewGraph(x,y,channel);
6741 }
6742 return QString();
6743 }
6744
6745 QString CsoundQt::createNewScope(int x , int y , QString channel, int index)
6746 {
6747 if (index == -1) {
6748 index = curPage;
6749 }
6750 if (index < documentTabs->count() && index >= 0) {
6751 return documentPages[index]->createNewScope(x,y,channel);
6752 }
6753 return QString();
6754 }
6755
6756 QStringList CsoundQt::getWidgetUuids(int index)
6757 {
6758 if (index == -1) {
6759 index = curPage;
6760 }
6761 if (index < documentTabs->count() && index >= 0) {
6762 return documentPages[index]->getWidgetUuids();
6763 }
6764 return QStringList();
6765 }
6766
6767 QStringList CsoundQt::listWidgetProperties(QString widgetid, int index)
6768 {
6769 if (index == -1) {
6770 index = curPage;
6771 }
6772 if (index < documentTabs->count() && index >= 0) {
6773 return documentPages[index]->listWidgetProperties(widgetid);
6774 }
6775 return QStringList();
6776 }
6777
6778 bool CsoundQt::destroyWidget(QString widgetid,int index)
6779 {
6780 if (index == -1) {
6781 index = curPage;
6782 }
6783 if (index < documentTabs->count() && index >= 0) {
6784 return documentPages[index]->destroyWidget(widgetid);
6785 }
6786 return false;
6787 }
6788
6789 EventSheet* CsoundQt::getSheet(int index, int sheetIndex)
6790 {
6791 if (index == -1) {
6792 index = curPage;
6793 }
6794 if (index < documentTabs->count() && index >= 0) {
6795 return documentPages[index]->getSheet(sheetIndex);
6796 }
6797 else {
6798 return NULL;
6799 }
6800 }
6801
6802 CsoundEngine *CsoundQt::getEngine(int index)
6803 {
6804 if (index == -1) {
6805 index = curPage;
6806 }
6807 if (index < documentTabs->count() && index >= 0) {
6808 return documentPages[index]->getEngine();
6809 }
6810 else {
6811 return NULL;
6812 }
6813 }
6814
6815 bool CsoundQt::startServer()
6816 {
6817 m_server->removeServer("csoundqt"); // for any case, if socket was not cleard due crash before
6818 return m_server->listen("csoundqt");
6819 }
6820
6821 #if defined(QCS_QTHTML)
6822 void CsoundQt::updateHtmlView()
6823 {
6824 QString htmlText = documentPages[curPage]->getHtmlText();
6825 if (!htmlText.isEmpty()) {
6826 ///csoundHtmlView->setCsoundEngine(getEngine(curPage));
6827 csoundHtmlView->load(documentPages[curPage]);
6828 } else {
6829 csoundHtmlView->clear();
6830 }
6831 }
6832 #endif
6833
6834 EventSheet* CsoundQt::getSheet(int index, QString sheetName)
6835 {
6836 if (index == -1) {
6837 index = curPage;
6838 }
6839 if (index < documentTabs->count() && index >= 0) {
6840 return documentPages[index]->getSheet(sheetName);
6841 }
6842 else {
6843 return NULL;
6844 }
6845 }
6846
6847 void CsoundQt::loadPreset(int preSetIndex, int index) {
6848 if (index == -1) {
6849 index = curPage;
6850 }
6851
6852 if (index < documentTabs->count() && index >= 0) {
6853 return documentPages[index]->loadPreset(preSetIndex);
6854 }
6855 else {
6856 return;
6857 }
6858 }
6859
6860 void CsoundQt::setParsedUDOs() {
6861 auto udos = m_inspector->getParsedUDOs();
6862 auto doc = documentPages[curPage];
6863 doc->setParsedUDOs(udos);
6864 }
6865
6866 void CsoundQt::gotoLineDialog() {
6867 auto doc = this->getCurrentDocumentPage();
6868 doc->gotoLineDialog();
6869 }