From 2e2bda1dbdd8edc9cf8f02941d0c4884decc3c9a Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 19 Jul 2018 13:22:55 +0200 Subject: [PATCH] Remove MASTER_KEY_PIN code. It was awful. I hope I can make this better the next days. Added and fixed stereo panning code of. --- MicroDexed.ino | 82 ++++++++++++++++++-------------------------------- config.h | 3 +- dexed.cpp | 2 +- 3 files changed, 32 insertions(+), 55 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 6032d94..2639b97 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -34,16 +34,13 @@ #ifdef USE_ONBOARD_USB_HOST #include #endif -#ifdef MASTER_BUTTON_PIN -#include -#endif -#if !defined(MASTER_KEY_MIDI) || !defined(MASTER_BUTTON_PIN) // selecting sounds by encoder, button and display +#ifndef MASTER_KEY_MIDI // selecting sounds by encoder, button and display #include #include #include #endif -#if !defined(MASTER_KEY_MIDI) || !defined(MASTER_BUTTON_PIN) +#ifndef MASTER_KEY_MIDI // [I2C] SCL: Pin 19, SDA: Pin 18 (https://www.pjrc.com/teensy/td_libs_Wire.html) #define LCD_I2C_ADDRESS 0x3f #define LCD_CHARS 20 @@ -53,23 +50,18 @@ Encoder enc1(ENC1_PIN_A, ENC1_PIN_B); Bounce but1 = Bounce(BUT1_PIN, 10); // 10 ms debounce #endif -#ifdef MASTER_BUTTON_PIN -Bounce master_key = Bounce(MASTER_BUTTON_PIN, 10); // 10 ms debounce -#endif - // GUItool: begin automatically generated code -AudioPlayQueue queue1; //xy=335,318 -AudioAmplifier amp1; //xy=873,270 -AudioAmplifier amp2; //xy=876,319 -AudioOutputI2S i2s1; //xy=1212,300 +AudioPlayQueue queue1; //xy=950,406 +AudioAmplifier amp2; //xy=1172,438 +AudioAmplifier amp1; //xy=1173,378 +AudioOutputI2S i2s1; //xy=1321,403 AudioConnection patchCord1(queue1, amp1); AudioConnection patchCord2(queue1, amp2); -AudioConnection patchCord3(amp1, 0, i2s1, 0); -AudioConnection patchCord4(amp2, 0, i2s1, 1); -AudioControlSGTL5000 sgtl5000_1; //xy=758,427 +AudioConnection patchCord3(amp2, 0, i2s1, 1); +AudioConnection patchCord4(amp1, 0, i2s1, 0); +AudioControlSGTL5000 sgtl5000_1; //xy=1323,459 // GUItool: end automatically generated code - Dexed* dexed = new Dexed(SAMPLE_RATE); bool sd_card_available = false; uint8_t bank = EEPROM.read(EEPROM_BANK_ADDR); @@ -77,7 +69,7 @@ uint8_t midi_channel = DEFAULT_MIDI_CHANNEL; uint32_t xrun = 0; uint32_t overload = 0; -#if defined(MASTER_KEY_MIDI) || defined(MASTER_BUTTON_PIN) +#ifdef MASTER_KEY_MIDI bool master_key_enabled = false; #endif @@ -105,7 +97,7 @@ void setup() Serial.begin(SERIAL_SPEED); delay(200); -#if !defined(MASTER_KEY_MIDI) && !defined(MASTER_BUTTON_PIN) +#ifndef MASTER_KEY_MIDI lcd.init(); lcd.blink_off(); lcd.cursor_off(); @@ -139,7 +131,7 @@ void setup() sgtl5000_1.volume(VOLUME); amp1.gain(0.5); amp2.gain(0.5); - + // start SD card SPI.setMOSI(SDCARD_MOSI_PIN); SPI.setSCK(SDCARD_SCK_PIN); @@ -181,10 +173,6 @@ void setup() cpu_mem_millis = 0; #endif -#ifdef MASTER_BUTTON_PIN - pinMode(MASTER_BUTTON_PIN, INPUT_PULLUP); -#endif - #ifdef TEST_NOTE //dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_DEP] = 99; // full pitch mod depth //dexed->data[DEXED_VOICE_OFFSET+DEXED_LFO_PITCH_MOD_SENS] = 99; // full pitch mod sense @@ -203,7 +191,7 @@ void setup() void loop() { int16_t* audio_buffer; // pointer to 128 * int16_t (=256 bytes!) - + while (42 == 42) // DON'T PANIC! { #if defined (DEBUG) && defined (SHOW_CPU_LOAD_MSEC) @@ -214,23 +202,6 @@ void loop() } #endif -#if MASTER_BUTTON_PIN - if (master_key.update()) - { - if (master_key.fallingEdge()) - { - master_key_enabled = true; - dexed->notesOff(); - Serial.println(F("Master key enabled")); - } - else if (master_key.risingEdge()) - { - master_key_enabled = false; - Serial.println(F("Master key disabled")); - } - } -#endif - handle_input(); audio_buffer = queue1.getBuffer(); @@ -238,10 +209,10 @@ void loop() { Serial.println(F("E: audio_buffer allocation problems!")); } - + if (!queue1.available()) continue; - + elapsedMicros t1; dexed->getSamples(AUDIO_BLOCK_SAMPLES, audio_buffer); uint32_t t2 = t1; @@ -286,7 +257,7 @@ void handle_input(void) } #endif -#if !defined(MASTER_KEY_MIDI) && !defined(MASTER_BUTTON_PIN) +#ifndef MASTER_KEY_MIDI int enc1_val = enc1.read(); if (but1.update()) @@ -368,7 +339,7 @@ void print_midi_event(uint8_t type, uint8_t data1, uint8_t data2) #endif #endif -#if defined(MASTER_KEY_MIDI) || defined(MASTER_BUTTON_PIN) +#ifdef MASTER_KEY_MIDI bool handle_master_key(uint8_t data) { int8_t num = num_key_base_c(data); @@ -439,7 +410,16 @@ bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) { uint8_t c = type & 0x0f; if (c != midi_channel) - return (true); + { +#ifdef DEBUG + Serial.print(F("Ignoring MIDI data on channel ")); + Serial.print(c); + Serial.print(F("(listening on ")); + Serial.print(midi_channel); + Serial.println(F(")")); +#endif + return (false); + } } // now throw away the MIDI channel information @@ -463,8 +443,6 @@ bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) } else { -#endif -#if defined(MASTER_KEY_MIDI) || defined(MASTER_BUTTON_PIN) if (master_key_enabled) { if (type == 0x80) // handle when note is released @@ -473,14 +451,14 @@ bool queue_midi_event(uint8_t type, uint8_t data1, uint8_t data2) else #endif ret = dexed->processMidiMessage(type, data1, data2); -#if defined(MASTER_KEY_MIDI) + +#ifdef MASTER_KEY_MIDI } #endif - return (ret); } -#if defined(MASTER_KEY_MIDI) || defined(MASTER_BUTTON_PIN) +#ifdef MASTER_KEY_MIDI int8_t num_key_base_c(uint8_t midi_note) { int8_t num = 0; diff --git a/config.h b/config.h index 5782cb9..b022ced 100644 --- a/config.h +++ b/config.h @@ -33,7 +33,7 @@ #define DEFAULT_SYSEXBANK 0 #define DEFAULT_SYSEXSOUND 0 //#define DEXED_ENGINE DEXED_ENGINE_MODERN -#define AUDIO_MEM 2 +#define AUDIO_MEM 4 #if !defined(__MK66FX1M0__) // check for Teensy-3.6 #define MAX_NOTES 11 // No? @@ -44,7 +44,6 @@ // Master key handling (comment for disabling) #define MASTER_KEY_MIDI MIDI_C7 #define MASTER_NUM1 MIDI_C2 -//#define MASTER_BUTTON_PIN 25 // overrides the MASTER_KEY_MIDI if enabled // Debug output #define SERIAL_SPEED 38400 diff --git a/dexed.cpp b/dexed.cpp index 70a6ba9..5dcb875 100644 --- a/dexed.cpp +++ b/dexed.cpp @@ -41,7 +41,7 @@ extern uint8_t bank; extern uint32_t overload; extern bool load_sysex(uint8_t bank, uint8_t voice_number); -extern AudioControlSGTL5000 sgtl5000_1; +extern AudioControlSGTL5000 sgtl5000_1; extern AudioAmplifier amp1; extern AudioAmplifier amp2;