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
Notes: sideshowbarker 2024-07-17 10:55:40 +09:00
9 changed files with 48 additions and 46 deletions

View File

@ -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))
{

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
*/
#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;
};

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
*/
#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 {

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
*/
#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);

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
*/
@ -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 {

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
*/
@ -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 {

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
*/
#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>

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
*/
#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

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
*/
#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 };