KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sound > midi > Patch


1 /*
2  * @(#)Patch.java 1.12 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sound.midi;
9
10
11 /**
12  * A <code>Patch</code> object represents a location, on a MIDI
13  * synthesizer, into which a single instrument is stored (loaded).
14  * Every <code>Instrument</code> object has its own <code>Patch</code>
15  * object that specifies the memory location
16  * into which that instrument should be loaded. The
17  * location is specified abstractly by a bank index and a program number (not by
18  * any scheme that directly refers to a specific address or offset in RAM).
19  * This is a hierarchical indexing scheme: MIDI provides for up to 16384 banks,
20  * each of which contains up to 128 program locations. For example, a
21  * minimal sort of synthesizer might have only one bank of instruments, and
22  * only 32 instruments (programs) in that bank.
23  * <p>
24  * To select what instrument should play the notes on a particular MIDI
25  * channel, two kinds of MIDI message are used that specify a patch location:
26  * a bank-select command, and a program-change channel command. The Java Sound
27  * equivalent is the
28  * {@link MidiChannel#programChange(int, int) programChange(int, int)}
29  * method of <code>MidiChannel</code>.
30  *
31  * @see Instrument
32  * @see Instrument#getPatch()
33  * @see MidiChannel#programChange(int, int)
34  * @see Synthesizer#loadInstruments(Soundbank, Patch[])
35  * @see Soundbank
36  * @see Sequence#getPatchList()
37  *
38  * @author Kara Kytle
39  */

40
41 public class Patch {
42
43
44     /**
45      * Bank index
46      */

47     private final int bank;
48
49
50     /**
51      * Program change number
52      */

53     private final int program;
54
55     
56     /**
57      * Constructs a new patch object from the specified bank and program
58      * numbers.
59      * @param bank the bank index (in the range from 0 to 16383)
60      * @param program the program index (in the range from 0 to 127)
61      */

62     public Patch(int bank, int program) {
63
64     this.bank = bank;
65     this.program = program;
66     }
67
68
69     /**
70      * Returns the number of the bank that contains the instrument
71      * whose location this <code>Patch</code> specifies.
72      * @return the bank number, whose range is from 0 to 16383
73      * @see MidiChannel#programChange(int, int)
74      */

75     public int getBank() {
76
77     return bank;
78     }
79
80
81     /**
82      * Returns the index, within
83      * a bank, of the instrument whose location this <code>Patch</code> specifies.
84      * @return the instrument's program number, whose range is from 0 to 127
85      *
86      * @see MidiChannel#getProgram
87      * @see MidiChannel#programChange(int)
88      * @see MidiChannel#programChange(int, int)
89      */

90     public int getProgram() {
91
92     return program;
93     }
94 }
95
96
Popular Tags