GithubHelp home page GithubHelp logo

dsrc12 / arcore Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rkistner/arcore

0.0 2.0 0.0 1.18 MB

MIDI-USB Support for Arduino

License: GNU Lesser General Public License v2.1

C 22.82% C++ 76.98% Batchfile 0.06% Shell 0.14%

arcore's Introduction

Arduino hardware cores

Introduction

This is a fork of the core Arduino core hardware libraries.

The goal is to have a simple base to customize the core libraries to add or modify core functionality, without needing to clone the entire Arduino repository.

Currently the only addition is support for MIDI-USB for the Arduino Leonardo and similar boards, but this should serve as a good base for other modifications to the cores libraries. Let me know if you do anything interesting with this!

Installation and Usage

Version 1.5.4 (or greater) of the Arduino IDE is required to build projects with this library.

  1. Clone this repository.
  2. On Linux, run ./install.sh. The script creates a symlink in ~/Arduino/hardware to the hardware folder in repository. On Windows or Mac you have to do this manually (you may copy the hardware folder there instead of creating a symlink).
  3. Launch the Arduino IDE (only tested on 1.5.7, will not work pre-1.5.x).
  4. Under Tools -> Board, select Arduino Leonardo (arcore).
  5. Upload your sketch as usual.

Update 2014-12-18

The folder structure has changed. If you previously used this project, you will have to run ./install.sh again.

MIDI-USB support

This fork currently contains a basic version of USB-MIDI support. It it still under development, and the API should be considered unstable.

The implementation currently has a single IN and a single OUT endpoint. It can be used together with CDC and HID (as a composite USB device), or standalone (by modifying USBDesc.h).

Currently there are no high-level API's. However, the MIDI event format is very simple to read and write (see examples below). For more info on the MIDI-USB event format, see the official USB-MIDI specification.

Send a note-on and note-off every two seconds

// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).

void noteOn(byte channel, byte pitch, byte velocity) {
  MIDIEvent noteOn = {0x09, 0x90 | channel, pitch, velocity};
  MIDIUSB.write(noteOn);
}

void noteOff(byte channel, byte pitch, byte velocity) {
  MIDIEvent noteOff = {0x08, 0x80 | channel, pitch, velocity};
  MIDIUSB.write(noteOff);
}

// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).

void controlChange(byte channel, byte control, byte value) {
  MIDIEvent event = {0x0B, 0xB0 | channel, control, value};
  MIDIUSB.write(event);
}

void loop() {
  noteOn(0, 48, 64);   // Channel 0, middle C, normal velocity
  MIDIUSB.flush();
  delay(500);
  
  noteOff(0, 48, 64);  // Channel 0, middle C, normal velocity
  MIDIUSB.flush();
  delay(1500);
  
  // controlChange(0, 10, 65); // Set the value of controller 10 on channel 0 to 65
}

void setup() {

}

Read and echo MIDI messages back to the PC

void loop() {
   while(MIDIUSB.available() > 0) {  // Repeat while notes are available to read.
      MIDIEvent e;
      e = MIDIUSB.read();
      if(e.type == 0x09 || e.type == 0x08) { // Only echo note-on and note-off
         MIDIEvent response;
         response.type = e.type; // Same event type (note-on/note-off)
         response.m1 = e.m1;     // Same event type and channel
         response.m2 = (e.m2 + 12) % 128;  // Shift by one octave
         response.m3 = e.m3;     // Same velocity
      }
      MIDIUSB.write(e);
      MIDIUSB.flush();
   }
}

void setup() {

}

Supported Boards

This is only officially tested on the Arduino Leonardo. Users have also reported it working on the Arduino Micro and Freeduino Leonardo.

Supporting more boards should be as simple as copying the configuration over from the official boards.txt to the one in this repository, with minor changes to build.core and build.variant.

ARM (sam) boards might require more work.

Host support

This should work out-of-the-box on recent versions of Linux and Mac OS.

On Windows 7 or later, it might be required to install the Arduino drivers, especially when using it in compound USB mode.

Windows XP does not support compound devices, but should still work as a plain MIDI device (might also need drivers). Compound mode can be disabled by editing USBDesc.h.

Users have reported success with iPads. The main requirement here is that the device should not request a high current (as it does by default). A different board configuration, Arduino Leonardo (arcore, iPad compatible) is provided for this.

arcore's People

Contributors

adamcdunlap avatar aethaniel avatar amcewen avatar aposada avatar bitron avatar chiva avatar cmaglie avatar damellis avatar fede85 avatar ffissore avatar jcbuda avatar lauszus avatar ricklon avatar rkistner avatar stefandz avatar tigoe avatar travisg avatar tub avatar vdorr avatar westfw avatar zeveland avatar

Watchers

 avatar  avatar

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.