summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorasynts <asynts@gmail.com>2020-09-06 21:40:46 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-08 14:01:21 +0200
commit9c83d6ff468870c58f2a81673b29d96106f543fb (patch)
tree0a66b1d4477cae34d806360daa739cd3a4bd7e45 /Applications
parent76e37e8c968e62abf597afdd4554714c6d40ef92 (diff)
downloadserenity-9c83d6ff468870c58f2a81673b29d96106f543fb.zip
Refactor: Replace usages of FixedArray with Array.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/Piano/Track.h1
-rw-r--r--Applications/Piano/TrackManager.cpp10
-rw-r--r--Applications/Piano/TrackManager.h13
-rw-r--r--Applications/Piano/main.cpp3
4 files changed, 14 insertions, 13 deletions
diff --git a/Applications/Piano/Track.h b/Applications/Piano/Track.h
index 276e7e8bdb..0acca429b0 100644
--- a/Applications/Piano/Track.h
+++ b/Applications/Piano/Track.h
@@ -28,7 +28,6 @@
#pragma once
#include "Music.h"
-#include <AK/FixedArray.h>
#include <AK/Noncopyable.h>
#include <AK/SinglyLinkedList.h>
#include <LibAudio/Buffer.h>
diff --git a/Applications/Piano/TrackManager.cpp b/Applications/Piano/TrackManager.cpp
index 18ae568d09..5aa1856a11 100644
--- a/Applications/Piano/TrackManager.cpp
+++ b/Applications/Piano/TrackManager.cpp
@@ -36,7 +36,7 @@ TrackManager::~TrackManager()
{
}
-void TrackManager::fill_buffer(FixedArray<Sample>& buffer)
+void TrackManager::fill_buffer(Span<Sample> buffer)
{
memset(buffer.data(), 0, buffer_size);
@@ -51,8 +51,8 @@ void TrackManager::fill_buffer(FixedArray<Sample>& buffer)
}
}
- memcpy(m_back_buffer_ptr->data(), buffer.data(), buffer_size);
- swap(m_front_buffer_ptr, m_back_buffer_ptr);
+ memcpy(m_current_back_buffer.data(), buffer.data(), buffer_size);
+ swap(m_current_front_buffer, m_current_back_buffer);
}
void TrackManager::reset()
@@ -60,8 +60,8 @@ void TrackManager::reset()
memset(m_front_buffer.data(), 0, buffer_size);
memset(m_back_buffer.data(), 0, buffer_size);
- m_front_buffer_ptr = &m_front_buffer;
- m_back_buffer_ptr = &m_back_buffer;
+ m_current_front_buffer = m_front_buffer.span();
+ m_current_back_buffer = m_back_buffer.span();
m_time = 0;
diff --git a/Applications/Piano/TrackManager.h b/Applications/Piano/TrackManager.h
index 79331a5586..70cb661bc4 100644
--- a/Applications/Piano/TrackManager.h
+++ b/Applications/Piano/TrackManager.h
@@ -29,6 +29,7 @@
#include "Music.h"
#include "Track.h"
+#include <AK/Array.h>
#include <AK/Noncopyable.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/Vector.h>
@@ -42,12 +43,12 @@ public:
~TrackManager();
Track& current_track() { return *m_tracks[m_current_track]; }
- const FixedArray<Sample>& buffer() const { return *m_front_buffer_ptr; }
+ Span<const Sample> buffer() const { return m_current_front_buffer; }
int octave() const { return m_octave; }
int octave_base() const { return (m_octave - octave_min) * 12; }
int time() const { return m_time; }
- void fill_buffer(FixedArray<Sample>& buffer);
+ void fill_buffer(Span<Sample>);
void reset();
void set_should_loop(bool b) { m_should_loop = b; }
void set_note_current_octave(int note, Switch);
@@ -60,10 +61,10 @@ private:
Vector<NonnullOwnPtr<Track>> m_tracks;
size_t m_current_track { 0 };
- FixedArray<Sample> m_front_buffer { sample_count };
- FixedArray<Sample> m_back_buffer { sample_count };
- FixedArray<Sample>* m_front_buffer_ptr { &m_front_buffer };
- FixedArray<Sample>* m_back_buffer_ptr { &m_back_buffer };
+ Array<Sample, sample_count> m_front_buffer;
+ Array<Sample, sample_count> m_back_buffer;
+ Span<Sample> m_current_front_buffer { m_front_buffer.span() };
+ Span<Sample> m_current_back_buffer { m_back_buffer.span() };
int m_octave { 4 };
diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp
index cfcee1a709..5666f7aa20 100644
--- a/Applications/Piano/main.cpp
+++ b/Applications/Piano/main.cpp
@@ -27,6 +27,7 @@
#include "MainWidget.h"
#include "TrackManager.h"
+#include <AK/Array.h>
#include <LibAudio/ClientConnection.h>
#include <LibAudio/WavWriter.h>
#include <LibCore/EventLoop.h>
@@ -69,7 +70,7 @@ int main(int argc, char** argv)
return 1;
}
- FixedArray<Sample> buffer(sample_count);
+ Array<Sample, sample_count> buffer;
for (;;) {
track_manager.fill_buffer(buffer);
audio->write(reinterpret_cast<u8*>(buffer.data()), buffer_size);