|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include "classicactions.h"
|
|
|
|
|
#include "classictimeline.h"
|
|
|
|
|
#include "note.h"
|
|
|
|
|
#include "classicnote.h"
|
|
|
|
|
|
|
|
|
|
ClassicTimeline::ClassicTimeline()
|
|
|
|
|
{
|
|
|
|
@ -9,6 +9,12 @@ ClassicTimeline::ClassicTimeline()
|
|
|
|
|
// Length is 1:14
|
|
|
|
|
// I calculated that the time between beats is about 1412162 microseconds
|
|
|
|
|
|
|
|
|
|
std::string song_filename = "/home/naiji/METEOR.flac";
|
|
|
|
|
|
|
|
|
|
_music.openFromFile(song_filename);
|
|
|
|
|
_music.play();
|
|
|
|
|
_music.setVolume(30);
|
|
|
|
|
|
|
|
|
|
_timeline.reserve(1000);
|
|
|
|
|
|
|
|
|
|
microsec starting_beat_offset = 372162;
|
|
|
|
@ -19,91 +25,100 @@ ClassicTimeline::ClassicTimeline()
|
|
|
|
|
microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);
|
|
|
|
|
_visibility_offset = note_input_offset * 12;
|
|
|
|
|
|
|
|
|
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Button::DOWN));
|
|
|
|
|
_timeline.emplace_back(new ClassicNote({note_input_offset}, bpm_iterator, Action::PRESS_DOWN));
|
|
|
|
|
bpm_iterator += interval;
|
|
|
|
|
|
|
|
|
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Button::LEFT));
|
|
|
|
|
_timeline.emplace_back(new ClassicNote({note_input_offset}, bpm_iterator, Action::PRESS_LEFT));
|
|
|
|
|
bpm_iterator += interval;
|
|
|
|
|
|
|
|
|
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset, Button::LEFT));
|
|
|
|
|
_timeline.emplace_back(new ClassicNote({note_input_offset}, bpm_iterator, Action::PRESS_LEFT));
|
|
|
|
|
bpm_iterator += interval;
|
|
|
|
|
|
|
|
|
|
while (bpm_iterator < bpm_end)
|
|
|
|
|
{
|
|
|
|
|
_timeline.emplace_back(new Note(bpm_iterator, note_input_offset));
|
|
|
|
|
_timeline.emplace_back(new ClassicNote({note_input_offset}, bpm_iterator, Action::PRESS_UP));
|
|
|
|
|
bpm_iterator += interval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_active_note = nullptr;
|
|
|
|
|
_last_visible_note = _timeline.end();
|
|
|
|
|
expire(_active_note);
|
|
|
|
|
_top_note = _timeline.begin();
|
|
|
|
|
|
|
|
|
|
_last_visible_note = _top_note;
|
|
|
|
|
_view_manager->initNoteGraphics(*_top_note);
|
|
|
|
|
prepareNotesToDraw(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Timeline::prepareNotesToDraw(const microsec &music_offset)
|
|
|
|
|
{
|
|
|
|
|
auto note_iterator = _top_note;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timeline::~Timeline()
|
|
|
|
|
ClassicTimeline::~ClassicTimeline()
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Timeline::clear()
|
|
|
|
|
void ClassicTimeline::clear()
|
|
|
|
|
{
|
|
|
|
|
for (auto note : _timeline)
|
|
|
|
|
delete note;
|
|
|
|
|
|
|
|
|
|
_timeline.clear();
|
|
|
|
|
_top_note = _timeline.end();
|
|
|
|
|
_last_visible_note = _timeline.end();
|
|
|
|
|
_active_note = nullptr;
|
|
|
|
|
|
|
|
|
|
Note::resetPrecisionQualifier();
|
|
|
|
|
expire(_top_note);
|
|
|
|
|
expire(_last_visible_note);
|
|
|
|
|
expire(_active_note);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Timeline::update(const microsec &music_offset)
|
|
|
|
|
void ClassicTimeline::update()
|
|
|
|
|
{
|
|
|
|
|
checkCurrentActiveNote(music_offset);
|
|
|
|
|
checkForNextActiveNote(music_offset);
|
|
|
|
|
prepareNotesToDraw(music_offset);
|
|
|
|
|
const auto& offset = currentMusicOffset();
|
|
|
|
|
std::cout << "Upadting at: " << offset << '\n';
|
|
|
|
|
checkCurrentActiveNote(offset);
|
|
|
|
|
checkForNextActiveNote(offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Timeline::checkCurrentActiveNote(const microsec &music_offset)
|
|
|
|
|
void ClassicTimeline::checkCurrentActiveNote(const microsec &music_offset)
|
|
|
|
|
{
|
|
|
|
|
if (_active_note && !_active_note->isActive(music_offset))
|
|
|
|
|
if (!isExpired(_active_note) && !(*_active_note)->isActive(music_offset))
|
|
|
|
|
{
|
|
|
|
|
_active_note = nullptr;
|
|
|
|
|
(*_top_note)->resetSprite();
|
|
|
|
|
expire(_active_note);
|
|
|
|
|
++_top_note;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Timeline::checkForNextActiveNote(const microsec &music_offset)
|
|
|
|
|
void ClassicTimeline::checkForNextActiveNote(const microsec &music_offset)
|
|
|
|
|
{
|
|
|
|
|
if (!_active_note && (*_top_note)->isActive(music_offset))
|
|
|
|
|
if (isExpired(_active_note) && (*_top_note)->isActive(music_offset))
|
|
|
|
|
{
|
|
|
|
|
std::cout << "New active note: " << music_offset << '\n';
|
|
|
|
|
_active_note = *_top_note;
|
|
|
|
|
_active_note = _top_note;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Note* Timeline::fetchActiveNote(const microsec &music_offset) noexcept
|
|
|
|
|
ClassicTimeline::Iterator ClassicTimeline::getActiveNote() noexcept
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Clicked at: " << music_offset << '\n';
|
|
|
|
|
update(music_offset);
|
|
|
|
|
update();
|
|
|
|
|
return _active_note;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ClassicTimeline::isExpired(const Iterator &iterator)
|
|
|
|
|
{
|
|
|
|
|
return iterator == _timeline.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClassicTimeline::expire(Iterator &iterator)
|
|
|
|
|
{
|
|
|
|
|
iterator = _timeline.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
microsec ClassicTimeline::currentMusicOffset() const
|
|
|
|
|
{
|
|
|
|
|
return _music.getPlayingOffset().asMicroseconds();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClassicTimeline::fetchVisibleNotes(const std::unique_ptr<ClassicViewManager>& view_manager)
|
|
|
|
|
{
|
|
|
|
|
Iterator note_iterator = _top_note;
|
|
|
|
|
auto music_offset = currentMusicOffset();
|
|
|
|
|
|
|
|
|
|
while (((*note_iterator)->offset() - _visibility_offset) <= music_offset)
|
|
|
|
|
{
|
|
|
|
|
++note_iterator;
|
|
|
|
|
if (note_iterator > _last_visible_note)
|
|
|
|
|
(void) view_manager;//_view_manager->initNoteGraphics((*note_iterator));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_last_visible_note = note_iterator;
|
|
|
|
|
}
|
|
|
|
|