Browse Source

put includes into library

oloturia 3 weeks ago
parent
commit
9128b7256b

+ 3 - 0
README.md

@@ -16,3 +16,6 @@ They have also a dead zone that filters small variations in the readings. If you
 There are two experimental improvements:
 - In the "console" folder there is a PCB made in Kicad, ready to be printed. Some of the footprints come from Digi-Key/digikey-kicad-library. The example configuration is trained on this PCB.
 - If you need more analog controls, there is a version that features a multiplexer. I've tested with three potentiometers and worked, I've not tested it yet for a full console anyway.
+
+To compile:
+- Link the folder include into Arduino libraries folder (usually <Arduino folder>/libraries) with the name "Controllers"

+ 0 - 0
mixxx_controller_with_mux/Controllers.cpp → include/Controllers.cpp


+ 0 - 0
mixxx_controller_with_mux/Controllers.h → include/Controllers.h


+ 0 - 129
mixxx_controller/Controllers.cpp

@@ -1,129 +0,0 @@
-#include "Controllers.h"
-
-
-// MIDI
-
-// First parameter is the event type (0x09 = note on, 0x08 = note off).
-// Second parameter is note-on/note-off, combined with the channel.
-// Channel can be anything between 0-15. Typically reported to the user as 1-16.
-// Third parameter is the note number (48 = middle C).
-// Fourth parameter is the velocity (64 = normal, 127 = fastest).
-
-// First parameter is the event type (0x0B = control change).
-// Second parameter is the event type, combined with the channel.
-// Third parameter is the control number number (0-119).
-// Fourth parameter is the control value (0-127).
-
-void noteOn(byte channel, byte pitch, byte velocity) {
-  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
-  #ifdef DEBUG
-    Serial.print("Note on:");
-    Serial.print(channel);
-    Serial.print(",");
-    Serial.print(pitch);
-    Serial.print(",");
-    Serial.println(velocity);
-  #endif
-  MidiUSB.sendMIDI(noteOn);
-}
-
-void noteOff(byte channel, byte pitch, byte velocity) {
-  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
-   #ifdef DEBUG
-    Serial.print("Note off:");
-    Serial.print(channel);
-    Serial.print(",");
-    Serial.print(pitch);
-    Serial.print(",");
-    Serial.println(velocity);
-  #endif
-  MidiUSB.sendMIDI(noteOff);
-}
-
-void controlChange(byte channel, byte control, byte value) {
-  midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
-  #ifdef DEBUG
-    Serial.print("Control change:");
-    Serial.print(channel);
-    Serial.print(",");
-    Serial.print(control);
-    Serial.print(",");
-    Serial.println(value);
-  #endif
-  MidiUSB.sendMIDI(event);
-}
-
-// Constructor and methods for analog controls and buttons (encoders use a different library)
-
-AnalogControl::AnalogControl(int pin, byte effect, int middle) {
-  this->pin = pin;
-  this->effect = effect;
-  this->middle = middle;
-  pinMode(pin,INPUT);
-}
-
-void AnalogControl::checkStatus() {
-  value = analogRead(pin);
-  if (value < 0+STICKYNESS){
-      value = 0;
-  } else if (value > 1023-STICKYNESS) {
-      value = 1023;
-  } else if (value > middle-STICKYNESS && value < middle+STICKYNESS) {
-      value = middle;
-  }
-  if ( abs(value - prev_value) > DEAD_ZONE ){
-    controlChange(1,effect, map(value,0,1023,0,127) );
-    prev_value = value;
-    MidiUSB.flush();
-  }
-}
-
-DigitalButton::DigitalButton(int pin, byte effect, byte effect_toggle, byte effect_long, byte effect_long_toggle) {
-  this->effect = effect;
-  this->effect_toggle = effect_toggle;
-  this->effect_long = effect_long;
-  this->effect_long_toggle = effect_long_toggle;
-  this->pin = pin;
-  pinMode(pin,INPUT_PULLUP);
-}
-
-
-void DigitalButton::checkStatus() {
-  if (digitalRead(pin) == LOW && pressed == false) {
-      pressed = true;
-      long_pressed = false;
-      debounce = millis();
-    }
-    if (pressed && (millis() - debounce <= 10) && digitalRead(pin) == HIGH) {
-      pressed = false;
-      return;
-    }
-    if (pressed && (millis() - debounce > 10) && digitalRead(pin) == HIGH) {
-        if (long_pressed == true) {
-          long_pressed = false;
-        } else if (effect_toggle == 0) {
-          controlChange(1,effect,1);
-        } else if (toggled) {
-          controlChange(1,effect,1);
-          toggled = false;
-        } else {
-          controlChange(1,effect_toggle,1);
-          toggled = true;
-        }
-      MidiUSB.flush();        
-      pressed = false;
-    }
-    if (pressed && (millis() - debounce > LONG_INTERVAL) && (digitalRead(pin) == LOW) && (long_pressed == false)) {
-      long_pressed = true;
-      if (effect_long_toggle == 0) {
-        controlChange(1,effect_long,1);
-      } else if (long_toggled) {
-        controlChange(1,effect_long,1);
-        long_toggled = false;     
-      } else {
-        controlChange(1,effect_long_toggle,1);
-        long_toggled = true;              
-      }
-      MidiUSB.flush();
-    }
-}

