Mostrando entradas con la etiqueta midi. Mostrar todas las entradas
Mostrando entradas con la etiqueta midi. Mostrar todas las entradas

Arduino MIDI drums paso a paso - instalacion de hiduino

ATENCION: Todo esto fue testeado en arduino UNO R3, que corresponde a atmega16u2
LOS PROBLEMAS DE LATENCIA SE SOLUCIONAN CON ESTE POST!

ANTES QUE NADA
Hay que pasar el sketch que queramos utilizar, porque despues de actualizar el firmware ya no es posible pasarlo. Lo que si se puede es revertir (colocar el firmware original de arduino UNO)
(ver un sketch de ejemplo al final de este post)


Para instalar hiduino:

Tocar y soltar los dos pines que aparecen en la imagen:


NOTA: Si en los próximos pasos el dfu-programmer da error diciendo que no encuentra libusb0.dll:
           Copiar el archivo libusb0_x86.dll
               desde dfu-programmer-win-0.7.0\dfu-prog-usb-1.2.2\x86
               hacia dfu-programmer-win-0.7.0
           Entrar a dfu-programmer-win-0.7.0 y renombrar libusb0_x86.dll a libusb0.dll


Transferir el firmware hiduino de esta forma:

dfu-programmer atmega16u2 erase
dfu-programmer atmega16u2 flash arduino_midi.hex
dfu-programmer atmega16u2 reset

[Para ver los dispositivos usb se puede usar la utilidad lsusb.exe]

Para volver el arduino UNO a su origen

dfu-programmer atmega16u2 erase
dfu-programmer atmega16u2 flash "c:\Program Files (x86)\Arduino\hardware\arduino\avr\firmwares\atmegaxxu2\Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex" --suppress-bootloader-mem

[Para ver los dispositivos usb se puede usar la utilidad lsusb.exe]


Acá está la lista de notas utilizadas para DRUMS
http://soundprogramming.net/file-formats/general-midi-drum-note-numbers/


Sketch de ejemplo (toca DO cuando el piezo se golpea)

#include <MIDI.h> // Incluimos la libreria MIDI

//Xylophone
//Adapted for an ArduinoMega
//from Jenna deBoisblanc and Spiekenzie Labs initial code

//*******************************************************************
// User settable variables
//*******************************************************************
MIDI_CREATE_DEFAULT_INSTANCE();

int pinRead;
char pinAssignments[6] ={'A0','A1','A2','A3','A4','A5'};
byte PadNote[16] = {57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72};         // MIDI notes from 0 to 127 (Mid C = 60)
int PadCutOff[16] =
{
  400,400,200,800,400,400,400,400,400,400,400,400,400,400,400,400};           // Minimum Analog value to cause a drum hit
int MaxPlayTime[16] = {
  90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90};               // Cycles before a 2nd hit is allowed
#define  midichannel 1;                              // MIDI channel from 0 to 15 (+1 in "real world")
boolean VelocityFlag  = true;                           // Velocity ON (true) or OFF (false)

//*******************************************************************
// Internal Use Variables
//*******************************************************************
boolean activePad[16] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};                   // Array of flags of pad currently playing
int PinPlayTime[16] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};                     // Counter since pad started to play
byte status1;

int pin = 0;  
int hitavg = 0;
//*******************************************************************
// Setup
//*******************************************************************
void setup()
{
    MIDI.begin();
}
//*******************************************************************
// Main Program
//*******************************************************************
void loop()
{
  for(int pin=0; pin < 16; pin++)                          //
  {
    //int pin = 3;
    //   for (pinRead=0; pinRead < 16, pin++){
    hitavg = analogRead(pinAssignments[pin]);
    //Serial.println(hitavg);
    // read the input pin

    if((hitavg > PadCutOff[pin]))
    {
      if((activePad[pin] == false))
      {
        if(VelocityFlag == true)
        {
          //          hitavg = 127 / ((1023 - PadCutOff[pin]) / (hitavg - PadCutOff[pin]));    // With full range (Too sensitive ?)
          hitavg = (hitavg / 8) -1 ;                                                 // Upper range
        }
        else
        {
          hitavg = 127;
        }
//        MIDI.sendNoteOn(144,PadNote[pin],hitavg); //note on
MIDI.sendNoteOn(48, 127, 1);

        PinPlayTime[pin] = 0;
        activePad[pin] = true;
      }
      else
      {
        PinPlayTime[pin] = PinPlayTime[pin] + 1;
      }
    }
    else if((activePad[pin] == true))
    {
      PinPlayTime[pin] = PinPlayTime[pin] + 1;
      if(PinPlayTime[pin] > MaxPlayTime[pin])
      {
        activePad[pin] = false;
        MIDI.sendNoteOn(144,PadNote[pin],0);
      }
    }
  }
}



