source: trunk/src/org/apollo/ApolloSystem.java@ 1242

Last change on this file since 1242 was 1242, checked in by bln4, 5 years ago

Support for new regime in the form of new fields and conditional setting of all paths fields.

Settings are now able to generate their own representation. This allows for the user to explicitly inspect the default values.

When profiles are created, an optional parameter may now be provided. If not null, the new map parameter can contain default values for settings to apply to this profile. This allows for the creation of profiles to that have (for example), their username set to an explicit value. Multiuser mode uses this functionality for usernames and key values among other things.

Frames can now be asked were they are located on the file system. Furthermore, frame indirection is now a thing. Rather than containing data to display, an exp file can contain a line in the format of "REDIRECT:<path>" to go looking for that data. Frames are able to return both their logical (their exp file) and real (the file actually containing the data) paths.

Frames can now store data.

Further fixes to how edits from other users are loaded in.

File size: 7.5 KB
Line 
1package org.apollo;
2
3import java.util.Collection;
4import java.util.HashSet;
5import java.util.Set;
6
7import javax.swing.UIManager;
8
9import org.apollo.actions.ApolloActions;
10import org.apollo.agents.MelodySearch;
11import org.apollo.audio.ApolloPlaybackMixer;
12import org.apollo.audio.RecordManager;
13import org.apollo.audio.SampledAudioManager;
14import org.apollo.audio.util.MultiTrackPlaybackController;
15import org.apollo.audio.util.PlaybackClock;
16import org.apollo.audio.util.SoundDesk;
17import org.apollo.gui.FrameLayoutDaemon;
18import org.apollo.gui.FramePlaybackBarRenderer;
19import org.apollo.gui.FrameRenderPasses;
20import org.apollo.io.SampledAudioFileImporter;
21import org.apollo.util.ApolloSystemLog;
22import org.apollo.util.Mutable;
23import org.apollo.widgets.FramePlayer;
24import org.expeditee.actions.Actions;
25import org.expeditee.core.BlockingRunnable;
26import org.expeditee.gio.EcosystemManager;
27import org.expeditee.gio.EcosystemManager.Ecosystem;
28import org.expeditee.gio.GraphicsManager;
29import org.expeditee.gio.InputManager.WindowEventListener;
30import org.expeditee.gio.InputManager.WindowEventType;
31import org.expeditee.gui.Browser;
32import org.expeditee.gui.Frame;
33import org.expeditee.gui.FrameIO;
34import org.expeditee.items.Item;
35import org.expeditee.items.Text;
36import org.expeditee.settings.UserSettings;
37
38/**
39 * Provides initialization and shutdown services for the Apollo system.
40 *
41 * @author Brook Novak
42 *
43 */
44public final class ApolloSystem {
45
46 private static final String APOLLO_ICON = "org/apollo/icons/mainicon.png";
47
48 // TODO: Create actual frames
49 public static final String SYSTEM_FRAMESET_NAME = "apollosystem";
50 public static final String HELP_TOP_FRAMENAME = SYSTEM_FRAMESET_NAME + 2;
51
52 // TODO: How to get good results: collection (moteef) and querry
53 // TODO: How to omit indexing on tracks
54 public static final String HELP_MELODYSEARCH_FRAMENAME = SYSTEM_FRAMESET_NAME + 3;
55
56 public static final String SETTINGS_NAME_TIMELINE_RMARGIN = "timelinerightmargin";
57 public static final String SETTINGS_NAME_TIMELINE_LMARGIN = "timelineleftmargin";
58
59 public static boolean useQualityGraphics = true;
60
61 private static boolean hasInitialized = false;
62
63 private ApolloSystem()
64 {
65 }
66
67 /**
68 * Initializes Apollo mod for expeditee - prepares all subsystems.
69 */
70 public static void initialize()
71 {
72 if (hasInitialized) return;
73
74 ApolloSystemLog.println("Initializing...");
75
76 // Ensure that resources are released before the application is closed.
77 EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener() {
78 @Override
79 public void onWindowEvent(WindowEventType type)
80 {
81 if (type != WindowEventType.WINDOW_CLOSED) return;
82 ApolloSystem.shutdown();
83 }
84 });
85
86 EcosystemManager.getInputManager().registerGestureListener(ApolloGestureActions.getInstance());
87 EcosystemManager.getInputManager().addInputEventToGestureTranslator(new ApolloKBMGestureTranslator());
88
89 // Set title
90 //Browser._theBrowser.setTitle("Apollo");
91
92 loadSettings();
93
94 ApolloSystemLog.println(" Preparing sub-systems...");
95
96 SampledAudioManager.getInstance();
97
98 RecordManager.getInstance();
99
100 ApolloPlaybackMixer.getInstance();
101
102 FrameLayoutDaemon.getInstance();
103
104 FrameRenderPasses.getInstance();
105
106 PlaybackClock.getInstance();
107
108 FramePlaybackBarRenderer.getInstance();
109
110 // Setup for importing audio
111 EcosystemManager.getDragAndDropManager().addCustomFileImporter(new SampledAudioFileImporter());
112
113 ApolloSystemLog.println(" Loading actions and agents...");
114
115 // Add apollo actions
116 Actions.LoadMethods(ApolloActions.class);
117
118 Set<String> agents = new HashSet<String>();
119 agents.add(MelodySearch.class.getName());
120
121 Collection<String> omitted = Actions.addAgents(agents);
122
123 for (String agent : omitted) {
124
125 if (agent == null || agent.length() == 0) continue;
126
127 String name = agent;
128
129 int index = agent.lastIndexOf('.');
130 if (index > 0 && agent.length() > (index - 1)) {
131 name = agent.substring(index);
132 }
133 ApolloSystemLog.println(" WARNING: Failed to add agent \"" + name + "\"");
134
135 }
136
137 ApolloSystemLog.println(" Loading banks...");
138 SoundDesk.getInstance(); // loads upon creation
139
140 ApolloSystemLog.println("Initialized");
141
142 hasInitialized = true;
143 }
144
145 /**
146 * TODO: This is temporary and should be integrated with expeditees settings system.. once it is desinged
147 * to support plugins...
148 *
149 * When invoked, the apollo setting frame is loaded and parsed... setting apollo-specific settings.
150 */
151 public static void loadSettings()
152 {
153 // Load apollo settings frame from the default profile
154 Frame profile = FrameIO.LoadProfile(UserSettings.DEFAULT_PROFILE_NAME);
155 if (profile == null) {
156 try {
157 profile = FrameIO.CreateNewProfile(UserSettings.DEFAULT_PROFILE_NAME, null);
158 } catch (Exception e) {
159 e.printStackTrace();
160 return;
161 }
162 }
163 assert(profile != null);
164
165 for (Item i : profile.getItems()) {
166 if (i instanceof Text) {
167 Text textItem = (Text)i;
168
169 if (textItem.getText().toLowerCase().trim().startsWith(SETTINGS_NAME_TIMELINE_LMARGIN)) {
170 Mutable.Integer val = stripNameValueStringInteger(textItem.getText());
171 if (val != null) {
172 FrameLayoutDaemon.getInstance().setTimelineMargins(
173 val.value,
174 FrameLayoutDaemon.getInstance().getRightMargin());
175 }
176
177 } else if (textItem.getText().toLowerCase().trim().startsWith(SETTINGS_NAME_TIMELINE_RMARGIN)) {
178 Mutable.Integer val = stripNameValueStringInteger(textItem.getText());
179 if (val != null) {
180 FrameLayoutDaemon.getInstance().setTimelineMargins(
181 FrameLayoutDaemon.getInstance().getLeftMargin(),
182 val.value);
183 }
184 }
185 }
186 }
187
188 }
189
190 private static Mutable.Integer stripNameValueStringInteger(String namevalue)
191 {
192 assert (namevalue != null);
193 int valueIndex = namevalue.indexOf(':') + 1;
194 if (valueIndex == 0 || valueIndex >= (namevalue.length() - 1)) return null;
195
196 try {
197 int value = Integer.parseInt(namevalue.substring(valueIndex));
198 return Mutable.createMutableInteger(value);
199 } catch (NumberFormatException e) { /* Consume*/ }
200
201 return null;
202 }
203
204
205
206 /**
207 * Releases all resources currently used by the SampledAudioManager.
208 */
209 public static void shutdown()
210 {
211 ApolloSystemLog.println("Saving banks...");
212 SoundDesk.getInstance().saveMasterMix();
213 SoundDesk.getInstance().saveMixes();
214
215 FramePlayer.saveTypedFrames();
216
217 ApolloSystemLog.println("Releasing resources...");
218
219 ApolloPlaybackMixer.getInstance().releaseResources();
220 RecordManager.getInstance().releaseResources(); // blocking
221 MultiTrackPlaybackController.getInstance().releaseResources();
222
223 ApolloSystemLog.println("Subsystems shutdown");
224 }
225
226 /**
227 * @return
228 * True if has initialized.
229 */
230 public static boolean isInitialized()
231 {
232 return hasInitialized;
233 }
234
235
236
237 /**
238 * The apollo main just ensures that apollo is initialized during startup.
239 *
240 * This may eventually become redundant once Expeditee implements a plugin system
241 * that allows a plugin / mod to initialize itself at started...
242 *
243 * @param args
244 */
245 public static void main(String[] args)
246 {
247 if (Browser.ECOSYSTEM_TYPE == Ecosystem.Swing) {
248 try {
249 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
250 } catch (Exception e) {
251 e.printStackTrace();
252 return;
253 }
254 }
255
256 // Window icon must be set before initialisation
257 GraphicsManager.setWindowIcon(APOLLO_ICON);
258
259 // Run expeditee
260 Browser.main(args);
261
262 // Initialize apollo
263 EcosystemManager.getMiscManager().runOnGIOThread(new BlockingRunnable() {
264 public void execute() {
265 ApolloSystem.initialize();
266 }
267 });
268 }
269
270}
Note: See TracBrowser for help on using the repository browser.