Controller.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. This file is part of QTau
  3. Copyright (C) 2013-2018 Tobias "Tomoko" Platen <tplaten@posteo.de>
  4. Copyright (C) 2013 digited <https://github.com/digited>
  5. Copyright (C) 2010-2013 HAL@ShurabaP <https://github.com/haruneko>
  6. QTau is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. SPDX-License-Identifier: GPL-3.0+
  17. */
  18. #ifndef CONTROLLER_H
  19. #define CONTROLLER_H
  20. #include <QDir>
  21. #include <QMap>
  22. #include <QObject>
  23. #include <QThread>
  24. #include "Utils.h"
  25. class MainWindow;
  26. class qtauSynth;
  27. class qtmmPlayer;
  28. class qtauAudioSource;
  29. class qtauSession;
  30. class AudioEngine;
  31. class JackAudio;
  32. #include "PluginInterfaces.h"
  33. #include "audio/outputbuffer.h"
  34. // main class of QTau that ties everything together, also used in headless mode
  35. // (TODO)
  36. class qtauController : public QObject, public IController {
  37. Q_OBJECT
  38. public:
  39. explicit qtauController(QString dir, QObject* parent = 0);
  40. ~qtauController();
  41. void shutdown(int rc); // must be called before destoying the object
  42. bool run(); // app startup & setup, window creation
  43. ISynth* activeSynth() {
  44. return _synth;
  45. }
  46. ISynth* selectedSynth() {
  47. return _synth;
  48. };
  49. static qtauController* instance();
  50. void startPlayback(float startPos);
  51. void stopPlayback();
  52. void selectSinger(QString singerName);
  53. void updateTempoTimeSignature(int tempo);
  54. int sampleRate();
  55. void startOfflinePlayback(const QString& fileName);
  56. QString lastPlay() {
  57. return _lastPlay;
  58. }
  59. signals:
  60. void playStart();
  61. void playPause();
  62. void playStop();
  63. void playerSetVolume(int level);
  64. void transportPositionChanged(float pos);
  65. void voiceListChanged();
  66. public slots:
  67. void onLoadUST(QString fileName);
  68. void onSaveUST(QString fileName, bool rewrite);
  69. void onRequestStartPlayback();
  70. void onRequestStopPlayback();
  71. void onRequestResetPlayback();
  72. void pianoKeyPressed(int);
  73. void pianoKeyReleased(int);
  74. void openVoiceDirectory();
  75. void rescanVoiceDirectory();
  76. private slots:
  77. void jackTimer();
  78. void outbuf_startPlayback();
  79. void outbuf_stopPlayback();
  80. private:
  81. // void transportStarting();
  82. void addFileToRecentFiles(QString fileName);
  83. bool validateScore(const QJsonArray& ust);
  84. protected:
  85. JackAudio* _jack = nullptr;
  86. AudioEngine* _audio = nullptr;
  87. OutputBuffer* _outbuf = nullptr;
  88. MainWindow* _mainWindow;
  89. qtauSession* _activeSession;
  90. // float _samplesToMeasures;
  91. bool setupTranslations();
  92. bool setupPlugins();
  93. bool setupVoicebanks();
  94. void initSynth(ISynth* s);
  95. void initPreviewSynth(IPreviewSynth* ps);
  96. QMap<QString, ISynth*> _synths;
  97. // FIXME: synth selection
  98. ISynth* _synth = nullptr;
  99. // ISynth* _activeSynth=nullptr;
  100. // ISynth* _selectedSynth=nullptr;
  101. int _nonzeroStart = 0;
  102. QDir _pluginsDir;
  103. QString _prefix;
  104. // QStringList _voices;
  105. QMap<QString, QString> _voicesMap;
  106. bool _needDownload=false;
  107. bool _previewRunning = false;
  108. bool _localRequestStartPlayback = false;
  109. IPreviewSynth* _preview = nullptr;
  110. QString _lastPlay;
  111. float _lastNoteEnd = 0;
  112. int _jackSampleRate = 0;
  113. void newEmptySession();
  114. void logError(const QString& error);
  115. void logDebug(const QString& debug);
  116. void logSuccess(const QString& success);
  117. void addPluginAction(QAction* action);
  118. public:
  119. const QStringList voices() {
  120. return _voicesMap.keys();
  121. }
  122. void setJackTranportEnabled(bool enabled);
  123. bool needDownload() { return _needDownload; }
  124. };
  125. #endif // CONTROLLER_H