2021-04-04 22:43:12 +02:00
|
|
|
#include "note.h"
|
2021-04-08 21:51:59 +02:00
|
|
|
#include <iostream>
|
2021-04-04 22:43:12 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
Note::Note(microsec offset, microsec life_span_offset, Note::Arrow type) :
|
2021-04-08 21:51:59 +02:00
|
|
|
_offset(offset),
|
|
|
|
_start_handling_offset(_offset - life_span_offset),
|
|
|
|
_end_handling_offset(_offset + life_span_offset),
|
2021-04-04 22:43:12 +02:00
|
|
|
_type(type)
|
|
|
|
{}
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
void Note::setPosition(coordinates position)
|
2021-04-05 16:17:57 +02:00
|
|
|
{
|
2021-04-06 19:39:29 +02:00
|
|
|
_position = position;
|
|
|
|
}
|
|
|
|
|
|
|
|
coordinates Note::position() const noexcept
|
|
|
|
{
|
|
|
|
return _position;
|
2021-04-05 16:17:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
microsec Note::offset() const noexcept
|
2021-04-04 22:43:12 +02:00
|
|
|
{
|
2021-04-06 19:39:29 +02:00
|
|
|
return _offset;
|
2021-04-04 22:43:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NoteGrade Note::onTap(Arrow arrow_type, microsec tap_time_stamp) const
|
|
|
|
{
|
|
|
|
if (arrow_type != _type)
|
|
|
|
return {0, NoteGrade::Rating::WRONG};
|
|
|
|
|
|
|
|
microsec odds = std::abs(tap_time_stamp - _offset);
|
|
|
|
return calculatePrecision(odds);
|
|
|
|
}
|
|
|
|
|
|
|
|
NoteGrade Note::calculatePrecision(microsec odds) const
|
|
|
|
{
|
2021-04-06 19:39:29 +02:00
|
|
|
NoteGrade ret(0, NoteGrade::Rating::BAD);
|
|
|
|
|
|
|
|
if (odds < _precision_qualifier)
|
2021-04-04 22:43:12 +02:00
|
|
|
{
|
2021-04-06 19:39:29 +02:00
|
|
|
ret = {50, NoteGrade::Rating::GREAT};
|
2021-04-04 22:43:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2021-04-06 19:39:29 +02:00
|
|
|
|
|
|
|
bool Note::isActive(microsec music_play_offset) const noexcept
|
|
|
|
{
|
|
|
|
return music_play_offset > _start_handling_offset
|
|
|
|
&& music_play_offset < _end_handling_offset;
|
|
|
|
}
|
|
|
|
|
2021-04-08 15:34:03 +02:00
|
|
|
void Note::resetPrecisionQualifier(microsec qualifier)
|
2021-04-06 19:39:29 +02:00
|
|
|
{
|
|
|
|
_precision_qualifier = qualifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
microsec Note::_precision_qualifier = 500000; // Default initialization as 0.5 second.
|