tttapa / MIDI_controller

This is a library for creating a MIDI controller using an Arduino or Teensy board.
GNU General Public License v3.0
402 stars 70 forks source link

appleMIDI Ethernet #21

Closed FoxPerdana closed 6 years ago

FoxPerdana commented 6 years ago

How to using this library with AppleMIDI Library? Im not to good In arduino stuff, I hope can help me trough it.

I dont know where to put the "const uint8_t velocity = 0b1111111; const uint8_t C4 = 60; "

and

"Digital button(2, C4, 1, velocity);"

and

"MIDI_Controller.refresh();"

Im using Arduino Uno with Ethernet Shield

Library version 3.0.1 and AppleMIDI

Please dont judge or laugh because my stupid code I made

#include <MIDI_Controller.h>

#include <Ethernet.h>

#include "AppleMidi.h"

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

unsigned long t0 = millis();
bool isConnected = false;

APPLEMIDI_CREATE_DEFAULT_INSTANCE(); // see definition in AppleMidi_Defs.h

// Code size:
//
// IDE 1.8.3
//
// Arduino Ethernet / Uno
// Sketch uses 23976 bytes (74%) of program storage space. Maximum is 32256 bytes.
// Global variables use 969 bytes (47%) of dynamic memory, leaving 1079 bytes for local variables. Maximum is 2048 bytes.
const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t C4 = 60;              // Note number 60 is defined as middle C in the MIDI specification
Digital button(2, C4, 1, velocity);

void setup()
{
  // Serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print(F("Getting IP address..."));

  if (Ethernet.begin(mac) == 0) {
    Serial.println();
    Serial.println(F("Failed DHCP, check network cable & reboot"));
    for (;;)
      ;
  }

  Serial.println();
  Serial.print(F("IP address is "));
  Serial.println(Ethernet.localIP());

  Serial.println(F("OK, now make sure you an rtpMIDI session that is Enabled"));
  Serial.print(F("Add device named Arduino with Host/Port "));
  Serial.print(Ethernet.localIP());
  Serial.println(F(":5004"));
  Serial.println(F("Then press the Connect button"));
  Serial.println(F("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes"));

  // Create a session and wait for a remote host to connect to us
  AppleMIDI.begin("test");

Digital button(2, C4, 1, velocity);

}

void loop()
{
  // Listen to incoming notes
  AppleMIDI.run();

  MIDI_Controller.refresh();

Thank You

tttapa commented 6 years ago

RTP MIDI is currently not supported. Although, I'm planning on adding it in the near future.
It should be as simple as creating a new class that derives from the MIDI_Interface class. You have to implement two virtual functions: sendImpl and refresh, and a constructor.

class RTPMIDI_Interface : public MIDI_Interface
{
  public:
    RTPMIDI_Interface() {
        // Constructor (initialize RTP MIDI etc.)
    }

    bool refresh() {
        // Ignore MIDI input:
        // Empty the incomming MIDI buffer, return false if it's empty, return true otherwise
    }

  protected:
    void sendImpl(uint8_t m, uint8_t c, uint8_t d1, uint8_t d2) {
        // Send a three-byte MIDI message
    }
    void sendImpl(uint8_t m, uint8_t c, uint8_t d1) {
        // Send a two-byte MIDI message
    }
};
FoxPerdana commented 6 years ago

Well. I think Its better to wait the Update Version of MIDI Controller Library that support rtp stuff (AplleMIDI, etc). Im Closing this Issue