2020-01-30 19:02:45 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* Copyright (c) 2019-2020, William McPherson <willmcpherson2@gmail.com>
|
2022-02-10 22:28:48 +03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-30 19:02:45 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-30 19:02:45 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "KnobsWidget.h"
|
|
|
|
#include "MainWidget.h"
|
2022-07-23 16:52:50 +03:00
|
|
|
#include "ProcessorParameterWidget/ParameterWidget.h"
|
2020-06-15 08:33:53 +03:00
|
|
|
#include "TrackManager.h"
|
2021-09-28 19:01:39 +03:00
|
|
|
#include <LibDSP/ProcessorParameter.h>
|
2020-02-06 22:33:02 +03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
#include <LibGUI/Label.h>
|
|
|
|
#include <LibGUI/Slider.h>
|
2021-08-27 17:20:09 +03:00
|
|
|
#include <LibGfx/Orientation.h>
|
2020-01-30 19:02:45 +03:00
|
|
|
|
2020-06-15 08:33:53 +03:00
|
|
|
KnobsWidget::KnobsWidget(TrackManager& track_manager, MainWidget& main_widget)
|
|
|
|
: m_track_manager(track_manager)
|
2020-01-30 19:02:45 +03:00
|
|
|
, m_main_widget(main_widget)
|
|
|
|
{
|
2022-07-23 16:52:50 +03:00
|
|
|
set_layout<GUI::HorizontalBoxLayout>();
|
2020-01-30 19:02:45 +03:00
|
|
|
set_fill_with_background_color(true);
|
|
|
|
|
2022-07-23 16:52:50 +03:00
|
|
|
m_octave_container = add<GUI::Widget>();
|
|
|
|
m_octave_container->set_layout<GUI::VerticalBoxLayout>();
|
|
|
|
m_octave_container->add<GUI::Label>("Octave");
|
2022-12-04 21:02:33 +03:00
|
|
|
m_octave_value = m_octave_container->add<GUI::Label>(DeprecatedString::number(m_track_manager.keyboard()->virtual_keyboard_octave()));
|
2020-01-30 19:02:45 +03:00
|
|
|
|
2020-03-20 00:38:54 +03:00
|
|
|
// FIXME: Implement vertical flipping in GUI::Slider, not here.
|
2022-07-23 16:52:50 +03:00
|
|
|
m_octave_knob = m_octave_container->add<GUI::VerticalSlider>();
|
2020-01-30 19:02:45 +03:00
|
|
|
m_octave_knob->set_tooltip("Z: octave down, X: octave up");
|
|
|
|
m_octave_knob->set_range(octave_min - 1, octave_max - 1);
|
2022-05-14 02:11:23 +03:00
|
|
|
m_octave_knob->set_value((octave_max - 1) - (m_track_manager.keyboard()->virtual_keyboard_octave() - 1));
|
2021-04-21 21:32:21 +03:00
|
|
|
m_octave_knob->set_step(1);
|
2020-12-30 17:11:46 +03:00
|
|
|
m_octave_knob->on_change = [this](int value) {
|
2020-01-30 19:02:45 +03:00
|
|
|
int new_octave = octave_max - value;
|
2020-06-17 12:34:25 +03:00
|
|
|
if (m_change_underlying)
|
2020-07-06 23:52:29 +03:00
|
|
|
m_main_widget.set_octave_and_ensure_note_change(new_octave);
|
2022-05-14 02:11:23 +03:00
|
|
|
VERIFY(new_octave == m_track_manager.keyboard()->virtual_keyboard_octave());
|
2022-12-04 21:02:33 +03:00
|
|
|
m_octave_value->set_text(DeprecatedString::number(new_octave));
|
2020-01-30 19:02:45 +03:00
|
|
|
};
|
|
|
|
|
2022-07-23 16:52:50 +03:00
|
|
|
for (auto& parameter : m_track_manager.current_track()->track_mastering()->parameters())
|
|
|
|
m_parameter_widgets.append(add<ProcessorParameterWidget>(parameter));
|
|
|
|
|
|
|
|
for (auto& parameter : m_track_manager.current_track()->synth()->parameters())
|
|
|
|
m_parameter_widgets.append(add<ProcessorParameterWidget>(parameter));
|
2020-02-05 10:00:16 +03:00
|
|
|
|
2022-07-23 16:52:50 +03:00
|
|
|
for (auto& parameter : m_track_manager.current_track()->delay()->parameters())
|
|
|
|
m_parameter_widgets.append(add<ProcessorParameterWidget>(parameter));
|
2020-01-30 19:02:45 +03:00
|
|
|
}
|
|
|
|
|
2021-09-28 19:01:39 +03:00
|
|
|
void KnobsWidget::update_knobs()
|
|
|
|
{
|
2020-06-17 12:34:25 +03:00
|
|
|
// FIXME: This is needed because when the slider is changed normally, we
|
|
|
|
// need to change the underlying value, but if the keyboard was used, we
|
|
|
|
// need to change the slider without changing the underlying value.
|
|
|
|
m_change_underlying = false;
|
|
|
|
|
2022-05-14 02:11:23 +03:00
|
|
|
m_octave_knob->set_value(octave_max - m_track_manager.keyboard()->virtual_keyboard_octave());
|
2020-06-17 12:34:25 +03:00
|
|
|
|
|
|
|
m_change_underlying = true;
|
2020-01-30 19:02:45 +03:00
|
|
|
}
|