Fuentes:
http://geekytheory.com/arduinomidi-tu-propio-piano/
http://bartruffle.blogspot.com/2013/09/dfu-programming-atmega16u2-on-arduino.html
http://answers.microsoft.com/en-us/windows/forum/windows_7-pictures/latency-problem-using-ms-gs-wavetable-synth/1e85704a-803c-438f-b472-fb0cb5211be4

Configuracion de instrumento MIDI en Ableton Live

ATENCION!!! Si se esta utilizando EZdrummer y el driver ASIO, los sonidos NO salen por los parlantes. Hay que conectar auriculares!!!!!

(Otra opcion es ir a las propiedades del dispositivo de salida, y en la ficha Avanzadas, desmarcar "Allow applications to take exclusive control of this device")


1. Arrastrar External Instrument a donde dice Drag and Drop Devices Here


2. Luego de agregarlo, ver que aparece abajo a la izquierda un recuadro que dice External Instrument


3. En MIDI To, elegir el dispositivo por el cual queremos que salga el audio *elegir USB Midi Cable"


Luego hay que arrastrar al external instrument recien agregado, el instrumento que queramos utilizar (los instrumentos elegirlos de la carpeta instrument rack) .



Recordar que el audio sale por los auriculares y no por el parlante!!!





Configuración de EZdrummer

ABRIR LIVE COMO ADMINISTRADOR! SINO EL EZDRUMMER DA ERROR DICIENDO QUE NO ENCUENTRA LOS ARCHIVOS DE SONIDO.

ATENCION!!!!! Si no sale el sonido utilizando los drivers ASIO, conectar auriculares!!! no sale por los parlantes, sale por los auriculares!!!!

(Otra opcion es ir a las propiedades del dispositivo de salida, y en la ficha Avanzadas, desmarcar "Allow applications to take exclusive control of this device")


1. Instalar EZDrummer

2. Instalar ASIO4ALL y configurarlo:



3. Instalar Ableton Live y configurarlo:







5. Agregar plugin de EZDrummer en Ableton:

Para que aparezca en la lista de plugins, es necesario poner en On la opcion marcada a continuación:







6. Solucionar el problema de la latencia (configurar sonido en windows):




7. Aumentar el volumen:



8. Si se cierra la pantalla del EZDrummer, se abre de nuevo así:










Midi drum kit con Arduino

Ejemplo 1:

http://lusorobotica.com/index.php?topic=1237.0





Ejemplo 2:
Conexion de un piezo al arduino:
http://www.sparkfun.com/tutorials/330


Ejemplo 2:

http://www.spikenzielabs.com/SpikenzieLabs/DrumKitKit.html


Ejemplo 3:

-En los ejemplos de Fritzing: Arduino/Sound/Midi Drum Kit

-Fuente: http://todbot.com/blog/2006/10/29/spooky-arduino-projects-4-and-musical-arduino/

-Codigo:


/*
 * MIDI Drum Kit
 * -------------
 * Convert Arduino to a MIDI controller using various inputs and
 * the serial port as a MIDI output.
 *
 * This sketch is set up to send General MIDI (GM) drum notes 
 * on MIDI channel 1, but it can be easily reconfigured for other
 * notes and channels
 *
 * It uses switch inputs to send MIDI notes of a fixed velocity with
 * note on time determined by duration of keypress and it uses
 * piezo buzzer elements as inputs to send MIDI notes of a varying velocity
 * & duration, depending on forced of impulse imparted to piezo sensor.
 *
 * To send MIDI, attach a MIDI out jack (female DIN-5) to Arduino.
 * DIN-5 pinout is:                               _____ 
 *    pin 2 - Gnd                                /     \
 *    pin 4 - 220 ohm resistor to +5V           | 3   1 |  MIDI jack
 *    pin 5 - Arduino D1 (TX)                   |  5 4  |
 *    all other pins - unconnected               \__2__/
 * On my midi jack, the color of the wires for the pins are:
 *   3 = n/c 
 *   5 = black  (blue)
 *   2 = red    (red)
 *   4 = orange (yellow)
 *   1 = brown
 *
 * Based off of Tom Igoe's work at:
 *    http://itp.nyu.edu/physcomp/Labs/MIDIOutput
 *
 * Created 25 October 2006
 * copyleft 2006 Tod E. Kurt <tod@todbot.com
 * http://todbot.com/
 *
 * Updates:
 * - 2 May 2009 - fixed noteOn() and noteOff() 
 *
 */

