Skip to content

Commit

Permalink
MIDIScene: apply new filter options.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosua20 committed Aug 23, 2023
1 parent 86d5609 commit fdf1970
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 52 deletions.
10 changes: 5 additions & 5 deletions src/rendering/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool Viewer::loadFile(const std::string& midiFilePath) {
std::shared_ptr<MIDIScene> scene(nullptr);

try {
scene = std::make_shared<MIDISceneFile>(midiFilePath, _state.setOptions);
scene = std::make_shared<MIDISceneFile>(midiFilePath, _state.setOptions, _state.filter);
} catch(...){
// Failed to load.
return false;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1318,7 +1318,7 @@ void Viewer::showSets(){

if(shouldUpdate){
_state.setOptions.rebuild();
_scene->updateSets(_state.setOptions);
_scene->updateSetsAndVisibleNotes(_state.setOptions, _state.filter);
}
ImGui::EndPopup();
}
Expand Down Expand Up @@ -1481,7 +1481,7 @@ void Viewer::showSetEditor(){
if(refreshSetOptions){
_state.setOptions.rebuild();
if(_scene){
_scene->updateSets(_state.setOptions);
_scene->updateSetsAndVisibleNotes(_state.setOptions, _state.filter);
}
}

Expand Down Expand Up @@ -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();

Expand Down
7 changes: 5 additions & 2 deletions src/rendering/scene/MIDIScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/rendering/scene/MIDIScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
66 changes: 37 additions & 29 deletions src/rendering/scene/MIDISceneFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MIDINote> notesM;
_midiFile.getNotes(notesM, NoteType::MAJOR, 0);
_midiFile.getNotes( notesM, NoteType::MAJOR, filter, 0 );
std::vector<MIDINote> 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.
Expand All @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/rendering/scene/MIDISceneFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 7 additions & 2 deletions src/rendering/scene/MIDISceneLive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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;

Expand Down
18 changes: 10 additions & 8 deletions src/rendering/scene/MIDISceneLive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit fdf1970

Please sign in to comment.