2021-08-27 16:18:11 +02:00
|
|
|
/*
|
2022-05-11 21:37:55 +02:00
|
|
|
* Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
2021-08-27 16:18:11 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-07-13 12:44:19 +02:00
|
|
|
#include <AK/DisjointChunks.h>
|
2022-07-23 15:51:00 +02:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
2022-05-11 21:37:55 +02:00
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
|
|
|
#include <AK/RefCounted.h>
|
|
|
|
#include <LibDSP/Clip.h>
|
2022-07-13 12:44:19 +02:00
|
|
|
#include <LibDSP/Effects.h>
|
|
|
|
#include <LibDSP/Keyboard.h>
|
2022-05-11 21:37:55 +02:00
|
|
|
#include <LibDSP/Music.h>
|
|
|
|
#include <LibDSP/Processor.h>
|
2022-07-13 12:44:19 +02:00
|
|
|
#include <LibDSP/Synthesizers.h>
|
2021-08-27 16:18:11 +02:00
|
|
|
|
2022-07-17 11:35:31 +02:00
|
|
|
namespace DSP {
|
2021-08-27 16:18:11 +02:00
|
|
|
|
|
|
|
// A track is also known as a channel and serves as a container for the audio pipeline: clips -> processors -> mixing & output
|
2022-05-11 21:37:55 +02:00
|
|
|
class Track : public RefCounted<Track> {
|
2021-08-27 16:18:11 +02:00
|
|
|
public:
|
2022-05-11 21:37:55 +02:00
|
|
|
virtual ~Track() = default;
|
2021-08-27 16:18:11 +02:00
|
|
|
|
|
|
|
virtual bool check_processor_chain_valid() const = 0;
|
|
|
|
bool add_processor(NonnullRefPtr<Processor> new_processor);
|
|
|
|
|
2022-05-11 23:24:46 +02:00
|
|
|
// Creates the current signal of the track by processing current note or audio data through the processing chain.
|
|
|
|
void current_signal(FixedArray<Sample>& output_signal);
|
|
|
|
|
|
|
|
// We are informed of an audio buffer size change. This happens off-audio-thread so we can allocate.
|
|
|
|
ErrorOr<void> resize_internal_buffers_to(size_t buffer_size);
|
2021-08-27 16:18:11 +02:00
|
|
|
|
|
|
|
NonnullRefPtrVector<Processor> const& processor_chain() const { return m_processor_chain; }
|
2022-05-11 21:49:41 +02:00
|
|
|
NonnullRefPtr<Transport const> transport() const { return m_transport; }
|
2022-07-23 15:51:00 +02:00
|
|
|
NonnullRefPtr<DSP::Effects::Mastering> track_mastering() { return m_track_mastering; }
|
2021-08-27 16:18:11 +02:00
|
|
|
|
2022-07-13 12:44:19 +02:00
|
|
|
// FIXME: These two getters are temporary until we have dynamic processor UI
|
|
|
|
NonnullRefPtr<Synthesizers::Classic> synth();
|
|
|
|
NonnullRefPtr<Effects::Delay> delay();
|
|
|
|
|
2021-08-27 16:18:11 +02:00
|
|
|
protected:
|
2022-07-13 12:44:19 +02:00
|
|
|
Track(NonnullRefPtr<Transport> transport, NonnullRefPtr<Keyboard> keyboard)
|
2022-05-11 21:37:55 +02:00
|
|
|
: m_transport(move(transport))
|
2022-07-23 15:51:00 +02:00
|
|
|
, m_track_mastering(make_ref_counted<Effects::Mastering>(m_transport))
|
2022-07-13 12:44:19 +02:00
|
|
|
, m_keyboard(move(keyboard))
|
2022-05-11 21:37:55 +02:00
|
|
|
{
|
|
|
|
}
|
2021-08-27 16:18:11 +02:00
|
|
|
bool check_processor_chain_valid_with_initial_type(SignalType initial_type) const;
|
|
|
|
|
|
|
|
// Subclasses override to provide the base signal to the processing chain
|
2021-09-28 17:54:48 +02:00
|
|
|
virtual void compute_current_clips_signal() = 0;
|
2021-08-27 16:18:11 +02:00
|
|
|
|
|
|
|
NonnullRefPtrVector<Processor> m_processor_chain;
|
2021-09-28 17:54:48 +02:00
|
|
|
NonnullRefPtr<Transport> m_transport;
|
2022-07-23 15:51:00 +02:00
|
|
|
NonnullRefPtr<Effects::Mastering> m_track_mastering;
|
2022-07-13 12:44:19 +02:00
|
|
|
NonnullRefPtr<Keyboard> m_keyboard;
|
2021-09-28 17:54:48 +02:00
|
|
|
// The current signal is stored here, to prevent unnecessary reallocation.
|
2022-05-11 23:24:46 +02:00
|
|
|
Signal m_current_signal { FixedArray<Sample> {} };
|
|
|
|
|
|
|
|
// These are so that we don't have to allocate a secondary buffer in current_signal().
|
|
|
|
// A sample buffer possibly used by the processor chain.
|
|
|
|
Signal m_secondary_sample_buffer { FixedArray<Sample> {} };
|
|
|
|
// A note buffer possibly used by the processor chain.
|
|
|
|
Signal m_secondary_note_buffer { RollNotes {} };
|
2021-08-27 16:18:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class NoteTrack final : public Track {
|
|
|
|
public:
|
|
|
|
virtual ~NoteTrack() override = default;
|
|
|
|
|
2022-07-13 12:44:19 +02:00
|
|
|
NoteTrack(NonnullRefPtr<Transport> transport, NonnullRefPtr<Keyboard> keyboard)
|
|
|
|
: Track(move(transport), move(keyboard))
|
|
|
|
{
|
|
|
|
m_current_signal = RollNotes {};
|
|
|
|
}
|
|
|
|
|
2021-08-27 16:18:11 +02:00
|
|
|
bool check_processor_chain_valid() const override;
|
2022-07-13 12:44:19 +02:00
|
|
|
Span<NonnullRefPtr<NoteClip> const> notes() const { return m_clips.span(); }
|
|
|
|
|
|
|
|
void set_note(RollNote note);
|
|
|
|
void remove_note(RollNote note);
|
|
|
|
|
|
|
|
void add_clip(u32 start_time, u32 end_time);
|
2021-08-27 16:18:11 +02:00
|
|
|
|
|
|
|
protected:
|
2021-11-15 22:27:28 +01:00
|
|
|
void compute_current_clips_signal() override;
|
2021-08-27 16:18:11 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
NonnullRefPtrVector<NoteClip> m_clips;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioTrack final : public Track {
|
|
|
|
public:
|
|
|
|
virtual ~AudioTrack() override = default;
|
|
|
|
|
2022-07-13 12:44:19 +02:00
|
|
|
AudioTrack(NonnullRefPtr<Transport> transport, NonnullRefPtr<Keyboard> keyboard)
|
|
|
|
: Track(move(transport), move(keyboard))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-27 16:18:11 +02:00
|
|
|
bool check_processor_chain_valid() const override;
|
|
|
|
NonnullRefPtrVector<AudioClip> const& clips() const { return m_clips; }
|
|
|
|
|
|
|
|
protected:
|
2021-11-15 22:27:28 +01:00
|
|
|
void compute_current_clips_signal() override;
|
2021-08-27 16:18:11 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
NonnullRefPtrVector<AudioClip> m_clips;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|