cpstmid
Prev | Orchestra Opcodes and Operators | Next

## cpstmid

cpstmid — Get a MIDI note number (allows customized micro-tuning scales).

## Description

This unit is similar to cpsmidi, but allows fully customized micro-tuning scales.

## Syntax

    icps cpstmid ifn

## Initialization

ifn -- function table containing the parameters (numgrades, interval, basefreq, basekeymidi) and the tuning ratios.

## Performance

Init-rate only

cpsmid requires five parameters, the first, ifn, is the function table number of the tuning ratios, and the other parameters must be stored in the function table itself. The function table ifn should be generated by GEN02, with normalization inhibited. The first four values stored in this function are:

1. numgrades -- the number of grades of the micro-tuning scale

2. interval -- the frequency range covered before repeating the grade ratios, for example 2 for one octave, 1.5 for a fifth etc.

3. basefreq -- the base frequency of the scale in Hz

4. basekeymidi -- the MIDI note number to which basefreq is assigned unmodified

After these four values, the user can begin to insert the tuning ratios. For example, for a standard 12 note scale with the base frequency of 261 Hz assigned to the key number 60, the corresponding f-statement in the score to generate the table should be:

; numgrades interval basefreq basekeymidi tuning ratios (equal temp)
f1 0 64 -2 12 2 261 60 1 1.059463094359 1.122462048309 1.189207115003 ..etc...

Another example with a 24 note scale with a base frequency of 440 assigned to the key number 48, and a repetition interval of 1.5:

; numgrades interval basefreq basekeymidi tuning-ratios (equal temp)
f1 0 64 -2 24 1.5 440 48 1 1.01 1.02 1.03 ..etc...

## Examples

Here is an example of the cpstmid opcode. It uses the file cpstmid.csd.

Example 96. Example of the cpstmid opcode.

See the sections Real-time Audio and Command Line Flags for more information on using command line flags.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    ; Audio out   Audio in   No messages  MIDI in
    -odac           -iadc     -d         -M0  ;;;RT audio I/O with MIDI in
    ; For Non-realtime ouput leave only the line below:
    ; -o cpstmid.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Table #1, a normal 12-tone equal temperament scale.
    ; numgrades = 12 (twelve tones)
    ; interval = 2 (one octave)
    ; basefreq = 261.659 (Middle C)
    ; basekeymidi = 60 (Middle C)
    gitemp ftgen 1, 0, 64, -2, 12, 2, 261.659, 60, 1.00, \
                 1.059, 1.122, 1.189, 1.260, 1.335, 1.414, \
                 1.498, 1.588, 1.682, 1.782, 1.888, 2.000

    ; Instrument #1.
    instr 1
      ; Use Table #1.
      ifn = 1
      i1 cpstmid ifn

      print i1
    endin

    </CsInstruments>
    <CsScore>

    ; Play Instrument #1 for 12 seconds.
    i 1 0 12
    e

    </CsScore>
    </CsoundSynthesizer>

## See Also

cpsmidi, GEN02

## Credits

Author: Gabriel Maldonado
Italy
1998

Example written by Kevin Conder.

New in Csound version 3.492

Prev | Up | Next
cpspch | Home | cpstun