Skip to content

Commit

Permalink
No upper case cs namespace, Channel_x constants
Browse files Browse the repository at this point in the history
To avoid conflicts with macros, use the lower case `cs` namespace
instead of `CS`, and provide title case constants `Channel_x`,
deprecating the old `CHANNEL_X` versions.
  • Loading branch information
tttapa committed Sep 3, 2023
1 parent f2fc513 commit aaf6eea
Show file tree
Hide file tree
Showing 121 changed files with 525 additions and 498 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ CD74HC4051 mux {
// Create an array of CCPotentiometer objects that send out MIDI Control Change
// messages when you turn the potentiometers connected to the 8 inputs of the mux.
CCPotentiometer volumePotentiometers[] {
{ mux.pin(0), { MIDI_CC::Channel_Volume, CHANNEL_1 } },
{ mux.pin(1), { MIDI_CC::Channel_Volume, CHANNEL_2 } },
{ mux.pin(2), { MIDI_CC::Channel_Volume, CHANNEL_3 } },
{ mux.pin(3), { MIDI_CC::Channel_Volume, CHANNEL_4 } },
{ mux.pin(4), { MIDI_CC::Channel_Volume, CHANNEL_5 } },
{ mux.pin(5), { MIDI_CC::Channel_Volume, CHANNEL_6 } },
{ mux.pin(6), { MIDI_CC::Channel_Volume, CHANNEL_7 } },
{ mux.pin(7), { MIDI_CC::Channel_Volume, CHANNEL_8 } },
{ mux.pin(0), { MIDI_CC::Channel_Volume, Channel_1 } },
{ mux.pin(1), { MIDI_CC::Channel_Volume, Channel_2 } },
{ mux.pin(2), { MIDI_CC::Channel_Volume, Channel_3 } },
{ mux.pin(3), { MIDI_CC::Channel_Volume, Channel_4 } },
{ mux.pin(4), { MIDI_CC::Channel_Volume, Channel_5 } },
{ mux.pin(5), { MIDI_CC::Channel_Volume, Channel_6 } },
{ mux.pin(6), { MIDI_CC::Channel_Volume, Channel_7 } },
{ mux.pin(7), { MIDI_CC::Channel_Volume, Channel_8 } },
};
void setup() {
Expand Down
2 changes: 1 addition & 1 deletion doxygen/pages/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Here's a basic MIDI output example:
```cpp
USBMIDI_Interface midi; // Instantiate the MIDI over USB interface

const MIDIAddress noteAddress = {MIDI_Notes::C(4), CHANNEL_1};
const MIDIAddress noteAddress = {MIDI_Notes::C(4), Channel_1};
const uint8_t velocity = 0x7F;

void setup() {
Expand Down
52 changes: 26 additions & 26 deletions doxygen/pages/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ analog pin number, and the second is the MIDI address.
The MIDI address is a structure that consists of an address number,
the MIDI channel, and the cable number.
In this case, the address number is the controller number, which is a number
from 0 to 119. The MIDI channel is a channel from `CHANNEL_1` until
`CHANNEL_16`. We'll ignore the cable number for now, if you don't specifically
from 0 to 119. The MIDI channel is a channel from `Channel_1` until
`Channel_16`. We'll ignore the cable number for now, if you don't specifically
set it, it'll just use the default cable.
You can find more information about MIDI addresses in the
@ref midi_md-midi-addresses "MIDI Tutorial: MIDI addresses".
Expand All @@ -125,10 +125,10 @@ For the MIDI controller numbers, you can use the
@ref MIDI_CC "predefined constants", or you can just use a number.
```cpp
CCPotentiometer potentiometer { A1, {MIDI_CC::Channel_Volume, CHANNEL_1} };
CCPotentiometer potentiometer { A1, {MIDI_CC::Channel_Volume, Channel_1} };
```
```cpp
CCPotentiometer potentiometer { A1, {7, CHANNEL_1} };
CCPotentiometer potentiometer { A1, {7, Channel_1} };
```
In our case, we don't want a single potentiometer, we want eight. It's much
Expand All @@ -155,14 +155,14 @@ in more meaningful error messages if you get any of the arguments wrong:
```cpp
CCPotentiometer volumePotentiometers[] {
{ mux.pin(0), {MIDI_CC::Channel_Volume, CHANNEL_1} },
{ mux.pin(1), {MIDI_CC::Channel_Volume, CHANNEL_2} },
{ mux.pin(2), {MIDI_CC::Channel_Volume, CHANNEL_3} },
{ mux.pin(3), {MIDI_CC::Channel_Volume, CHANNEL_4} },
{ mux.pin(4), {MIDI_CC::Channel_Volume, CHANNEL_5} },
{ mux.pin(5), {MIDI_CC::Channel_Volume, CHANNEL_6} },
{ mux.pin(6), {MIDI_CC::Channel_Volume, CHANNEL_7} },
{ mux.pin(7), {MIDI_CC::Channel_Volume, CHANNEL_8} },
{ mux.pin(0), {MIDI_CC::Channel_Volume, Channel_1} },
{ mux.pin(1), {MIDI_CC::Channel_Volume, Channel_2} },
{ mux.pin(2), {MIDI_CC::Channel_Volume, Channel_3} },
{ mux.pin(3), {MIDI_CC::Channel_Volume, Channel_4} },
{ mux.pin(4), {MIDI_CC::Channel_Volume, Channel_5} },
{ mux.pin(5), {MIDI_CC::Channel_Volume, Channel_6} },
{ mux.pin(6), {MIDI_CC::Channel_Volume, Channel_7} },
{ mux.pin(7), {MIDI_CC::Channel_Volume, Channel_8} },
};
```

Expand All @@ -172,7 +172,7 @@ CCPotentiometer volumePotentiometers[] {
> For example, a `PBPotentiometer` doesn't need an address number, just a
> channel, so you can instantiate it as follows:
> ```cpp
> PBPotentiometer potentiometer { A1, CHANNEL_9 };
> PBPotentiometer potentiometer { A1, Channel_9 };
> ```
### 5. Initialize the Control Surface {#first-output-init}
Expand Down Expand Up @@ -237,14 +237,14 @@ CD74HC4051 mux {
// potentiometers connected to the eight input pins of
// the multiplexer
CCPotentiometer volumePotentiometers[] {
{mux.pin(0), {MIDI_CC::Channel_Volume, CHANNEL_1}},
{mux.pin(1), {MIDI_CC::Channel_Volume, CHANNEL_2}},
{mux.pin(2), {MIDI_CC::Channel_Volume, CHANNEL_3}},
{mux.pin(3), {MIDI_CC::Channel_Volume, CHANNEL_4}},
{mux.pin(4), {MIDI_CC::Channel_Volume, CHANNEL_5}},
{mux.pin(5), {MIDI_CC::Channel_Volume, CHANNEL_6}},
{mux.pin(6), {MIDI_CC::Channel_Volume, CHANNEL_7}},
{mux.pin(7), {MIDI_CC::Channel_Volume, CHANNEL_8}},
{mux.pin(0), {MIDI_CC::Channel_Volume, Channel_1}},
{mux.pin(1), {MIDI_CC::Channel_Volume, Channel_2}},
{mux.pin(2), {MIDI_CC::Channel_Volume, Channel_3}},
{mux.pin(3), {MIDI_CC::Channel_Volume, Channel_4}},
{mux.pin(4), {MIDI_CC::Channel_Volume, Channel_5}},
{mux.pin(5), {MIDI_CC::Channel_Volume, Channel_6}},
{mux.pin(6), {MIDI_CC::Channel_Volume, Channel_7}},
{mux.pin(7), {MIDI_CC::Channel_Volume, Channel_8}},
};
// Initialize the Control Surface
Expand Down Expand Up @@ -340,23 +340,23 @@ number of the pin with the LED connected, and the second is the MIDI address.
The MIDI address is a structure that consists of an address number,
the MIDI channel, and the cable number.
In this case, the address number is the note number, which is a number
from 0 to 127. The MIDI channel is a channel from `CHANNEL_1` until
`CHANNEL_16`. We'll ignore the cable number for now, if you don't specifically
from 0 to 127. The MIDI channel is a channel from `Channel_1` until
`Channel_16`. We'll ignore the cable number for now, if you don't specifically
set it, it'll just use the default cable.
For the MIDI note numbers, you can use the note constants and the `note`
function in the @ref MIDI_Notes namespace,
or you can just use a number.
```cpp
NoteLED noteLed { 13, {MIDI_Notes::C(4), CHANNEL_1} }; // C4 = middle C
NoteLED noteLed { 13, {MIDI_Notes::C(4), Channel_1} }; // C4 = middle C
```
In our case, we don't want a single LED, we want eight. It's much easier to
define them in an array.
Also note how we state that it should use the pins of the shift register we
defined in the previous step. We omit the channel here, so it'll just use the
default channel, `CHANNEL_1`.
default channel, `Channel_1`.
> **Note**: The first pin is `pin(0)`, not `pin(1)`.
Expand Down Expand Up @@ -475,7 +475,7 @@ void loop() {
If you enable debug output, you'll get a helpful error message as soon as you
open the Serial Monitor:
```text
[bool CS::Control_Surface_::connectDefaultMIDI_Interface() @ line 53]: Fatal Error: No default MIDI Interface (0xF123)
[bool cs::Control_Surface_::connectDefaultMIDI_Interface() @ line 53]: Fatal Error: No default MIDI Interface (0xF123)
```
The error code at the end can be used to easily locate the source of the error
in the library source code, and in this case the message also includes the name
Expand Down
18 changes: 9 additions & 9 deletions doxygen/pages/MIDI.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ This is the most important one:

~~~cpp
MIDIAddress(int address,
Channel channel = CHANNEL_1,
Channel channel = Channel_1,
Cable cableNumber = CABLE_1)
~~~
Expand All @@ -239,10 +239,10 @@ For example:
MIDIAddress myAddress = 16;
// Address 42 on channel 2 and cable 1:
MIDIAddress myAddress = {42, CHANNEL_2};
MIDIAddress myAddress = {42, Channel_2};
// Address 111 on channel 2 and cable 3:
MIDIAddress myAddress = {111, CHANNEL_2, CABLE_3};
MIDIAddress myAddress = {111, Channel_2, CABLE_3};
~~~

If you specify just a single argument, as in the first example, you don't have
Expand All @@ -255,15 +255,15 @@ For entering MIDI note numbers, you can use the note names in the
@ref MIDI_Notes namespace:
~~~cpp
// MIDI Note middle C (C in the fourth octave) on MIDI Channel 16:
MIDIAddress myAddress = {MIDI_Notes::C(4), CHANNEL_16};
MIDIAddress myAddress = {MIDI_Notes::C(4), Channel_16};
~~~
For reasons explained [here](@ref faq-midi-note-f), the note F is an exception,
you have to add a trailing underscore to avoid conflicts with Arduino's `F(...)`
macro:
~~~cpp
// MIDI Note F in the fourth octave on MIDI Channel 16:
MIDIAddress myAddress = {MIDI_Notes::F_(4), CHANNEL_16};
MIDIAddress myAddress = {MIDI_Notes::F_(4), Channel_16};
// note the underscore here ^
~~~
If you look at the full list of note names in the @ref MIDI_Notes namespace,
Expand All @@ -276,7 +276,7 @@ Instead of specifying the controller number (address) as a number, you can also
use the predefined constants in the @ref MIDI_CC namespace:
~~~cpp
// Control Change General Purpose Controller #1 on MIDI Channel 2:
MIDIAddress myAddress = {MIDI_CC::General_Purpose_Controller_1, CHANNEL_2};
MIDIAddress myAddress = {MIDI_CC::General_Purpose_Controller_1, Channel_2};
~~~
#### MIDI Program Change names {#midi_md-midi-program-change-names}
Expand All @@ -285,7 +285,7 @@ Similar to the constants for controller numbers, you can find the constants for
all General MIDI program numbers in the @ref MIDI_PC namespace:
~~~cpp
// Harpsichord voice on MIDI Channel 9.
MIDIAddress myAddress = {MIDI_PC::Harpsichord, CHANNEL_9};
MIDIAddress myAddress = {MIDI_PC::Harpsichord, Channel_9};
~~~

### More examples {#midi_md-sending-more-examples}
Expand Down Expand Up @@ -507,7 +507,7 @@ struct MyMIDI_Callbacks : MIDI_Callbacks {
// Check if it's a note message:
bool note_msg = type == msg.NOTE_ON || type == msg.NOTE_OFF;
// Check if it's the specific note and channel we're looking for
bool our_note = channel == CHANNEL_1 && note == MIDI_Notes::C(4);
bool our_note = channel == Channel_1 && note == MIDI_Notes::C(4);
// If both conditions are satisfies, print the message
if (note_msg && our_note)
Serial << type << " middle C on Channel 1 with velocity "
Expand Down Expand Up @@ -538,7 +538,7 @@ struct MyMIDI_Callbacks : MIDI_Callbacks {
// Check if it's a note message:
bool note_msg = type == msg.NOTE_ON || type == msg.NOTE_OFF;
// Define the address we're interested in
const MIDIAddress our_special_note = {MIDI_Notes::C(4), CHANNEL_1};
const MIDIAddress our_special_note = {MIDI_Notes::C(4), Channel_1};
// If it's a note message that matches our specific address, print it
if (note_msg && msg.getAddress() == our_special_note)
Serial << type << " middle C on Channel 1 with velocity "
Expand Down
16 changes: 8 additions & 8 deletions examples/0. Getting-Started/1.First-Output/1.First-Output.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ CD74HC4051 mux {
// potentiometers connected to the eight input pins of
// the multiplexer
CCPotentiometer volumePotentiometers[] {
{mux.pin(0), {MIDI_CC::Channel_Volume, CHANNEL_1}},
{mux.pin(1), {MIDI_CC::Channel_Volume, CHANNEL_2}},
{mux.pin(2), {MIDI_CC::Channel_Volume, CHANNEL_3}},
{mux.pin(3), {MIDI_CC::Channel_Volume, CHANNEL_4}},
{mux.pin(4), {MIDI_CC::Channel_Volume, CHANNEL_5}},
{mux.pin(5), {MIDI_CC::Channel_Volume, CHANNEL_6}},
{mux.pin(6), {MIDI_CC::Channel_Volume, CHANNEL_7}},
{mux.pin(7), {MIDI_CC::Channel_Volume, CHANNEL_8}},
{mux.pin(0), {MIDI_CC::Channel_Volume, Channel_1}},
{mux.pin(1), {MIDI_CC::Channel_Volume, Channel_2}},
{mux.pin(2), {MIDI_CC::Channel_Volume, Channel_3}},
{mux.pin(3), {MIDI_CC::Channel_Volume, Channel_4}},
{mux.pin(4), {MIDI_CC::Channel_Volume, Channel_5}},
{mux.pin(5), {MIDI_CC::Channel_Volume, Channel_6}},
{mux.pin(6), {MIDI_CC::Channel_Volume, Channel_7}},
{mux.pin(7), {MIDI_CC::Channel_Volume, Channel_8}},
};

// Initialize the Control Surface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ USBMIDI_Interface midi;
// on pin A0, that sends MIDI messages with controller 7 (channel volume)
// on channel 1.
CCPotentiometer potentiometer {
A0, {MIDI_CC::Channel_Volume, CHANNEL_1}
A0, {MIDI_CC::Channel_Volume, Channel_1}
};

// The filtered value read when potentiometer is at the 0% position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ USBMIDI_Interface midi;
// Instantiate a CCPotentiometer object
CCPotentiometer potentiometer {
A0, // Analog pin connected to potentiometer
{MIDI_CC::Channel_Volume, CHANNEL_1}, // Channel volume of channel 1
{MIDI_CC::Channel_Volume, Channel_1}, // Channel volume of channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ USBMIDI_Interface midi;
// Instantiate a PBPotentiometer object
PBPotentiometer potentiometer {
A0, // Analog pin connected to potentiometer
CHANNEL_1, // MIDI Channel 1
Channel_1, // MIDI Channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ CCButton button {
// Push button on pin 5:
5,
// General Purpose Controller #1 on MIDI channel 1:
{MIDI_CC::General_Purpose_Controller_1, CHANNEL_1},
{MIDI_CC::General_Purpose_Controller_1, Channel_1},
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ USBMIDI_Interface midi;
// Instantiate a NoteButton object
NoteButton button {
5, // Push button on pin 5
{MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ NoteButtonMatrix<4, 3> buttonmatrix {
{2, 3, 4, 5}, // row pins
{6, 7, 8}, // column pins
addresses, // address matrix
CHANNEL_1, // channel and cable number
Channel_1, // channel and cable number
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CCAbsoluteEncoder enc {
// Similarly, for Pitch Bend
// PBAbsoluteEncoder enc {
// {2, 3}, // pins
// CHANNEL_1, // MIDI channel
// Channel_1, // MIDI channel
// 127, // large multiplier because Pitch Bend has high resolution
// };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ USBMIDI_Interface midi;
// a MIDI Program Change message when it's pressed.
PCButton pcBtn {
2, // pin
{MIDI_PC::Steel_Drums, CHANNEL_1}, // address
{MIDI_PC::Steel_Drums, Channel_1}, // address
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ProgramChanger<3> programChanger {
MIDI_PC::Rock_Organ,
MIDI_PC::Electric_Bass_Pick,
},
CHANNEL_1, // MIDI channel to use
Channel_1, // MIDI channel to use
};

// Instantiate a selector that reads three buttons and controls the program
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const int speedMultiplier = 1;
Bank<2> bank(4); // A bank with four channels, and 2 bank settings

Bankable::CCPotentiometer faders[] {
{{bank, BankType::CHANGE_CHANNEL}, A0, {MIDI_CC::Channel_Volume, CHANNEL_1}},
{{bank, BankType::CHANGE_CHANNEL}, A1, {MIDI_CC::Channel_Volume, CHANNEL_2}},
{{bank, BankType::CHANGE_CHANNEL}, A2, {MIDI_CC::Channel_Volume, CHANNEL_3}},
{{bank, BankType::CHANGE_CHANNEL}, A3, {MIDI_CC::Channel_Volume, CHANNEL_4}},
{{bank, BankType::CHANGE_CHANNEL}, A0, {MIDI_CC::Channel_Volume, Channel_1}},
{{bank, BankType::CHANGE_CHANNEL}, A1, {MIDI_CC::Channel_Volume, Channel_2}},
{{bank, BankType::CHANGE_CHANNEL}, A2, {MIDI_CC::Channel_Volume, Channel_3}},
{{bank, BankType::CHANGE_CHANNEL}, A3, {MIDI_CC::Channel_Volume, Channel_4}},
};

CCPotentiometer knobsTop[] {
Expand All @@ -61,10 +61,10 @@ CCPotentiometer knobsTop[] {
};

Bankable::CCPotentiometer knobsSide[] {
{{bank, BankType::CHANGE_CHANNEL}, A8, {MIDI_CC::Pan, CHANNEL_1}},
{{bank, BankType::CHANGE_CHANNEL}, A9, {MIDI_CC::Pan, CHANNEL_2}},
{{bank, BankType::CHANGE_CHANNEL}, A10, {MIDI_CC::Pan, CHANNEL_3}},
{{bank, BankType::CHANGE_CHANNEL}, A11, {MIDI_CC::Pan, CHANNEL_4}},
{{bank, BankType::CHANGE_CHANNEL}, A8, {MIDI_CC::Pan, Channel_1}},
{{bank, BankType::CHANGE_CHANNEL}, A9, {MIDI_CC::Pan, Channel_2}},
{{bank, BankType::CHANGE_CHANNEL}, A10, {MIDI_CC::Pan, Channel_3}},
{{bank, BankType::CHANGE_CHANNEL}, A11, {MIDI_CC::Pan, Channel_4}},
};

Bankable::NoteButtonLatching switches[] {
Expand Down
2 changes: 1 addition & 1 deletion examples/2. MIDI Input/1. LEDs/1.Note-LED/1.Note-LED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ USBMIDI_Interface midi;
// Instantiate the LED that will light up when middle C is playing
NoteLED led {
LED_BUILTIN, // Pin of built-in LED
{MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const pin_t ledPin = LED_BUILTIN; // Change this to your PWM pin <------
// Instantiate the LED that will light up when middle C is playing
NoteLEDPWM led {
ledPin, // Pin of the LED, must be PWM pin
{MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MAX7219<1> max7219 {SPI, SS};
// Instantiate the LED that will light up when middle C is playing
NoteLED led {
max7219.pin(0), // First pin of the MAX7219
{MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1
{MIDI_Notes::C(4), Channel_1}, // Note C4 on MIDI channel 1
};

void setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
USBMIDI_Interface midi;

// Instantiate an object that listens for MIDI Pitch Bend messages on channel 1.
PBValue pb {CHANNEL_1};
PBValue pb {Channel_1};

void setup() {
Control_Surface.begin();
Expand Down
Loading

0 comments on commit aaf6eea

Please sign in to comment.