50 ways... Wacom Theremin

De wikijoan
Salta a la navegació Salta a la cerca

Referències

Objectius

A part de fer sonar un so de Theremin amb el JV-2080, disposo de un soundfont i plugins VSTi (http://freemusicsoftware.org/category/free-vst/theremin).

Desenvolupament

De fet, es pot començar fent un Theremin del ratolí. El primer que s'ha de saber fer és captar la informació del ratolí USB.

$ sudo cat /dev/input/mice 

i quan movem el ratolí per la consola veiem informació

De http://letsmakerobots.com/node/9355 obtinc el codi que m'interessa. Un fitxer amb llenguatge C que obté i decodifica la informació del ratolí USB.

fitxer prova_mouse.c

#include <stdio.h>
#include <stdlib.h>
main(){
        FILE *fmouse;
        char b[3];
        fmouse = fopen("/dev/input/mice","r");
        int xd=0,yd=0; //x/y movement delta
        int xo=0,yo=0; //x/y overflow (out of range -255 to +255)
        int lb=0,mb=0,rb=0,hs=0,vs=0; //left/middle/right mousebutton
        int run=0;
        while(!run){
                fread(b,sizeof(char),3,fmouse);
                lb=(b[0]&1)>0;
                rb=(b[0]&2)>0;
                mb=(b[0]&4)>0;
                hs=(b[0]&16)>0;
                vs=(b[0]&32)>0;
                xo=(b[0]&64)>0;
                yo=(b[0]&128)>0;
                xd=b[1];
                yd=b[2];
                printf("hs=%d,vs=%d,lb=%d rm=%d mb=%d xo=%d yo=%d xd=%d yd=%d\n",hs,vs,lb,rb,mb,xo,yo,xd,yd);
        }
        fclose(fmouse);
}
$ gcc -o prova_mouse prova_mouse.c
$ sudo ./prova_mouse

si volem llegir un dispositiu wacom, en comptes de /dev/input/mice haurem de ficar el dispositiu que representa el wacom, i és clar, també hem de saber decodificar la informació que ens arriba.

Ja puc passar a fer un Mouse Theremin: he d'integrar aquest codi amb codi C de MidiShare, i si vull, fer una interfície gràfica. Puc fer tot això abans no disposi d'una tauleta wacom.

Definint el so del Theremin amb pitch bend

Nota. La configuració del JV-2080 per aconseguir el so del Theremin està a: Roland_JV-2080

The pitch bend wheel is also a continuous controller on many MIDI keyboards. Possibly, the Pitch Bend message is in its own category because it is something likely to be done frequently. The two bytes of the pitch bend message form a 14 bit number, 0 to 16383. The value 8192 (sent, LSB first, as 0x00 0x40), is centered, or "no pitch bend." The value 0 (0x00 0x00) means, "bend as low as possible," and, similarly, 16383 (0x7F 0x7F) is to "bend as high as possible." The exact range of the pitch bend is specific to the synthesizer.

While almost all channel voice messages assign a single data byte to a single parameter such as key # or velocity (128 values because they start with '0,' so = 2^7=128), the exception is pitch bend. If pitch bend used only 128 values, discreet steps might be heard if the bend range were large (this range is set on the instrument, not by MIDI). So the 7 non-zero bits of the first data byte (called the most significant byte or MSB) are combined with the 7 non-zero bits from the second data byte (called the least significant byte or LSB) to create a 14-bit data value, giving pitch bend data a range of 16,384 values.

El tema que em preocupa és... amb pitch bend tinc prou marge com per tocar una cançó? Aquí dalt es comenta que el rang del pitch bend depèn del sintetitzador. Amb el CASIO sembla ser que no. Amb el JV-2080 no ho he probat. Amb el fluidsynth no me n'en surto. La qüestió de fons és... com s'implementa un theremin amb midi? Jo pensava que la solució passava per pitch bend.

El Etherbox MIDI Theremin és un theremin-midi comercial que ja no es fabrica (http://www.moogmusic.com/theremin/?section=product&product_id=11). Llegeixo:

The Ethervox integrates easily into any MIDI studio or stage setup. Several menu options let you match your Ethervox's MIDI data to the other resources of your MIDI setup. Many MIDI sequencers provide editable high resolution graphic displays of pitch bend and control change data streams, which enable you to use standard techniques to modify your MIDI recording. The Ethervox's MIDI data can be played back through the Ethervox itself, or through any MIDI sound generator that is capable of wide-range pitch-bend. Thus you can create a virtually limitless array of dramatic and expressive continuously varying musical gestures simply by moving your hands around the Ethervox's antennas, and you can fine-tune each gesture once you've recorded it in your sequencer.

Per tant, suposadament el meu Roland JV-2080 ha de tenir un wide-range pitch-bend que em permeti tocar tota una cançó. He de mirar el manual del JV-2080.

Llegint la pàgina 187 i 186 del manual, entenc que el missatge Pitch Bend Change actua com s'espera (-8192-0-8191); però després hi ha el paràmetre Pitch Bend Sensitivity que defineix la sensibilitat del pitch bend, i que pot ser de 12 semitons, és a dir, 6 tons, just per poder tocar Una Plata d'Enciam. He de ficar els dos bytes de RPN a 0, i els dos bytes de Data a 0CH (MSB) i o (LSB) (això es pot llegir a l'inici de la pàgina 186). Els RPN (Registered Parameters Number) és un tipus de missatge Control Change que estan definits en l'especificació MIDI.

Repasso el mail que em va enviar el Ken Moore. Efectivament, amb el Roland JV-2080 no he de tenir cap problema:

Hi Joan,

I apologize for the delays in responding, life has just been very busy.  Here are the details of the parameters I used for my Theremin sound (note, this is a really basic approximator, and I think now that I own a real Theremin if I were to try to mimic that sound I'd come up with something very different):

  Patch Common
   Level 105
  Output
   Reverb 80
  Reverb
   Type STAGE1
   Time 80
   Level 110
   Feedback 0
   HF damp BYPASS
  Key Mode & Bender
   Assign Poly
   Legato Off
   Bend range -48 : 0
  Portamento
   Tm 18
   Mode Legato
   Start Pitch
  Wave
   Group INT-B 046 (Sine)
   Gain +12
   Switch ON


Note that the bend range here is specifically for the purpose of using the gloves to bend the sound -- my program plays a single high pitch and based upon the position of the gloves it bends the sound downward to match the distance (I use downward bend because the JV supports 4 octave downward bend but only 2 octave upward bend).

I hope this helps and isn't too late... let me know if you have other questions.  Also let me know how your project goes - can't wait to check it out!

En el mail diu que hi ha 6 octaves de bending. En el manual del JV-2080, busco en el index Bend Range i diu que he d'anar a mirar les pàgines 72 i 96.

Llegeixo en el manual, a la pàgina 72, les característiques Bend Range Up i Bend Range Down que s'accedeixen fent: Common General Page [PATCH] -> [F1] (Common) -> [F1] (General)

Bend Range Up
   Specify the amount (in semitones) of pitch bend that will occur when the bender level of a connected MIDI keyboard
   is moved to the far right position (or for a whell, the fully upward position). With a setting of 12, moving the
   pitch bend to the far right position will raise the pitch 1 octave.

Bend Range Down
   Specify the amount (in semitones) of pitch bend that will occur when the bender level of a connected MIDI keyboard
   is moved to the far left position (or for a whell, the fully downward position). With a setting of 48, moving the
   pitch bend to the far left position will lower the pitch 4octaves.

D'aquí ve el valor de -48:0 que utilitza el Ken. Fem sonar una nota alta, i posiciono el sensor cap a l'esquerra buscant una zona central. Aleshores sé que tinc 2 octaves per la dreta i 2 octaves per l'esquerre.

Per tant, com a conclusió, si vull fer servir el missatge pitch bend per fer sonar el theremin, la solució correcta és utilitzar i configurar el Roland JV-2080. No me n'en sortiré amb el fluidsynth o amb el CASIO CTK-731. És la única solució vàlida per cantar cançons. Una altra cosa és que es poden aconseguir efectes interessants només amb KeyOn i NoteOn, tocant un rang molt ample de notes... però no per tocar cançons.

Efectivament, la primera prova que he fet, que és moure el ratolí i fer sonar el pitch bend del CASIO, ja em diu que com a molt puc pujar i baixar un to per cada banda.

Nota. Al fincal de tot, en el projecte, com que toquem Una Plata d'Enciam amb la Wacom, i per tal d'utilitzar tota l'amplada de la wacom, s'ha d'ajustar els paràmetres per tal de tenir aquest rang. Al final he utiltizat: rang de pitch bend a +12 (up) i -8 (down)

Programant el mouse

opció 1: a baix nivell. no m'ha sortit

$ sudo apt-get install libgpm-dev
General purpose Mouse - development files
#include <stdio.h>
#include <gpm.h>
int my_handler(Gpm_Event *event, void *data)
{       printf("Event Type : %d at x=%d y=%d\n", event->type, event->x, event->y);
        return 0;       
}
int main()
{       Gpm_Connect conn;
        int c;
        conn.eventMask  = ~0;   /* Want to know about all the events */
        conn.defaultMask = 0;   /* don't handle anything by default  */
        conn.minMod     = 0;    /* want everything                   */  
        conn.maxMod     = ~0;   /* all modifiers included            */
        
        if(Gpm_Open(&conn, 0) == -1)
                printf("Cannot connect to mouse server\n");
        
        gpm_handler = my_handler;
        while((c = Gpm_Getc(stdin)) != EOF)
                printf("%c", c);
        Gpm_Close();
        return 0;
}
gcc mouse.c -lgpm

opció 2. Utilizo OpenGL i SDL

em baso e el Ejemplo3_1, i amb una mica de documentació ràpidament puc imprimir a consola els valors de les posicions del ratolí.

	while(done == 0) {


		while ( SDL_PollEvent(&event) ) {

			if ( event.type == SDL_MOUSEMOTION ) 
				printf("%i - %i\n",event.motion.x,event.motion.xrel);

	}


   }

De moment no m'ha sortit, però ho hauria d'aconseguir (TBD)

opció 3. xopen.c (opció vàlida)

Està discutit àmpliament a Històries_amb_la_Wacom#Programaci.C3.B3_Wacom_.2B_GIMP.

funciona. És una solució elegant perquè representa interceptar els missatges del mouse/wacom sense necessitar interfície gràfica. No estic supeditat a cap finestra. El codi funciona per tota la pantalla, independentment de les finestres que tingui obertes. El problema està en què em fa gràcia integrar el Wacom Theremin amb el GIMP per tal que quedi el video més xulo, i això m'ha portat problemes amb el comportament del GIMP (quan tenia el focus en la finestra del GIMP la meva aplicació de consola deixava de detectar els events). Al final ho he solucionat detectant els events buttonpress i buttonrelease (a més del moviment), i també he d'arrencar el GIMP com a sudo.

Per tant, ara el següent pas ja és fer el Wacom Theremin integrant aquest codi amb el codi d'un client MIDI de JACK (ho faig amb JACK, res de MidiShare).

Programar el so theremin

modulació

Modulació: és l'equivalent al vibrato musical. Els controladors (com el Axiom25) tenen la rodeta de modulació. La modulació va de 0-127, i la posició normal és la 0 (al contrari que el pritchbend que va de 0 a ... i la posició central és la del mig)

Modulació. És un missatge Control Change: 3 bytes

  • 1r byte: 1011nnnn nnnn és el canal, 1011 és el Control Change (CC)
  • 2n byte: 0ccccccc. Valor dek controlador (0-119, 120-127 estan reservats) La modulació és el 00000001
  • 3r byte: el valor del control, en el nostre cas el valor de la modulació: 0vvvvvvv (0-127)

Download

Es pot descarregar el codi del projecte a Fitxer:Wacom theremin 1 06.c.zip (wacom_theremin_1_06.c (v1.06))

Video


creat per Joan Quintana Compte, gener 2010, febrer 2012