Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/fluidsynth/api/Configuration.java


1   /*
2    * Copyright (C) 2003 Ken Ellinwood.
3    * 
4    * This file is part of FluidGUI.
5    * 
6    * FluidGUI is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  
21  package org.fluidsynth.api;
22  
23  import org.fluidsynth.api.settings.*;
24  import org.fluidsynth.api.sf2.*;
25  
26  import java.io.File;
27  import java.util.*;
28  
29  /** An object representing a user configuration of the synth. */
30  public class Configuration
31  {
32  
33      private Settings settings;
34      private boolean dirty = false;
35      private File file;
36  
37      private boolean settingsMerged = false;
38  
39      /** No-arg constructor is required in order to be persisted to XML via Castor. */
40      public Configuration()
41      {
42      }
43  
44      /** Construct a Configuration with the given settings. */
45      public Configuration( Settings settings)
46      {
47          setSettings( settings);
48      }
49      
50  
51      /** Set the file that this Configuration object is persisted in. */
52      public void setFile( File f)
53      {
54          file = f;
55      }
56  
57      /** Get the file that this Configuration object is persisted in. */
58      public File getFile()
59      {
60          return file;
61      }
62  
63  
64      /** Get the display name of this configuration. */
65      public String getName()
66      {
67          if (file == null) return "none";
68  
69          String name = file.getName();
70  
71          // Strip file extension
72          int dot = name.lastIndexOf('.');
73          if (dot != -1) name = name.substring( 0, dot);
74          return name;
75      }
76      
77      /** Get the settings associated with this configuration. */
78      public Settings getSettings()
79      {
80          return settings;
81      }
82  
83      /** Set the settings associated with this configuration. */
84      public void setSettings( Settings settings)
85      {
86          this.settings = settings;
87          settings.setConfiguration( this);
88      }
89  
90      /** Get a version of this configuration suitable for persistence to disk. */
91      public Configuration getModifiedConfiguration()
92      {
93          Configuration result = new Configuration( settings.getModifiedSettings());
94          result.soundFonts = this.soundFonts;
95          result.channels = this.channels;
96          return result;
97      }
98  
99      /** Sets the dirty flag. Dirty configuration are in need of being saved to disk. */
100     public void dirty()
101     {
102         dirty = true;
103     }
104 
105     /** Clear the dirty flag. */
106     public void clearDirty()
107     {
108         dirty = false;
109     }
110     
111     /** Gets the dirty flag. Dirty configuration are in need of being saved to disk. */
112     public boolean isDirty()
113     {
114         return dirty;
115     }
116 
117     public boolean getSettingsMerged()
118     {
119         return settingsMerged;
120     }
121 
122     void setSettingsMerged( boolean merged)
123     {
124         this.settingsMerged = merged;
125     }
126 
127     Map soundFonts = new LinkedHashMap();
128     
129     public void insertSoundFont( SoundFont soundFont)
130     {
131         soundFonts.put( soundFont.getPath(), soundFont);
132     }
133 
134     public void unloadSoundFont( SoundFont soundFont)
135     {
136         soundFonts.remove( soundFont.getPath());
137     }
138     
139     public SoundFont lookupSoundFont( String path)
140     {
141         return (SoundFont)soundFonts.get( path);
142     }
143 
144     public SoundFont lookupSoundFont( int id)
145     {
146         for (Iterator i = soundFonts.values().iterator(); i.hasNext(); )
147         {
148             SoundFont sf = (SoundFont)i.next();
149             if (sf.getId() == id) return sf;
150         }
151         return null;
152     }
153 
154     public void setSoundFont( SoundFont[] sf2s)
155     {
156         for (int i = 0; i < sf2s.length; i++) insertSoundFont( sf2s[i]);
157     }
158 
159     public SoundFont[] getSoundFont()
160     {
161         return (SoundFont[])soundFonts.values().toArray( new SoundFont[ soundFonts.values().size()]);
162     }
163 
164     Map channels = new TreeMap();
165     
166     public void insertChannel( Channel channel)
167     {
168         channels.put( new Integer( channel.getNumber()), channel);
169     }
170 
171     public Channel lookupChannel( int channel)
172     {
173         return (Channel)channels.get( new Integer( channel));
174     }
175 
176     public void setChannel( Channel[] channels)
177     {
178         for (int i = 0; i < channels.length; i++) insertChannel( channels[i]);
179     }
180 
181     public Channel[] getChannel()
182     {
183         return (Channel[])channels.values().toArray( new Channel[ channels.values().size()]);
184     }
185     
186 }