forked from NaiJi/project-kyoku
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.8 KiB
C++
110 lines
2.8 KiB
C++
4 years ago
|
#include <iostream>
|
||
3 years ago
|
#include "classicactions.h"
|
||
|
#include "classictimeline.h"
|
||
|
#include "note.h"
|
||
4 years ago
|
|
||
3 years ago
|
ClassicTimeline::ClassicTimeline()
|
||
4 years ago
|
{
|
||
|
// BPM of METEOR is 170.
|
||
|
// Length is 1:14
|
||
|
// I calculated that the time between beats is about 1412162 microseconds
|
||
|
|
||
4 years ago
|
_timeline.reserve(1000);
|
||
|
|
||
4 years ago
|
microsec starting_beat_offset = 372162;
|
||
|
int amount_of_beats = 209;
|
||
4 years ago
|
microsec interval = 1412162;
|
||
4 years ago
|
microsec note_input_offset = 412162;
|
||
4 years ago
|
microsec bpm_iterator = starting_beat_offset;
|
||
|
microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);
|
||
4 years ago
|
_visibility_offset = note_input_offset * 12;
|
||
4 years ago
|
|
||
3 years ago
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Button::DOWN));
|
||
4 years ago
|
bpm_iterator += interval;
|
||
|
|
||
3 years ago
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Button::LEFT));
|
||
4 years ago
|
bpm_iterator += interval;
|
||
|
|
||
3 years ago
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Button::LEFT));
|
||
4 years ago
|
bpm_iterator += interval;
|
||
|
|
||
4 years ago
|
while (bpm_iterator < bpm_end)
|
||
4 years ago
|
{
|
||
4 years ago
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset));
|
||
|
bpm_iterator += interval;
|
||
4 years ago
|
}
|
||
|
|
||
|
_active_note = nullptr;
|
||
4 years ago
|
_last_visible_note = _timeline.end();
|
||
4 years ago
|
_top_note = _timeline.begin();
|
||
4 years ago
|
|
||
4 years ago
|
_last_visible_note = _top_note;
|
||
|
_view_manager->initNoteGraphics(*_top_note);
|
||
4 years ago
|
prepareNotesToDraw(0);
|
||
|
}
|
||
|
|
||
|
void Timeline::prepareNotesToDraw(const microsec &music_offset)
|
||
|
{
|
||
|
auto note_iterator = _top_note;
|
||
|
|
||
4 years ago
|
while (((*note_iterator)->offset() - _visibility_offset) <= music_offset)
|
||
|
{
|
||
4 years ago
|
++note_iterator;
|
||
4 years ago
|
if (note_iterator > _last_visible_note)
|
||
|
_view_manager->initNoteGraphics((*note_iterator));
|
||
|
}
|
||
4 years ago
|
|
||
|
_last_visible_note = note_iterator;
|
||
4 years ago
|
}
|
||
|
|
||
|
Timeline::~Timeline()
|
||
4 years ago
|
{
|
||
|
clear();
|
||
|
}
|
||
|
|
||
|
void Timeline::clear()
|
||
4 years ago
|
{
|
||
|
for (auto note : _timeline)
|
||
|
delete note;
|
||
|
|
||
|
_timeline.clear();
|
||
|
_top_note = _timeline.end();
|
||
4 years ago
|
_last_visible_note = _timeline.end();
|
||
4 years ago
|
_active_note = nullptr;
|
||
|
|
||
|
Note::resetPrecisionQualifier();
|
||
|
}
|
||
|
|
||
4 years ago
|
void Timeline::update(const microsec &music_offset)
|
||
4 years ago
|
{
|
||
4 years ago
|
checkCurrentActiveNote(music_offset);
|
||
|
checkForNextActiveNote(music_offset);
|
||
|
prepareNotesToDraw(music_offset);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
void Timeline::checkCurrentActiveNote(const microsec &music_offset)
|
||
4 years ago
|
{
|
||
4 years ago
|
if (_active_note && !_active_note->isActive(music_offset))
|
||
4 years ago
|
{
|
||
|
_active_note = nullptr;
|
||
4 years ago
|
(*_top_note)->resetSprite();
|
||
4 years ago
|
++_top_note;
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
void Timeline::checkForNextActiveNote(const microsec &music_offset)
|
||
4 years ago
|
{
|
||
4 years ago
|
if (!_active_note && (*_top_note)->isActive(music_offset))
|
||
4 years ago
|
{
|
||
4 years ago
|
std::cout << "New active note: " << music_offset << '\n';
|
||
4 years ago
|
_active_note = *_top_note;
|
||
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
Note* Timeline::fetchActiveNote(const microsec &music_offset) noexcept
|
||
4 years ago
|
{
|
||
4 years ago
|
std::cout << "Clicked at: " << music_offset << '\n';
|
||
|
update(music_offset);
|
||
4 years ago
|
return _active_note;
|
||
|
}
|