/[svn]/jsampler/trunk/src/org/jsampler/MidiInstrument.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/MidiInstrument.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1144 - (show annotations) (download)
Mon Apr 2 21:39:15 2007 UTC (17 years ago) by iliev
File size: 4161 byte(s)
- upgrading to version 0.4a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler;
24
25 import java.util.Vector;
26 import javax.swing.SwingUtilities;
27
28 import org.linuxsampler.lscp.MidiInstrumentInfo;
29
30 import org.jsampler.event.MidiInstrumentEvent;
31 import org.jsampler.event.MidiInstrumentListener;
32
33
34 /**
35 * Represents a MIDI instrument.
36 * @author Grigor Iliev
37 */
38 public class MidiInstrument {
39 private MidiInstrumentInfo info;
40 private final Vector<MidiInstrumentListener> listeners =
41 new Vector<MidiInstrumentListener>();
42
43
44 /** Creates a new instance of MidiInstrument */
45 public
46 MidiInstrument() { }
47
48 /**
49 * Creates a new instance of <code>MidiInstrument</code>.
50 * @param info Provides mapping information about this instrument.
51 */
52 public
53 MidiInstrument(MidiInstrumentInfo info) { this.info = info; }
54
55 /**
56 * Registers the specified listener for receiving event messages.
57 * @param l The <code>MidiInstrumentListener</code> to register.
58 */
59 public void
60 addMidiInstrumentListener(MidiInstrumentListener l) {
61 listeners.add(l);
62 }
63
64 /**
65 * Removes the specified listener.
66 * @param l The <code>MidiInstrumentListener</code> to remove.
67 */
68 public void
69 removeMidiInstrumentListener(MidiInstrumentListener l) {
70 listeners.remove(l);
71 }
72
73
74 /**
75 * Gets the name of this MIDI instrument.
76 * @return The name of this MIDI instrument.
77 */
78 public String
79 getName() { return info.getName(); }
80
81 /**
82 * Sets the name of this MIDI instrument.
83 * @param name The new name of this MIDI instrument.
84 */
85 public void
86 setName(String name) {
87 info.setName(name);
88 fireInfoChanged();
89 }
90
91 /**
92 * Gets the information about this instrument.
93 * @return The information about this instrument.
94 */
95 public MidiInstrumentInfo
96 getInfo() { return info; }
97
98 /**
99 * Sets the information about this MIDI instrument.
100 * @param info The new information about this MIDI instrument.
101 */
102 public void
103 setInfo(MidiInstrumentInfo info) {
104 this.info = info;
105 fireInfoChanged();
106 }
107
108 /**
109 * Determines whether the specified object is of type
110 * <code>MidiInstrument</code> and has equal map ID, MIDI bank and MIDI program.
111 * @param obj The reference object with which to compare.
112 * @return <code>true</code> if the specified object is of type
113 * <code>MidiInstrument</code> and has equal map ID, MIDI bank and MIDI program.
114 */
115 public boolean
116 equals(Object obj) {
117 if(obj == null || getInfo() == null) return false;
118 if(!(obj instanceof MidiInstrument)) return false;
119 MidiInstrument i = (MidiInstrument)obj;
120 return getInfo().equals(i.getInfo());
121 }
122
123 /**
124 * Returns the program number and name of this instrument.
125 * @return The program number and name of this instrument.
126 */
127 public String
128 toString() { return String.valueOf(getInfo().getMidiProgram()) + ". " + getName(); }
129
130 /**
131 * Notifies listeners that the the MIDI instrument settings are changed.
132 * Note that this method can be invoked outside the event-dispatching thread.
133 */
134 private void
135 fireInfoChanged() {
136 final MidiInstrumentEvent e = new MidiInstrumentEvent(this);
137
138 SwingUtilities.invokeLater(new Runnable() {
139 public void
140 run() { fireInfoChanged(e); }
141 });
142 }
143
144
145 /** Notifies listeners that the MIDI instrument settings are changed. */
146 private void
147 fireInfoChanged(MidiInstrumentEvent e) {
148 for(MidiInstrumentListener l : listeners) l.instrumentInfoChanged(e);
149 }
150 }

  ViewVC Help
Powered by ViewVC