FLOSS Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

CSOUND Español

MIDI OUTPUT SALIDA MIDI

 

Csound's ability to output midi data in real-time can open up many possibilities. We can relay the Csound score to a hardware synthesizer so that it plays the notes in our score, instead of a Csound instrument. We can algorithmically generate streams of notes within the orchestra and have these played by the external device. We could even route midi data internally to another piece of software. Csound could be used as a device to transform incoming midi data, transforming, transposing or arpeggiating incoming notes before they are output again. Midi output could also be used to preset faders on a motorized fader box to desired initial locations.

Csounds capacidad de salida de datos midi en tiempo real puede abrir muchas posibilidades. Podemos transmitir la puntuación Csound a un sintetizador de hardware para que reproduzca las notas en nuestra partitura, en lugar de un instrumento Csound. Podemos algorítmicamente generar corrientes de notas dentro de la orquesta y tenerlas interpretadas por el dispositivo externo. Incluso podríamos dirigir los datos MIDI internamente a otra pieza de software. Csound podría utilizarse como un dispositivo para transformar los datos midi entrantes, transformar, transponer o arpejar las notas entrantes antes de que se vuelvan a emitir. La salida Midi también podría usarse para ajustar los faders en una caja de fader motorizada a las ubicaciones iniciales deseadas.

Initiating Realtime MIDI Output

Inicio de la salida MIDI en tiempo real

The command line flag for realtime midi output is -Q. Just as when setting up an audio input or output device or a midi input device we must define the desired device number after the flag. When in doubt what midi output devices we have on our system we can always specify an 'out of range' device number (e.g. -Q999) in which case Csound will not run but will instead give an error and provide us with a list of available devices and their corresponding numbers. We can then insert an appropriate device number.

El indicador de línea de comandos para la salida MIDI en tiempo real es -Q. Al igual que al configurar un dispositivo de entrada o salida de audio o un dispositivo de entrada MIDI, debemos definir el número de dispositivo deseado después del indicador. Cuando tengamos dudas sobre los dispositivos de salida midi que tenemos en nuestro sistema siempre podemos especificar un número de dispositivo fuera de rango (por ejemplo, -Q999), en cuyo caso Csound no se ejecutará, sino que dará un error y nos proporcionará una lista de dispositivos disponibles y Sus números correspondientes. A continuación, podemos insertar un número de dispositivo adecuado.

midiout - Outputting Raw MIDI Data

Midiout - Salida de datos MIDI brutos

The analog of the opcode for the input of raw midi data, midiin, is midiout. midiout will output a midi message with its given input arguments once every k period - this could very quickly lead to clogging of incoming midi data in the device to which midi is begin sent unless measures are taken to restrain its output. In the following example this is dealt with by turning off the instrument as soon as the midiout line has been executed just once by using the turnoff opcode. Alternative approaches would be to set the status byte to zero after the first k pass or to embed the midiout within a conditional (if... then...) so that its rate of execution can be controlled in some way.

El análogo del opcode para la entrada de datos midi crudos, midiin, es midiout. Midiout emitirá un mensaje midi con sus argumentos de entrada dados una vez cada período k - esto podría conducir muy rápidamente a la obstrucción de los datos midi entrantes en el dispositivo al que se inicia midi, a menos que se tomen medidas para restringir su salida. En el ejemplo siguiente se trata de apagar el instrumento tan pronto como la línea midiout se haya ejecutado una vez usando el opcode turnoff. Los enfoques alternativos serían establecer el byte de estado a cero después del primer kpass o incrustar el midiout dentro de un condicional (si ... entonces ...) para que su tasa de ejecución pueda ser controlada de alguna manera.

Another thing we need to be aware of is that midi notes do not contain any information about note duration; instead the device playing the note waits until it receives a corresponding note-off instruction on the same midi channel and with the same note number before stopping the note. We must be mindful of this when working with midiout. The status byte for a midi note-off is 128 but it is more common for note-offs to be expressed as a note-on (status byte 144) with zero velocity. In the following example two notes (and corresponding note offs) are send to the midi output - the first note-off makes use of the zero velocity convention whereas the second makes use of the note-off status byte. Hardware and software synths should respond similarly to both. One advantage of the note-off message using status byte 128 is that we can also send a note-off velocity, i.e. how forcefully we release the key. Only more expensive midi keyboards actually sense and send note-off velocity and it is even rarer for hardware to respond to received note-off velocities in a meaningful way. Using Csound as a sound engine we could respond to this data in a creative way however.

