HulaLoop
Simple cross-platform audio loopback and recording.
QMLBridge.h
1 #ifndef QMLBRIDGE_H
2 #define QMLBRIDGE_H
3 
4 #include <atomic>
5 #include <QObject>
6 #include <QString>
7 #include <QStringList>
8 #include <thread>
9 #include <vector>
10 
11 #include <hlaudio/hlaudio.h>
12 #include <hlcontrol/hlcontrol.h>
13 
14 namespace hula
15 {
20  class QMLBridge : public QObject {
21  Q_OBJECT
22  Q_PROPERTY(QString emptyStr READ getEmptyStr NOTIFY languageChanged)
23  Q_PROPERTY(QString visType READ getVisualizerType WRITE setVisualizerType)
24 
25  private:
26  Transport *transport;
27  HulaRingBuffer *rb;
28 
29  std::vector<std::thread> visThreads;
30  std::atomic<bool> endVis;
31 
32  bool showRecDevices;
33  QString visType, language;
34 
35  public:
36  explicit QMLBridge(QObject *parent = nullptr);
37  virtual ~QMLBridge();
38 
39  Q_INVOKABLE void saveSettings();
40  void loadSettings();
41 
42  QString getVisualizerType();
43  void setVisualizerType(const QString &);
44 
45  Q_INVOKABLE void setActiveInputDevice(QString QDeviceName);
46  Q_INVOKABLE void setActiveOutputDevice(QString QDeviceName);
47  Q_INVOKABLE QString getInputDevices();
48  Q_INVOKABLE QString getOutputDevices();
49 
50  Q_INVOKABLE void setShowRecordDevices(bool);
51  Q_INVOKABLE bool getShowRecordDevices();
52  Q_INVOKABLE bool loadLanguage(const QString &);
53  Q_INVOKABLE QString getSelectedLanguage();
54 
55  Q_INVOKABLE QString getTransportState() const;
56  Q_INVOKABLE bool record();
57  Q_INVOKABLE bool stop();
58  Q_INVOKABLE bool play();
59  Q_INVOKABLE bool pause();
60  Q_INVOKABLE void discard();
61 
62  QString getEmptyStr();
63 
64  Q_INVOKABLE void saveFile(QString dir);
65  Q_INVOKABLE void cleanTempFiles();
66  Q_INVOKABLE bool wannaClose();
67 
68  void startVisThread();
69  void stopVisThread();
70  static void updateVisualizer(QMLBridge *_this);
71  static void reverseBits(size_t x, int n);
72 
73  Q_INVOKABLE void launchUpdateProcess();
74 
75  signals:
80  void stateChanged();
81 
85  void languageChanged();
86 
90  void visData(const std::vector<qreal> &rawData, const std::vector<qreal> &dataIn);
91 
95  void discarded();
96  };
97 }
98 
99 #endif // QMLBRIDGE_H
<hlcontrol/hlcontrol.h>
Q_INVOKABLE bool stop()
Trigger stop in the Transport and update the UI state via signal.
Definition: QMLBridge.cpp:151
Q_INVOKABLE QString getOutputDevices()
Get the current output devices.
Definition: QMLBridge.cpp:285
void startVisThread()
Start the thread that reads the ring buffer and updates the visualizer.
Definition: QMLBridge.cpp:376
Q_INVOKABLE void saveSettings()
Saves all settings into a JSON settings file.
Definition: QMLBridge.cpp:76
Q_INVOKABLE QString getSelectedLanguage()
Returns the setting value for showing record devices.
Definition: QMLBridge.cpp:347
Q_INVOKABLE void discard()
Deletes all the temp files that the program has created.
Definition: QMLBridge.cpp:194
void languageChanged()
Signal emmitted when the language changes.
Extra class for managing the state of the application and all audio related processes.
Definition: Transport.h:33
QMLBridge(QObject *parent=nullptr)
Construct a new instance of the QMLBridge class.
Definition: QMLBridge.cpp:32
QString getEmptyStr()
Return an empty QString to force QML to update when a new language is loaded.
Definition: QMLBridge.cpp:207
<hlaudio/hlaudio.h>
void stateChanged()
Signal emmitted when the Transport changes states.
Q_INVOKABLE void cleanTempFiles()
Deletes all the temp files that the program has created.
Definition: QMLBridge.cpp:558
Q_INVOKABLE void launchUpdateProcess()
Launch the updater process.
Definition: QMLBridge.cpp:500
Q_INVOKABLE bool wannaClose()
Get if the user has unsaved files.
Definition: QMLBridge.cpp:520
Q_INVOKABLE bool record()
Trigger record in the Transport and update the UI state via signal.
Definition: QMLBridge.cpp:134
Q_INVOKABLE bool loadLanguage(const QString &)
Modifies settings to load the specified language.
Definition: QMLBridge.cpp:329
Q_INVOKABLE void setActiveInputDevice(QString QDeviceName)
Match a string that the user chose to the input device list and notify the backend.
Definition: QMLBridge.cpp:216
QString getVisualizerType()
Return the current visualizer type.
Definition: QMLBridge.cpp:106
Q_INVOKABLE QString getInputDevices()
Get the current input devices.
Definition: QMLBridge.cpp:263
Q_INVOKABLE void setActiveOutputDevice(QString QDeviceName)
Match a string that the user chose to the output device list and notify the backend.
Definition: QMLBridge.cpp:240
static void updateVisualizer(QMLBridge *_this)
Perform FFT and update the visualizer.
Definition: QMLBridge.cpp:408
HulaLoop wrapper class for PortAudio ring buffer.
Definition: HulaRingBuffer.h:86
virtual ~QMLBridge()
Destructor for QMLBridge.
Definition: QMLBridge.cpp:566
void discarded()
Signal emmitted when the Transport successfully discards.
void setVisualizerType(const QString &)
Sets the current visualizer type.
Definition: QMLBridge.cpp:116
void loadSettings()
Loads all settings stored in the JSON settings file.
Definition: QMLBridge.cpp:43
Q_INVOKABLE bool pause()
Trigger pause in the Transport and update the UI state via signal.
Definition: QMLBridge.cpp:181
Q_INVOKABLE QString getTransportState() const
Return the current state of the Transport instance as a QString.
Definition: QMLBridge.cpp:126
void stopVisThread()
Stop the thread that updates the visualizer.
Definition: QMLBridge.cpp:391
Wrapper around translation functions for Qt.
Definition: Controller.h:10
Q_INVOKABLE void setShowRecordDevices(bool)
Modifies settings to display record devices.
Definition: QMLBridge.cpp:307
void visData(const std::vector< qreal > &rawData, const std::vector< qreal > &dataIn)
Signal emitted when the visualizer needs to update.
Class for communicating between QML and C++.
Definition: QMLBridge.h:20
Q_INVOKABLE bool getShowRecordDevices()
Returns the setting value for showing record devices.
Definition: QMLBridge.cpp:319
Q_INVOKABLE void saveFile(QString dir)
Get the directory the user wants to save to.
Definition: QMLBridge.cpp:359
Q_INVOKABLE bool play()
Trigger playback in the Transport and update the UI state via signal.
Definition: QMLBridge.cpp:164