From bb1bb880856c5c44238d9b946ba80e0e225064c2 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Mon, 13 Dec 2021 19:52:26 +0300 Subject: [PATCH] Remove ticks as a concept from Editor --- core/shared/core/editor.h | 3 +- modes/classicmode/editor/classiceditor.cpp | 64 ++----------------- src/application/editorstate.cpp | 6 +- .../widgets/bpmcalculatorwidget.cpp | 2 +- 4 files changed, 12 insertions(+), 63 deletions(-) diff --git a/core/shared/core/editor.h b/core/shared/core/editor.h index 583da49..8929f44 100644 --- a/core/shared/core/editor.h +++ b/core/shared/core/editor.h @@ -32,7 +32,7 @@ public: bool insertBPMSection(BPMSection&& section) { - return _bpm_sections.insert(std::move(section)).second; + return _bpm_sections.insert(section).second; } bool removeBPMSectionAt(const microsec& offset) @@ -78,5 +78,4 @@ public: protected: std::set _bpm_sections; - std::set _ticks; }; diff --git a/modes/classicmode/editor/classiceditor.cpp b/modes/classicmode/editor/classiceditor.cpp index 161dcd4..e139245 100644 --- a/modes/classicmode/editor/classiceditor.cpp +++ b/modes/classicmode/editor/classiceditor.cpp @@ -8,69 +8,17 @@ ClassicEditor::ClassicEditor(std::shared_ptr&& manager) { _context.graphics_manager = _graphics_manager; - int basic_offset = 500000 * 6; + std::set set = {}; - std::set _set = {}; - - NoteInitializer init; - init.context = &_context; - init.intervals = {}; - init.perfect_offset = basic_offset + (500000 * 20); - - ElementInitializer elem_init; - elem_init.type = _selected_type; - elem_init.coordinates = Coordinates{ 700 - (5 * 120), 550 }; - elem_init.falling_curve_interpolation = {}; - - MockArrowNoteInitializer mock_init; - mock_init.elements = {elem_init}; - mock_init.initializer = init; - _set.insert(new MockClassicNote(std::move(mock_init))); - - _timeline.setNotes(_set, 1648648); + _timeline.setNotes(set, 1648648); } microsec ClassicEditor::adjustOffset(microsec offset) const noexcept { - microsec left = -1; - microsec right = -1; - - std::set::iterator i; - - for (i = _ticks.begin(); i != _ticks.end(); ++i) - { - if (*i >= offset) - { - right = *i; - break; - } - } - - for (; i != _ticks.end(); --i) - { - if (*i <= offset) - { - left = *i; - break; - } - } - - if (right == -1) - offset = left; - else if (left == -1) - offset = right; - else - { - const microsec right_distance = right - offset; - const microsec left_distance = offset - left; - - offset = (right_distance > left_distance) - ? left_distance - : right_distance; - } - + const auto& section = getBPMSectionAt(offset); + const microsec actual_offset = offset - section.offset_start; - return offset; + return actual_offset + (actual_offset % section.interval); } void ClassicEditor::input(PlayerInput&& inputdata) @@ -87,7 +35,7 @@ void ClassicEditor::input(PlayerInput&& inputdata) case sf::Event::MouseButtonPressed: { const auto note = _timeline.getNoteBy(_current_time); - if (_timeline.isExpired(note) && !_ticks.empty()) + if (_timeline.isExpired(note) && !_bpm_sections.empty() && _current_time >= (*_bpm_sections.begin()).offset_start) { NoteInitializer init; init.context = &_context; diff --git a/src/application/editorstate.cpp b/src/application/editorstate.cpp index 5de65b9..277df8c 100644 --- a/src/application/editorstate.cpp +++ b/src/application/editorstate.cpp @@ -38,7 +38,7 @@ void EditorState::draw() const void EditorState::enter() { - _music.openFromFile("Uta-test.flac"); + _music.openFromFile("METEOR.flac"); _music.setVolume(5); auto& group = _group; @@ -72,7 +72,9 @@ void EditorState::enter() button_apply->setCallback([&editor, bpm_calculator]() { BPMSection section; - section.bpm = bpm_calculator->fetchApproximatedInfo().BPM; + const auto& info = bpm_calculator->fetchApproximatedInfo(); + section.bpm = info.BPM; + section.interval = info.interval; section.fraction = 2; section.offset_start = bpm_calculator->getStartingOffset(); diff --git a/src/application/widgets/bpmcalculatorwidget.cpp b/src/application/widgets/bpmcalculatorwidget.cpp index 5fadc65..85cff34 100644 --- a/src/application/widgets/bpmcalculatorwidget.cpp +++ b/src/application/widgets/bpmcalculatorwidget.cpp @@ -92,7 +92,7 @@ void BPMCalculatorWidget::setRect(const sf::FloatRect& rect) _window_content.getGlobalBounds().top + _window_content.getGlobalBounds().height - 40}); _button_apply->setRect(sf::FloatRect{0, 0, rect.width / 10 * 3, 30}); - _button_apply->setPosition({_window_content.getGlobalBounds().left + 20 + (2 * (rect.width / 7)), + _button_apply->setPosition({_window_content.getGlobalBounds().left + 50 + (2 * (rect.width / 7)), _window_content.getGlobalBounds().top + _window_content.getGlobalBounds().height - 40}); _bpm_value.setPosition({_window_content.getGlobalBounds().left + rect.width / 8,