From fdf19702b381ac755e1552414cec60792dbbe69c Mon Sep 17 00:00:00 2001 From: Simon Rodriguez Date: Wed, 23 Aug 2023 13:59:39 +0200 Subject: [PATCH] MIDIScene: apply new filter options. --- src/rendering/Viewer.cpp | 10 ++-- src/rendering/scene/MIDIScene.cpp | 7 ++- src/rendering/scene/MIDIScene.h | 6 ++- src/rendering/scene/MIDISceneFile.cpp | 66 +++++++++++++++------------ src/rendering/scene/MIDISceneFile.h | 10 ++-- src/rendering/scene/MIDISceneLive.cpp | 9 +++- src/rendering/scene/MIDISceneLive.h | 18 ++++---- 7 files changed, 74 insertions(+), 52 deletions(-) diff --git a/src/rendering/Viewer.cpp b/src/rendering/Viewer.cpp index 6bb2cbe..ada15da 100755 --- a/src/rendering/Viewer.cpp +++ b/src/rendering/Viewer.cpp @@ -141,7 +141,7 @@ bool Viewer::loadFile(const std::string& midiFilePath) { std::shared_ptr scene(nullptr); try { - scene = std::make_shared(midiFilePath, _state.setOptions); + scene = std::make_shared(midiFilePath, _state.setOptions, _state.filter); } catch(...){ // Failed to load. return false; @@ -238,7 +238,7 @@ SystemAction Viewer::draw(float currentTime) { void Viewer::drawScene(bool transparentBG){ // Update active notes listing. - _scene->updatesActiveNotes(_state.scrollSpeed * _timer, _state.scrollSpeed); + _scene->updatesActiveNotes(_state.scrollSpeed * _timer, _state.scrollSpeed, _state.filter); // Let renderer update GPU data if needed. _renderer.upload(_scene); @@ -1318,7 +1318,7 @@ void Viewer::showSets(){ if(shouldUpdate){ _state.setOptions.rebuild(); - _scene->updateSets(_state.setOptions); + _scene->updateSetsAndVisibleNotes(_state.setOptions, _state.filter); } ImGui::EndPopup(); } @@ -1481,7 +1481,7 @@ void Viewer::showSetEditor(){ if(refreshSetOptions){ _state.setOptions.rebuild(); if(_scene){ - _scene->updateSets(_state.setOptions); + _scene->updateSetsAndVisibleNotes(_state.setOptions, _state.filter); } } @@ -2005,7 +2005,7 @@ void Viewer::setState(const State & state){ // Update split notes. if(_scene){ - _scene->updateSets(_state.setOptions); + _scene->updateSetsAndVisibleNotes(_state.setOptions, _state.filter); } applyAllSettings(); diff --git a/src/rendering/scene/MIDIScene.cpp b/src/rendering/scene/MIDIScene.cpp index 79e90cf..63b6c87 100755 --- a/src/rendering/scene/MIDIScene.cpp +++ b/src/rendering/scene/MIDIScene.cpp @@ -30,10 +30,13 @@ void MIDIScene::resetParticles() { } } -void MIDIScene::updateSets(const SetOptions & options){ +void MIDIScene::updateSetsAndVisibleNotes(const SetOptions & options, const FilterOptions& filter){ } -void MIDIScene::updatesActiveNotes(double time, double speed){ +void MIDIScene::updateVisibleNotes( const FilterOptions& filter ){ +} + +void MIDIScene::updatesActiveNotes(double time, double speed, const FilterOptions& filter ){ } double MIDIScene::duration() const { diff --git a/src/rendering/scene/MIDIScene.h b/src/rendering/scene/MIDIScene.h index 41f7484..14dafcd 100755 --- a/src/rendering/scene/MIDIScene.h +++ b/src/rendering/scene/MIDIScene.h @@ -39,9 +39,11 @@ class MIDIScene { void resetParticles(); - virtual void updateSets(const SetOptions & options); + virtual void updateSetsAndVisibleNotes( const SetOptions& options, const FilterOptions& filter ); - virtual void updatesActiveNotes(double time, double speed); + virtual void updateVisibleNotes( const FilterOptions& filter); + + virtual void updatesActiveNotes(double time, double speed, const FilterOptions& filter); virtual double duration() const; diff --git a/src/rendering/scene/MIDISceneFile.cpp b/src/rendering/scene/MIDISceneFile.cpp index 4cac253..861d9a2 100755 --- a/src/rendering/scene/MIDISceneFile.cpp +++ b/src/rendering/scene/MIDISceneFile.cpp @@ -17,60 +17,68 @@ MIDISceneFile::~MIDISceneFile(){} -MIDISceneFile::MIDISceneFile(const std::string & midiFilePath, const SetOptions & options) : MIDIScene() { +MIDISceneFile::MIDISceneFile(const std::string & midiFilePath, const SetOptions & options, const FilterOptions& filter) : MIDIScene() { _filePath = midiFilePath; // MIDI processing. _midiFile = MIDIFile(_filePath); - updateSets(options); + _midiFile.updateSets( options ); + updateVisibleNotes( filter ); std::cout << "[INFO]: Final track duration " << _midiFile.duration() << " sec." << std::endl; } -void MIDISceneFile::updateSets(const SetOptions & options){ - // Generate note data for rendering. - _midiFile.updateSets(options); +void MIDISceneFile::updateSetsAndVisibleNotes( const SetOptions& options, const FilterOptions& filter ) +{ + _midiFile.updateSets( options ); + updateVisibleNotes( filter ); +} +void MIDISceneFile::updateVisibleNotes( const FilterOptions& filter ) +{ + // Generate note data for rendering. std::vector notesM; - _midiFile.getNotes(notesM, NoteType::MAJOR, 0); + _midiFile.getNotes( notesM, NoteType::MAJOR, filter, 0 ); std::vector notesm; - _midiFile.getNotes(notesm, NoteType::MINOR, 0); + _midiFile.getNotes( notesm, NoteType::MINOR, filter, 0 ); // Load notes shared data. const size_t majorCount = notesM.size(); const size_t minorCount = notesm.size(); const size_t totalCount = majorCount + minorCount; - _notes.resize(totalCount); - - for(size_t i = 0; i < majorCount; ++i){ - const MIDINote& note = notesM[i]; - GPUNote& data = _notes[i]; - data.note = float(note.note); - data.start = float(note.start); - data.duration = float(note.duration); + _notes.resize( totalCount ); + + for( size_t i = 0; i < majorCount; ++i ) + { + const MIDINote& note = notesM[ i ]; + GPUNote& data = _notes[ i ]; + data.note = float( note.note ); + data.start = float( note.start ); + data.duration = float( note.duration ); data.isMinor = 0.0f; - data.set = float(note.set); + data.set = float( note.set ); } - for(size_t i = 0; i < minorCount; ++i){ - const MIDINote& note = notesm[i]; - GPUNote& data = _notes[i + majorCount]; - data.note = float(note.note); - data.start = float(note.start); - data.duration = float(note.duration); - data.isMinor = 1.0f; - data.set = float(note.set); + for( size_t i = 0; i < minorCount; ++i ) + { + const MIDINote& note = notesm[ i ]; + GPUNote& data = _notes[ i + majorCount ]; + data.note = float( note.note ); + data.start = float( note.start ); + data.duration = float( note.duration ); + data.isMinor = 1.0f; + data.set = float( note.set ); } // Upload to the GPU. - assert(totalCount < (1 << 31)); + assert( totalCount < ( 1 << 31 ) ); _dirtyNotes = true; - _effectiveNotesCount = int(totalCount); - _dirtyNotesRange = {0, 0}; // Means full array + _effectiveNotesCount = int( totalCount ); + _dirtyNotesRange = { 0, 0 }; // Means full array } -void MIDISceneFile::updatesActiveNotes(double time, double speed){ +void MIDISceneFile::updatesActiveNotes(double time, double speed, const FilterOptions& filter){ // Update the particle systems lifetimes. for(auto & particle : _particles){ // Give a bit of a head start to the animation. @@ -84,7 +92,7 @@ void MIDISceneFile::updatesActiveNotes(double time, double speed){ } // Get notes actives. auto actives = ActiveNotesArray(); - _midiFile.getNotesActive(actives, time, 0); + _midiFile.getNotesActive(actives, time, filter, 0); for(int i = 0; i < 128; ++i){ const auto & note = actives[i]; _actives[i] = note.enabled ? note.set : -1; diff --git a/src/rendering/scene/MIDISceneFile.h b/src/rendering/scene/MIDISceneFile.h index 60a8b64..37dfa88 100755 --- a/src/rendering/scene/MIDISceneFile.h +++ b/src/rendering/scene/MIDISceneFile.h @@ -10,13 +10,15 @@ class MIDISceneFile : public MIDIScene { public: - MIDISceneFile(const std::string & midiFilePath, const SetOptions & options); - - void updateSets(const SetOptions & options) override; + MIDISceneFile(const std::string & midiFilePath, const SetOptions & options, const FilterOptions& filter ); ~MIDISceneFile(); - void updatesActiveNotes(double time, double speed) override; + virtual void updateSetsAndVisibleNotes( const SetOptions& options, const FilterOptions& filter ) override; + + virtual void updateVisibleNotes( const FilterOptions& filter ) override; + + void updatesActiveNotes(double time, double speed, const FilterOptions& filter ) override; double duration() const override; diff --git a/src/rendering/scene/MIDISceneLive.cpp b/src/rendering/scene/MIDISceneLive.cpp index 24c585d..e07465f 100755 --- a/src/rendering/scene/MIDISceneLive.cpp +++ b/src/rendering/scene/MIDISceneLive.cpp @@ -52,7 +52,7 @@ MIDISceneLive::MIDISceneLive(int port, bool verbose) : MIDIScene() { _dirtyNotesRange = {0, 0}; // Full array } -void MIDISceneLive::updateSets(const SetOptions & options){ +void MIDISceneLive::updateSetsAndVisibleNotes(const SetOptions & options, const FilterOptions& filter){ _currentSetOption = options; for(size_t nid = 0; nid < _notesCount; ++nid){ @@ -65,7 +65,12 @@ void MIDISceneLive::updateSets(const SetOptions & options){ _dirtyNotesRange = {0, 0}; // Full array } -void MIDISceneLive::updatesActiveNotes(double time, double speed){ +void MIDISceneLive::updateVisibleNotes(const FilterOptions& filter) +{ + // No tracks +} + +void MIDISceneLive::updatesActiveNotes(double time, double speed, const FilterOptions& filter){ int minUpdated = MAX_NOTES_IN_FLIGHT; int maxUpdated = 0; diff --git a/src/rendering/scene/MIDISceneLive.h b/src/rendering/scene/MIDISceneLive.h index ed65a99..f1bea1d 100755 --- a/src/rendering/scene/MIDISceneLive.h +++ b/src/rendering/scene/MIDISceneLive.h @@ -17,21 +17,23 @@ class MIDISceneLive : public MIDIScene { MIDISceneLive(int port, bool verbose); - void updateSets(const SetOptions & options); - ~MIDISceneLive(); - void updatesActiveNotes(double time, double speed); + virtual void updateSetsAndVisibleNotes( const SetOptions& options, const FilterOptions& filter ) override; + + virtual void updateVisibleNotes( const FilterOptions& filter ) override; + + void updatesActiveNotes(double time, double speed, const FilterOptions& filter ) override; - double duration() const; + double duration() const override; - double secondsPerMeasure() const; + double secondsPerMeasure() const override; - int notesCount() const; + int notesCount() const override; - void print() const; + void print() const override; - void save(std::ofstream& file) const; + void save(std::ofstream& file) const override; const std::string& deviceName() const;