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. package javax.sound.midi;
  8. /**
  9. * A <code>Patch</code> object represents a location, on a MIDI
  10. * synthesizer, into which a single instrument is stored (loaded).
  11. * Every <code>Instrument</code> object has its own <code>Patch</code>
  12. * object that specifies the memory location
  13. * into which that instrument should be loaded. The
  14. * location is specified abstractly by a bank index and a program number (not by
  15. * any scheme that directly refers to a specific address or offset in RAM).
  16. * This is a hierarchical indexing scheme: MIDI provides for up to 16384 banks,
  17. * each of which contains up to 128 program locations. For example, a
  18. * minimal sort of synthesizer might have only one bank of instruments, and
  19. * only 32 instruments (programs) in that bank.
  20. * <p>
  21. * To select what instrument should play the notes on a particular MIDI
  22. * channel, two kinds of MIDI message are used that specify a patch location:
  23. * a bank-select command, and a program-change channel command. The Java Sound
  24. * equivalent is the
  25. * {@link MidiChannel#programChange(int, int) programChange(int, int)}
  26. * method of <code>MidiChannel</code>.
  27. *
  28. * @see Instrument
  29. * @see Instrument#getPatch()
  30. * @see MidiChannel#programChange(int, int)
  31. * @see Synthesizer#loadInstruments(Soundbank, Patch[])
  32. * @see Soundbank
  33. * @see Sequence#getPatchList()
  34. *
  35. * @author Kara Kytle
  36. */
  37. public class Patch {
  38. /**
  39. * Bank index
  40. */
  41. private final int bank;
  42. /**
  43. * Program change number
  44. */
  45. private final int program;
  46. /**
  47. * Constructs a new patch object from the specified bank and program
  48. * numbers.
  49. * @param bank the bank index (in the range from 0 to 16383)
  50. * @param program the program index (in the range from 0 to 127)
  51. */
  52. public Patch(int bank, int program) {
  53. this.bank = bank;
  54. this.program = program;
  55. }
  56. /**
  57. * Returns the number of the bank that contains the instrument
  58. * whose location this <code>Patch</code> specifies.
  59. * @return the bank number, whose range is from 0 to 16383
  60. * @see MidiChannel#programChange(int, int)
  61. */
  62. public int getBank() {
  63. return bank;
  64. }
  65. /**
  66. * Returns the index, within
  67. * a bank, of the instrument whose location this <code>Patch</code> specifies.
  68. * @return the instrument's program number, whose range is from 0 to 127
  69. *
  70. * @see MidiChannel#getProgram
  71. * @see MidiChannel#programChange(int)
  72. * @see MidiChannel#programChange(int, int)
  73. */
  74. public int getProgram() {
  75. return program;
  76. }
  77. }