-
Notifications
You must be signed in to change notification settings - Fork 1
/
mainMelody.hpp
50 lines (47 loc) · 1.69 KB
/
mainMelody.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef LIBMIDI_mainMelody
#define LIBMIDI_mainMelody
#include "step.hpp"
namespace libmidi{
class mainMelody:public step{
private:
int lastNote;
public:
virtual void onStep(const noteStatus * notes,float tm,const std::set<int> & sound){
int i;
for(auto it=sound.rbegin();it!=sound.rend();it++){
i=*it;
if(!notes[i].noteOn)
continue;
if(i==this->lastNote){
int min=i-12;
if(min<0)min=0;
for(;it!=sound.rend();it++){
i=*it;
if(i<min)
break;
if(!notes[i].noteOn)
continue;
if(this->beginAtThisStep(i)){
this->onNoteOn(i , notes[i].velocity);
this->lastNote=i;
break;
}
}
return;
}
if(i!=this->lastNote && (this->lastNote-i)<12){
if(this->beginAtThisStep(i)){
this->onNoteOn(i , notes[i].velocity);
this->lastNote=i;
}
}
return;
}
}
virtual void onNoteOn(int note,int velocity)=0;
virtual void reset(){
this->lastNote=0;
}
};
}
#endif