Fixed gate logic.
This commit is contained in:
		
							parent
							
								
									532b0d3843
								
							
						
					
					
						commit
						7980d5f881
					
				|  | @ -18,12 +18,12 @@ MidiNoteList<sMaxNumNotes> midiNotes; | ||||||
| 
 | 
 | ||||||
| // -----------------------------------------------------------------------------
 | // -----------------------------------------------------------------------------
 | ||||||
| 
 | 
 | ||||||
| void handleGateChanged(bool inGateActive) | inline void handleGateChanged(bool inGateActive) | ||||||
| { | { | ||||||
|     digitalWrite(sGatePin, inGateActive ? HIGH : LOW); |     digitalWrite(sGatePin, inGateActive ? HIGH : LOW); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void pulseGate() | inline void pulseGate() | ||||||
| { | { | ||||||
|     handleGateChanged(false); |     handleGateChanged(false); | ||||||
|     delay(1); |     delay(1); | ||||||
|  | @ -32,41 +32,40 @@ void pulseGate() | ||||||
| 
 | 
 | ||||||
| // -----------------------------------------------------------------------------
 | // -----------------------------------------------------------------------------
 | ||||||
| 
 | 
 | ||||||
| void handleNotesChanged() | void handleNoteOn(byte inChannel, byte inNote, byte inVelocity) | ||||||
| { | { | ||||||
|     if (midiNotes.empty()) |     const bool firstNote = midiNotes.empty(); | ||||||
|     { |     midiNotes.add(MidiNote(inNote, inVelocity)); | ||||||
|         handleGateChanged(false); |      | ||||||
|         noTone(sAudioOutPin); |     // Possible playing modes:
 | ||||||
|     } |     // Mono Low:  use midiNotes.getLow
 | ||||||
|     else |     // Mono High: use midiNotes.getHigh
 | ||||||
|     { |     // Mono Last: use midiNotes.getLast
 | ||||||
|         // Possible playing modes:
 |  | ||||||
|         // Mono Low:  use midiNotes.getLow
 |  | ||||||
|         // Mono High: use midiNotes.getHigh
 |  | ||||||
|         // Mono Last: use midiNotes.getLast
 |  | ||||||
| 
 | 
 | ||||||
|         byte currentNote = 0; |     byte currentNote = 0; | ||||||
|         if (midiNotes.getLast(currentNote)) |     if (midiNotes.getLast(currentNote)) | ||||||
|  |     { | ||||||
|  |         tone(sAudioOutPin, sNotePitches[currentNote]); | ||||||
|  |          | ||||||
|  |         if (firstNote) | ||||||
|  |         { | ||||||
|  |             handleGateChanged(true); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|         { |         { | ||||||
|             tone(sAudioOutPin, sNotePitches[currentNote]); |  | ||||||
|             pulseGate(); // Retrigger envelopes. Remove for legato effect.
 |             pulseGate(); // Retrigger envelopes. Remove for legato effect.
 | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // -----------------------------------------------------------------------------
 |  | ||||||
| 
 |  | ||||||
| void handleNoteOn(byte inChannel, byte inNote, byte inVelocity) |  | ||||||
| { |  | ||||||
|     midiNotes.add(MidiNote(inNote, inVelocity)); |  | ||||||
|     handleNotesChanged(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void handleNoteOff(byte inChannel, byte inNote, byte inVelocity) | void handleNoteOff(byte inChannel, byte inNote, byte inVelocity) | ||||||
| { | { | ||||||
|     midiNotes.remove(inNote); |     midiNotes.remove(inNote); | ||||||
|     handleNotesChanged(); |     if (midiNotes.empty()) | ||||||
|  |     { | ||||||
|  |         handleGateChanged(false); | ||||||
|  |         noTone(sAudioOutPin); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // -----------------------------------------------------------------------------
 | // -----------------------------------------------------------------------------
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Francois Best
						Francois Best