rkistner / arcore

MIDI-USB Support for Arduino
Other
192 stars 33 forks source link

need more code usage examples. #5

Closed Reggi3 closed 10 years ago

Reggi3 commented 10 years ago

Hi, I wasn't sure where to put this so I thought it would be useful here. You need more code examples, midi echo is fine but examples of filling the MIDIEvent structs and sending note on, note off, CC etc. would help the end user a lot more.

On a related note, have you seen this project? http://www.instructables.com/id/Arcade-Button-MIDI-Controller/

It's very simple, I fixed it up to recognise the 32u4 chip as a leonardo instead of a teensy2, and put in some extra #ifdefs so that it uses arcore to send midi if LEONARDO is defined.

void noteOn(byte channel, byte pitch, byte velocity) { // 0x90 is the first of 16 note on channels. Subtract one to go from MIDI's 1-16 channels to 0-15 channel += 0x90 - 1;

// Ensure we're between channels 1 and 16 for a note on message if (channel >= 0x90 && channel <= 0x9F) {

ifdef DEBUG

  Serial.print("Button pressed: ");
  Serial.println(pitch);
#elif defined(TEENSY_PLUS_PLUS) || defined(TEENSY_2) || defined(TEENSY_PLUS_PLUS_2)
  usbMIDI.sendNoteOn(pitch, velocity, channel);
#elif defined(LEONARDO)
  e.type = 0x09;
  e.m1 = channel;
  e.m2 = pitch;
  e.m3 = velocity;
  MIDIUSB.write(e);
  MIDIUSB.flush();  
#else
  Serial.write(channel);
  Serial.write(pitch);
  Serial.write(velocity);  
#endif

} }

I'm going to try and contact the code writer to see if it's hosted anywhere and offer to github it if it's not.

rkistner commented 10 years ago

I added more examples in the readme. Can investigate building a common low-level API or high-level MIDI library at some point.

Reggi3 commented 10 years ago

I contacted the guy from the midi controller instructable but he hasn't got back to me yet. It's got an open license on it though, so probably no issues using it.

I also added my own sendNoteOn, noteOff and CC functions into arcore, very simple but effective.