// what midi channel we're sending on
// ranges from 0-15
#define drumchan           1

// general midi drum notes
#define note_bassdrum     35
#define note_snaredrum    38
#define note_hihatclosed  42
#define note_hihatopen    44
#define note_crash        49

// define the pins we use
#define switchAPin 7
#define switchBPin 6
#define switchCPin 5
#define piezoAPin  0
#define piezoBPin  1
#define ledPin     13  // for midi out status

// analog threshold for piezo sensing
#define PIEZOTHRESHOLD 100

int switchAState = LOW;
int switchBState = LOW;
int switchCState = LOW;
int currentSwitchState = LOW;

int val,t;

void setup() {
  pinMode(switchAPin, INPUT);
  pinMode(switchBPin, INPUT);
  pinMode(switchCPin, INPUT);
  digitalWrite(switchAPin, HIGH);  // turn on internal pullup
  digitalWrite(switchBPin, HIGH);  // turn on internal pullup
  digitalWrite(switchCPin, HIGH);  // turn on internal pullup

  pinMode(ledPin, OUTPUT);
  Serial.begin(31250);   // set MIDI baud rate
}

void loop() {
  // deal with switchA
  currentSwitchState = digitalRead(switchAPin);
  if( currentSwitchState == LOW && switchAState == HIGH ) // push
    noteOn(drumchan,  note_bassdrum, 100);
  if( currentSwitchState == HIGH && switchAState == LOW ) // release
    noteOff(drumchan, note_bassdrum, 0);
  switchAState = currentSwitchState;

  // deal with switchB
  currentSwitchState = digitalRead(switchBPin);
  if( currentSwitchState == LOW && switchBState == HIGH ) // push
    noteOn(drumchan,  note_snaredrum, 100);
  if( currentSwitchState == HIGH && switchBState == LOW ) // release
    noteOff(drumchan, note_snaredrum, 0);
  switchBState = currentSwitchState;

  // deal with switchC
  currentSwitchState = digitalRead(switchCPin);
  if( currentSwitchState == LOW && switchCState == HIGH ) // push
    noteOn(drumchan,  note_hihatclosed, 100);
  if( currentSwitchState == HIGH && switchCState == LOW ) // release
    noteOff(drumchan, note_hihatclosed, 0);
  switchCState = currentSwitchState;

  // deal with first piezo, this is kind of a hack
  val = analogRead(piezoAPin);
  if( val >= PIEZOTHRESHOLD ) {
    t=0;
    while(analogRead(piezoAPin) >= PIEZOTHRESHOLD/2) {
      t++;
    }
    noteOn(drumchan,note_hihatopen, t*2);
    delay(t);
    noteOff(drumchan,note_hihatopen,0);
  }

  // deal with second piezos, this is kind of a hack
  val = analogRead(piezoBPin);
  if( val >= PIEZOTHRESHOLD ) {
    t=0;
    while(analogRead(piezoBPin) >= PIEZOTHRESHOLD/2) {
      t++;
    }
    noteOn(drumchan,note_crash, t*2);
    delay(t);
    noteOff(drumchan,note_crash,0);
  }
}

// Send a MIDI note-on message.  Like pressing a piano key
// channel ranges from 0-15
void noteOn(byte channel, byte note, byte velocity) {
  midiMsg( (0x90 | channel), note, velocity);
}

// Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
  midiMsg( (0x80 | channel), note, velocity);
}

// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
  digitalWrite(ledPin,HIGH);  // indicate we're sending MIDI data
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
  digitalWrite(ledPin,LOW);
}