1 | package org.apollo;
|
---|
2 |
|
---|
3 | import java.awt.Image;
|
---|
4 | import java.awt.Toolkit;
|
---|
5 | import java.awt.event.WindowEvent;
|
---|
6 | import java.awt.event.WindowListener;
|
---|
7 | import java.net.URL;
|
---|
8 | import java.util.Collection;
|
---|
9 | import java.util.HashSet;
|
---|
10 | import java.util.Set;
|
---|
11 |
|
---|
12 | import javax.swing.SwingUtilities;
|
---|
13 |
|
---|
14 | import org.apollo.actions.ApolloActions;
|
---|
15 | import org.apollo.agents.MelodySearch;
|
---|
16 | import org.apollo.audio.ApolloPlaybackMixer;
|
---|
17 | import org.apollo.audio.RecordManager;
|
---|
18 | import org.apollo.audio.SampledAudioManager;
|
---|
19 | import org.apollo.audio.util.FrameLayoutDaemon;
|
---|
20 | import org.apollo.audio.util.MultiTrackPlaybackController;
|
---|
21 | import org.apollo.audio.util.PlaybackClock;
|
---|
22 | import org.apollo.audio.util.SoundDesk;
|
---|
23 | import org.apollo.gui.FramePlaybackBarRenderer;
|
---|
24 | import org.apollo.gui.FrameRenderPasses;
|
---|
25 | import org.apollo.io.SampledAudioFileImporter;
|
---|
26 | import org.apollo.util.AudioSystemLog;
|
---|
27 | import org.expeditee.actions.Actions;
|
---|
28 | import org.expeditee.gui.Browser;
|
---|
29 | import org.expeditee.gui.FrameMouseActions;
|
---|
30 | import org.expeditee.importer.FrameDNDTransferHandler;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Provides initialization and shutdown services for the Apollo system.
|
---|
34 | *
|
---|
35 | * @author Brook Novak
|
---|
36 | *
|
---|
37 | */
|
---|
38 | public final class ApolloSystem {
|
---|
39 |
|
---|
40 | // TODO: Create actual frames
|
---|
41 | public static final String SYSTEM_FRAMESET_NAME = "apollosystem";
|
---|
42 | public static final String HELP_TOP_FRAMENAME = SYSTEM_FRAMESET_NAME + 2;
|
---|
43 |
|
---|
44 | // TODO: How to get good results: collection (moteef) and querry
|
---|
45 | // TODO: How to omit indexing on tracks
|
---|
46 | public static final String HELP_MELODYSEARCH_FRAMENAME = SYSTEM_FRAMESET_NAME + 3;
|
---|
47 |
|
---|
48 |
|
---|
49 | public static boolean useQualityGraphics = true;
|
---|
50 |
|
---|
51 | private ApolloSystem() {
|
---|
52 | }
|
---|
53 |
|
---|
54 | private static boolean hasInitialized = false;
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Initializes Apollo mod for expeditee - prepares all subsystems.
|
---|
58 | */
|
---|
59 | public static void initialize() {
|
---|
60 |
|
---|
61 | if (hasInitialized) return;
|
---|
62 |
|
---|
63 | AudioSystemLog.println("Initializing...");
|
---|
64 |
|
---|
65 | SwingUtilities.invokeLater(new Runnable() {
|
---|
66 | public void run() {
|
---|
67 |
|
---|
68 | try {
|
---|
69 |
|
---|
70 | URL url = ClassLoader.getSystemResource("org/apollo/icons/mainicon.png");
|
---|
71 |
|
---|
72 | if (url != null) {
|
---|
73 | Image img = Toolkit.getDefaultToolkit().getImage(url);
|
---|
74 | Browser._theBrowser.setIconImage(img);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | } catch (Exception e) {
|
---|
80 | e.printStackTrace();
|
---|
81 | }
|
---|
82 |
|
---|
83 | // Ensure that resources are released before the application is closed.
|
---|
84 | Browser._theBrowser.addWindowListener(new WindowListener() {
|
---|
85 |
|
---|
86 | public void windowActivated(WindowEvent e) {
|
---|
87 | }
|
---|
88 |
|
---|
89 | public void windowClosed(WindowEvent e) {
|
---|
90 | }
|
---|
91 |
|
---|
92 | public void windowClosing(WindowEvent e) {
|
---|
93 | ApolloSystem.shutdown();
|
---|
94 | }
|
---|
95 |
|
---|
96 | public void windowDeactivated(WindowEvent e) {
|
---|
97 | }
|
---|
98 |
|
---|
99 | public void windowDeiconified(WindowEvent e) {
|
---|
100 | }
|
---|
101 |
|
---|
102 | public void windowIconified(WindowEvent e) {
|
---|
103 | }
|
---|
104 |
|
---|
105 | public void windowOpened(WindowEvent e) {
|
---|
106 | }
|
---|
107 |
|
---|
108 | });
|
---|
109 |
|
---|
110 | Browser._theBrowser.getContentPane().addKeyListener(new AudioFrameKeyboardActions());
|
---|
111 |
|
---|
112 | // Filter out some special mouse move cases
|
---|
113 | Browser._theBrowser.getMouseEventRouter().removeExpediteeMouseMotionListener(
|
---|
114 | FrameMouseActions.getInstance());
|
---|
115 |
|
---|
116 | Browser._theBrowser.getMouseEventRouter().addExpediteeMouseMotionListener(new AudioFrameMouseActions());
|
---|
117 | }
|
---|
118 | });
|
---|
119 |
|
---|
120 | // Set title and icon
|
---|
121 | //Browser._theBrowser.etTitle("Apollo");
|
---|
122 |
|
---|
123 | AudioSystemLog.println(" Preparing sub-systems...");
|
---|
124 |
|
---|
125 | SampledAudioManager.getInstance();
|
---|
126 |
|
---|
127 | RecordManager.getInstance();
|
---|
128 |
|
---|
129 | ApolloPlaybackMixer.getInstance();
|
---|
130 |
|
---|
131 | FrameLayoutDaemon.getInstance();
|
---|
132 |
|
---|
133 | FrameRenderPasses.getInstance();
|
---|
134 |
|
---|
135 | PlaybackClock.getInstance();
|
---|
136 |
|
---|
137 | FramePlaybackBarRenderer.getInstance();
|
---|
138 |
|
---|
139 | // Setup for importing audio
|
---|
140 | FrameDNDTransferHandler.getInstance().addCustomFileImporter(
|
---|
141 | new SampledAudioFileImporter());
|
---|
142 |
|
---|
143 | AudioSystemLog.println(" Loading actions and agents...");
|
---|
144 |
|
---|
145 | // Add apollo actions
|
---|
146 | Actions.LoadMethods(ApolloActions.class);
|
---|
147 |
|
---|
148 | Set<String> agents = new HashSet<String>();
|
---|
149 | agents.add(MelodySearch.class.getName());
|
---|
150 |
|
---|
151 | Collection<String> omitted = Actions.addAgents(agents);
|
---|
152 |
|
---|
153 | for (String agent : omitted) {
|
---|
154 |
|
---|
155 | if (agent == null || agent.length() == 0) continue;
|
---|
156 |
|
---|
157 | String name = agent;
|
---|
158 |
|
---|
159 | int index = agent.lastIndexOf('.');
|
---|
160 | if (index > 0 && agent.length() > (index - 1)) {
|
---|
161 | name = agent.substring(index);
|
---|
162 | }
|
---|
163 | AudioSystemLog.println(" WARNING: Failed to add agent \"" + name + "\"");
|
---|
164 |
|
---|
165 | }
|
---|
166 |
|
---|
167 | AudioSystemLog.println(" Loading banks...");
|
---|
168 | SoundDesk.getInstance(); // loads upon creation
|
---|
169 |
|
---|
170 | AudioSystemLog.println("Initialized");
|
---|
171 |
|
---|
172 | hasInitialized = true;
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 |
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * Releases all resources currently used by the SampledAudioManager.
|
---|
180 | */
|
---|
181 | private static void shutdown() {
|
---|
182 |
|
---|
183 | AudioSystemLog.println("Saving banks...");
|
---|
184 | SoundDesk.getInstance().saveMasterMix();
|
---|
185 | SoundDesk.getInstance().saveMixes();
|
---|
186 |
|
---|
187 | AudioSystemLog.println("Releasing resources...");
|
---|
188 |
|
---|
189 | ApolloPlaybackMixer.getInstance().releaseResources();
|
---|
190 | RecordManager.getInstance().releaseResources(); // blocking
|
---|
191 | MultiTrackPlaybackController.getInstance().releaseResources();
|
---|
192 |
|
---|
193 | AudioSystemLog.println("Audio subsystems shutdown");
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * @return
|
---|
198 | * True if has initialized.
|
---|
199 | */
|
---|
200 | public static boolean isInitialized() {
|
---|
201 | return hasInitialized;
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * The apollo main just ensures that apollo is initialized during startup.
|
---|
208 | *
|
---|
209 | * This may eventually become redundant once Expeditee implements a plugin system
|
---|
210 | * that allows a plugin / mod to initialize itself at started...
|
---|
211 | *
|
---|
212 | * @param args
|
---|
213 | */
|
---|
214 | public static void main(String[] args) {
|
---|
215 |
|
---|
216 | // Run expeditee
|
---|
217 | Browser.main(args);
|
---|
218 |
|
---|
219 | // Initialize apollo
|
---|
220 | SwingUtilities.invokeLater(new Runnable() {
|
---|
221 | public void run() {
|
---|
222 | ApolloSystem.initialize();
|
---|
223 | }
|
---|
224 | });
|
---|
225 | }
|
---|
226 |
|
---|
227 | }
|
---|