User-Defined Opcode Database

pgmin

Read program change messages from MIDI input.

Download UDO File

Description

Much like the externals in popular dataflow languages (eg. MaxMSP, Pd, jMax, etc) this opcode is intended to be used where program change messages are necessary, for example to trigger events or change presets in General MIDI orchestra.

Syntax

kpgm, kchan pgmin

Performance

kpgm - The program change message number (0-127).
kchan - The channel number (0-16) that the program change message was received on.

Code

	opcode	pgmin, kk, 0

kstatus, kchan, kdata1, kdata2	midiin

if	(kstatus == 192 && kchan == 1) then
kpgm	=	kdata1
else
	endif

	xout	kpgm, kchan

		endop

Examples

<CsoundSynthesizer>
<CsInstruments>

sr		=	44100
kr		=	441
ksmps	=	100
nchnls	=	2
	massign	1, 1
	pgmassign	-1, -1

/* change soundfont here */
gi2 sfload "/Library/Audio/Sounds/Banks/synthgms.sf2"

gipres	init	1
gkpres	init	1

	sfilist	gi2
	sfplist	gi2
	sfpassign	0, gi2

;//
	opcode	pgmin, kk, 0

kstatus, kchan, kdata1, kdata2	midiin

if	(kstatus == 192 && kchan == 1) then
kpgm	=	kdata1
else
	endif

	xout	kpgm, kchan

		endop
;//
/*--- ---*/

		instr 1

ifreq	cpsmidi
iamp	ampmidi 2
inum	notnum
ivel	veloc
kfreq	init	1

kvol	ctrl7	1, 7, -2, 8

gipres	=	i(gkpres)

;	printk2	gipres

kamp	linsegr	1, 1, 1, 0.618, 0 ; adjust the release time to suit the 
sample set
a1,a2	sfplay	ivel, inum, kamp*(iamp+kvol), kfreq, gipres, 0

	outs	a1,a2

		endin

/*--- ---*/

		instr	2

kmodw	ctrl7	1, 1, 0, 2

kpgm, kchan		pgmin

gkpres	=	kpgm

if	(kmodw >= 1) then
	printks	"\nPreset index: %i\n\n", 2, kpgm+1
else
	endif

		endin

/*--- ---*/
</CsInstruments>
<CsScore>

i1	0	3600
i2	0	3600

e
</CsScore>

</CsoundSynthesizer>

Credits

David Akbari, 2006


Previous Home Next
midiMonitor   BufFiPl1