-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathArdStkMidiAction.h
86 lines (69 loc) · 2.66 KB
/
ArdStkMidiAction.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "ArdConfig.h"
#include "ArdStkLogger.h"
#include "MidiAction.h"
#include "Voicer.h"
namespace stk {
/***************************************************/
/*! \class stk::MidiVoicer
\brief MidiAction which forwards the midi commands
to a stk Voicer
by Phil Schatzmann
*/
/***************************************************/
class StkMidiAction : public midi::MidiAction {
public:
StkMidiAction() = default;
StkMidiAction(Instrmnt *instrument, int group=0, int midiChannel = -1) {
addInstrument(instrument, group);
this->group = group;
this->midiChannel = midiChannel;
};
Voicer &voicer() {
return voicer_obj;
}
virtual void addInstrument( Instrmnt *instrument, int group=0 ){
STK_LOGI(__PRETTY_FUNCTION__);
voicer_obj.addInstrument(instrument, group);
}
virtual void removeInstrument( Instrmnt *instrument ){
STK_LOGI(__PRETTY_FUNCTION__);
voicer_obj.removeInstrument(instrument);
}
virtual void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity=87) {
STK_LOGI("StkMidiAction::onNoteOn: channel=%d, note=%d, velocity=%d", channel, note, velocity);
if (midiChannel<=-1 || midiChannel==channel){
voicer_obj.noteOn(note, velocity, group);
}
}
virtual void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity=87) {
STK_LOGI("StkMidiAction::onNoteOff: channel=%d, note=%d, velocity=%d", channel, note, velocity);
if (midiChannel<=-1 || midiChannel==channel){
velocity = velocity > 0 ? velocity : 87;
voicer_obj.noteOff(note, velocity, group);
}
}
virtual void onControlChange(uint8_t channel, uint8_t controller, uint8_t value) {
STK_LOGI(__PRETTY_FUNCTION__);
if (midiChannel<=-1 || midiChannel==channel){
voicer_obj.controlChange(controller,(StkFloat) value, channel);
}
}
virtual void onPitchBend(uint8_t channel, uint8_t value) {
STK_LOGI(__PRETTY_FUNCTION__);
if (midiChannel<=-1 || midiChannel==channel){
voicer_obj.pitchBend(value, channel);
}
}
StkFloat tick( unsigned int channel = 0 ){
return voicer_obj.tick(channel);
}
StkFrames& tick( StkFrames& frames, unsigned int channel = 0 ){
return voicer_obj.tick(frames, channel);
}
protected:
Voicer voicer_obj;
int group;
int midiChannel;
};
}