1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
53 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
54 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
55 |
import javax.swing.JCheckBoxMenuItem; |
import javax.swing.JCheckBoxMenuItem; |
|
import javax.swing.JFileChooser; |
|
56 |
import javax.swing.JMenu; |
import javax.swing.JMenu; |
57 |
import javax.swing.JMenuBar; |
import javax.swing.JMenuBar; |
58 |
import javax.swing.JMenuItem; |
import javax.swing.JMenuItem; |
71 |
import org.jsampler.Server; |
import org.jsampler.Server; |
72 |
|
|
73 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
|
import org.jsampler.view.LscpFileFilter; |
|
74 |
import org.jsampler.view.SessionViewConfig; |
import org.jsampler.view.SessionViewConfig; |
75 |
|
|
76 |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
96 |
* @author Grigor Iliev |
* @author Grigor Iliev |
97 |
*/ |
*/ |
98 |
public class MainFrame extends StdMainFrame { |
public class MainFrame extends StdMainFrame { |
99 |
|
public final static int MAX_CHANNEL_LANE_NUMBER = 8; |
100 |
|
|
101 |
private final StandardBar standardBar = new StandardBar(); |
private final StandardBar standardBar = new StandardBar(); |
102 |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
103 |
private final JPanel rootPane = new RootPane(); |
private final JPanel rootPane = new RootPane(); |
167 |
addChannelsPane(mainPane.getChannelsPane(i)); |
addChannelsPane(mainPane.getChannelsPane(i)); |
168 |
getChannelsPane(i).addListSelectionListener(pianoKeyboardPane); |
getChannelsPane(i).addListSelectionListener(pianoKeyboardPane); |
169 |
} |
} |
170 |
|
|
171 |
|
PropertyChangeListener l = new PropertyChangeListener() { |
172 |
|
public void |
173 |
|
propertyChange(PropertyChangeEvent e) { |
174 |
|
onChangeChannelLaneCount(); |
175 |
|
} |
176 |
|
}; |
177 |
|
|
178 |
|
preferences().addPropertyChangeListener("channelLanes.count", l); |
179 |
|
|
180 |
int h = preferences().getIntProperty("midiKeyboard.height"); |
int h = preferences().getIntProperty("midiKeyboard.height"); |
181 |
setMidiKeyboardHeight(h); |
setMidiKeyboardHeight(h); |
182 |
|
|
183 |
PropertyChangeListener l = new PropertyChangeListener() { |
l = new PropertyChangeListener() { |
184 |
public void |
public void |
185 |
propertyChange(PropertyChangeEvent e) { |
propertyChange(PropertyChangeEvent e) { |
186 |
int h = preferences().getIntProperty("midiKeyboard.height"); |
int h = preferences().getIntProperty("midiKeyboard.height"); |
196 |
rootPane.add(hSplitPane); |
rootPane.add(hSplitPane); |
197 |
rootPane.add(bottomPane, BorderLayout.SOUTH); |
rootPane.add(bottomPane, BorderLayout.SOUTH); |
198 |
add(rootPane); |
add(rootPane); |
199 |
|
|
200 |
|
if(CC.isMacOS()) { |
201 |
|
try { |
202 |
|
String s = "org.jsampler.view.fantasia.MacOSApplicationHandler"; |
203 |
|
Class.forName(s).newInstance(); } |
204 |
|
catch(Throwable e) { } |
205 |
|
} |
206 |
|
|
207 |
addMenu(); |
addMenu(); |
208 |
|
|
209 |
|
if(CC.getViewConfig().isUsingScreenMenuBar()) { |
210 |
|
// fix for moving the menu bar on top of the screen |
211 |
|
// when running on Mac OS and third party plugin is used |
212 |
|
((ViewConfig)CC.getViewConfig()).restoreMenuProperties(); |
213 |
|
} |
214 |
|
|
215 |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
216 |
hSplitPane.setDividerLocation(i); |
hSplitPane.setDividerLocation(i); |
217 |
|
|
273 |
|
|
274 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
275 |
@Override |
@Override |
276 |
protected void |
public void |
277 |
onWindowClose() { |
onWindowClose() { |
278 |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
279 |
if(b && CC.getSamplerModel().isModified()) { |
if(b && CC.getSamplerModel().isModified()) { |
312 |
|
|
313 |
super.onWindowClose(); |
super.onWindowClose(); |
314 |
} |
} |
315 |
|
|
316 |
|
private void |
317 |
|
onChangeChannelLaneCount() { |
318 |
|
int newCount = preferences().getIntProperty("channelLanes.count"); |
319 |
|
if(newCount < 1 || newCount > MAX_CHANNEL_LANE_NUMBER) return; |
320 |
|
if(newCount == getChannelsPaneCount()) return; |
321 |
|
int current = getChannelsPaneIndex(getSelectedChannelsPane()); |
322 |
|
|
323 |
|
if(newCount > getChannelsPaneCount()) { |
324 |
|
int d = newCount - getChannelsPaneCount(); |
325 |
|
for(int i = 0; i < d; i++) { |
326 |
|
JSChannelsPane p = mainPane.addChannelsPane(); |
327 |
|
addChannelsPane(p); |
328 |
|
p.addListSelectionListener(pianoKeyboardPane); |
329 |
|
} |
330 |
|
} else { |
331 |
|
int d = getChannelsPaneCount() - newCount; |
332 |
|
for(int i = 0; i < d; i++) { |
333 |
|
int idx = getChannelsPaneCount() - 1 - i; |
334 |
|
if(getChannelsPane(idx).getChannelCount() > 0) { |
335 |
|
String s; |
336 |
|
s = i18n.getError("MainFrame.notEmptyChannelLane!", idx + 1); |
337 |
|
HF.showErrorMessage(s); |
338 |
|
return; |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
|
for(int i = 0; i < d; i++) { |
343 |
|
int idx = getChannelsPaneCount() - 1; |
344 |
|
JSChannelsPane p = getChannelsPane(idx); |
345 |
|
removeChannelsPane(p); |
346 |
|
p.removeListSelectionListener(pianoKeyboardPane); |
347 |
|
mainPane.removeChannelsPane(idx); |
348 |
|
} |
349 |
|
} |
350 |
|
|
351 |
|
if(newCount == 1) { |
352 |
|
mainPane.getButtonsPanel().setVisible(false); |
353 |
|
} else if(!mainPane.getButtonsPanel().isVisible()) { |
354 |
|
mainPane.getButtonsPanel().setVisible(true); |
355 |
|
} |
356 |
|
mainPane.getButtonsPanel().setButtonNumber(newCount); |
357 |
|
if(current < 0 || current >= getChannelsPaneCount()) current = 0; |
358 |
|
setSelectedChannelsPane(getChannelsPane(current)); |
359 |
|
} |
360 |
|
|
361 |
@Override |
@Override |
362 |
public void |
public void |
397 |
|
|
398 |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
399 |
m.add(exportMenu); |
m.add(exportMenu); |
400 |
|
|
401 |
|
int modKey = CC.getViewConfig().getDefaultModKey(); |
402 |
|
|
403 |
mi = new JMenuItem(a4n.exportSamplerConfig); |
mi = new JMenuItem(a4n.exportSamplerConfig); |
404 |
mi.setIcon(null); |
mi.setIcon(null); |
405 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey)); |
406 |
exportMenu.add(mi); |
exportMenu.add(mi); |
407 |
|
|
408 |
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
413 |
|
|
414 |
mi = new JMenuItem(a4n.loadScript); |
mi = new JMenuItem(a4n.loadScript); |
415 |
mi.setIcon(null); |
mi.setIcon(null); |
416 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey)); |
417 |
m.add(mi); |
m.add(mi); |
418 |
|
|
419 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
427 |
|
|
428 |
mi = new JMenuItem(a4n.changeBackend); |
mi = new JMenuItem(a4n.changeBackend); |
429 |
mi.setIcon(null); |
mi.setIcon(null); |
430 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey)); |
431 |
m.add(mi); |
m.add(mi); |
432 |
|
|
433 |
m.addSeparator(); |
m.addSeparator(); |
470 |
mi = new JMenuItem(a4n.editPreferences); |
mi = new JMenuItem(a4n.editPreferences); |
471 |
mi.setIcon(null); |
mi.setIcon(null); |
472 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
473 |
KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK |
474 |
)); |
)); |
475 |
m.add(mi); |
m.add(mi); |
476 |
|
|
492 |
showToolBar(b); |
showToolBar(b); |
493 |
|
|
494 |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
495 |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK |
496 |
)); |
)); |
497 |
m.add(cbmiLeftSidePaneVisible); |
m.add(cbmiLeftSidePaneVisible); |
498 |
|
|
508 |
showSidePane(b); |
showSidePane(b); |
509 |
|
|
510 |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
511 |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK |
512 |
)); |
)); |
513 |
m.add(cbmiRightSidePaneVisible); |
m.add(cbmiRightSidePaneVisible); |
514 |
|
|
571 |
|
|
572 |
mi = new JMenuItem(a4n.selectAllChannels); |
mi = new JMenuItem(a4n.selectAllChannels); |
573 |
mi.setIcon(null); |
mi.setIcon(null); |
574 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey)); |
575 |
m.add(mi); |
m.add(mi); |
576 |
|
|
577 |
mi = new JMenuItem(a4n.deselectChannels); |
mi = new JMenuItem(a4n.deselectChannels); |
578 |
mi.setIcon(null); |
mi.setIcon(null); |
579 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
580 |
KeyEvent.VK_A, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK |
581 |
)); |
)); |
582 |
m.add(mi); |
m.add(mi); |
583 |
|
|
767 |
|
|
768 |
protected boolean |
protected boolean |
769 |
runScript() { |
runScript() { |
770 |
String s = preferences().getStringProperty("lastScriptLocation"); |
File f = StdUtils.showOpenLscpFileChooser(); |
771 |
JFileChooser fc = new JFileChooser(s); |
if(f == null) return false; |
772 |
fc.setFileFilter(new LscpFileFilter()); |
runScript(f); |
|
int result = fc.showOpenDialog(this); |
|
|
if(result != JFileChooser.APPROVE_OPTION) return false; |
|
|
|
|
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
|
|
preferences().setStringProperty("lastScriptLocation", path); |
|
|
|
|
|
runScript(fc.getSelectedFile()); |
|
773 |
|
|
774 |
return true; |
return true; |
775 |
} |
} |
783 |
FileReader fr; |
FileReader fr; |
784 |
try { fr = new FileReader(script); } |
try { fr = new FileReader(script); } |
785 |
catch(FileNotFoundException e) { |
catch(FileNotFoundException e) { |
786 |
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
HF.showErrorMessage(i18n.getError("fileNotFound!")); |
787 |
return; |
return; |
788 |
} |
} |
789 |
|
|