Bringing PlaybackWorker to life
The user can play a sound live with a mouse click or a keyboard key. But when he records an awesome beat, the application must be able to play it again with the PlaybackWorker
class. Let's see how MainWindow
uses this worker. Here is the MainWindow.h
related to the PlaybackWorker
class:
class MainWindow : public QMainWindow { ... private slots: void playSoundEffect(int soundId); void clearPlayback(); void stopPlayback(); ... private: void startPlayback(); ... private: PlaybackWorker* mPlaybackWorker; QThread* mPlaybackThread; ... };
As you can see, MainWindow
has PlaybackWorker
and a QThread
member variables. Let's see the implementation of startPlayback()
:
void MainWindow::startPlayback() { clearPlayback(); mPlaybackThread = new QThread(); mPlaybackWorker = new PlaybackWorker(mTrack); mPlaybackWorker->moveToThread(mPlaybackThread...