summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>2021-10-31 23:38:04 +0100
committerAndreas Kling <kling@serenityos.org>2021-11-02 22:56:53 +0100
commit52a1ff4d4b519ce290da5c07a22a31b2b85bf45b (patch)
tree5772b8c8204310a14a0fa1f4450807ad017a01f2 /Userland
parent25032a02aab7fda7713c8b1d6546ca48ec2677e5 (diff)
downloadserenity-52a1ff4d4b519ce290da5c07a22a31b2b85bf45b.zip
LibDSP+Piano: Fix visibility of Object-derivative constructors
Derivatives of Core::Object should be constructed through ClassName::construct(), to avoid handling ref-counted objects with refcount zero. Fixing the visibility means that misuses like this are more difficult. This commit is separate from the other Applications/Libraries changes because it required additional adaption of the code. Note that the old code did precisely what these changes try to prevent: Create and handle a ref-counted object with a refcount of zero.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Piano/Track.cpp2
-rw-r--r--Userland/Libraries/LibDSP/Transport.h16
2 files changed, 9 insertions, 9 deletions
diff --git a/Userland/Applications/Piano/Track.cpp b/Userland/Applications/Piano/Track.cpp
index 5727a945f7..1cd6b7be71 100644
--- a/Userland/Applications/Piano/Track.cpp
+++ b/Userland/Applications/Piano/Track.cpp
@@ -15,7 +15,7 @@
Track::Track(const u32& time)
: m_time(time)
- , m_temporary_transport(make_ref_counted<LibDSP::Transport>(120, 4))
+ , m_temporary_transport(LibDSP::Transport::construct(120, 4))
, m_delay(make_ref_counted<LibDSP::Effects::Delay>(m_temporary_transport))
{
set_volume(volume_max);
diff --git a/Userland/Libraries/LibDSP/Transport.h b/Userland/Libraries/LibDSP/Transport.h
index d588ca0334..9fc77da63c 100644
--- a/Userland/Libraries/LibDSP/Transport.h
+++ b/Userland/Libraries/LibDSP/Transport.h
@@ -16,6 +16,14 @@ namespace LibDSP {
class Transport final : public Core::Object {
C_OBJECT(Transport)
public:
+ u32 const& time() const { return m_time; }
+ u16 beats_per_minute() const { return m_beats_per_minute; }
+ double current_second() const { return m_time / m_sample_rate; }
+ double samples_per_measure() const { return (1.0 / m_beats_per_minute) * 60.0 * m_sample_rate; }
+ double sample_rate() const { return m_sample_rate; }
+ 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)
@@ -27,14 +35,6 @@ public:
{
}
- u32 const& time() const { return m_time; }
- u16 beats_per_minute() const { return m_beats_per_minute; }
- double current_second() const { return m_time / m_sample_rate; }
- double samples_per_measure() const { return (1.0 / m_beats_per_minute) * 60.0 * m_sample_rate; }
- double sample_rate() const { return m_sample_rate; }
- double current_measure() const { return m_time / samples_per_measure(); }
-
-private:
u32 m_time { 0 };
u16 const m_beats_per_minute { 0 };
u8 const m_beats_per_measure { 0 };