diff --git a/code/daisy-looper/daisy-looper.ino b/code/daisy-looper/daisy-looper.ino index c9fd5132ba35eebac10b195ba07f2e34bac7f0b8..cb83c8130892c9e383b9e2c9e6e2126c73cd0b59 100644 --- a/code/daisy-looper/daisy-looper.ino +++ b/code/daisy-looper/daisy-looper.ino @@ -1,10 +1,3 @@ - - -// Title: moogladder -// Description: Sweeps the cutoff with an lfo -// Hardware: Daisy Seed -// Author: Ben Sergentanis - #include "DaisyDuino.h" #include <Wire.h> #include <Adafruit_GFX.h> @@ -23,6 +16,8 @@ MIDI_CREATE_DEFAULT_INSTANCE(); #define BUFFER_LENGTH_SECONDS 5 +#define DEBUGMODE + static const size_t buffer_length = 48000 * BUFFER_LENGTH_SECONDS; static float DSY_SDRAM_BSS buffer[buffer_length]; static float DSY_SDRAM_BSS buffer_b[buffer_length]; @@ -61,7 +56,7 @@ Potentiometer pot_6 = Potentiometer(A5); Potentiometer pot_7 = Potentiometer(A6); // RGB LED R G B -RGBLed rgb_led = RGBLed(A10, A9, A11); +RGBLed rgb_led = RGBLed(A10, A11, A11); // OLED Display @@ -77,8 +72,7 @@ Ui ui; DaisyHardware hw; // Variables for the Audio-Callback -size_t num_channels -; +size_t num_channels; float blocksize; float drywetmix = 0.0f; float delaymix = 0.0f; @@ -88,6 +82,8 @@ float lfo_amount = 0.0f; float pitch_val = 0.5f; float midi_pitch_offset = 0.0f; +float pressure = 0.0f; + // Actual audio-processing is orchestrated here void AudioCallback(float **in, float **out, size_t size) { float output = 0.0f; @@ -173,6 +169,8 @@ void AudioCallback(float **in, float **out, size_t size) { break; } + // looper_out = pressure * looper_out; + // Mix the dry/Wet of the looper output = drywetmix * looper_out + in[1][i] * (1.0f - drywetmix); @@ -206,8 +204,17 @@ void AudioCallback(float **in, float **out, size_t size) { // TODO: Is USB Midi possible? https://github.com/electro-smith/DaisyExamples/blob/master/seed/USB_MIDI/USB_MIDI.cpp void handleNoteOn(byte inChannel, byte inNote, byte inVelocity) { + #ifdef DEBUGMODE + Serial.print("[MIDI ON] chn<"); + Serial.print((int) inChannel); + Serial.print("> note<"); + Serial.print((int) inNote); + Serial.print("> velocity<"); + Serial.print((int) inVelocity); + Serial.println(">"); + #endif // Note Off can come in as Note On w/ 0 Velocity - if (inVelocity == 0.f) { + if (inVelocity == 0.0f) { midi_pitch_offset = 0.0f; } else { @@ -218,9 +225,29 @@ void handleNoteOn(byte inChannel, byte inNote, byte inVelocity) { void handleNoteOff(byte inChannel, byte inNote, byte inVelocity) { + #ifdef DEBUGMODE + Serial.print("[MIDI OFF] chn<"); + Serial.print((int) inChannel); + Serial.print("> note<"); + Serial.print((int) inNote); + Serial.print("> velocity<"); + Serial.print((int) inVelocity); + Serial.println(">"); + #endif midi_pitch_offset = 0.0f; } +void handleAftertouch(byte channel, byte channel_pressure) { + #ifdef DEBUGMODE + Serial.print("[MIDI AFTER] chn<"); + Serial.print((int) channel); + Serial.print("> pressure<"); + Serial.print((int) channel_pressure); + Serial.println(">"); + #endif + pressure = float(channel_pressure)/127.0f; +} + void setup() { @@ -289,6 +316,8 @@ void setup() { // Setup MIDI handlers MIDI.setHandleNoteOn(handleNoteOn); MIDI.setHandleNoteOff(handleNoteOff); + MIDI.setHandleAfterTouchChannel(handleAftertouch); + MIDI.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages // Set Knob names and display functions @@ -296,9 +325,9 @@ void setup() { pot_2.name = "Length"; pot_3.setDisplayMode("Pitch", 1000.0f, POT_DISPLAY_MODE_PERCENT); pot_4.setDisplayMode("Mix", 100.0f, POT_DISPLAY_MODE_PERCENT); - pot_5.setDisplayMode("Delay", 100.0f, POT_DISPLAY_MODE_PERCENT); - pot_6.setDisplayMode("Reverb", 100.0f, POT_DISPLAY_MODE_PERCENT); - pot_7.setDisplayMode("LFO", 100.0f, POT_DISPLAY_MODE_PERCENT); + pot_5.setDisplayMode("LFO", 100.0f, POT_DISPLAY_MODE_PERCENT); + pot_6.setDisplayMode("Delay", 100.0f, POT_DISPLAY_MODE_PERCENT); + pot_7.setDisplayMode("Reverb", 100.0f, POT_DISPLAY_MODE_PERCENT); // Set Knob Scaling Modes // pot_3.setBipolar(); @@ -349,12 +378,16 @@ void loop() { if (!isnan(p4)) { drywetmix = p4; } if (!isnan(p5)) { delaymix = p5; } // Delaytime is in samples - if (!isnan(p5)) { delaytime = 100.0f + p5 * 23900.0f; } - if (!isnan(p6)) { reverbmix = p6; } - if (!isnan(p7)) { lfo_amount = p7; } + if (!isnan(p5)) { lfo_amount = p5; } + if (!isnan(p6)) { delaytime = 100.0f + p6 * 23900.0f; } + if (!isnan(p7)) { reverbmix = p7; Serial.print("Reverb was not NaN: "); Serial.println(reverbmix); } // Render the UI (frame rate limited by UI_MAX_FPS in ui.h) + // double start = millis(); ui.Render(); + // Serial.print("ui Render took "); + // Serial.print(millis()-start); + // Serial.println("ms"); // Set the Color and brightness of the RGB LED in 8 bits rgb_led.setAudioLevelIndicator(input_envelope_follower.getValue());