2021-04-08 15:34:03 +02:00
|
|
|
#include "timeline.h"
|
|
|
|
#include "note.h"
|
|
|
|
|
2021-04-08 21:51:59 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2021-04-08 15:34:03 +02:00
|
|
|
Timeline::Timeline()
|
|
|
|
{
|
|
|
|
// BPM of METEOR is 170.
|
|
|
|
// Length is 1:14
|
|
|
|
// I calculated that the time between beats is about 1412162 microseconds
|
|
|
|
|
|
|
|
microsec starting_beat_offset = 372162;
|
|
|
|
int amount_of_beats = 209;
|
|
|
|
microsec time_between_beats = 1412162;
|
|
|
|
microsec note_input_offset = 412162;
|
2021-04-08 21:51:59 +02:00
|
|
|
microsec interval = starting_beat_offset;
|
|
|
|
microsec AAAAAAAAENDBLYAT = starting_beat_offset + (time_between_beats * amount_of_beats);
|
2021-04-08 15:34:03 +02:00
|
|
|
|
2021-04-08 21:51:59 +02:00
|
|
|
Note::resetPrecisionQualifier(note_input_offset / 3);
|
2021-04-08 15:34:03 +02:00
|
|
|
|
2021-04-08 21:51:59 +02:00
|
|
|
while (interval < AAAAAAAAENDBLYAT)
|
2021-04-08 15:34:03 +02:00
|
|
|
{
|
|
|
|
_timeline.emplace_back(new Note(interval, note_input_offset));
|
2021-04-08 21:51:59 +02:00
|
|
|
interval += time_between_beats;
|
2021-04-08 15:34:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_active_note = nullptr;
|
|
|
|
_top_note = _timeline.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
Timeline::~Timeline()
|
|
|
|
{
|
|
|
|
for (auto note : _timeline)
|
|
|
|
delete note;
|
|
|
|
|
|
|
|
_timeline.clear();
|
|
|
|
_top_note = _timeline.end();
|
|
|
|
_active_note = nullptr;
|
|
|
|
|
|
|
|
Note::resetPrecisionQualifier();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timeline::update(const microsec µseconds)
|
|
|
|
{
|
|
|
|
checkCurrentActiveNote(microseconds);
|
|
|
|
checkForNextActiveNote(microseconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timeline::checkCurrentActiveNote(const microsec µseconds)
|
|
|
|
{
|
|
|
|
if (_active_note && !_active_note->isActive(microseconds))
|
|
|
|
{
|
|
|
|
_active_note = nullptr;
|
|
|
|
++_top_note;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Timeline::checkForNextActiveNote(const microsec µseconds)
|
|
|
|
{
|
|
|
|
if (!_active_note && (*_top_note)->isActive(microseconds))
|
|
|
|
{
|
2021-04-08 21:51:59 +02:00
|
|
|
std::cout << "New active note: " << microseconds << '\n';
|
2021-04-08 15:34:03 +02:00
|
|
|
_active_note = *_top_note;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-08 18:08:01 +02:00
|
|
|
const Note* Timeline::fetchActiveNote(const microsec µseconds) noexcept
|
2021-04-08 15:34:03 +02:00
|
|
|
{
|
2021-04-08 21:51:59 +02:00
|
|
|
std::cout << "Clicked at: " << microseconds << '\n';
|
2021-04-08 18:08:01 +02:00
|
|
|
update(microseconds);
|
2021-04-08 15:34:03 +02:00
|
|
|
return _active_note;
|
|
|
|
}
|