tttapa / Control-Surface

Arduino library for creating MIDI controllers and other MIDI devices.
GNU General Public License v3.0
1.22k stars 137 forks source link

Velocity variable en CCButton. #160

Open alejamelissa opened 4 years ago

alejamelissa commented 4 years ago

Hola, abro este nuevo hilo para preguntarte si es posible que la velocidad de las notas varie segun la presion ejercida en las teclas, estoy pasando la teclas de mi organeta a usb con tu libreria y la velocity se la define el codigo de forma fija. En el teclas me he dado cuenta que tiene 2 pulsadores en lugar de uno solo, investigando encontre que se usan para con calculos matematicos establecer la velocidad con la que activada la tecla en concordancia con el tiempo de retraso entre una pulsacion y la otra. No he encontrado un codigo o ejemplo que me permita entender un poco esto pero la busqueda ha sido en vano. He estado tratando con una respuesta que diste en el hilo de pads pero la nota no se sostiene es decir, si bien se puede hacer que suene en diferentes volumenes con piezoelectricos la nota se va, para pads va bien, pero al ponerlo en un sintetizador suena una fraccion de segundo y se silencia. No se si tal vez puedas ayudarme un poco para darle mas expresividad a mi vieja organeta. Muchas gracias de manera anticipada por tu tiempo y esfuerzo. Un saludo

tttapa commented 4 years ago

There is no built-in support for velocity-sensitive keys in the library.
However, it isn't too hard to add it, you can start from this example: https://tttapa.github.io/Control-Surface-doc/Doxygen/d4/d3b/Custom-MIDI-Output-Element_8ino-example.html

You'll have to do some experimenting, but the basic principle is simple enough:

  1. The state is initialized to Idle.
  2. If neither of the two buttons is pressed, the update function doesn't do anything.
  3. If the first button is pressed, record the time using micros(), and set the state to Pressed_1.
  4. If the state is Pressed_1 and the first button is released, reset the state to Idle.
  5. If the state is Pressed_1 and the second button is pressed, record the time, and send a note message, with the velocity inversely proportional to the difference between when button 2 and button 1 were pressed. Set the state to Pressed_2.
  6. If the state is Pressed_2 and the second button is released, send a note off message and set the state to Idle (or Pressed_1?).