OpenWareLaboratory
MonophonicProcessor.h
Go to the documentation of this file.
1 #ifndef __MonophonicProcessor_h__
2 #define __MonophonicProcessor_h__
3 
4 #include "MidiProcessor.h"
5 #include "SignalGenerator.h"
6 #include "VoiceAllocator.h"
7 
8 template<class SynthVoice>
9 class MonophonicProcessor : public VoiceAllocator<SynthVoice, 1> {
11 protected:
12  uint8_t notes[16];
13  uint8_t lastNote = 0;
14 public:
16  virtual void noteOn(MidiMessage msg){
17  if(lastNote < 16)
18  notes[lastNote++] = msg.getNote();
19  Allocator::voice[0]->noteOn(msg);
20  }
21  virtual void noteOff(MidiMessage msg){
22  uint8_t note = msg.getNote();
23  int i;
24  for(i = 0; i < lastNote; ++i) {
25  if(notes[i] == note)
26  break;
27  }
28  if(lastNote > 1) {
29  lastNote--;
30  while (i < lastNote) {
31  notes[i] = notes[i + 1];
32  i++;
33  }
34  Allocator::voice[0]->setNote(notes[lastNote - 1]);
35  }else{
37  Allocator::voice[0]->gate(false);
38  lastNote = 0;
39  }
40  }
41  void allNotesOn() {
42  Allocator::voice[0]->gate(true);
43  }
44  void allNotesOff() {
45  Allocator::voice[0]->gate(false);
46  lastNote = 0;
47  }
48  virtual void sustainOff(){
49  if(lastNote == 0)
50  Allocator::voice[0]->gate(false);
51  }
52  // void sustain(MidiMessage msg){} // todo
53  void modulate(MidiMessage msg){
54  Allocator::voice[0]->modulate(msg);
55  }
57  Allocator::voice[0]->pitchbend(msg);
58  }
59 };
60 
61 #endif // __MonophonicProcessor_h__
uint8_t getNote()
Definition: MidiMessage.h:60
virtual void noteOff(MidiMessage msg)
virtual void sustainOff()
void modulate(MidiMessage msg)
void pitchbend(MidiMessage msg)
virtual void noteOn(MidiMessage msg)
SynthVoice * voice[VOICES]
Definition: VoiceAllocator.h:7