/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/MidiInstrumentInfo.java
ViewVC logotype

Annotation of /jlscp/trunk/src/org/linuxsampler/lscp/MidiInstrumentInfo.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1421 - (hide annotations) (download)
Sun Oct 14 18:08:45 2007 UTC (16 years, 7 months ago) by iliev
File size: 7315 byte(s)
* Client: renamed editInstrument to editChannelInstrument
* added extended support for escape sequences in LSCP response fields

1 iliev 1140 /*
2     * jlscp - a java LinuxSampler control protocol API
3     *
4     * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5     *
6     * This file is part of jlscp.
7     *
8     * jlscp 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     * jlscp 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 jlscp; 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.linuxsampler.lscp;
24    
25 iliev 1421 import static org.linuxsampler.lscp.Parser.*;
26    
27 iliev 1140 /**
28     * Provides information about a MIDI instrument.
29     * @author Grigor Iliev
30     */
31 iliev 1202 public class MidiInstrumentInfo extends AbstractInstrument implements Parseable {
32 iliev 1140 private int mapId = -1;
33     private MidiInstrumentEntry entry;
34    
35     private String engine;
36     private String instrName = "Untitled";
37     private double volume = 1.0;
38     private LoadMode loadMode = LoadMode.DEFAULT;
39    
40     public static enum LoadMode {
41     /** It will be up to the InstrumentManager to decide which mode to use. */
42     DEFAULT ("Default"),
43    
44     /**
45     * The instrument will be loaded when when demanded by
46     * at least one sampler channel. It will immediately be freed
47     * from memory when not needed by any sampler channel anymore.
48     */
49     ON_DEMAND ("On Demand"),
50    
51     /**
52     * Same as <code>ON_DEMAND</code> with the difference that the instrument
53     * will be kept in memory even when not needed by any sampler channel.
54     */
55     ON_DEMAND_HOLD ("On Demand and Hold"),
56    
57     /**
58     * The instrument will be immediately loaded into memory
59     * and the instrument will be kept all the time.
60     */
61     PERSISTENT ("Persistent");
62    
63     private final String name;
64    
65     LoadMode(String name) { this.name = name; }
66    
67     public String
68     toString() { return name; }
69     }
70    
71    
72     /** Creates a new instance of <code>MidiInstrumentInfo</code> */
73     public MidiInstrumentInfo() {
74    
75     }
76    
77     /**
78     * Creates a new instance of <code>MidiInstrumentInfo</code>.
79     * @param mapId The ID of the map containing this instrument.
80     * @param entry The instrument position in the map.
81     */
82     public MidiInstrumentInfo(int mapId, MidiInstrumentEntry entry) {
83     this.mapId = mapId;
84     this.entry = entry;
85     }
86    
87     /**
88     * Creates a new instance of <code>MidiInstrumentInfo</code> and parses the
89     * provided information about this instrument.
90     * @param mapId The ID of the map containing this instrument.
91     * @param entry Provides the position of the MIDI instrument in the MIDI instrument map.
92     * @param resultSet An array with information categories about a MIDI instrument.
93     * @throws LscpException If the parse fails.
94     */
95     public
96     MidiInstrumentInfo(int mapId, MidiInstrumentEntry entry, String[] resultSet)
97     throws LscpException {
98     this.mapId = mapId;
99     this.entry = entry;
100    
101     for(String s : resultSet)
102     if(!parse(s)) Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s));
103     }
104    
105     /**
106     * Gets the position of the MIDI instrument in a MIDI instrument map.
107     * @return The position of the MIDI instrument in a MIDI instrument map.
108     */
109     public MidiInstrumentEntry
110     getEntry() { return entry; }
111    
112     /**
113     * Gets the ID of the map containing this instrument.
114     * @return The ID of the map containing this instrument.
115     */
116     public int
117     getMapId() { return mapId; }
118    
119     /**
120     * Gets the index of the MIDI bank, containing this instrument.
121     * @return The index of the MIDI bank, containing this instrument.
122     */
123     public int
124     getMidiBank() { return entry.getMidiBank(); }
125    
126     /**
127     * Gets the MIDI program number of this instrument.
128     * @return The MIDI program number of this instrument.
129     */
130     public int
131     getMidiProgram() { return entry.getMidiProgram(); }
132    
133     /**
134     * Gets the name of the sampler engine to be used to load the instrument.
135     * @return The name of the sampler engine to be used to load the instrument.
136     */
137     public String
138     getEngine() { return engine; }
139    
140     /**
141     * Sets the name of the sampler engine to be used to load the instrument.
142     * @param engine The name of the sampler engine to be used to load the instrument.
143     */
144     public void
145     setEngine(String engine) { this.engine = engine; }
146    
147     /**
148     * Gets the name of the loaded instrument as reflected by its file.
149     * @return The name of the loaded instrument as reflected by its file.
150     */
151     public String
152     getInstrumentName() { return instrName; }
153    
154     /**
155     * Sets the name of this instrument as reflected by its file.
156     * @param name The name of the instrument as reflected by its file.
157     *
158     public void
159     setInstrumentName(String name) { this.instrName = name; }*/
160    
161     /**
162     * Returns the volume, specified for this instrument, where a
163     * value < 1.0 means attenuation and a value > 1.0 means amplification.
164     */
165     public double
166     getVolume() { return volume; }
167    
168     /**
169     * Sets the volume level for this instrument, where a
170     * value < 1.0 means attenuation and a value > 1.0 means amplification.
171     */
172     public void
173     setVolume(double volume) { this.volume = volume; }
174    
175     /**
176     * Gets the load mode of this MIDI instrument.
177     * @return The load mode of this MIDI instrument.
178     */
179     public LoadMode
180     getLoadMode() { return loadMode; }
181    
182     /**
183     * Sets the load mode of this MIDI instrument.
184     * @param loadMode Specifies the load mode for this MIDI instrument.
185     */
186     public void
187     setLoadMode(LoadMode loadMode) { this.loadMode = loadMode; }
188    
189     /**
190     * Parses a line of text.
191     * @param s The string to be parsed.
192     * @return <code>true</code> if the line has been processed, <code>false</code> otherwise.
193     * @throws LscpException If some error occurs.
194     */
195     public boolean
196     parse(String s) throws LscpException {
197     if(s.startsWith("NAME: ")) {
198 iliev 1421 setName(toNonEscapedString(s.substring("NAME: ".length())));
199 iliev 1140 } else if(s.startsWith("ENGINE_NAME: ")) {
200     setEngine(s.substring("ENGINE_NAME: ".length()));
201     } else if(s.startsWith("INSTRUMENT_NAME: ")) {
202 iliev 1421 instrName = toNonEscapedString(s.substring("INSTRUMENT_NAME: ".length()));
203 iliev 1140 } else if(s.startsWith("LOAD_MODE: ")) {
204     s = s.substring("LOAD_MODE: ".length());
205     if(s.length() == 0) setLoadMode(LoadMode.DEFAULT);
206     else setLoadMode(LoadMode.valueOf(s));
207     } else if(s.startsWith("VOLUME: ")) {
208     s = s.substring("VOLUME: ".length());
209     setVolume(Parser.parseFloat(s));
210 iliev 1421 } else return super.parse(s);
211 iliev 1140
212     return true;
213     }
214    
215     /**
216     * Determines whether the specified object is of type
217     * <code>MidiInstrumentInfo</code> and has equal map ID, MIDI bank and MIDI program.
218     * @param obj The reference object with which to compare.
219     * @return <code>true</code> if the specified object is of type
220     * <code>MidiInstrumentInfo</code> and has equal map ID, MIDI bank and MIDI program.
221     */
222     public boolean
223     equals(Object obj) {
224     if(obj == null) return false;
225     if(!(obj instanceof MidiInstrumentInfo)) return false;
226     MidiInstrumentInfo i = (MidiInstrumentInfo)obj;
227     if(getMapId() != i.getMapId()) return false;
228     if(getMidiBank() != i.getMidiBank()) return false;
229     if(getMidiProgram() != i.getMidiProgram()) return false;
230    
231     return true;
232     }
233     }

  ViewVC Help
Powered by ViewVC