/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/A4n.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/A4n.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (show annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 4 months ago) by iliev
File size: 8798 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler 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 * JSampler 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 JSampler; 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.jsampler.view.fantasia;
24
25 import java.awt.event.ActionEvent;
26
27 import javax.swing.AbstractAction;
28 import javax.swing.Action;
29
30 import org.jsampler.CC;
31 import org.jsampler.view.JSChannel;
32 import org.jsampler.view.std.JSNewAudioDeviceDlg;
33 import org.jsampler.view.std.JSNewMidiDeviceDlg;
34 import org.jsampler.view.std.StdA4n;
35 import org.jsampler.view.swing.SHF;
36
37 import static org.jsampler.JSPrefs.*;
38 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
39
40 /**
41 *
42 * @author Grigor Iliev
43 */
44 public class A4n extends StdA4n {
45 protected static A4n a4n = new A4n();
46
47 /** Forbids the instantiation of <code>A4n</code> */
48 private A4n() {
49 refresh.putValue(Action.SMALL_ICON, Res.iconReload32);
50 resetSampler.putValue(Action.SMALL_ICON, Res.iconReset32);
51 exportSamplerConfig.putValue(Action.SMALL_ICON, Res.iconSave32);
52 //exportMidiInstrumentMaps.putValue(Action.SMALL_ICON, Res.icon);
53 }
54
55 @Override
56 protected FantasiaPrefs
57 preferences() { return FantasiaPrefs.preferences(); }
58
59 public final Action samplerInfo = new SamplerInfo();
60
61 private static class SamplerInfo extends AbstractAction {
62 SamplerInfo() {
63 super(i18n.getMenuLabel("actions.samplerInfo"));
64
65 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.samplerInfo.tt"));
66 putValue(Action.SMALL_ICON, Res.iconSamplerInfo32);
67 }
68
69 @Override
70 public void
71 actionPerformed(ActionEvent e) {
72 new SamplerInfoDlg(SHF.getMainFrame()).setVisible(true);
73 }
74 }
75
76 public final Action loadScript = new LoadLscpScript();
77
78 private class LoadLscpScript extends AbstractAction {
79 LoadLscpScript() {
80 super(i18n.getMenuLabel("actions.runScript"));
81
82 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.runScript.tt"));
83 putValue(Action.SMALL_ICON, Res.iconOpen32);
84 }
85
86 @Override
87 public void
88 actionPerformed(ActionEvent e) {
89 if(!((MainFrame)SHF.getMainFrame()).runScript()) return;
90
91 if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
92 windowLSConsole.actionPerformed(null);
93 }
94 }
95 }
96
97 public final Action createMidiDevice = new CreateMidiDevice();
98
99 private class CreateMidiDevice extends AbstractAction {
100 CreateMidiDevice() {
101 super(i18n.getMenuLabel("edit.createMidiDevice"));
102
103 String s = i18n.getMenuLabel("edit.createMidiDevice.tt");
104 putValue(SHORT_DESCRIPTION, s);
105 //putValue(Action.SMALL_ICON, Res.iconNew16);
106 }
107
108 @Override
109 public void
110 actionPerformed(ActionEvent e) {
111 if(!CC.verifyConnection()) return;
112 new JSNewMidiDeviceDlg(SHF.getMainFrame()).setVisible(true);
113 }
114 }
115
116 public final Action createAudioDevice = new CreateAudioDevice();
117
118 private class CreateAudioDevice extends AbstractAction {
119 CreateAudioDevice() {
120 super(i18n.getMenuLabel("edit.createAudioDevice"));
121
122 String s = i18n.getMenuLabel("edit.createAudioDevice.tt");
123 putValue(SHORT_DESCRIPTION, s);
124 //putValue(Action.SMALL_ICON, Res.iconNew16);
125 }
126
127 @Override
128 public void
129 actionPerformed(ActionEvent e) {
130 if(!CC.verifyConnection()) return;
131 new JSNewAudioDeviceDlg(SHF.getMainFrame()).setVisible(true);
132 }
133 }
134
135 // EDIT
136
137 public final Action editPreferences = new EditPreferences();
138
139 private class EditPreferences extends AbstractAction {
140 EditPreferences() {
141 super(i18n.getMenuLabel("edit.preferences"));
142
143 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("edit.preferences.tt"));
144 putValue(Action.SMALL_ICON, Res.iconPreferences32);
145 }
146
147 @Override
148 public void
149 actionPerformed(ActionEvent e) { new PrefsDlg(SHF.getMainFrame()).setVisible(true); }
150 }
151
152
153 // CHANNELS
154
155 public final Action setSmallView = new SetView(ChannelView.Type.SMALL);
156 public final Action setNormalView = new SetView(ChannelView.Type.NORMAL);
157
158 public static class SetView extends AbstractAction {
159 private ChannelView.Type type;
160
161 SetView(ChannelView.Type type) {
162 this.type = type;
163
164 switch(type) {
165 case SMALL:
166 putValue(Action.NAME, i18n.getMenuLabel("channels.smallView"));
167 break;
168 case NORMAL:
169 putValue(Action.NAME, i18n.getMenuLabel("channels.normalView"));
170 break;
171 }
172 }
173
174 @Override
175 public void
176 actionPerformed(ActionEvent e) {
177 JSChannel[] channels =
178 CC.getMainFrame().getSelectedChannelsPane().getSelectedChannels();
179
180 for(JSChannel c : channels) {
181 Channel c2 = (Channel)c;
182 if(c2.getViewTracker().getOriginalView().getType() == type) {
183 continue;
184 }
185
186 c2.getViewTracker().setView(createView(type, c2));
187 }
188
189 MenuManager.getMenuManager().updateChannelViewGroups();
190 }
191
192 public static int
193 getViewCount(ChannelView.Type type) {
194 int count = 0;
195
196 JSChannel[] channels =
197 CC.getMainFrame().getSelectedChannelsPane().getSelectedChannels();
198
199 for(JSChannel c : channels) {
200 Channel c2 = (Channel)c;
201 if(c2.getViewTracker().getOriginalView().getType() == type) {
202 count++;
203 }
204 }
205
206 return count;
207 }
208
209 public ChannelView
210 createView(ChannelView.Type type, Channel channel) {
211 switch(type) {
212 case SMALL: return new SmallChannelView(channel);
213 case NORMAL: return new NormalChannelView(channel);
214 }
215
216 throw new IllegalArgumentException("Unknown channel type");
217 }
218 }
219
220 // WINDOW
221 public final Action windowLSConsole = new WindowLSConsole();
222
223 private class WindowLSConsole extends AbstractAction {
224 WindowLSConsole() {
225 super(i18n.getMenuLabel("window.lsConsole"));
226 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("window.lsConsole.tt"));
227 putValue(Action.SMALL_ICON, Res.iconLSConsole32);
228 }
229
230 @Override
231 public void
232 actionPerformed(ActionEvent e) {
233 LSConsoleFrame console = ((MainFrame)SHF.getMainFrame()).getLSConsoleFrame();
234
235 if(console.isVisible()) console.setVisible(false);
236
237 console.setVisible(true);
238 }
239 }
240
241 public final Action windowInstrumentsDb = new WindowInstrumentsDb();
242
243 private class WindowInstrumentsDb extends AbstractAction {
244 InstrumentsDbFrame instrumentsDbFrame = null;
245
246 WindowInstrumentsDb() {
247 super(i18n.getMenuLabel("window.instrumentsDb"));
248 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("window.instrumentsDb.tt"));
249 putValue(Action.SMALL_ICON, Res.iconDb32);
250 }
251
252 @Override
253 public void
254 actionPerformed(ActionEvent e) {
255 if(!CC.verifyConnection()) return;
256
257 if(SHF.getInstrumentsDbTreeModel() == null) {
258 String s = i18n.getMessage("A4n.noInstrumentsDbSupport!");
259 SHF.showErrorMessage(s, SHF.getMainFrame());
260 return;
261 }
262
263 if(instrumentsDbFrame != null) {
264 instrumentsDbFrame.setVisible(false);
265 instrumentsDbFrame.setVisible(true);
266 return;
267 }
268
269 if(CC.getViewConfig().isUsingScreenMenuBar()) {
270 // fix for moving the menu bar on top of the screen
271 // when running on Mac OS and third party plugin is used
272 ((ViewConfig)CC.getViewConfig()).setNativeMenuProperties();
273 instrumentsDbFrame = new InstrumentsDbFrame();
274 ((ViewConfig)CC.getViewConfig()).restoreMenuProperties();
275
276 } else {
277 instrumentsDbFrame = new InstrumentsDbFrame();
278 }
279
280 instrumentsDbFrame.setVisible(true);
281 }
282 }
283
284 public final Action windowSamplerBrowser = new WindowSamplerBrowser();
285
286 private class WindowSamplerBrowser extends AbstractAction {
287 WindowSamplerBrowser() {
288 super(i18n.getMenuLabel("window.SamplerBrowser"));
289 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("window.SamplerBrowser.tt"));
290 //putValue(Action.SMALL_ICON, Res.iconLSConsole32);
291 }
292
293 @Override
294 public void
295 actionPerformed(ActionEvent e) {
296 SamplerBrowserFrame browser =
297 ((MainFrame)SHF.getMainFrame()).getSamplerBrowserFrame();
298
299 if(browser.isVisible()) browser.setVisible(false);
300
301 browser.setVisible(true);
302 }
303 }
304
305 // HELP
306 public final Action helpAbout = new HelpAbout();
307
308 private class HelpAbout extends AbstractAction {
309 HelpAbout() {
310 super(i18n.getMenuLabel("help.about", "Fantasia"));
311 }
312
313 @Override
314 public void
315 actionPerformed(ActionEvent e) {
316 new HelpAboutDlg(SHF.getMainFrame()).setVisible(true);
317 }
318 }
319 }

  ViewVC Help
Powered by ViewVC