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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1767 - (hide annotations) (download)
Mon Sep 8 00:19:27 2008 UTC (15 years, 8 months ago) by iliev
File size: 4622 byte(s)
* Added `Copy To' and `Move To' commands to the MIDI bank context menu
  and to the MIDI instrument context menu
* Added commands to the MIDI instrument context menu for moving
  a MIDI instrument to another program
  (right-click on a MIDI instrument and choose `Change Program')
* Added option to choose between zero-based and one-based
  MIDI bank/program numbering
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to choose whether to include MIDI instrument
  mappings when exporting a sampler configuration to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to set the MIDI instrument loading in background
  when exporting MIDI instrument mappings to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Implemented an option to change the socket read timeout
  (choose Edit/Preferences, then click the `Backend' tab)
* Updated LscpTree
* Fantasia: Added option to hide the active stream/voice count statistic
  in the sampler channel's small view
  (choose Edit/Preferences, then click the `Channels' tab)
* Fantasia: `Turn off animation effects' checkbox moved to the `View' tab

1 iliev 1144 /*
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 iliev 1767 private static int firstProgramNumber = 0;
44 iliev 1144
45 iliev 1767
46 iliev 1144 /** Creates a new instance of MidiInstrument */
47     public
48     MidiInstrument() { }
49    
50     /**
51     * Creates a new instance of <code>MidiInstrument</code>.
52     * @param info Provides mapping information about this instrument.
53     */
54     public
55     MidiInstrument(MidiInstrumentInfo info) { this.info = info; }
56    
57     /**
58     * Registers the specified listener for receiving event messages.
59     * @param l The <code>MidiInstrumentListener</code> to register.
60     */
61     public void
62     addMidiInstrumentListener(MidiInstrumentListener l) {
63     listeners.add(l);
64     }
65    
66     /**
67     * Removes the specified listener.
68     * @param l The <code>MidiInstrumentListener</code> to remove.
69     */
70     public void
71     removeMidiInstrumentListener(MidiInstrumentListener l) {
72     listeners.remove(l);
73     }
74    
75    
76     /**
77     * Gets the name of this MIDI instrument.
78     * @return The name of this MIDI instrument.
79     */
80     public String
81     getName() { return info.getName(); }
82    
83     /**
84     * Sets the name of this MIDI instrument.
85     * @param name The new name of this MIDI instrument.
86     */
87     public void
88     setName(String name) {
89     info.setName(name);
90     fireInfoChanged();
91     }
92    
93     /**
94     * Gets the information about this instrument.
95     * @return The information about this instrument.
96     */
97     public MidiInstrumentInfo
98     getInfo() { return info; }
99    
100     /**
101     * Sets the information about this MIDI instrument.
102     * @param info The new information about this MIDI instrument.
103     */
104     public void
105     setInfo(MidiInstrumentInfo info) {
106     this.info = info;
107     fireInfoChanged();
108     }
109    
110     /**
111 iliev 1767 * Gets the MIDI program numbering, whether
112     * the index of the first MIDI program is 0 or 1.
113     */
114     public static int
115     getFirstProgramNumber() { return firstProgramNumber; }
116    
117     /**
118     * Sets the MIDI program numbering, whether
119     * the index of the first MIDI program is 0 or 1.
120     */
121     public static void
122     setFirstProgramNumber(int idx) { firstProgramNumber = idx; }
123    
124     /**
125 iliev 1144 * Determines whether the specified object is of type
126     * <code>MidiInstrument</code> and has equal map ID, MIDI bank and MIDI program.
127     * @param obj The reference object with which to compare.
128     * @return <code>true</code> if the specified object is of type
129     * <code>MidiInstrument</code> and has equal map ID, MIDI bank and MIDI program.
130     */
131     public boolean
132     equals(Object obj) {
133     if(obj == null || getInfo() == null) return false;
134     if(!(obj instanceof MidiInstrument)) return false;
135     MidiInstrument i = (MidiInstrument)obj;
136     return getInfo().equals(i.getInfo());
137     }
138    
139     /**
140     * Returns the program number and name of this instrument.
141     * @return The program number and name of this instrument.
142     */
143     public String
144 iliev 1767 toString() {
145     int i = getFirstProgramNumber() + getInfo().getMidiProgram();
146     return String.valueOf(i) + ". " + getName();
147     }
148 iliev 1144
149     /**
150     * Notifies listeners that the the MIDI instrument settings are changed.
151     * Note that this method can be invoked outside the event-dispatching thread.
152     */
153     private void
154     fireInfoChanged() {
155     final MidiInstrumentEvent e = new MidiInstrumentEvent(this);
156    
157     SwingUtilities.invokeLater(new Runnable() {
158     public void
159     run() { fireInfoChanged(e); }
160     });
161     }
162    
163    
164     /** Notifies listeners that the MIDI instrument settings are changed. */
165     private void
166     fireInfoChanged(MidiInstrumentEvent e) {
167     for(MidiInstrumentListener l : listeners) l.instrumentInfoChanged(e);
168     }
169     }

  ViewVC Help
Powered by ViewVC