Giter VIP home page Giter VIP logo

Comments (7)

tttapa avatar tttapa commented on June 19, 2024

The ESP32-S3 is already supported, see https://tttapa.github.io/Control-Surface-doc/Doxygen/d8/d4a/md_pages_MIDI-over-USB.html#espressif-esp32-boards-with-usb-support.

The ESP32-C3 does not have a general-purpose USB interface, so it cannot support MIDI over USB.

from control-surface.

DRCRecoveryData avatar DRCRecoveryData commented on June 19, 2024

The ESP32-S3 is already supported, see https://tttapa.github.io/Control-Surface-doc/Doxygen/d8/d4a/md_pages_MIDI-over-USB.html#espressif-esp32-boards-with-usb-support.

The ESP32-C3 does not have a general-purpose USB interface, so it cannot support MIDI over USB.

Can you check this: https://github.com/esp32beans/ESP32USBMIDI
They say that via otg port because esp32-s3 devkit c have 2 type c port

from control-surface.

tttapa avatar tttapa commented on June 19, 2024

They say that via otg port because esp32-s3 devkit c have 2 type c port

(micro B, not type C)

But yes, the same applies to Control Surface's MIDI over USB implementation. The "UART" USB port does not (and cannot) support MIDI over USB.

from control-surface.

DRCRecoveryData avatar DRCRecoveryData commented on June 19, 2024

They say that via otg port because esp32-s3 devkit c have 2 type c port

(micro B, not type C)

But yes, the same applies to Control Surface's MIDI over USB implementation. The "UART" USB port does not (and cannot) support MIDI over USB.

Could you update example midi via otg port?

from control-surface.

tttapa avatar tttapa commented on June 19, 2024

Most of the examples already have it enabled. You simply need to instantiate the USBMIDI_Interface (which is done in most examples), and then follow the instructions in https://tttapa.github.io/Control-Surface-doc/Doxygen/d8/d4a/md_pages_MIDI-over-USB.html#espressif-esp32-boards-with-usb-support (assuming you have the latest version of the arduino-esp32 core installed).

from control-surface.

DRCRecoveryData avatar DRCRecoveryData commented on June 19, 2024

Most of the examples already have it enabled. You simply need to instantiate the USBMIDI_Interface (which is done in most examples), and then follow the instructions in https://tttapa.github.io/Control-Surface-doc/Doxygen/d8/d4a/md_pages_MIDI-over-USB.html#espressif-esp32-boards-with-usb-support (assuming you have the latest version of the arduino-esp32 core installed).

Could you convert this code to work with control-surface library:

#include "MIDIUSB.h"
#include <Adafruit_NeoPixel.h>

#define NEO_PIN 10
#define NUM_PXL 32

// Color palette from the first code
const byte _R[128] = {0, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 36, 73, 109, 146, 182, 219, 255};
const byte _G[128] = {0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 36, 73, 109, 146, 182, 219, 255};
const byte _B[128] = {0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 0, 0, 0, 125, 0, 12, 28, 45, 158, 61, 28, 61, 93, 190, 125, 45, 93, 142, 223, 190, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 61, 125, 190, 255, 255, 45, 93, 142, 223, 190, 28, 61, 93, 190, 125, 12, 28, 45, 158, 61, 36, 73, 109, 146, 182, 219, 255};

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_PXL, NEO_PIN, NEO_GRB + NEO_KHZ800);

// Define AddressMatrix template
template <size_t ROWS, size_t COLS>
class AddressMatrix {
public:
  uint8_t matrix[ROWS][COLS];

  // Constructor
  AddressMatrix(uint8_t data[ROWS][COLS]) {
    for (size_t i = 0; i < ROWS; i++) {
      for (size_t j = 0; j < COLS; j++) {
        matrix[i][j] = data[i][j];
      }
    }
  }
};

// Define NoteButtonMatrix template
template <size_t ROWS, size_t COLS>
class NoteButtonMatrix {
public:
  uint8_t row_pins[ROWS];
  uint8_t col_pins[COLS];
  AddressMatrix<ROWS, COLS> address_matrix;
  uint8_t channel;

  // Constructor
  NoteButtonMatrix(uint8_t row_pins[ROWS], uint8_t col_pins[COLS], AddressMatrix<ROWS, COLS> address_matrix, uint8_t channel)
      : address_matrix(address_matrix) {
    for (size_t i = 0; i < ROWS; i++) {
      this->row_pins[i] = row_pins[i];
    }
    for (size_t j = 0; j < COLS; j++) {
      this->col_pins[j] = col_pins[j];
    }
    this->channel = channel;
  }

  int read() {
    // Implement your button read logic here
    // Return the button states as an integer
    return 0;
  }
};

// The note numbers corresponding to the buttons in the matrix
const uint8_t button_addresses[4][4] = {
  {1, 2, 3, 4},
  {5, 6, 7, 8},
  {9, 10, 11, 12},
  {13, 14, 15, 16},
};

// Define your NoteButtonMatrix object
uint8_t row_pins[4] = {2, 3, 4, 5}; // row pins
uint8_t col_pins[4] = {6, 7, 8, 9};  // column pins
NoteButtonMatrix<4, 4> buttonmatrix(row_pins, col_pins, AddressMatrix<4, 4>(button_addresses), 1);

void noteOn(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
  midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MidiUSB.sendMIDI(noteOff);
}

void setPixels(int pinStates){
  for(int i=0; i<16; i++){
    if(bitRead(pinStates, i)){ // Button down
      byte velocity = 127; // Maximum velocity when button is pressed
      noteOn(0, (36+i), velocity); // Send MIDI note on
      pixels.setPixelColor((i*2), pixels.Color(_R[velocity], _G[velocity], _B[velocity])); // Set LED color based on velocity
      pixels.setPixelColor((i*2)+1, pixels.Color(_R[velocity], _G[velocity], _B[velocity]));
    } else { // Button up
      byte velocity = 0; // Velocity 0 when button is released
      noteOff(0, (36+i), velocity); // Send MIDI note off
      pixels.setPixelColor((i*2), pixels.Color(_R[velocity], _G[velocity], _B[velocity])); // Set LED color based on velocity
      pixels.setPixelColor((i*2)+1, pixels.Color(_R[velocity], _G[velocity], _B[velocity]));
    }
  }
  pixels.show();
}

void setup() {
  pixels.begin();
  Serial.begin(115200);
}

void loop(){
  int pinStates = buttonmatrix.read();
  
  // Check for button state changes
  setPixels(pinStates);
}

from control-surface.

tttapa avatar tttapa commented on June 19, 2024

Simply replace your own NoteButtonMatrix class by Control Surface's version. Use this example as a starting point.

Then use NoteButtonMatrix::getPrevState(col, row) to get the button states to turn on/off the appropriate LEDs.

from control-surface.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.