Skip to content

Commit

Permalink
made midi channel a #defined const
Browse files Browse the repository at this point in the history
  • Loading branch information
vinmarshall committed Jan 16, 2012
1 parent 52270c5 commit 6eeed27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 4 additions & 3 deletions control_change/control_change.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions play_notes/play_notes.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
}
10 changes: 8 additions & 2 deletions read_notes/read_notes.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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:
{
Expand Down Expand Up @@ -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);
}

}
Expand Down

0 comments on commit 6eeed27

Please sign in to comment.