Creating a drum track
Let's buckle up and do this project! Create a new Qt Widgets Application project named ch11-drum-machine
. As usual, add the CONFIG += c++14
in ch11-drum-machine.pro
.
Now create a new C++ class named SoundEvent
. Here is SoundEvent.h
stripped from its functions:
#include <QtGlobal> class SoundEvent { public: SoundEvent(qint64 timestamp = 0, int soundId = 0); ~SoundEvent(); qint64 timestamp; int soundId; };
This class contains only two public members:
timestamp
: Aqint64
(long long
type) that contains the current time of theSoundEvent
in milliseconds since the beginning of the tracksoundId
: The ID of the sound that has been played
In recording mode, each time the user plays a sound, a SoundEvent
is created with the appropriate data. The SoundEvent.cpp
file is so boring that we will not inflict it on you.
The next class to build is Track
. Again, create the new C++ class. Let's review Track.h
...