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

Last change on this file since 1473 was 1473, checked in by bnemhaus, 4 years ago

We cannot see a reason why we shouldn't include Apollo functionality in multi user mode.

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