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; |
62 |
import javax.swing.SwingUtilities; |
import javax.swing.SwingUtilities; |
63 |
import javax.swing.Timer; |
import javax.swing.Timer; |
64 |
|
|
65 |
|
import javax.swing.event.ListSelectionEvent; |
66 |
|
import javax.swing.event.ListSelectionListener; |
67 |
|
|
68 |
import org.jsampler.CC; |
import org.jsampler.CC; |
69 |
import org.jsampler.HF; |
import org.jsampler.HF; |
70 |
import org.jsampler.LSConsoleModel; |
import org.jsampler.LSConsoleModel; |
71 |
import org.jsampler.Server; |
import org.jsampler.Server; |
72 |
|
|
73 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
74 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.SessionViewConfig; |
|
import org.jsampler.view.LscpFileFilter; |
|
75 |
|
|
76 |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
77 |
import org.jsampler.view.fantasia.basic.FantasiaPanel; |
import org.jsampler.view.fantasia.basic.FantasiaPanel; |
82 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
import org.jsampler.view.std.JSDetailedErrorDlg; |
83 |
import org.jsampler.view.std.JSQuitDlg; |
import org.jsampler.view.std.JSQuitDlg; |
84 |
import org.jsampler.view.std.JSamplerHomeChooser; |
import org.jsampler.view.std.JSamplerHomeChooser; |
85 |
|
import org.jsampler.view.std.StdMainFrame; |
86 |
import org.jsampler.view.std.StdUtils; |
import org.jsampler.view.std.StdUtils; |
87 |
|
|
88 |
import static org.jsampler.view.fantasia.A4n.a4n; |
import static org.jsampler.view.fantasia.A4n.a4n; |
95 |
* |
* |
96 |
* @author Grigor Iliev |
* @author Grigor Iliev |
97 |
*/ |
*/ |
98 |
public class MainFrame extends JSMainFrame { |
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 |
|
|
539 |
setMidiKeyboardVisible(b); |
setMidiKeyboardVisible(b); |
540 |
|
|
541 |
|
|
542 |
|
// Channels |
543 |
|
m = new FantasiaMenu(i18n.getMenuLabel("channels")); |
544 |
|
|
545 |
|
mi = new JMenuItem(i18n.getMenuLabel("channels.newChannel")); |
546 |
|
mi.addActionListener(new ActionListener() { |
547 |
|
public void |
548 |
|
actionPerformed(ActionEvent e) { |
549 |
|
CC.getSamplerModel().addBackendChannel(); |
550 |
|
} |
551 |
|
}); |
552 |
|
m.add(mi); |
553 |
|
|
554 |
|
m.addSeparator(); |
555 |
|
|
556 |
|
MenuManager.ChannelViewGroup group = new MenuManager.ChannelViewGroup(); |
557 |
|
MenuManager.getMenuManager().registerChannelViewGroup(group); |
558 |
|
|
559 |
|
for(JMenuItem menuItem : group.getMenuItems()) m.add(menuItem); |
560 |
|
|
561 |
|
m.addSeparator(); |
562 |
|
|
563 |
|
m.add(new JMenuItem(a4n.moveChannelsOnTop)); |
564 |
|
m.add(new JMenuItem(a4n.moveChannelsUp)); |
565 |
|
m.add(new JMenuItem(a4n.moveChannelsDown)); |
566 |
|
m.add(new JMenuItem(a4n.moveChannelsAtBottom)); |
567 |
|
|
568 |
|
m.add(new ToPanelMenu()); |
569 |
|
|
570 |
|
m.addSeparator(); |
571 |
|
|
572 |
|
mi = new JMenuItem(a4n.selectAllChannels); |
573 |
|
mi.setIcon(null); |
574 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey)); |
575 |
|
m.add(mi); |
576 |
|
|
577 |
|
mi = new JMenuItem(a4n.deselectChannels); |
578 |
|
mi.setIcon(null); |
579 |
|
mi.setAccelerator(KeyStroke.getKeyStroke ( |
580 |
|
KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK |
581 |
|
)); |
582 |
|
m.add(mi); |
583 |
|
|
584 |
|
menuBar.add(m); |
585 |
|
|
586 |
// Window |
// Window |
587 |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
588 |
menuBar.add(m); |
menuBar.add(m); |
636 |
menuBar.add(m); |
menuBar.add(m); |
637 |
} |
} |
638 |
|
|
639 |
|
public static class ToPanelMenu extends FantasiaMenu implements ListSelectionListener { |
640 |
|
public |
641 |
|
ToPanelMenu() { |
642 |
|
super(i18n.getMenuLabel("channels.toPanel")); |
643 |
|
setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel()); |
644 |
|
|
645 |
|
CC.getMainFrame().addChannelsPaneSelectionListener(this); |
646 |
|
|
647 |
|
for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) { |
648 |
|
JSChannelsPane p = CC.getMainFrame().getChannelsPane(i); |
649 |
|
add(new JMenuItem(new A4n.MoveChannelsToPanel(p))); |
650 |
|
p.addListSelectionListener(this); |
651 |
|
} |
652 |
|
} |
653 |
|
|
654 |
|
@Override |
655 |
|
public void |
656 |
|
valueChanged(ListSelectionEvent e) { |
657 |
|
setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel()); |
658 |
|
} |
659 |
|
} |
660 |
|
|
661 |
public RightSidePane |
public RightSidePane |
662 |
getRightSidePane() { return rightSidePane; } |
getRightSidePane() { return rightSidePane; } |
663 |
|
|
664 |
|
@Override |
665 |
|
public A4n |
666 |
|
getA4n() { return A4n.a4n; } |
667 |
|
|
668 |
/** |
/** |
669 |
* This method does nothing, because <b>Fantasia</b> has constant |
* This method does nothing, because <b>Fantasia</b> has constant |
670 |
* number of panes containing sampler channels, which can not be changed. |
* number of panes containing sampler channels, which can not be changed. |
751 |
public Timer |
public Timer |
752 |
getGuiTimer() { return guiTimer; } |
getGuiTimer() { return guiTimer; } |
753 |
|
|
754 |
protected LSConsoleModel |
@Override |
755 |
|
public LSConsoleModel |
756 |
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
757 |
|
|
758 |
protected LSConsolePane |
protected LSConsolePane |
768 |
|
|
769 |
protected boolean |
protected boolean |
770 |
runScript() { |
runScript() { |
771 |
String s = preferences().getStringProperty("lastScriptLocation"); |
File f = StdUtils.showOpenLscpFileChooser(); |
772 |
JFileChooser fc = new JFileChooser(s); |
if(f == null) return false; |
773 |
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()); |
|
774 |
|
|
775 |
return true; |
return true; |
776 |
} |
} |
784 |
FileReader fr; |
FileReader fr; |
785 |
try { fr = new FileReader(script); } |
try { fr = new FileReader(script); } |
786 |
catch(FileNotFoundException e) { |
catch(FileNotFoundException e) { |
787 |
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
HF.showErrorMessage(i18n.getError("fileNotFound!")); |
788 |
return; |
return; |
789 |
} |
} |
790 |
|
|
791 |
|
String prefix = "#jsampler.fantasia: "; |
792 |
|
Vector<String> v = new Vector<String>(); |
793 |
BufferedReader br = new BufferedReader(fr); |
BufferedReader br = new BufferedReader(fr); |
794 |
|
|
795 |
try { |
try { |
797 |
while(s != null) { |
while(s != null) { |
798 |
getLSConsoleModel().setCommandLineText(s); |
getLSConsoleModel().setCommandLineText(s); |
799 |
getLSConsoleModel().execCommand(); |
getLSConsoleModel().execCommand(); |
800 |
|
if(s.startsWith(prefix)) v.add(s.substring(prefix.length())); |
801 |
s = br.readLine(); |
s = br.readLine(); |
802 |
} |
} |
803 |
} catch(Exception e) { |
} catch(Exception e) { |
810 |
recentScripts.insertElementAt(s, 0); |
recentScripts.insertElementAt(s, 0); |
811 |
|
|
812 |
updateRecentScriptsMenu(); |
updateRecentScriptsMenu(); |
813 |
|
|
814 |
|
CC.getViewConfig().setSessionViewConfig( |
815 |
|
new SessionViewConfig(v.toArray(new String[v.size()])) |
816 |
|
); |
817 |
} |
} |
818 |
|
|
819 |
protected void |
protected void |