pgmassign

Name

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
pgmassign ipgm, "insname"

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.

Examples

Here is an example of the pgmassign opcode. It uses the files pgmassign.orc and pgmassign.sco.

Example 15-1. Example of the pgmassign opcode.

/* pgmassign.orc */
; 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
/* pgmassign.orc */
        
/* pgmassign.sco */
; Play Instrument #10 for one second.
i 10 0 1
e
/* pgmassign.sco */
        

Here is an example of the pgmassign opcode that will ignore program change events. It uses the files pgmassign_ignore.orc and pgmassign_ignore.sco.

Example 15-2. Example of the pgmassign opcode that will ignore program change events.

/* pgmassign_ignore.orc */
; 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
/* pgmassign_ignore.orc */
        
/* pgmassign_ignore.sco */
; Play Instrument #1 for one second.
i 1 0 1
e
/* pgmassign_ignore.sco */
        

Here is an advanced example of the pgmassign opcode. It uses the files pgmassign_advanced.mid, pgmassign_advanced.orc, and pgmassign_advanced.sco.

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

Example 15-3. An advanced example of the pgmassign opcode.

/* pgmassign_advanced.orc - written by Istvan Varga */
sr	=  44100
ksmps	=  10
nchnls	=  1

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

; 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 30000, kcps, 1
	out asnd

	endin

	instr 2		/* band-limited sawtooth */

kcps	cpsmidib 2	; note frequency
asnd	oscili 30000, kcps, 2
	out asnd

	endin

	instr 3		/* band-limited square */

kcps	cpsmidib 2	; note frequency
asnd	oscili 30000, kcps, 3
	out asnd

	endin
/* pgmassign_advanced.orc - written by Istvan Varga */
        
/* pgmassign_advanced.sco - written by Istvan Varga */
t 0 120
f 0 8.5 2 -2 0
e
/* pgmassign_advanced.sco - written by Istvan Varga */
        

See Also

midichn

Credits

Author: Istvan Varga
May 2002

New in version 4.20