From 4a6ebb8bebf73ee14aea873396bfc26a388bb762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Wed, 11 May 2022 21:37:55 +0200 Subject: [PATCH] LibDSP: Refactor OOP non-functionally * Don't inherit from Core::Object everywhere, that's overkill. Use RefCounted instead. * Change some constructor visibilites to facilitate the above. * default-implement all virtual destructors if possible. * Drive-by include hygiene. --- Userland/Applications/Piano/Track.cpp | 2 +- Userland/Libraries/LibDSP/Clip.h | 20 +++++++-------- Userland/Libraries/LibDSP/Effects.h | 8 +++--- Userland/Libraries/LibDSP/Processor.h | 14 +++++------ .../Libraries/LibDSP/ProcessorParameter.h | 5 ++-- Userland/Libraries/LibDSP/Synthesizers.cpp | 5 ++-- Userland/Libraries/LibDSP/Synthesizers.h | 4 +-- Userland/Libraries/LibDSP/Track.h | 25 ++++++++++--------- Userland/Libraries/LibDSP/Transport.h | 11 ++++---- 9 files changed, 48 insertions(+), 46 deletions(-) diff --git a/Userland/Applications/Piano/Track.cpp b/Userland/Applications/Piano/Track.cpp index f2cd6494a3..a074e89c3d 100644 --- a/Userland/Applications/Piano/Track.cpp +++ b/Userland/Applications/Piano/Track.cpp @@ -18,7 +18,7 @@ Track::Track(u32 const& time) : m_time(time) - , m_temporary_transport(LibDSP::Transport::construct(120, 4)) + , m_temporary_transport(make_ref_counted(120, 4)) , m_delay(make_ref_counted(m_temporary_transport)) , m_synth(make_ref_counted(m_temporary_transport)) { diff --git a/Userland/Libraries/LibDSP/Clip.h b/Userland/Libraries/LibDSP/Clip.h index 65e6a449e8..38a1dad17d 100644 --- a/Userland/Libraries/LibDSP/Clip.h +++ b/Userland/Libraries/LibDSP/Clip.h @@ -1,27 +1,21 @@ /* - * Copyright (c) 2021, kleines Filmröllchen + * Copyright (c) 2021-2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "Music.h" +#include #include #include -#include +#include namespace LibDSP { // A clip is a self-contained snippet of notes or audio that can freely move inside and in between tracks. -class Clip : public Core::Object { - C_OBJECT_ABSTRACT(Clip) +class Clip : public RefCounted { public: - Clip(u32 start, u32 length) - : m_start(start) - , m_length(length) - { - } virtual ~Clip() = default; u32 start() const { return m_start; } @@ -29,6 +23,12 @@ public: u32 end() const { return m_start + m_length; } protected: + Clip(u32 start, u32 length) + : m_start(start) + , m_length(length) + { + } + u32 m_start; u32 m_length; }; diff --git a/Userland/Libraries/LibDSP/Effects.h b/Userland/Libraries/LibDSP/Effects.h index ebc589f6e5..10ac20ac87 100644 --- a/Userland/Libraries/LibDSP/Effects.h +++ b/Userland/Libraries/LibDSP/Effects.h @@ -1,15 +1,15 @@ /* - * Copyright (c) 2021, kleines Filmröllchen + * Copyright (c) 2021-2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "Processor.h" -#include "ProcessorParameter.h" -#include "Transport.h" #include +#include +#include +#include namespace LibDSP::Effects { diff --git a/Userland/Libraries/LibDSP/Processor.h b/Userland/Libraries/LibDSP/Processor.h index c490a23bfe..f08421b9be 100644 --- a/Userland/Libraries/LibDSP/Processor.h +++ b/Userland/Libraries/LibDSP/Processor.h @@ -1,15 +1,18 @@ /* - * Copyright (c) 2021, kleines Filmröllchen + * Copyright (c) 2021-2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include +#include +#include #include +#include #include -#include #include #include #include @@ -17,13 +20,10 @@ namespace LibDSP { // A processor processes notes or audio into notes or audio. Processors are e.g. samplers, synthesizers, effects, arpeggiators etc. -class Processor : public Core::Object { - C_OBJECT_ABSTRACT(Processor); +class Processor : public RefCounted { public: - virtual ~Processor() - { - } + virtual ~Processor() = default; Signal process(Signal const& input_signal) { VERIFY(input_signal.type() == m_input_type); diff --git a/Userland/Libraries/LibDSP/ProcessorParameter.h b/Userland/Libraries/LibDSP/ProcessorParameter.h index 5d0d06d349..e65884476c 100644 --- a/Userland/Libraries/LibDSP/ProcessorParameter.h +++ b/Userland/Libraries/LibDSP/ProcessorParameter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, kleines Filmröllchen + * Copyright (c) 2021-2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ @@ -9,8 +9,9 @@ #include #include #include +#include +#include #include -#include #include namespace LibDSP { diff --git a/Userland/Libraries/LibDSP/Synthesizers.cpp b/Userland/Libraries/LibDSP/Synthesizers.cpp index 5c8b1dd4b8..561cd474ce 100644 --- a/Userland/Libraries/LibDSP/Synthesizers.cpp +++ b/Userland/Libraries/LibDSP/Synthesizers.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, kleines Filmröllchen . + * Copyright (c) 2021-2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,11 +7,12 @@ #include #include #include +#include +#include #include #include #include #include -#include namespace LibDSP::Synthesizers { diff --git a/Userland/Libraries/LibDSP/Synthesizers.h b/Userland/Libraries/LibDSP/Synthesizers.h index df4c366ffa..f0133f3bb3 100644 --- a/Userland/Libraries/LibDSP/Synthesizers.h +++ b/Userland/Libraries/LibDSP/Synthesizers.h @@ -1,13 +1,13 @@ /* - * Copyright (c) 2021, kleines Filmröllchen . + * Copyright (c) 2021-2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "LibDSP/Music.h" #include +#include #include #include #include diff --git a/Userland/Libraries/LibDSP/Track.h b/Userland/Libraries/LibDSP/Track.h index 995449eb33..bd9d614218 100644 --- a/Userland/Libraries/LibDSP/Track.h +++ b/Userland/Libraries/LibDSP/Track.h @@ -1,27 +1,24 @@ /* - * Copyright (c) 2021, kleines Filmröllchen + * Copyright (c) 2021-2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "Clip.h" -#include "Music.h" -#include "Processor.h" -#include +#include +#include +#include +#include +#include +#include namespace LibDSP { // A track is also known as a channel and serves as a container for the audio pipeline: clips -> processors -> mixing & output -class Track : public Core::Object { - C_OBJECT_ABSTRACT(Track) +class Track : public RefCounted { public: - Track(NonnullRefPtr transport) - : m_transport(move(transport)) - { - } - virtual ~Track() override = default; + virtual ~Track() = default; virtual bool check_processor_chain_valid() const = 0; bool add_processor(NonnullRefPtr new_processor); @@ -33,6 +30,10 @@ public: NonnullRefPtr const transport() const { return m_transport; } protected: + Track(NonnullRefPtr transport) + : m_transport(move(transport)) + { + } bool check_processor_chain_valid_with_initial_type(SignalType initial_type) const; // Subclasses override to provide the base signal to the processing chain diff --git a/Userland/Libraries/LibDSP/Transport.h b/Userland/Libraries/LibDSP/Transport.h index caf9ee305f..45f1b8af61 100644 --- a/Userland/Libraries/LibDSP/Transport.h +++ b/Userland/Libraries/LibDSP/Transport.h @@ -1,20 +1,19 @@ /* - * Copyright (c) 2021, kleines Filmröllchen + * Copyright (c) 2021-2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "Music.h" +#include #include -#include +#include namespace LibDSP { // The DAW-wide timekeeper and synchronizer -class Transport final : public Core::Object { - C_OBJECT(Transport) +class Transport final : public RefCounted { public: constexpr u32& time() { return m_time; } constexpr u16 beats_per_minute() const { return m_beats_per_minute; } @@ -24,7 +23,6 @@ public: constexpr double ms_sample_rate() const { return m_sample_rate / 1000.; } constexpr double current_measure() const { return m_time / samples_per_measure(); } -private: Transport(u16 beats_per_minute, u8 beats_per_measure, u32 sample_rate) : m_beats_per_minute(beats_per_minute) , m_beats_per_measure(beats_per_measure) @@ -36,6 +34,7 @@ private: { } +private: // FIXME: You can't make more than 24h of (48kHz) music with this. // But do you want to, really? :^) u32 m_time { 0 };