Otra cosa que debemos tener en cuenta es que las notas midi no contienen ninguna información sobre la duración de la nota; En lugar de eso, el dispositivo que toca la nota espera hasta recibir una instrucción de nota-apagado correspondiente en el mismo canal midi y con el mismo número de nota antes de detener la nota. Debemos ser conscientes de esto cuando trabajamos con midiout. El byte de estado para una nota de desconexión de midi es 128 pero es más común que las notas de desconexión se expresen como una nota (el byte de estado 144) con velocidad cero. En el ejemplo siguiente se envían dos notas (y notas de nota correspondientes) a la salida midi: la primera nota de salida hace uso de la convención de velocidad cero mientras que la segunda hace uso del byte de estado de desactivación de nota. Los sintetizadores de hardware y software deben responder de manera similar a ambos. Una ventaja del mensaje de desconexión que usa el byte de estado 128 es que también podemos enviar una velocidad de desprendimiento de la nota, es decir, cuán fuertemente liberamos la llave. Solamente los teclados midi más caros realmente detectan y envían la velocidad de la nota-apagado y es aún más raro para que el hardware responda a las velocidades de la nota-apagado recibidas de una manera significativa. Usando Csound como un motor de sonido podríamos responder a estos datos de una manera creativa sin embargo.

In order for the following example to work you must connect a midi sound module or keyboard receiving on channel 1 to the midi output of your computer. You will also need to set the appropriate device number after the '-Q' flag.

Para que funcione el siguiente ejemplo, debe conectar un módulo de sonido midi o recepción de teclado en el canal 1 a la salida midi de su computadora. También necesitará establecer el número de dispositivo apropiado después del indicador -Q.

No use is made of audio so sample rate (sr), and number of channels (nchnls) are left undefined - nonetheless they will assume default values.

No se hace uso de audio, por lo que la tasa de muestreo (sr) y el número de canales (nchnls) quedan indefinidos, pero asumirán valores predeterminados.

  EXAMPLE 07E01_midiout.csd 

<CsoundSynthesizer>

<CsOptions>
; amend device number accordingly
-Q999
</CsOptions>

<CsInstruments>
ksmps = 32 ;no audio so sr and nchnls irrelevant

  instr 1
; arguments for midiout are read from p-fields
istatus   init      p4
ichan     init      p5
idata1    init      p6
idata2    init      p7
          midiout   istatus, ichan, idata1, idata2; send raw midi data
          turnoff   ; turn instrument off to prevent reiterations of midiout
  endin

</CsInstruments>

<CsScore>
;p1 p2 p3   p4 p5 p6 p7
i 1 0 0.01 144 1  60 100 ; note on
i 1 2 0.01 144 1  60   0 ; note off (using velocity zero)

i 1 3 0.01 144 1  60 100 ; note on
i 1 5 0.01 128 1  60 100 ; note off (using 'note off' status byte)
</CsScore>

</CsoundSynthesizer>

The use of separate score events for note-ons and note-offs is rather cumbersome. It would be more sensible to use the Csound note duration (p3) to define when the midi note-off is sent. The next example does this by utilising a release flag generated by the release opcode whenever a note ends and sending the note-off then.

El uso de eventos de puntuación por separado para note-ons y note-offs es bastante engorroso. Sería más sensato utilizar la duración de la nota Csound (p3) para definir cuándo se envía la nota de apagado MIDI. El siguiente ejemplo lo hace mediante la utilización de un indicador de liberación generado por el código de liberación cada vez que una nota termina y enviando la nota apagada entonces.

  EXAMPLE 07E02_score_to_midiout.csd  

<CsoundSynthesizer>

<CsOptions>
; amend device number accordingly
-Q999
</CsOptions>

<CsInstruments>
ksmps = 32 ;no audio so sr and nchnls omitted

  instr 1
;arguments for midiout are read from p-fields
istatus   init      p4
ichan     init      p5
idata1    init      p6
idata2    init      p7
kskip     init      0
 if kskip=0 then
          midiout   istatus, ichan, idata1, idata2; send raw midi data (note on)
kskip     =         1; ensure that the note on will only be executed once
 endif
krelease  release; normally output is zero, on final k pass output is 1
 if krelease=1 then; i.e. if we are on the final k pass...
       midiout   istatus, ichan, idata1, 0; send raw midi data (note off)
 endif
  endin

</CsInstruments>

<CsScore>
;p1 p2 p3   p4 p5 p6 p7
i 1 0    4 144 1  60 100
i 1 1    3 144 1  64 100
i 1 2    2 144 1  67 100
f 0 5; extending performance time prevents note-offs from being lost
</CsScore>

