Posts Tagged ‘c++’
MIDI Elements Teensy Library
I have created a wrapper library to make programming MIDI controllers on the Teensy board dead easy and super fast. Simply instantiate object for each component like Buttons, Potentiometer, LED, rotary encoders, etc. and let the library handle all the dirty work of reading the raw values and deciding when to send MIDI signals. Enabling you to experiment and concentrate on your creative ideas and not waste too much time with the repetitive technical details and debugging code.
Just in a couple lines of code you can program a fully functioning MIDI controller.
Here’s an example of how simple things are:
boolean debug=false; // print to serial instead of midi
boolean secondary=true; // enable secondary midi messages
int midiChannel=1; // midi channel number
// declare all your components here
Button but(17,midiChannel,1,secondary,debug); // button 1 on pin 17
Button but2(16,midiChannel,2,secondary,debug); // button 2 on pin 16
Potentiometer pot(45,midiChannel,3,secondary,debug); // knob on pin 45 (A7)
Led led(15,midiChannel,3,true); // led on pin 15 with PWM enabled, triggered on the same number as pot
void setup(){
usbMIDI.setHandleControlChange(OnControlChange); // set event handler for CC
}
void loop(){
// add here all the input component reads
pot.read(); // read knob and send midi messages
but.read(); // read buttons and send midi messages
but2.read();
usbMIDI.read(); // read all the incoming midi messages
}
//====================================================================
// event handlers
void OnControlChange(byte channel, byte control, byte value){
// add all your output component sets that will trigger with cc
led.setOn(channel,control,value);
}
Currently only Buttons, Potentiometers and LEDs are supported. But I’m planning on adding RGB LED, rotary encoder, LED bars and ring and button pad classes.
Each component sends two sets of MIDI signals if enabled. For example Buttons send NoteOn, NoteOff, as well as ControlChange values so that they could be easily mapped in Toggle or Instant mode in software like Ableton Live. Also the Potentiometers send secondary NoteOns when values reach 0 or 127, à la MIDI Fighter Pro.
Download: github
To install extract the MIDIElements folder in your arduino/libraries directory
New home for code
From now on I will be committing examples and the source code of my latest projects on github. Make sure you follow for the latest updates https://github.com/ghztomash
[b]uttonPad updates (Growing Family)
I have a lot of updates on the project since last time, tons of changes made mostly on driver application. I discovered that one of the main sources of latency was the serial port class of Processing, so I decided to re-implement the driver in C#, since Max/MSP and Ableton Live are not running under Linux anyway.
Also this gave me the opportunity to implement monome applications compatibility and it works pretty much flawlessly with any Max patch I threw at it, tough I did not implement AutoConfig protocol so its limited to the monomeOSC version of applications that run with OSC extensions. Also further more, worked on reducing latency and read/write buffer bottlenecks with pleasing results, now I can finally enjoy mashing on mlrV
Also made some silly Processing sketches, like displaying 8×8 3bit image files on the pad.
Plus designed more plywood face plates for the pad and other devices.
This gives me the opportunity to introduce my new device [k]ontrolPad. This controller consists of 4 faders, 8 knobs, 8 buttons with LEDs, XYZ accelerometer and an infrared proximity sensor. But for now unfortunately only the buttons and LEDs seem to work properly. The rest of the analog values are quite unstable and must be normalized, also I have to figure out a way to send their values synchronously and only when it changes, instead of just sending a bunch of redundant data over the serial port, which by the way dead-locked my serial port in Linux..
And finally, since a lot of people asked me for, I have released the firmware and drivers, also some processing sketches. You can find everything on my Bazaar repository, just browse the code and you will find a zip/rar file to download. Or use the following direct links:
Driver
Firmware
Testing
And a bit older video just to demo it working with Live in MIDI mode.






