Skip to content

Commit

Permalink
Edges LEDs on via either MIDI or gate input
Browse files Browse the repository at this point in the history
  • Loading branch information
brianleu committed Oct 19, 2018
1 parent 35bf03a commit 8fe0bd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 7 additions & 5 deletions edges/edges.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,18 @@ ISR(TCE0_OVF_vect) {
{
// Otherwise, scan the gate.
uint8_t gate = ~gate_inputs.value();
bool g_1 = (gate & 1) || midi_handler.gate(0) || settings.arpeggio(0);
uint8_t midi_gate = midi_handler.gate();
bool g_1 = (gate & 1) || (midi_gate & 1) || settings.arpeggio(0);
channel_0.Gate<Channel0>(g_1);
channel_1.Gate<Channel1>(g_1);

bool g_2 = (gate & 2) || midi_handler.gate(1) || settings.arpeggio(1);
bool g_2 = (gate & 2) || (midi_gate & 2) || settings.arpeggio(1);
channel_2.Gate<Channel2>(g_2);

bool g_3 = (gate & 4) || midi_handler.gate(2) || settings.arpeggio(2);
bool g_3 = (gate & 4) || (midi_gate & 4) || settings.arpeggio(2);
channel_3.Gate<Channel3>(g_3);

bool g_4 = (gate & 8) || midi_handler.gate(3) || settings.arpeggio(3);
bool g_4 = (gate & 8) || (midi_gate & 8) || settings.arpeggio(3);
channel_4.Gate(g_4);

// Read some MIDI bytes, but process them later.
Expand Down Expand Up @@ -230,7 +231,8 @@ int main(void) {
}
mask <<= 1;
}
ui.set_gate(gate);
uint8_t midi_gate = midi_handler.gate();
ui.set_gate(gate|midi_gate);
ui.Poll();
}

Expand Down
2 changes: 1 addition & 1 deletion edges/midi_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
namespace edges {

/* static */
bool MidiHandler::gate_[kNumChannels];
uint8_t MidiHandler::gate_;

/* static */
int16_t MidiHandler::pitch_[kNumChannels];
Expand Down
12 changes: 6 additions & 6 deletions edges/midi_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MidiHandler : public midi::MidiDevice {
allocator_.Init();
allocator_.set_size(4);
learning_ = false;
memset(gate_, false, sizeof(gate_));
gate_ = 0;
memset(pitch_, -1, sizeof(pitch_));
}

Expand Down Expand Up @@ -74,7 +74,7 @@ class MidiHandler : public midi::MidiDevice {
channel = allocator_.NoteOn(note);
pitch_[channel] = note << 7;
}
gate_[channel] = true;
gate_ |= (1 << channel);
}

static inline void NoteOff(uint8_t channel, uint8_t note, uint8_t velocity) {
Expand All @@ -85,11 +85,11 @@ class MidiHandler : public midi::MidiDevice {
if (stack_[channel].size()) {
pitch_[channel] = stack_[channel].most_recent_note().note << 7;
}
gate_[channel] = stack_[channel].size() != 0;
(stack_[channel].size() != 0) ? gate_ |= (1 << channel) : gate_ &= ~(1 << channel);
} else {
channel = allocator_.NoteOff(note);
if (channel != 0xff) {
gate_[channel] = false;
gate_ &= ~(1 << channel);
}
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ class MidiHandler : public midi::MidiDevice {

static inline bool learning() { return learning_; }

static inline bool gate(uint8_t channel) { return gate_[channel]; }
static inline uint8_t gate() { return gate_; }
static int16_t shift_pitch(uint8_t channel, int16_t pitch) {
if (pitch_[channel] == -1) {
return pitch;
Expand Down Expand Up @@ -161,7 +161,7 @@ class MidiHandler : public midi::MidiDevice {

private:
static bool learning_;
static bool gate_[kNumChannels];
static uint8_t gate_;
static int16_t pitch_[kNumChannels];
static int16_t pitch_bend_[kNumChannels];

Expand Down

0 comments on commit 8fe0bd4

Please sign in to comment.