1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:07:36 +00:00

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.
This commit is contained in:
kleines Filmröllchen 2022-05-11 21:37:55 +02:00 committed by Linus Groh
parent 3cfa9b63b5
commit 4a6ebb8beb
9 changed files with 48 additions and 46 deletions

View file

@ -18,7 +18,7 @@
Track::Track(u32 const& time) Track::Track(u32 const& time)
: m_time(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_delay(make_ref_counted<LibDSP::Effects::Delay>(m_temporary_transport))
, m_synth(make_ref_counted<LibDSP::Synthesizers::Classic>(m_temporary_transport)) , m_synth(make_ref_counted<LibDSP::Synthesizers::Classic>(m_temporary_transport))
{ {

View file

@ -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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
#pragma once #pragma once
#include "Music.h" #include <AK/RefCounted.h>
#include <AK/SinglyLinkedList.h> #include <AK/SinglyLinkedList.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <LibCore/Object.h> #include <LibDSP/Music.h>
namespace LibDSP { namespace LibDSP {
// A clip is a self-contained snippet of notes or audio that can freely move inside and in between tracks. // 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 { class Clip : public RefCounted<Clip> {
C_OBJECT_ABSTRACT(Clip)
public: public:
Clip(u32 start, u32 length)
: m_start(start)
, m_length(length)
{
}
virtual ~Clip() = default; virtual ~Clip() = default;
u32 start() const { return m_start; } u32 start() const { return m_start; }
@ -29,6 +23,12 @@ public:
u32 end() const { return m_start + m_length; } u32 end() const { return m_start + m_length; }
protected: protected:
Clip(u32 start, u32 length)
: m_start(start)
, m_length(length)
{
}
u32 m_start; u32 m_start;
u32 m_length; u32 m_length;
}; };

View file

@ -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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
#pragma once #pragma once
#include "Processor.h"
#include "ProcessorParameter.h"
#include "Transport.h"
#include <AK/Types.h> #include <AK/Types.h>
#include <LibDSP/Processor.h>
#include <LibDSP/ProcessorParameter.h>
#include <LibDSP/Transport.h>
namespace LibDSP::Effects { namespace LibDSP::Effects {

View file

@ -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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
#pragma once #pragma once
#include <AK/Function.h>
#include <AK/Noncopyable.h> #include <AK/Noncopyable.h>
#include <AK/RefCounted.h>
#include <AK/RefPtr.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <LibCore/Object.h>
#include <LibDSP/Music.h> #include <LibDSP/Music.h>
#include <LibDSP/ProcessorParameter.h> #include <LibDSP/ProcessorParameter.h>
#include <LibDSP/Transport.h> #include <LibDSP/Transport.h>
@ -17,13 +20,10 @@
namespace LibDSP { namespace LibDSP {
// A processor processes notes or audio into notes or audio. Processors are e.g. samplers, synthesizers, effects, arpeggiators etc. // A processor processes notes or audio into notes or audio. Processors are e.g. samplers, synthesizers, effects, arpeggiators etc.
class Processor : public Core::Object { class Processor : public RefCounted<Processor> {
C_OBJECT_ABSTRACT(Processor);
public: public:
virtual ~Processor() virtual ~Processor() = default;
{
}
Signal process(Signal const& input_signal) Signal process(Signal const& input_signal)
{ {
VERIFY(input_signal.type() == m_input_type); VERIFY(input_signal.type() == m_input_type);

View file

@ -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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -9,8 +9,9 @@
#include <AK/FixedPoint.h> #include <AK/FixedPoint.h>
#include <AK/Format.h> #include <AK/Format.h>
#include <AK/Forward.h> #include <AK/Forward.h>
#include <AK/Function.h>
#include <AK/String.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <LibCore/Object.h>
#include <LibDSP/Music.h> #include <LibDSP/Music.h>
namespace LibDSP { namespace LibDSP {

View file

@ -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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -7,11 +7,12 @@
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/Math.h> #include <AK/Math.h>
#include <AK/Random.h> #include <AK/Random.h>
#include <AK/RefPtr.h>
#include <AK/StdLibExtras.h>
#include <LibAudio/Sample.h> #include <LibAudio/Sample.h>
#include <LibDSP/Envelope.h> #include <LibDSP/Envelope.h>
#include <LibDSP/Processor.h> #include <LibDSP/Processor.h>
#include <LibDSP/Synthesizers.h> #include <LibDSP/Synthesizers.h>
#include <math.h>
namespace LibDSP::Synthesizers { namespace LibDSP::Synthesizers {

View file

@ -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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
#pragma once #pragma once
#include "LibDSP/Music.h"
#include <AK/SinglyLinkedList.h> #include <AK/SinglyLinkedList.h>
#include <LibDSP/Music.h>
#include <LibDSP/Processor.h> #include <LibDSP/Processor.h>
#include <LibDSP/ProcessorParameter.h> #include <LibDSP/ProcessorParameter.h>
#include <LibDSP/Transport.h> #include <LibDSP/Transport.h>

View file

@ -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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
#pragma once #pragma once
#include "Clip.h" #include <AK/NonnullRefPtrVector.h>
#include "Music.h" #include <AK/RefCounted.h>
#include "Processor.h" #include <AK/RefPtr.h>
#include <LibCore/Object.h> #include <LibDSP/Clip.h>
#include <LibDSP/Music.h>
#include <LibDSP/Processor.h>
namespace LibDSP { namespace LibDSP {
// A track is also known as a channel and serves as a container for the audio pipeline: clips -> processors -> mixing & output // 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 { class Track : public RefCounted<Track> {
C_OBJECT_ABSTRACT(Track)
public: public:
Track(NonnullRefPtr<Transport> transport) virtual ~Track() = default;
: m_transport(move(transport))
{
}
virtual ~Track() override = default;
virtual bool check_processor_chain_valid() const = 0; virtual bool check_processor_chain_valid() const = 0;
bool add_processor(NonnullRefPtr<Processor> new_processor); bool add_processor(NonnullRefPtr<Processor> new_processor);
@ -33,6 +30,10 @@ public:
NonnullRefPtr<Transport> const transport() const { return m_transport; } NonnullRefPtr<Transport> const transport() const { return m_transport; }
protected: protected:
Track(NonnullRefPtr<Transport> transport)
: m_transport(move(transport))
{
}
bool check_processor_chain_valid_with_initial_type(SignalType initial_type) const; bool check_processor_chain_valid_with_initial_type(SignalType initial_type) const;
// Subclasses override to provide the base signal to the processing chain // Subclasses override to provide the base signal to the processing chain

View file

@ -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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
#pragma once #pragma once
#include "Music.h" #include <AK/RefCounted.h>
#include <AK/Types.h> #include <AK/Types.h>
#include <LibCore/Object.h> #include <LibDSP/Music.h>
namespace LibDSP { namespace LibDSP {
// The DAW-wide timekeeper and synchronizer // The DAW-wide timekeeper and synchronizer
class Transport final : public Core::Object { class Transport final : public RefCounted<Transport> {
C_OBJECT(Transport)
public: public:
constexpr u32& time() { return m_time; } constexpr u32& time() { return m_time; }
constexpr u16 beats_per_minute() const { return m_beats_per_minute; } 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 ms_sample_rate() const { return m_sample_rate / 1000.; }
constexpr double current_measure() const { return m_time / samples_per_measure(); } constexpr double current_measure() const { return m_time / samples_per_measure(); }
private:
Transport(u16 beats_per_minute, u8 beats_per_measure, u32 sample_rate) Transport(u16 beats_per_minute, u8 beats_per_measure, u32 sample_rate)
: m_beats_per_minute(beats_per_minute) : m_beats_per_minute(beats_per_minute)
, m_beats_per_measure(beats_per_measure) , 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. // FIXME: You can't make more than 24h of (48kHz) music with this.
// But do you want to, really? :^) // But do you want to, really? :^)
u32 m_time { 0 }; u32 m_time { 0 };