Skip to content

Commit

Permalink
send(FORCE) - bulk send - 'MIDIswitch'
Browse files Browse the repository at this point in the history
  • Loading branch information
joshnishikawa committed Apr 25, 2022
1 parent 1ed9b43 commit f345d2e
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 212 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# MIDIcontroller v2.4.3
# MIDIcontroller v2.5.3
### A library for creating Teensy MIDI controllers.
###### by Josh Nishikawa <github.com/joshnishikawa/MIDIcontroller>

Expand All @@ -16,6 +16,14 @@ ___
___

### VERSION LOG:
v2.5.3
- 'MIDIswitch' now preferred over 'MIDIbutton' ( 'MIDIbutton' still works ).
- Added a send(FORCE) function to allow event-based sending of current CC value.
This works for MIDIswitch, MIDIpot, MIDIenc and MIDItouch. This allows
'bulk send' to be implemented. WARNING! In the main loop, just use send()

- MIDIswitch default of MOMENTARY works now. use MIDIswitch(pin, CC)

v2.4.3
- Fixed the PER_DETENT bug (again).
- Made PER_DETENT the default since it works cleaner and is probably more useful
Expand Down
45 changes: 0 additions & 45 deletions examples/MIDIbutton/MIDIbutton.ino.d

This file was deleted.

45 changes: 0 additions & 45 deletions examples/MIDIenc/MIDIenc.ino.d

This file was deleted.

45 changes: 0 additions & 45 deletions examples/MIDIpot/MIDIpot.ino.d

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ byte MIDIchannel = 5;
const int latchPin = 10; //any digital pin
const int ledPin = 13; //Set an LED to show the state of a latch button.

// MOMENTARY buttons are the default. LATCH or TRIGGER may also be set
MIDIbutton myInput(latchPin, 21, LATCH); // Control Change #21
// MOMENTARY, LATCH or TRIGGER may be specified (MOMENTARY is default)
// MOMENTARY: Sends ON message when connection is made, OFF when connection is broken.
// LATCH: Sends alternating ON OFF messages each time a connection is made.
// TRIGGER: Sends an ON *and* OFF message each time a connection is made.
MIDIswitch myInput(latchPin, 21, LATCH); // Control Change #21

void setup(){
pinMode(ledPin, OUTPUT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const int touchPin = 17; //any Capacitive Touch capable pin
const int ledPin = 13; //Set an LED to show the state of a latch button.

// MOMENTARY buttons are the default. LATCH or TRIGGER may also be set
MIDIbutton myInput(touchPin, 15, TRIGGER, TOUCH);// CC #15, capacitive touch
MIDIswitch myInput(touchPin, 15, TRIGGER, TOUCH);// CC #15, capacitive touch

void setup(){
pinMode(ledPin, OUTPUT);
Expand Down
45 changes: 0 additions & 45 deletions examples/afterTouch/afterTouch.ino.d

This file was deleted.

2 changes: 0 additions & 2 deletions examples/rangeFinder/rangeFinder.ino.d

This file was deleted.

3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIDIbutton KEYWORD1
MIDIswitch KEYWORD1
MIDIenc KEYWORD1
MIDIpot KEYWORD1
MIDItouch KEYWORD1
Expand All @@ -23,6 +23,7 @@ TOUCH LITERAL1
FSR LITERAL1
PIEZO LITERAL1
KILL LITERAL1
FORCE LITERAL1
OFF LITERAL1
PER_VALUE LITERAL1
PER_DETENT LITERAL1
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=MIDIcontroller
version=2.4.3
version=2.5.3
author=Josh Nishikawa <joshnishikawa@gmail.com>
maintainer=Josh Nishikawa <joshnishikawa@gmail.com>
sentence=A library for creating Teensy MIDI controllers.
Expand Down
2 changes: 1 addition & 1 deletion src/MIDIcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MIDIcontroller_h

#include <Arduino.h>
#include "MIDIbutton.h"
#include "MIDIswitch.h"
#include "MIDIpot.h"
#include "MIDIenc.h"
#include "MIDItouch.h"
Expand Down
10 changes: 10 additions & 0 deletions src/MIDIenc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ int MIDIenc::send(){
return newValue;
}


int MIDIenc::send(bool force){
if (force){
usbMIDI.sendControlChange(number, value, MIDIchannel);
return value;
}
else{ return -1; }
}


// Manually set the value.
void MIDIenc::write(byte val){
value = val;
Expand Down
1 change: 1 addition & 0 deletions src/MIDIenc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MIDIenc{

int read(); // read input and return a MIDI value (or -1 if none)
int send(); // calls read(), sends and returns a MIDI value (or -1 if none)
int send(bool force); // forces MIDI output regardless of input
byte number;
byte value;
byte outLo, outHi;
Expand Down
17 changes: 17 additions & 0 deletions src/MIDIpot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ int MIDIpot::read(){
return newValue;
};


int MIDIpot::send(){
int newValue = read();
if (killSwitch != 0 && value == outLo && newValue > outLo){//ON before main CC
usbMIDI.sendControlChange(killSwitch, 127, MIDIchannel);
}

if (newValue >= 0){
usbMIDI.sendControlChange(number, newValue, MIDIchannel); //MAIN CC MESSAGE
if (killSwitch != 0 && value >= outLo && newValue == outLo){//OFF after main
Expand All @@ -116,6 +118,21 @@ int MIDIpot::send(){
};


int MIDIpot::send(bool force){
if (force){
balancedValue = analogRead(pin);

int newValue = map(balancedValue, inLo, inHi, outLo, outHi);
newValue = invert ? constrain(newValue, outHi, outLo)
: constrain(newValue, outLo, outHi);

usbMIDI.sendControlChange(number, newValue, MIDIchannel);
return newValue;
}
else{ return -1; }
}


void MIDIpot::setControlNumber(byte num){ // Set the CC number.
number = num;
};
Expand Down
4 changes: 3 additions & 1 deletion src/MIDIpot.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define SMOOTHING 50 // Can be increased at the cost of some responsiveness
#define KILL 9 // previously undefined CC# safe for general purpose assignment
#define OFF 0
#define FORCE true

extern byte MIDIchannel;

Expand Down Expand Up @@ -37,7 +38,8 @@ class MIDIpot{
~MIDIpot();

int read(); // read input and return a MIDI value (or -1 if none)
int send(); // calls read(), sends and returns a MIDI value (or -1 if none)
int send(); //calls read(), sends/returns MIDI val (or -1 if none)
int send(bool force); // forces MIDI output regardless of input
int inLo = 0;
int inHi = 1023;
int outLo = 0;
Expand Down
Loading

0 comments on commit f345d2e

Please sign in to comment.