Controller.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <QObject>
  21. #include <QMap>
  22. #include <QDir>
  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 (TODO)
  35. class qtauController : public QObject, public IController
  36. {
  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(){return _activeSynth;}
  44. ISynth* selectedSynth(){return _selectedSynth;};
  45. static qtauController* instance();
  46. void startPlayback(float startPos);
  47. void stopPlayback();
  48. void selectSinger(QString singerName);
  49. void updateTempoTimeSignature(int tempo);
  50. int sampleRate();
  51. void startOfflinePlayback(const QString& fileName);
  52. QString lastPlay(){return _lastPlay;}
  53. signals:
  54. void playStart();
  55. void playPause();
  56. void playStop();
  57. void playerSetVolume(int level);
  58. void transportPositionChanged(float pos);
  59. public slots:
  60. void onLoadUST(QString fileName);
  61. void onSaveUST(QString fileName, bool rewrite);
  62. //void onRequestSynthesis();
  63. void onRequestStartPlayback();
  64. void onRequestStopPlayback();
  65. void onRequestResetPlayback();
  66. void pianoKeyPressed(int);
  67. void pianoKeyReleased(int);
  68. private slots:
  69. void jackTimer();
  70. void outbuf_startPlayback();
  71. void outbuf_stopPlayback();
  72. private:
  73. //void transportStarting();
  74. void addFileToRecentFiles(QString fileName);
  75. bool validateScore(const QJsonArray& ust);
  76. protected:
  77. JackAudio* _jack=nullptr;
  78. AudioEngine* _audio=nullptr;
  79. OutputBuffer* _outbuf=nullptr;
  80. MainWindow *_mainWindow;
  81. qtauSession *_activeSession;
  82. //float _samplesToMeasures;
  83. bool setupTranslations();
  84. bool setupPlugins();
  85. bool setupVoicebanks();
  86. void initSynth(ISynth *s);
  87. void initPreviewSynth(IPreviewSynth* ps);
  88. QMap<QString, ISynth*> _synths;
  89. ISynth* _activeSynth;
  90. ISynth* _selectedSynth;
  91. int _nonzeroStart=0;
  92. QDir _pluginsDir;
  93. QString _prefix;
  94. QStringList _voices;
  95. //bool _synthrunning;
  96. bool _previewRunning=false;
  97. bool _localRequestStartPlayback=false;
  98. IPreviewSynth* _preview=nullptr;
  99. QString _lastPlay;
  100. float _lastNoteEnd=0;
  101. int _jackSampleRate=0;
  102. void newEmptySession();
  103. void logError(const QString& error);
  104. void logDebug(const QString& debug);
  105. void logSuccess(const QString& success);
  106. void addPluginAction(QAction *action);
  107. public:
  108. const QStringList& voices(){return _voices;}
  109. void setJackTranportEnabled(bool enabled);
  110. };
  111. #endif // CONTROLLER_H