2020-02-08 03:04:05 -03:00
|
|
|
/*
|
2020-12-25 08:15:16 -03:00
|
|
|
* Copyright (c) 2020, William McPherson <willmcpherson2@gmail.com>
|
2022-02-10 16:28:48 -03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-02-08 03:04:05 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-08 03:04:05 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "SamplerWidget.h"
|
2020-06-15 02:33:53 -03:00
|
|
|
#include "TrackManager.h"
|
2020-02-08 03:04:05 -03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Button.h>
|
|
|
|
|
#include <LibGUI/FilePicker.h>
|
|
|
|
|
#include <LibGUI/Label.h>
|
|
|
|
|
#include <LibGUI/MessageBox.h>
|
|
|
|
|
#include <LibGUI/Painter.h>
|
|
|
|
|
|
2020-06-15 02:33:53 -03:00
|
|
|
WaveEditor::WaveEditor(TrackManager& track_manager)
|
|
|
|
|
: m_track_manager(track_manager)
|
2020-02-08 03:04:05 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 09:45:10 -03:00
|
|
|
int WaveEditor::sample_to_y(double percentage) const
|
2020-02-08 03:04:05 -03:00
|
|
|
{
|
|
|
|
|
double portion_of_half_height = percentage * ((frame_inner_rect().height() - 1) / 2.0);
|
|
|
|
|
double y = (frame_inner_rect().height() / 2.0) + portion_of_half_height;
|
|
|
|
|
return y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WaveEditor::paint_event(GUI::PaintEvent& event)
|
|
|
|
|
{
|
|
|
|
|
GUI::Frame::paint_event(event);
|
|
|
|
|
|
|
|
|
|
GUI::Painter painter(*this);
|
|
|
|
|
painter.fill_rect(frame_inner_rect(), Color::Black);
|
|
|
|
|
|
2022-07-13 07:44:19 -03:00
|
|
|
// FIXME: This widget currently can't display anything.
|
|
|
|
|
return;
|
2020-02-08 03:04:05 -03:00
|
|
|
}
|
|
|
|
|
|
2020-06-15 02:33:53 -03:00
|
|
|
SamplerWidget::SamplerWidget(TrackManager& track_manager)
|
|
|
|
|
: m_track_manager(track_manager)
|
2020-02-08 03:04:05 -03:00
|
|
|
{
|
2020-03-04 05:43:54 -03:00
|
|
|
set_layout<GUI::VerticalBoxLayout>();
|
Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:
- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
the top margin, the second argument to the left and right margins,
and the third argument to the bottom margin.
2021-08-16 21:11:38 -03:00
|
|
|
layout()->set_margins(10);
|
2020-02-08 03:04:05 -03:00
|
|
|
layout()->set_spacing(10);
|
|
|
|
|
set_fill_with_background_color(true);
|
|
|
|
|
|
2020-02-23 06:57:42 -03:00
|
|
|
m_open_button_and_recorded_sample_name_container = add<GUI::Widget>();
|
2020-03-04 05:43:54 -03:00
|
|
|
m_open_button_and_recorded_sample_name_container->set_layout<GUI::HorizontalBoxLayout>();
|
2020-02-08 03:04:05 -03:00
|
|
|
m_open_button_and_recorded_sample_name_container->layout()->set_spacing(10);
|
2020-12-29 21:23:32 -03:00
|
|
|
m_open_button_and_recorded_sample_name_container->set_fixed_height(24);
|
2020-02-08 03:04:05 -03:00
|
|
|
|
2020-02-23 06:57:42 -03:00
|
|
|
m_open_button = m_open_button_and_recorded_sample_name_container->add<GUI::Button>();
|
2020-12-29 21:23:32 -03:00
|
|
|
m_open_button->set_fixed_size(24, 24);
|
2020-10-30 06:58:27 -03:00
|
|
|
m_open_button->set_focus_policy(GUI::FocusPolicy::TabFocus);
|
2022-07-11 14:32:29 -03:00
|
|
|
m_open_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors());
|
2020-05-12 15:30:33 -03:00
|
|
|
m_open_button->on_click = [this](auto) {
|
2020-07-15 22:52:02 -03:00
|
|
|
Optional<String> open_path = GUI::FilePicker::get_open_filepath(window());
|
2020-02-08 03:04:05 -03:00
|
|
|
if (!open_path.has_value())
|
|
|
|
|
return;
|
2021-09-28 13:01:39 -03:00
|
|
|
// TODO: We don't actually load the sample.
|
2020-02-08 03:04:05 -03:00
|
|
|
m_recorded_sample_name->set_text(open_path.value());
|
|
|
|
|
m_wave_editor->update();
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-23 06:57:42 -03:00
|
|
|
m_recorded_sample_name = m_open_button_and_recorded_sample_name_container->add<GUI::Label>("No sample loaded");
|
2020-02-08 03:04:05 -03:00
|
|
|
m_recorded_sample_name->set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
|
|
|
|
|
2020-06-15 02:33:53 -03:00
|
|
|
m_wave_editor = add<WaveEditor>(m_track_manager);
|
2020-12-29 21:23:32 -03:00
|
|
|
m_wave_editor->set_fixed_height(100);
|
2020-02-08 03:04:05 -03:00
|
|
|
}
|