Midi - Control Surface - NoteChordButton Syntax

I have a set of buttons on my custom midi controller (Arduino Pro Micro) that I would like to send different preset chords to my DAW.

I'm using the awesome Control Surface library.

I figured out the syntax for one NoteChordButton:

NoteChordButton A1_But8 {mux_1.pin(12), {MIDI_Notes::C(4), CHANNEL_16}, Bass::Double + Chords::Major};

These are the chords I would like to play from a set of buttons:

E 9sus4
C# min7 (4)
C Maj7
D 9sus4
E 9sus4
C# min7(4)
C Maj7
D 9sus4

Does anyone familiar with this library know the correct syntax to create NoteChordButtons for these chords? This might question requires more music theory than programming expertise, which is why I'm a bit lost.

@PieterP

You can find the definitions of the built-in chords here:

You can easily add your own chords in a similar fashion, e.g.

namespace cs::Chords {

/// 9sus4 consists of major fourth, perfect fifth, minor seventh, and major ninth:
const Chord<4> Dominant9sus4 = {{M4, P5, m7, P8 + M2}};

}

Thanks for the quick reply @PieterP

I let the Arduino IDE update my local copy of Control Surface library which seems to have broken my midi apps which use multiplexers.

// Instantiate a multiplexer
CD74HC4067 mux_1{4, {6, 7, 8, 9} , }; //input, S0-S3, optional enable
CD74HC4067 mux_2{14, {6, 7, 8, 9} , }; //input, S0-S3, optional enable


// MIC BYPASS
//B1 Button
CCButton B2_But1 {mux_2.pin(2), {28, CHANNEL_16},};

This is the error I get when the compiler gets to the line creating the button:

Compilation error: 'using CD74HC4067 = class CS::AH::AnalogMultiplex<4> {aka class CS::AH::AnalogMultiplex<4>}' has no member named 'pin'; did you mean 'pins'?

Is there a syntax change for creating buttons using pins from multiplexers?

I tried:

CCButton B2_But1 {mux_2.digitalRead(2), {28, CHANNEL_16},}

Which silences error but I get this new error with this code block here:

// // Instantiate a program changer with 9 programs
ProgramChanger<9> programChanger {
  {
    10, // Vox Robo 1
    11, // Vox Robo 2
    12, // Vox Robo 3
    13, // Single Drone
    14, // Major Drone
    15, // Minor Drone
    16, // Transpostion
    17, // Instrument CTRL
    18, // Reflex Tune
  },
  CHANNEL_16, // MIDI channel to use
};

//B1 Buttons 1 and 2

IncrementDecrementSelector<9> selector = {
    programChanger, // what to select
    {mux_2.digitalRead(0), mux_2.digitalRead(1)},         // push button pins (increment, decrement)
    Wrap::Wrap,     // wrap around if min/max program is reached
}

Error :

"Compilation error: could not convert '{CS::programChanger, {CS::mux_2.CS::AH::AnalogMultiplex<4>::digitalRead(0), CS::mux_2.CS::AH::AnalogMultiplex<4>::digitalRead(1)}, Wrap}' from '' to 'CS::CS::IncrementDecrementSelector<9>'"

This is a good reminder to not let the IDE autoupdate my libs!

I'm not sure how that's possible. The Control Surface library is not available from the library manager in the Arduino IDE (if it is, then that version was published by someone else).
Where did you download Control Surface from? Which version do you have installed now?

The pin method of the multiplexers has existed since the very first release of the Control Surface library. There hasn't been a syntax change related to it. The fact that it's missing indicates that something's wrong with your Control Surface installation.

No, that can't work. The digitalRead() function reads the current value (high or low) of the pin, you cannot use it this way (the CCButton constructor accepts a pin number, not high/low, and you cannot use it before the multiplexer has been initialized during the setup()).

Something is seriously wrong here: first of all, you seem to be using a version of Control Surface that's quite old (the namespace CS was renamed to cs in September ‘23), and there's some strange nesting of the namespaces going on (CS::CS shouldn't happen). Did you edit the library files by any chance? Maybe one of the closing } was somehow removed?

I'd recommend removing ~/Arduino/libraries/Control-Surface and downloading the latest version from GitHub again: GitHub - tttapa/Control-Surface: Arduino library for creating MIDI controllers and other MIDI devices.

@PieterP

Ok I tried removing the lib and dling fresh from github. All my errors are gone. Thank you!

I originally got the Control Surface lib from github, and last compiled successfully in May 2023.

My IDE updated a bunch of different installed libs since May, so if Control Surface isn't available by the package manager it must've gotten changed another way.

My only changes to the lib have been adding the custom chords, which I just discovered is what's throwing the pin error.

I was missing a '}' in my chord edit

Thanks again for you help.

There's no need to edit the library for that, you can just add the chords in your sketch.

I'm made some good progress with my custom chord buttons.

I stuck on this one modification, where I want to split the notes of a chord between two buttons.

The D minor seventh is a four-note chord D-F-A-C.

I want to play the 'D' with a NoteButton button and the rest of the chord 'F-A-C' with a NoteChordButton.

This is my chord minus the 'D':

const Chord<3> Dmin7 = {{P1 + P5, P1 + m7, P1 + P8 + m3}};

And Buttons:

NoteButton A1_But1 {mux_1.pin(0), {MIDI_Notes::D(4), CHANNEL_16}};
NoteChordButton A1_But5 {mux_1.pin(4), {MIDI_Notes::D(4), CHANNEL_16}, Chords::Dmin7};

What's happening is the NoteChordButton is playing all four notes of the chord instead of just 'F-A-C'.

Is there a way to achieve what I'm trying to do? @PieterP

NoteChordButtons always play their base note*. In this case, replacing the second button by an F major chord should achieve what you want:

NoteButton A1_But1 {mux_1.pin(0), {MIDI_Notes::D[4], CHANNEL_16}};
NoteChordButton A1_But5 {mux_1.pin(4), {MIDI_Notes::F[4], CHANNEL_16}, Chords::Major};

(If you're using an old version of Control Surface, you should use F_(4) instead of F[4].)


(*) The ChordButton implementation is quite simple:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.