Saturday 19 May 2012

Arduino drum kit, part 2 (The Blastmachine!)

Hi everyone, some more info on the Arduino drum machine...

The state which I left the drum kit in before my Arduino had to be repurposed for university work is covered in this post. The first thing I did was to test how well MIDI works with the Arduino with a simple test from this site:

http://arduino.cc/en/Tutorial/Midi

All the code and stuff in the link above is already in the Arduino IDE under Examples -> Communication -> MIDI.

Sending MIDI messages with the Arduino is very simple. RS232, the standard communications protocol that the Arduino (and all sorts of other things), is almost exactly the same as MIDI. The only thing that needs doing before using simple Serial.write commands is setting the baud rate to the MIDI standard - 31250 baud, which is shown in the link above. The program provided transmits a whole range of notes. The code can be modified to just send one note by removing the 'for' loop and replacing where it says 'note' with the note that you want. This note is in hexadecimal, so use this for reference:

http://www.wavosaur.com/download/midi-note-hex.php

(I may create a better diagram later on)

The example code creates a 'note on' message. This contains the note number, velocity and channel. For those not familiar with MIDI, velocity emulates the speed at which a piano key or any other instrument is hit, therefore bigger velocity translates to louder sound.The maximum velocity level is 127, minimum is 0, which translates to 0x7F and 0x00 in hex respectively. It is standard practise to send a note with velocity set to 0, as opposed to using the dedicated 'note off' command.

In my setup, I'm using a drum sampler within the recording software Cubase. Cubase is full of all sorts of good stuff, but the bit that we're concerned with here is its VST hosting capability. Whats that? Well, a VST is a virtual instrument that can, amongst other things, accept MIDI and output audio. A VST host sets up the environment for providing the MIDI and audio I/O. I'm using Cubase as a host and Native Instruments Studio Drummer as the instrument, but free alternatives exist, and I hope to write something about this towards the end of the project. Because free alternatives are always a bonus, right?

To test this MIDI communications functionality, and with a certain level of control, I hooked together the MIDI output as specified on that example page, a couple of switched and a couple of LEDs...

(CODE COMING SOON!)

In this case, the code waits for an input from the switch before transmitting a MIDI note. There's one button to trigger the bass drum note, and one to trigger the snare note.

I'd like to add - this has been very poorly coded and you'd never try and run a proper drum kit this way, this was just to test the thing. However it had a quite funny side effect - if you hold a button down, it will continually cycle and play the sample very fast. If you hold down both buttons, it will alternate between both very quickly, and essentially emulates a traditional 'blast beat', the staple drum pattern of extreme metal. Awesome! Good example of what I'm getting at here:



Let's compare...




No comments:

Post a Comment