+ 0 - 60
mixxx_controller/Controllers.h

@@ -1,60 +0,0 @@
-#ifndef CONTROLLERS_H
-#define CONTROLLERS_H
-#include <EncoderButton.h>
-#include "Arduino.h"
-#include "MIDIUSB.h"
-
-
-// Uncomment this line if you want pin and values printed on the serial, remember to open a console because it waits until a connection is established.
-//#define DEBUG
-
-// Analog controls (sliders and potentiometers), the deadzone is the smallest increment that the control must have to trigger the effect.
-#define DEAD_ZONE 15
-
-// Stickyness is a deazone that lies around extreme positions (0-1023) and the middle (511, but trimmable) of readings.
-#define STICKYNESS 30
-
-// Time, in ms, needed for a long press
-#define LONG_INTERVAL 1000
-
-void noteOn(byte channel, byte pitch, byte velocity);
-void noteOff(byte channel, byte pitch, byte velocity);
-void controlChange(byte channel, byte control, byte value);
-
-class AnalogControl {
-  private:
-    int pin;
-    byte effect;
-    int middle;
-    int value;
-    int prev_value;
-  public:
-    AnalogControl(int pin, byte effect, int middle);
-    void checkStatus();
-};
-
-class DigitalButton {
-  private:
-    int pin;
-    bool pressed;
-    long debounce;
-    long countdown;
-    byte effect;
-    byte effect_toggle;
-    bool toggled;
-    byte effect_long;
-    byte effect_long_toggle;
-    bool long_toggled;
-    bool long_pressed;
-  public:
-    DigitalButton(int pin, byte effect, byte effect_toggle, byte effect_long, byte effect_long_toggle);
-    void checkStatus();
-};
-
-
-struct RotaryEncoderControl {
-  EncoderButton rotary_encoder;
-  byte effect;
-};
-
-#endif

+ 1 - 1
mixxx_controller/mixxx_controller.ino

@@ -1,4 +1,4 @@
-#include "Controllers.h"
+#include <Controllers.h>
 
 /* This is a sketch that it transforms your Arduino Leonardo or Leonardo like (i.e. boards with atmega32u4) in a MIDI console for interfacing
  * with Mixxx (https://mixxx.org). Perhaps you can also use an UNO but you have to sacrifice some pins in order to add a MIDI interface to your Arduino.

+ 1 - 1
mixxx_controller_with_mux/mixxx_controller_with_mux.ino

@@ -1,4 +1,4 @@
-#include "Controllers.h"
+#include <Controllers.h>
 
 /* This is a sketch that it transforms your Arduino Leonardo or Leonardo like (i.e. boards with atmega32u4) in a MIDI console for interfacing
  * with Mixxx (https://mixxx.org). Perhaps you can also use an UNO but you have to sacrifice some pins in order to add a MIDI interface to your Arduino.