Permalink
Browse files

made midi channel a #defined const

  • Loading branch information...
1 parent 52270c5 commit 6eeed275899b13b654a73e886e693f3c6de0ae28 @vinmarshall committed Jan 16, 2012
Showing with 16 additions and 8 deletions.
  1. +4 −3 control_change/control_change.pde
  2. +4 −3 play_notes/play_notes.pde
  3. +8 −2 read_notes/read_notes.pde
@@ -47,6 +47,7 @@
#define THRESHOLD 5 // Hysterisis threshold
#define CONTROLLER 11 // Choose a Controller ID -
// http://www.somascape.org/midi/tech/spec.html#ctrlnums
+#define CHANNEL 1 // MIDI Channel
SparkSoftLCD lcd = SparkSoftLCD(LCD_PIN); // Serial LCD
unsigned long intervalTimer; // mark interval time
@@ -63,7 +64,7 @@ void setup() {
lcd.print("Waiting...");
// MIDI Setup
- MIDI.begin(1);
+ MIDI.begin(CHANNEL);
// Other I/O Setup
pinMode(BUTTON_PIN, INPUT);
@@ -93,9 +94,9 @@ void loop() {
lcd.print(value);
// Send the MIDI Control Change Message
- MIDI.sendControlChange(CONTROLLER, value, 1);
+ MIDI.sendControlChange(CONTROLLER, value, CHANNEL);
- // OR - Send the MIDI pitch bend message on channel 1
+ // OR - Send the MIDI pitch bend message
// define value above as: unsigned int value
// value = pot * 16; // Map to pitch bend value 0-16383
// MIDI.sendPitchBend(pitch, 1);
@@ -41,6 +41,7 @@
#define BUTTON_PIN 2 // Pushbutton
#define LCD_PIN 4 // Serial LCD RX line
#define POT_PIN A0 // Potentiometer wiper
+#define CHANNEL 1 // MIDI Channel
SparkSoftLCD lcd = SparkSoftLCD(LCD_PIN); // Serial LCD
bool btnPressed; // is button depressed?
@@ -59,7 +60,7 @@ void setup() {
lcd.print("Waiting...");
// MIDI Setup
- MIDI.begin(1);
+ MIDI.begin(CHANNEL);
// Other I/O Setup
pinMode(BUTTON_PIN, INPUT);
@@ -102,7 +103,7 @@ void loop() {
lcd.print(note);
// Play the MIDI note. Consider expanding this by adding another
// potentiometer for attack / release velocity.
- MIDI.sendNoteOn(note, 64, 1);
+ MIDI.sendNoteOn(note, 64, CHANNEL);
notePlayed = true;
}
@@ -117,7 +118,7 @@ void loop() {
lcd.print("Note Off: ");
lcd.print(note);
// Send the Note Off message to stop playing the note.
- MIDI.sendNoteOff(note, 0, 1);
+ MIDI.sendNoteOff(note, 0, CHANNEL);
notePlayed = false;
}
}
View
@@ -38,6 +38,7 @@
#include <MIDI.h> // download from http://sourceforge.net/projects/arduinomidilib
#define LCD_PIN 4 // Serial LCD RX line
+#define CHANNEL 1 // MIDI Channel
SparkSoftLCD lcd = SparkSoftLCD(LCD_PIN);
@@ -50,11 +51,11 @@ void setup() {
lcd.print("Waiting...");
// MIDI Setup
- MIDI.begin(1);
+ MIDI.begin(CHANNEL);
}
void loop() {
- if (MIDI.read()) {
+ if (MIDI.read(CHANNEL)) { // Channel arg is optional
switch(MIDI.getType()) {
case NoteOn:
{
@@ -83,6 +84,11 @@ void loop() {
break;
}
}
+
+ // We need this so that the MIDI OUT will parrot the data on MIDI IN
+ // without errors. See the comment about this in the Control Change
+ // demo code.
+ MIDI.send(InvalidType, 0, 0, 0);
}
}

0 comments on commit 6eeed27

Please sign in to comment.