pgmassign

pgmassign — Assigns an instrument number to a specified MIDI program.

Description

Assigns an instrument number to a specified (or all) MIDI program(s).

By default, the instrument is the same as the program number. If the selected instrument is zero or negative or does not exist, the program change is ignored. This opcode is normally used in the orchestra header. Although, like massign, it also works in instruments.

Syntax

pgmassign ipgm, inst[, ichn]
pgmassign ipgm, "insname"[, ichn]

Initialization

ipgm -- MIDI program number (1 to 128). A value of zero selects all programs.

inst -- instrument number. If set to zero, or negative, MIDI program changes to ipgm are ignored. Currently, assignment to an instrument that does not exist has the same effect. This may be changed in a later release to print an error message.

insname -- A string (in double-quotes) representing a named instrument.

ichn (optional, defaults to zero) -- channel number. If zero, program changes are assigned on all channels.

You can disable the turning on of any instruments by using the following in the header:

        massign 0, 0
        pgmassign 0, 0
      

Examples

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

Example 599. Example of the pgmassign 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 pgmassign.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

; Program 55 (synth vox) uses Instrument #10.
pgmassign 55, 10 

; Instrument #10.
instr 10
  ; Just an example, no working code in here!
endin


</CsInstruments>
<CsScore>

; Play Instrument #10 for one second.
i 10 0 1
e


</CsScore>
</CsoundSynthesizer>


Here is an example of the pgmassign opcode that will ignore program change events. It uses the file pgmassign_ignore.csd.

Example 600. Example of the pgmassign opcode that will ignore program change events.

<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 pgmassign_ignore.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

; Ignore all program change events.
pgmassign 0, -1

; Instrument #1.
instr 1
  ; Just an example, no working code in here!
endin


</CsInstruments>
<CsScore>

; Play Instrument #1 for one second.
i 1 0 1
e


</CsScore>
</CsoundSynthesizer>


Here is an advanced example of the pgmassign opcode. It uses the file pgmassign_advanced.csd.

Don't forget that you must include the -F flag when using an external MIDI file like pgmassign_advanced.mid.

Example 601. An advanced example of the pgmassign opcode.

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

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

	massign 1, 1	; channels 1 to 4 use instr 1 by default
	massign 2, 1
	massign 3, 1
	massign 4, 1

; pgmassign_advanced.mid can be found in /manual/examples
; pgmassign.mid has 4 notes with these parameters:
;
;	    Start time	Channel	Program
;
; note 1	0.5	   1	  10
; note 2	1.5	   2	  11
; note 3	2.5	   3	  12
; note 4	3.5	   4	  13

	pgmassign 0, 0		; disable program changes
	pgmassign 11, 3		; program 11 uses instr 3
	pgmassign 12, 2		; program 12 uses instr 2

; waveforms for instruments
itmp	ftgen 1, 0, 1024, 10, 1
itmp	ftgen 2, 0, 1024, 10, 1, 0.5, 0.3333, 0.25, 0.2, 0.1667, 0.1429, 0.125
itmp	ftgen 3, 0, 1024, 10, 1, 0, 0.3333, 0, 0.2, 0, 0.1429, 0, 0.10101

	instr 1		/* sine */

kcps	cpsmidib 2	; note frequency
asnd	oscili .6, kcps, 1
	outs asnd, asnd

	endin

	instr 2		/* band-limited sawtooth */

kcps	cpsmidib 2	; note frequency
asnd	oscili .6, kcps, 2
	outs asnd, asnd

	endin

	instr 3		/* band-limited square */

kcps	cpsmidib 2	; note frequency
asnd	oscili .6, kcps, 3
	outs asnd, asnd

	endin


</CsInstruments>
<CsScore>

t 0 120
f 0 8.5 2 -2 0
e


</CsScore>
</CsoundSynthesizer>


See Also

midichn and massign

Credits

Author: Istvan Varga
May 2002

New in version 4.20