|
|
|
@ -1,10 +1,12 @@
|
|
|
|
|
#include "timeline.h"
|
|
|
|
|
#include "note.h"
|
|
|
|
|
#include "timelineviews/timelineviewmanager.h"
|
|
|
|
|
|
|
|
|
|
#include <SFML/Graphics/RenderTarget.hpp>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
Timeline::Timeline()
|
|
|
|
|
Timeline::Timeline(std::unique_ptr<TimelineViewManager> view_manager) :
|
|
|
|
|
_view_manager(std::move(view_manager))
|
|
|
|
|
{
|
|
|
|
|
// BPM of METEOR is 170.
|
|
|
|
|
// Length is 1:14
|
|
|
|
@ -18,10 +20,19 @@ Timeline::Timeline()
|
|
|
|
|
microsec note_input_offset = 412162;
|
|
|
|
|
microsec bpm_iterator = starting_beat_offset;
|
|
|
|
|
microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);
|
|
|
|
|
_visibility_offset = note_input_offset * 3;
|
|
|
|
|
_visibility_offset = note_input_offset * 12;
|
|
|
|
|
|
|
|
|
|
Note::resetPrecisionQualifier(note_input_offset / 3);
|
|
|
|
|
|
|
|
|
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Note::Arrow::DOWN));
|
|
|
|
|
bpm_iterator += interval;
|
|
|
|
|
|
|
|
|
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Note::Arrow::LEFT));
|
|
|
|
|
bpm_iterator += interval;
|
|
|
|
|
|
|
|
|
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Note::Arrow::LEFT));
|
|
|
|
|
bpm_iterator += interval;
|
|
|
|
|
|
|
|
|
|
while (bpm_iterator < bpm_end)
|
|
|
|
|
{
|
|
|
|
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset));
|
|
|
|
@ -45,6 +56,8 @@ Timeline::Timeline()
|
|
|
|
|
_last_visible_note = _timeline.end();
|
|
|
|
|
_top_note = _timeline.begin();
|
|
|
|
|
|
|
|
|
|
_last_visible_note = _top_note;
|
|
|
|
|
_view_manager->initNoteGraphics(*_top_note);
|
|
|
|
|
prepareNotesToDraw(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -52,8 +65,12 @@ void Timeline::prepareNotesToDraw(const microsec &music_offset)
|
|
|
|
|
{
|
|
|
|
|
auto note_iterator = _top_note;
|
|
|
|
|
|
|
|
|
|
while (((*note_iterator)->offset() - _visibility_offset) >= music_offset)
|
|
|
|
|
while (((*note_iterator)->offset() - _visibility_offset) <= music_offset)
|
|
|
|
|
{
|
|
|
|
|
++note_iterator;
|
|
|
|
|
if (note_iterator > _last_visible_note)
|
|
|
|
|
_view_manager->initNoteGraphics((*note_iterator));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_last_visible_note = note_iterator;
|
|
|
|
|
}
|
|
|
|
@ -76,16 +93,6 @@ void Timeline::clear()
|
|
|
|
|
Note::resetPrecisionQualifier();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static sf::RectangleShape createNoteGlyph(const std::vector<Note*>::const_iterator& note_to_draw)
|
|
|
|
|
{ // Temporary solution
|
|
|
|
|
sf::RectangleShape ret;
|
|
|
|
|
const auto position = (*note_to_draw)->position();
|
|
|
|
|
ret.setPosition(position.x, position.y);
|
|
|
|
|
ret.setFillColor(sf::Color(255, 100, 0));
|
|
|
|
|
ret.setSize({10.f, 10.f});
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Timeline::draw(sf::RenderTarget& target, sf::RenderStates states) const // Temporary solution
|
|
|
|
|
{
|
|
|
|
|
if (_last_visible_note == _timeline.end() || _top_note > _last_visible_note)
|
|
|
|
@ -94,7 +101,7 @@ void Timeline::draw(sf::RenderTarget& target, sf::RenderStates states) const //
|
|
|
|
|
auto note_to_draw = _top_note;
|
|
|
|
|
while (note_to_draw != (_last_visible_note + 1))
|
|
|
|
|
{
|
|
|
|
|
target.draw(createNoteGlyph(note_to_draw), states);
|
|
|
|
|
target.draw(*(*note_to_draw), states);
|
|
|
|
|
++note_to_draw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -111,6 +118,7 @@ void Timeline::checkCurrentActiveNote(const microsec &music_offset)
|
|
|
|
|
if (_active_note && !_active_note->isActive(music_offset))
|
|
|
|
|
{
|
|
|
|
|
_active_note = nullptr;
|
|
|
|
|
(*_top_note)->resetSprite();
|
|
|
|
|
++_top_note;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|