diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-05-11 21:37:55 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-05-13 00:47:26 +0200 |
commit | 4a6ebb8bebf73ee14aea873396bfc26a388bb762 (patch) | |
tree | 3c1265996150af252da73100dcd50311015e147a /Userland | |
parent | 3cfa9b63b5fbcd6688c921c7c9b35f95030e4e8b (diff) | |
download | serenity-4a6ebb8bebf73ee14aea873396bfc26a388bb762.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Applications/Piano/Track.cpp | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/Clip.h | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/Effects.h | 8 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/Processor.h | 14 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/ProcessorParameter.h | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/Synthesizers.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/Synthesizers.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibDSP/Track.h | 25 | ||||
-rw-r--r-- | 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<LibDSP::Transport>(120, 4)) , m_delay(make_ref_counted<LibDSP::Effects::Delay>(m_temporary_transport)) , m_synth(make_ref_counted<LibDSP::Synthesizers::Classic>(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 <filmroellchen@serenityos.org> + * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "Music.h" +#include <AK/RefCounted.h> #include <AK/SinglyLinkedList.h> #include <AK/Types.h> -#include <LibCore/Object.h> +#include <LibDSP/Music.h> 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<Clip> { 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 <filmroellchen@serenityos.org> + * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "Processor.h" -#include "ProcessorParameter.h" -#include "Transport.h" #include <AK/Types.h> +#include <LibDSP/Processor.h> +#include <LibDSP/ProcessorParameter.h> +#include <LibDSP/Transport.h> 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 <filmroellchen@serenityos.org> + * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include <AK/Function.h> #include <AK/Noncopyable.h> +#include <AK/RefCounted.h> +#include <AK/RefPtr.h> #include <AK/StdLibExtras.h> +#include <AK/String.h> #include <AK/Types.h> -#include <LibCore/Object.h> #include <LibDSP/Music.h> #include <LibDSP/ProcessorParameter.h> #include <LibDSP/Transport.h> @@ -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<Processor> { 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 <filmroellchen@serenityos.org> + * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -9,8 +9,9 @@ #include <AK/FixedPoint.h> #include <AK/Format.h> #include <AK/Forward.h> +#include <AK/Function.h> +#include <AK/String.h> #include <AK/Types.h> -#include <LibCore/Object.h> #include <LibDSP/Music.h> 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 <filmroellchen@serenityos.org>. + * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,11 +7,12 @@ #include <AK/HashMap.h> #include <AK/Math.h> #include <AK/Random.h> +#include <AK/RefPtr.h> +#include <AK/StdLibExtras.h> #include <LibAudio/Sample.h> #include <LibDSP/Envelope.h> #include <LibDSP/Processor.h> #include <LibDSP/Synthesizers.h> -#include <math.h> 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 <filmroellchen@serenityos.org>. + * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "LibDSP/Music.h" #include <AK/SinglyLinkedList.h> +#include <LibDSP/Music.h> #include <LibDSP/Processor.h> #include <LibDSP/ProcessorParameter.h> #include <LibDSP/Transport.h> 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 <filmroellchen@serenityos.org> + * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "Clip.h" -#include "Music.h" -#include "Processor.h" -#include <LibCore/Object.h> +#include <AK/NonnullRefPtrVector.h> +#include <AK/RefCounted.h> +#include <AK/RefPtr.h> +#include <LibDSP/Clip.h> +#include <LibDSP/Music.h> +#include <LibDSP/Processor.h> 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<Track> { public: - Track(NonnullRefPtr<Transport> transport) - : m_transport(move(transport)) - { - } - virtual ~Track() override = default; + virtual ~Track() = default; virtual bool check_processor_chain_valid() const = 0; bool add_processor(NonnullRefPtr<Processor> new_processor); @@ -33,6 +30,10 @@ public: NonnullRefPtr<Transport> const transport() const { return m_transport; } protected: + Track(NonnullRefPtr<Transport> 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 <filmroellchen@serenityos.org> + * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include "Music.h" +#include <AK/RefCounted.h> #include <AK/Types.h> -#include <LibCore/Object.h> +#include <LibDSP/Music.h> namespace LibDSP { // The DAW-wide timekeeper and synchronizer -class Transport final : public Core::Object { - C_OBJECT(Transport) +class Transport final : public RefCounted<Transport> { 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 }; |