mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:57:35 +00:00
Piano: Allow multiple tracks internally
This commit adds multi-track functionality without exposing it to the user. All I really did was rename AudioEngine to Track and allow more than one Track in TrackManager. A lot of the changes are just changing widgets to take a TrackManager and use current_track(). The TrackManager creates Tracks and gives them a read-only reference to the global time value. When the TrackManager wants to fill a sample in the buffer (in fill_buffer()), it calls fill_sample() on each Track. The delay code is slightly different - a Track will fill its m_delay_buffer with the sample it just created rather than the most recent sample in the buffer (which used to be the same thing). TrackManager manages the current octave. Other than those few things, this is a pretty basic separation of concerns.
This commit is contained in:
parent
db5b28b78e
commit
ee52572ca1
18 changed files with 371 additions and 247 deletions
|
@ -26,7 +26,7 @@
|
|||
*/
|
||||
|
||||
#include "RollWidget.h"
|
||||
#include "AudioEngine.h"
|
||||
#include "TrackManager.h"
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/ScrollBar.h>
|
||||
#include <math.h>
|
||||
|
@ -37,8 +37,8 @@ constexpr int roll_height = note_count * note_height;
|
|||
constexpr int horizontal_scroll_sensitivity = 20;
|
||||
constexpr int max_zoom = 1 << 8;
|
||||
|
||||
RollWidget::RollWidget(AudioEngine& audio_engine)
|
||||
: m_audio_engine(audio_engine)
|
||||
RollWidget::RollWidget(TrackManager& track_manager)
|
||||
: m_track_manager(track_manager)
|
||||
{
|
||||
set_should_hide_unnecessary_scrollbars(true);
|
||||
set_content_size({ 0, roll_height });
|
||||
|
@ -117,7 +117,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event)
|
|||
painter.translate(horizontal_note_offset_remainder, note_offset_remainder);
|
||||
|
||||
for (int note = note_count - (note_offset + notes_to_paint); note <= (note_count - 1) - note_offset; ++note) {
|
||||
for (auto roll_note : m_audio_engine.roll_notes(note)) {
|
||||
for (auto roll_note : m_track_manager.current_track().roll_notes(note)) {
|
||||
int x = m_roll_width * (static_cast<double>(roll_note.on_sample) / roll_length);
|
||||
int width = m_roll_width * (static_cast<double>(roll_note.length()) / roll_length);
|
||||
if (x + width < x_offset || x > x_offset + widget_inner_rect().width())
|
||||
|
@ -134,7 +134,7 @@ void RollWidget::paint_event(GUI::PaintEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
int x = m_roll_width * (static_cast<double>(m_audio_engine.time()) / roll_length);
|
||||
int x = m_roll_width * (static_cast<double>(m_track_manager.time()) / roll_length);
|
||||
if (x > x_offset && x <= x_offset + widget_inner_rect().width())
|
||||
painter.draw_line({ x, 0 }, { x, roll_height }, Gfx::Color::Black);
|
||||
|
||||
|
@ -164,7 +164,7 @@ void RollWidget::mousedown_event(GUI::MouseEvent& event)
|
|||
int note = (note_count - 1) - y;
|
||||
u32 on_sample = roll_length * (static_cast<double>(x) / m_num_notes);
|
||||
u32 off_sample = (roll_length * (static_cast<double>(x + 1) / m_num_notes)) - 1;
|
||||
m_audio_engine.set_roll_note(note, on_sample, off_sample);
|
||||
m_track_manager.current_track().set_roll_note(note, on_sample, off_sample);
|
||||
|
||||
update();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue