pindex

pindex — Retourne la valeur d'un p-champ spécifié.

Description

pindex retourne la valeur d'un p-champ spécifié.

Syntaxe

ivalue pindex ipfieldIndex

Initialisation

ipfieldIndex -- numéro du p-champ à interroger.

ivalue - valeur du p-champ.

Exemples

Voici un exemple de l'opcode pindex. Il utilise le fichier pindex.csd.

Exemple 758. Exemple de l'opcode pindex.

Voir les sections Audio en Temps Réel et Options de la Ligne de Commande pour plus d'information sur l'utilisation des options de la ligne de commande.

<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 pindex.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
;Example by Anthony Kozar Dec 2006

instr 1
    inum    pcount
    index   init 1
    loop1:
        ivalue pindex index
        printf_i "p%d = %f\n", 1, index, ivalue
        index   = index + 1
    if  (index <= inum) igoto loop1
    print inum
endin

</CsInstruments>
<CsScore>
i1  0 3 40 50         ; has 5 pfields
i1  1 2 80            ; has 5 due to carry
i1  2 1 40 50 60 70   ; has 7
e
</CsScore>
</CsoundSynthesizer>


L'exemple produira la sortie suivante :

new alloc for instr 1:
WARNING: instr 1 uses 3 p-fields but is given 5
p1 = 1.000000
p2 = 0.000000
p3 = 3.000000
p4 = 40.000000
p5 = 50.000000
instr 1:  inum = 5.000
B  0.000 ..  1.000 T  1.000 TT  1.000 M:      0.0
new alloc for instr 1:
WARNING: instr 1 uses 3 p-fields but is given 5
p1 = 1.000000
p2 = 1.000000
p3 = 2.000000
p4 = 80.000000
p5 = 50.000000
instr 1:  inum = 5.000
B  1.000 ..  2.000 T  2.000 TT  2.000 M:      0.0
new alloc for instr 1:
WARNING: instr 1 uses 3 p-fields but is given 7
p1 = 1.000000
p2 = 2.000000
p3 = 1.000000
p4 = 40.000000
p5 = 50.000000
p6 = 60.000000
p7 = 70.000000
instr 1:  inum = 7.000

On peut ignorer les avertissements, car les p-champs sont utilisés indirectement par pindex plutôt que de manière explicite par p4, p5, etc.

Voici un autre exemple de l'opcode pindex. Il utilise le fichier pindex-2.csd.

Exemple 759. Second exemple de l'opcode pindex.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac  ;;;realtime audio
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o pindex-2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 2
0dbfs  = 1

; This UDO returns a pfield value but returns 0 if it does not exist.
opcode  mypvalue, i, i
	index  xin
	inum   pcount
	if	  (index > inum)  then
		iout = 0.0
	else
		iout pindex index
	endif
	
	xout	iout
endop
	
; Envelope UDO that reads parameters from a flexible number of pfields
; Syntax:   kenv  flexlinseg  ipstart
;           ipstart is the first pfield of the envelope
;               parameters.  Reads remaining pfields (up to 21 of them).
;           kenv is the output envelope.

opcode  flexlinseg, k, i
	ipstart xin
	
	iep1   mypvalue	ipstart
	iep2   mypvalue	ipstart + 1
	iep3   mypvalue	ipstart + 2
	iep4   mypvalue	ipstart + 3
	iep5   mypvalue	ipstart + 4
	iep6   mypvalue	ipstart + 5
	iep7   mypvalue	ipstart + 6
	iep8   mypvalue	ipstart + 7
	iep9   mypvalue	ipstart + 8
	iepa   mypvalue	ipstart + 9
	iepb   mypvalue	ipstart + 10
	iepc   mypvalue	ipstart + 11
	iepd   mypvalue	ipstart + 12
	iepe   mypvalue	ipstart + 13
	iepf   mypvalue	ipstart + 14
	iepg   mypvalue	ipstart + 15
	ieph   mypvalue	ipstart + 16
	iepi   mypvalue	ipstart + 17
	iepj   mypvalue	ipstart + 18
	iepk   mypvalue	ipstart + 19
	iepl   mypvalue	ipstart + 20

	kenv   linseg	 iep1, iep2, iep3, iep4, iep5, iep6, iep7, iep8, \
	                   iep9, iepa, iepb, iepc, iepd, iepe, iepf, iepg, \
	                   ieph, iepi, iepj, iepk, iepl	
	xout   kenv
endop
	
instr 1
; This instrument only requires 3 pfields but can accept up to 24.
; (You will still get warnings about more than 3).	
kenv flexlinseg  4		; envelope params start at p4
aout oscili kenv*.5, 256, 1
     outs aout, aout

endin
</CsInstruments>
<CsScore>
f1  0 8192 10 1

i1  0 2  0.0 1.0 1.0 1.0 0.0
i1  2 2  0.0 0.1 1.0 1.0 1.0 0.1 0.0
i1  4 2  0.0 0.5 0.0	  			; one problem is that "missing" pfields carry
i1  6 2  0.0 0.5 0.0 !	  			; now we can fix this problem with !
i1  8 10  0.0  3.0 1.0  0.3 0.1  0.3 1.0  0.3 0.1  0.3 1.0  0.3 0.1  0.8 0.9  5.0 0.0

e
</CsScore>
</CsoundSynthesizer>


L'exemple produit la sortie suivante :

WARNING: instr 1 uses 3 p-fields but is given 8
B  0.000 ..  2.000 T  2.000 TT  2.000 M:  0.49966  0.49966
WARNING: instr 1 uses 3 p-fields but is given 10
B  2.000 ..  4.000 T  4.000 TT  4.000 M:  0.50000  0.50000
WARNING: instr 1 uses 3 p-fields but is given 10
B  4.000 ..  6.000 T  6.000 TT  6.000 M:  0.49943  0.49943
WARNING: instr 1 uses 3 p-fields but is given 6
B  6.000 ..  8.000 T  8.000 TT  8.000 M:  0.00000  0.00000
WARNING: instr 1 uses 3 p-fields but is given 20
B  8.000 .. 18.000 T 18.000 TT 18.000 M:  0.49994  0.49994
      

Voir aussi

pcount

Crédits

Exemple par : Anthony Kozar

Décembre 2006