</CsoundSynthesizer>

Obviously midiout is not limited to only sending only midi note information but instead this information could include continuous controller information, pitch bend, system exclusive data and so on. The next example, as well as playing a note, sends controller 1 (modulation) data which rises from zero to maximum (127) across the duration of the note. To ensure that unnessessary midi data is not sent out, the output of the line function is first converted into integers, and midiout for the continuous controller data is only executed whenever this integer value changes. The function that creates this stream of data goes slightly above this maximum value (it finishes at a value of 127.1) to ensure that a rounded value of 127 is actually achieved.

Obviamente, midiout no se limita a enviar sólo información de nota midi, sino que esta información podría incluir información continua del controlador, pitch bend, datos exclusivos del sistema y así sucesivamente. El siguiente ejemplo, además de reproducir una nota, envía datos del controlador 1 (modulación) que suben de cero a máximo (127) a lo largo de la duración de la nota. Para asegurarse de que no se envían datos MIDI no necesitados, la salida de la función de línea se convierte primero en números enteros, y midiout para los datos del controlador continuo sólo se ejecuta cuando cambia este valor entero. La función que crea este flujo de datos va ligeramente por encima de este valor máximo (termina en un valor de 127.1) para asegurarse de que realmente se alcanza un valor redondeado de 127.

In practice it may be necessary to start sending the continuous controller data slightly before the note-on to allow the hardware time to respond.

En la práctica, puede ser necesario comenzar a enviar los datos del controlador continuamente un poco antes de la nota para permitir que el tiempo del hardware responda.

  EXAMPLE 07E03_midiout_cc.csd  

<CsoundSynthesizer>

<CsOptions>
; amend device number accordingly
-Q999
</CsOptions>

<CsInstruments>
ksmps = 32 ; no audio so sr and nchnls irrelevant

  instr 1
; play a midi note
; read in values from p-fields
ichan     init      p4
inote     init      p5
iveloc    init      p6
kskip     init      0 ; 'skip' flag ensures that note-on is executed just once
 if kskip=0 then
          midiout   144, ichan, inote, iveloc; send raw midi data (note on)
kskip     =         1   ; flip flag to prevent repeating the above line
 endif
krelease  release       ; normally zero, on final k pass this will output 1
 if krelease=1 then     ; if we are on the final k pass...
          midiout   144, ichan, inote, 0  ; send a note off
 endif

; send continuous controller data
iCCnum    =         p7
kCCval    line      0, p3, 127.1  ; continuous controller data function
kCCval    =         int(kCCval)   ; convert data function to integers
ktrig     changed   kCCval        ; generate a trigger each time kCCval changes
 if ktrig=1 then                  ; if kCCval has changed...
          midiout   176, ichan, iCCnum, kCCval  ; ...send a controller message
 endif
  endin

</CsInstruments>

<CsScore>
;p1 p2 p3   p4 p5 p6  p7
i 1 0  5    1  60 100 1
f 0 7 ; extending performance time prevents note-offs from being lost
</CsScore>

</CsoundSynthesizer>

midion - Outputting MIDI Notes Made Easier

Midion - La salida de notas MIDI se hace más fácil

 

midiout is the most powerful opcode for midi output but if we are only interested in sending out midi notes from an instrument then the midion opcode simplifies the procedure as the following example demonstrates by playing a simple major arpeggio.

Midiout es el opcode más potente para la salida midi, pero si solo estamos interesados en enviar notas MIDI desde un instrumento, el opcode midion simplifica el procedimiento como muestra el siguiente ejemplo al tocar un simple arpegio mayor.

  EXAMPLE 07E04_midion.csd

<CsoundSynthesizer>

<CsOptions>
; amend device number accordingly
-Q999
</CsOptions>

<CsInstruments>
; Example by Iain McCurdy

ksmps = 32 ;no audio so sr and nchnls irrelevant

  instr 1
; read values in from p-fields
kchn    =       p4
knum    =       p5
kvel    =       p6
        midion  kchn, knum, kvel ; send a midi note
  endin

</CsInstruments>

<CsScore>
;p1 p2  p3  p4 p5 p6
i 1 0   2.5 1 60  100
i 1 0.5 2   1 64  100
i 1 1   1.5 1 67  100
i 1 1.5 1   1 72  100
f 0 30 ; extending performance time prevents note-offs from being missed
</CsScore>

</CsoundSynthesizer>

