Arduino STK 4.6.2
ArdStkMidiAction.h
1#pragma once
2#include "ArdConfig.h"
3
4#include "ArdStkLogger.h"
5#include "MidiAction.h"
6#include "Voicer.h"
7
8namespace stk {
9
10
11/***************************************************/
17/***************************************************/
18
19class StkMidiAction : public midi::MidiAction {
20 public:
21 StkMidiAction() = default;
22
23 StkMidiAction(Instrmnt *instrument, int group=0, int midiChannel = -1) {
24 addInstrument(instrument, group);
25 this->group = group;
26 this->midiChannel = midiChannel;
27 };
28
29 Voicer &voicer() {
30 return voicer_obj;
31 }
32
33 virtual void addInstrument( Instrmnt *instrument, int group=0 ){
34 STK_LOGI(__PRETTY_FUNCTION__);
35 voicer_obj.addInstrument(instrument, group);
36 }
37
38 virtual void removeInstrument( Instrmnt *instrument ){
39 STK_LOGI(__PRETTY_FUNCTION__);
40 voicer_obj.removeInstrument(instrument);
41 }
42
43 virtual void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity=87) {
44 STK_LOGI("StkMidiAction::onNoteOn: channel=%d, note=%d, velocity=%d", channel, note, velocity);
45 if (midiChannel<=-1 || midiChannel==channel){
46 voicer_obj.noteOn(note, velocity, group);
47 }
48 }
49
50 virtual void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity=87) {
51 STK_LOGI("StkMidiAction::onNoteOff: channel=%d, note=%d, velocity=%d", channel, note, velocity);
52 if (midiChannel<=-1 || midiChannel==channel){
53 velocity = velocity > 0 ? velocity : 87;
54 voicer_obj.noteOff(note, velocity, group);
55 }
56 }
57
58 virtual void onControlChange(uint8_t channel, uint8_t controller, uint8_t value) {
59 STK_LOGI(__PRETTY_FUNCTION__);
60 if (midiChannel<=-1 || midiChannel==channel){
61 voicer_obj.controlChange(controller,(StkFloat) value, channel);
62 }
63 }
64
65 virtual void onPitchBend(uint8_t channel, uint8_t value) {
66 STK_LOGI(__PRETTY_FUNCTION__);
67 if (midiChannel<=-1 || midiChannel==channel){
68 voicer_obj.pitchBend(value, channel);
69 }
70 }
71
72 StkFloat tick( unsigned int channel = 0 ){
73 return voicer_obj.tick(channel);
74 }
75
76 StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ){
77 return voicer_obj.tick(frames, channel);
78 }
79 protected:
80 Voicer voicer_obj;
81 int group;
82 int midiChannel;
83};
84
85}
86
The STK namespace.
Definition ADSR.h:8