20#include "model/drum/gate_drum.h"
23struct InterruptsDisabled;
25#define WHICH_GATE_OUTPUT_IS_RUN 2
26#define WHICH_GATE_OUTPUT_IS_CLOCK 3
28const uint8_t gatePort[] = {2, 2, 2, 4};
29const uint8_t gatePin[] = {7, 8, 9, 0};
34 noteCurrentlyPlaying = -32768;
40 int16_t noteCurrentlyPlaying;
41 uint8_t voltsPerOctave;
51 GateChannel() { on =
false; }
54 uint32_t timeLastSwitchedOff;
70 void sendNote(
bool on, uint8_t channel, int16_t note = -32768);
71 void setGateType(uint8_t whichGate, GateType value);
72 void setCVVoltsPerOctave(uint8_t channel, uint8_t value);
73 void setCVTranspose(uint8_t channel, int32_t semitones, int32_t cents);
74 void setCVPitchBend(uint8_t channel, int32_t value,
bool outputToo =
true);
75 int32_t calculateVoltage(int32_t note, uint8_t channel);
76 void physicallySwitchGate(int32_t channel);
78 void cvOutUpdated(
const InterruptsDisabled&);
85 void updateRunOutput();
86 bool isTriggerClockOutputEnabled();
96 bool isAnythingPending()
const {
return pendingGates != 0; }
99 CVChannel cvChannels[NUM_PHYSICAL_CV_CHANNELS];
101 uint8_t minGateOffTime;
108 uint32_t mostRecentSwitchOffTimeOfPendingNoteOn;
110 void sendVoltageOut(uint8_t channel, uint16_t voltage);
112 inline bool isNoteOn(int32_t channel, int32_t note) {
113 return (gateChannels[channel].on && cvChannels[channel].noteCurrentlyPlaying == note);
117 void recalculateCVChannelVoltage(uint8_t channel);
118 void switchGateOff(int32_t channel);
119 void switchGateOn(int32_t channel, int32_t doInstantlyIfPossible =
false);
122 uint8_t gateLevel(int32_t channel)
const {
124 return gateChannels[channel].on == (gateChannels[channel].mode == GateType::S_TRIG);
136 uint8_t levelsAwaitingCV{0};
Definition cv_engine.h:31
Definition cv_engine.h:66
void outputGates(const GateOutputs &outputs, const InterruptsDisabled &)
physically output a snapshot of gates
Definition cv_engine.cpp:127
void switchGateNow(int32_t channel)
physically switch a gate right now, superseding any pending or scheduled output for it
Definition cv_engine.cpp:145
void updateGateOutputs()
physically send all pending gate outs right now
Definition cv_engine.cpp:93
bool cvOutPending
signifies there's a gate that can't go until the cv is output
Definition cv_engine.h:127
uint8_t pendingGates
bitmask of gate channels which have changed but haven't been taken for output yet
Definition cv_engine.h:129
void updateClockOutput()
toggles clock, does not physically update until updateGateOutputs called
Definition cv_engine.cpp:367
uint8_t pendingNoteOnGates
subset of pendingGates which are deferred note-ons (must wait for CV and respect minGateOffTime)
Definition cv_engine.h:133
uint8_t pendingAsapGates
subset of pendingGates which should go asap (run signal), respecting minGateOffTime
Definition cv_engine.h:131
GateOutputs takePendingGateOutputs(bool includeAsap)
Definition cv_engine.cpp:104
uint8_t gatesAwaitingCV
gates whose scheduled time has passed but are being held until their cv is output
Definition cv_engine.h:135
Definition cv_engine.h:49
Definition cv_engine.h:59
uint8_t cvWaitMask
channels in mask which can't switch until any pending CV has been sent
Definition cv_engine.h:62
uint8_t levels
pin level for each channel in mask
Definition cv_engine.h:61
bool needsMinOffTime
contains a note-on which must respect minGateOffTime
Definition cv_engine.h:63
uint8_t mask
bitmask of gate channels to physically switch
Definition cv_engine.h:60