Changing any of midion's k-rate input arguments in realtime will force it to stop the current midi note and send out a new one with the new parameters.

Cambiar cualquiera de los argumentos de entrada de k-rate midios en tiempo real lo obligará a detener la nota midi actual y enviar una nueva con los nuevos parámetros.

midion2 allows us to control when new notes are sent (and the current note is stopped) through the use of a trigger input. The next example uses 'midion2' to algorithmically generate a melodic line. New note generation is controlled by a metro, the rate of which undulates slowly through the use of a randomi function.

Midion2 nos permite controlar cuándo se envían nuevas notas (y la nota actual se detiene) mediante el uso de una entrada de disparo. El siguiente ejemplo utiliza midion2 para generar algorítmicamente una línea melódica. La nueva generación de notas es controlada por un metro, cuya velocidad ondula lentamente mediante el uso de una función aleatoria.

 

  EXAMPLE 07E05_midion2.csd

<CsoundSynthesizer>

<CsOptions>
; amend device number accordingly
-Q999
</CsOptions>

<CsInstruments>
; Example by Iain McCurdy

ksmps = 32 ; no audio so sr and nchnls irrelevant

  instr 1
; read values in from p-fields
kchn    =        p4
knum    random   48,72.99  ; note numbers chosen randomly across a 2 octaves
kvel    random   40, 115   ; velocities are chosen randomly
krate   randomi  1,2,1     ; rate at which new notes will be output
ktrig   metro    krate^2   ; 'new note' trigger
        midion2  kchn, int(knum), int(kvel), ktrig ; send midi note if ktrig=1
  endin

</CsInstruments>

<CsScore>
i 1 0 20 1
f 0 21 ; extending performance time prevents the final note-off being lost
</CsScore>

</CsoundSynthesizer>

'midion' and 'midion2' generate monophonic melody lines with no gaps between notes.

Midion y midion2 generan líneas de melodías monofónicas sin espacios entre las notas.

moscil works in a slightly different way and allows us to explicitly define note durations as well as the pauses between notes thereby permitting the generation of more staccato melodic lines. Like 'midion' and 'midion2', 'moscil' will not generate overlapping notes (unless two or more instances of it are concurrent). The next example algorithmically generates a melodic line using 'moscil'.

Moscil trabaja de una manera ligeramente diferente y nos permite definir explícitamente las duraciones de notas así como las pausas entre notas permitiendo así la generación de líneas melódicas más staccato. Al igual que midion y midion2, moscil no generará notas superpuestas (a menos que dos o más instancias de ella sean concurrentes). El siguiente ejemplo genera algorítmicamente una línea melódica usando moscil.

  EXAMPLE 07E06_moscil.csd

<CsoundSynthesizer>

<CsOptions>
; amend device number accordingly
-Q999
</CsOptions>

<CsInstruments>
; Example by Iain McCurdy

ksmps = 32 ;no audio so sr and nchnls omitted

seed 0; random number generators seeded by system clock

  instr 1
; read value in from p-field
kchn    =         p4
knum    random    48,72.99  ; note numbers chosen randomly across a 2 octaves
kvel    random    40, 115   ; velocities are chosen randomly
kdur    random    0.2, 1    ; note durations chosen randomly from 0.2 to 1
kpause  random    0, 0.4    ; pauses betw. notes chosen randomly from 0 to 0.4
        moscil    kchn, knum, kvel, kdur, kpause ; send a stream of midi notes
  endin

</CsInstruments>

<CsScore>
;p1 p2 p3 p4
i 1 0  20 1
f 0 21 ; extending performance time prevents final note-off from being lost
</CsScore>

</CsoundSynthesizer>

MIDI File Output Salida de archivo MIDI

As well as (or instead of) outputting midi in realtime, Csound can render data from all of its midi output opcodes to a midi file. To do this we use the '--midioutfile=' flag followed by the desired name for our file. For example:

Además de (o en lugar de) emitir MIDI en tiempo real, Csound puede procesar los datos de todos sus opcodes de salida midi a un archivo midi. Para hacer esto usamos el indicador --midioutfile = seguido del nombre deseado para nuestro archivo. Por ejemplo:

<CsOptions>

-Q2 --midioutfile=midiout.mid
</CsOptions>

will simultaneously stream realtime midi to midi output device number 2 and render to a file named 'midiout.mid' which will be saved in our home directory.

Transmitirá simultáneamente en tiempo real midi a midi el dispositivo de salida número 2 y renderizará a un archivo denominado midiout.mid que se guardará en nuestro directorio personal.

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.