mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-15 02:40:38 +00:00
bc319d9e88
Okay, I've spent a whole day on this now, and it finally kinda works! With this patch, CObject and all of its derived classes are reference counted instead of tree-owned. The previous, Qt-like model was nice and familiar, but ultimately also outdated and difficult to reason about. CObject-derived types should now be stored in RefPtr/NonnullRefPtr and each class can be constructed using the forwarding construct() helper: auto widget = GWidget::construct(parent_widget); Note that construct() simply forwards all arguments to an existing constructor. It is inserted into each class by the C_OBJECT macro, see CObject.h to understand how that works. CObject::delete_later() disappears in this patch, as there is no longer a single logical owner of a CObject.
36 lines
1,022 B
C++
36 lines
1,022 B
C++
#include <LibAudio/ABuffer.h>
|
|
#include <LibAudio/AClientConnection.h>
|
|
#include <LibAudio/AWavLoader.h>
|
|
#include <LibCore/CEventLoop.h>
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
CEventLoop loop;
|
|
if (argc < 2) {
|
|
fprintf(stderr, "Need a WAV to play\n");
|
|
return 1;
|
|
}
|
|
|
|
auto audio_client = AClientConnection::construct();
|
|
audio_client->handshake();
|
|
AWavLoader loader(argv[1]);
|
|
|
|
printf("\033[34;1m Playing\033[0m: %s\n", argv[1]);
|
|
printf("\033[34;1m Format\033[0m: %u Hz, %u-bit, %s\n",
|
|
loader.sample_rate(),
|
|
loader.bits_per_sample(),
|
|
loader.num_channels() == 1 ? "Mono" : "Stereo");
|
|
printf("\033[34;1mProgress\033[0m: \033[s");
|
|
for (;;) {
|
|
auto samples = loader.get_more_samples();
|
|
if (!samples)
|
|
break;
|
|
printf("\033[u");
|
|
printf("%d/%d", loader.loaded_samples(), loader.total_samples());
|
|
fflush(stdout);
|
|
audio_client->enqueue(*samples);
|
|
}
|
|
printf("\n");
|
|
return 0;
|
|
}
|