16template <
int CHANNELS>
36 for (
int c = 0; c < CHANNELS; c++) {
43 for (
int i = 0; i < 128; i++) {
56 for (
int note = 0; note <= 127; note++) {
73 bool changedNote = gate &&
gates[c] && (note !=
notes[c]);
74 bool enabledGate = gate && !
gates[c];
75 bool disabledGate = !gate &&
gates[c];
76 if (changedNote || disabledGate) {
85 if (changedNote || enabledGate) {
171 if (this->clk ==
clk)
186 if (this->start ==
start)
201 if (this->cont ==
cont)
216 if (this->stop ==
stop)
241template <u
int8_t MAX_CHANNELS>
285 int16_t
pws[MAX_CHANNELS];
319 for (uint8_t c = 0; c < MAX_CHANNELS; c++) {
337 for (uint8_t c = 0; c < wheelChannels; c++) {
338 float pw =
pws[c] / 8191.f;
345 float mod =
mods[c] / 127.f;
360 for (uint8_t c = 0; c <
channels; c++) {
389 for (uint8_t c = 0; c < MAX_CHANNELS; c++) {
406 for (uint8_t c = 0; c < MAX_CHANNELS; c++) {
490 for (uint8_t c = 0; c <
channels; c++) {
491 if (
notes[c] == note)
498 for (uint8_t i = 0; i <
channels; i++) {
513 for (uint8_t c = 0; c <
channels; c++) {
545 notes[channel] = note;
546 gates[channel] =
true;
560 for (uint8_t c = 0; c <
channels; c++) {
561 if (
notes[c] == note) {
600 for (uint8_t c = 0; c <
channels; c++) {
607 if (
notes[c] == note) {
641 for (uint8_t c = 0; c < MAX_CHANNELS; c++) {
663 json_t* rootJ = json_object();
664 json_object_set_new(rootJ,
"pwRange", json_real(
pwRange));
665 json_object_set_new(rootJ,
"smooth", json_boolean(
smooth));
666 json_object_set_new(rootJ,
"channels", json_integer(
channels));
667 json_object_set_new(rootJ,
"polyMode", json_integer(
polyMode));
668 json_object_set_new(rootJ,
"clockDivision", json_integer(
clockDivision));
671 json_object_set_new(rootJ,
"lastPw", json_integer(
pws[0]));
672 json_object_set_new(rootJ,
"lastMod", json_integer(
mods[0]));
675 json_object_set_new(rootJ,
"filterLambda", json_real(
pwFilters[0].lambda));
680 json_t* pwRangeJ = json_object_get(rootJ,
"pwRange");
682 pwRange = json_number_value(pwRangeJ);
684 json_t* smoothJ = json_object_get(rootJ,
"smooth");
686 smooth = json_boolean_value(smoothJ);
688 json_t* channelsJ = json_object_get(rootJ,
"channels");
692 json_t* polyModeJ = json_object_get(rootJ,
"polyMode");
696 json_t* clockDivisionJ = json_object_get(rootJ,
"clockDivision");
700 json_t* lastPwJ = json_object_get(rootJ,
"lastPw");
702 pws[0] = json_integer_value(lastPwJ);
705 json_t* lastPitchJ = json_object_get(rootJ,
"lastPitch");
707 pws[0] = json_integer_value(lastPitchJ) - 8192;
709 json_t* lastModJ = json_object_get(rootJ,
"lastMod");
711 mods[0] = json_integer_value(lastModJ);
714 json_t* filterLambdaJ = json_object_get(rootJ,
"filterLambda");
int clamp(int x, int a, int b)
Limits x between a and b.
Definition math.hpp:32
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Converts gates and CV to MIDI messages.
Definition midi.hpp:17
bool gates[CHANNELS]
Definition midi.hpp:20
void reset()
Definition midi.hpp:35
void setSustainPedal(int8_t cc)
Definition midi.hpp:153
void setChannelPressure(int8_t val)
Definition midi.hpp:111
void setContinue(bool cont)
Definition midi.hpp:200
void panic()
Definition midi.hpp:53
bool stop
Definition midi.hpp:27
bool cont
Definition midi.hpp:28
MidiGenerator()
Definition midi.hpp:31
void setPitchWheel(int16_t pw)
Definition midi.hpp:157
void setCc(int8_t cc, int id)
Definition midi.hpp:124
void setBalance(int8_t cc)
Definition midi.hpp:145
bool start
Definition midi.hpp:26
void setPan(int8_t cc)
Definition midi.hpp:149
int8_t notes[CHANNELS]
Definition midi.hpp:19
int16_t pw
Definition midi.hpp:24
void setNoteGate(int8_t note, bool gate, int c)
Definition midi.hpp:72
void setClock(bool clk)
Definition midi.hpp:170
void setFrame(int64_t frame)
Definition midi.hpp:230
void setVelocity(int8_t vel, int c)
Must be called before setNoteGate().
Definition midi.hpp:68
int8_t channelPressure
Definition midi.hpp:22
void setStop(bool stop)
Definition midi.hpp:215
bool clk
Definition midi.hpp:25
void setVolume(int8_t cc)
Definition midi.hpp:141
void setKeyPressure(int8_t val, int c)
Definition midi.hpp:98
int8_t ccs[128]
Definition midi.hpp:23
void setModWheel(int8_t cc)
Definition midi.hpp:137
int8_t keyPressures[CHANNELS]
Definition midi.hpp:21
void setStart(bool start)
Definition midi.hpp:185
int64_t frame
Definition midi.hpp:29
int8_t vels[CHANNELS]
Definition midi.hpp:18
virtual void onMessage(const midi::Message &message)
Definition midi.hpp:234
Converts MIDI note and transport messages to gates, CV, and other states.
Definition midi.hpp:242
dsp::PulseGenerator retriggerPulses[MAX_CHANNELS]
Definition midi.hpp:295
uint8_t velocities[MAX_CHANNELS]
Definition midi.hpp:277
bool smooth
Enables pitch-wheel and mod-wheel exponential smoothing.
Definition midi.hpp:249
void setFilterLambda(float lambda)
Sets exponential smoothing filter lambda speed.
Definition midi.hpp:640
void setChannels(uint8_t channels)
Definition midi.hpp:620
bool gates[MAX_CHANNELS]
Definition midi.hpp:276
uint8_t channels
Actual number of polyphonic channels.
Definition midi.hpp:255
void releasePedal()
Definition midi.hpp:582
dsp::PulseGenerator clockDividerPulse
Definition midi.hpp:294
float getPw(uint8_t channel)
Returns pitch wheel value, from -1 to 1.
Definition midi.hpp:648
dsp::PulseGenerator stopPulse
Definition midi.hpp:297
uint8_t pressNote(uint8_t note, uint8_t channel)
Returns actual assigned channel.
Definition midi.hpp:530
uint8_t getWheelChannels()
Returns number of polyphonic channels for pitch and mod wheels.
Definition midi.hpp:658
dsp::ExponentialFilter pwFilters[MAX_CHANNELS]
Smoothing filters for wheel values.
Definition midi.hpp:290
void setPolyMode(PolyMode polyMode)
Definition midi.hpp:627
uint8_t assignChannel(uint8_t note)
Definition midi.hpp:483
PolyMode polyMode
Definition midi.hpp:265
uint8_t aftertouches[MAX_CHANNELS]
Definition midi.hpp:278
int64_t clock
Clock index from song start.
Definition midi.hpp:270
float getMod(uint8_t channel)
Returns mod wheel value, from 0 to 1.
Definition midi.hpp:653
float getPitchVoltage(uint8_t channel)
Definition midi.hpp:634
dsp::PulseGenerator startPulse
Definition midi.hpp:296
void panic()
Resets performance state.
Definition midi.hpp:318
std::vector< uint8_t > heldNotes
Definition midi.hpp:279
bool pedal
Whether sustain pedal is held.
Definition midi.hpp:273
void processFilters(float deltaTime)
Definition midi.hpp:335
MidiParser()
Definition midi.hpp:300
json_t * toJson()
Definition midi.hpp:662
float pwRange
Number of semitones to bend up/down by pitch wheel.
Definition midi.hpp:246
dsp::PulseGenerator clockPulse
Definition midi.hpp:293
uint8_t mods[MAX_CHANNELS]
Mod wheel values, from 0 to 127.
Definition midi.hpp:288
dsp::PulseGenerator continuePulse
Definition midi.hpp:298
int16_t pws[MAX_CHANNELS]
Pitch wheel values, from -8192 to 8191.
Definition midi.hpp:285
uint32_t clockDivision
Number of 24 PPQN clocks between clock divider pulses.
Definition midi.hpp:252
void pressPedal()
Definition midi.hpp:576
int8_t rotateIndex
Definition midi.hpp:280
dsp::ExponentialFilter modFilters[MAX_CHANNELS]
Definition midi.hpp:291
uint8_t notes[MAX_CHANNELS]
Definition midi.hpp:275
PolyMode
Method for assigning notes to polyphony channels.
Definition midi.hpp:258
@ ROTATE_MODE
Definition midi.hpp:259
@ REUSE_MODE
Definition midi.hpp:260
@ RESET_MODE
Definition midi.hpp:261
@ NUM_POLY_MODES
Definition midi.hpp:263
@ MPE_MODE
Definition midi.hpp:262
void processCC(const midi::Message &msg)
Definition midi.hpp:427
void processMessage(const midi::Message &msg)
Definition midi.hpp:365
void reset()
Resets settings and performance state.
Definition midi.hpp:306
void processPulses(float deltaTime)
Definition midi.hpp:354
void fromJson(json_t *rootJ)
Definition midi.hpp:679
void processSystem(const midi::Message &msg)
Definition midi.hpp:451
void releaseNote(uint8_t note)
Definition midi.hpp:551
uint8_t getChannels()
Definition midi.hpp:616
When triggered, holds a high value for a specified time before going low again.
Definition digital.hpp:167
void trigger(float duration=1e-3f)
Begins a trigger with the given duration.
Definition digital.hpp:189
bool process(float deltaTime)
Advances the state by deltaTime.
Definition digital.hpp:176
Applies exponential smoothing to a signal with the ODE .
Definition filter.hpp:59
T process(T deltaTime, T in)
Definition filter.hpp:76
void setLambda(T lambda)
Definition filter.hpp:67
void reset()
Definition filter.hpp:63
T out
Definition filter.hpp:60
void setSize(int size)
Definition midi.hpp:31
void setFrame(int64_t frame)
Definition midi.hpp:85
void setValue(uint8_t value)
Definition midi.hpp:73
void setStatus(uint8_t status)
Definition midi.hpp:51
uint8_t getNote() const
Definition midi.hpp:57
void setNote(uint8_t note)
Definition midi.hpp:62
void setChannel(uint8_t channel)
Definition midi.hpp:40
uint8_t getChannel() const
Definition midi.hpp:35
uint8_t getStatus() const
Definition midi.hpp:46
uint8_t getValue() const
Definition midi.hpp:68