/[svn]/jsampler/trunk/src/org/jsampler/view/classic/MidiInstrumentMapsPage.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/classic/MidiInstrumentMapsPage.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1767 - (show annotations) (download)
Mon Sep 8 00:19:27 2008 UTC (15 years, 7 months ago) by iliev
File size: 9713 byte(s)
* Added `Copy To' and `Move To' commands to the MIDI bank context menu
  and to the MIDI instrument context menu
* Added commands to the MIDI instrument context menu for moving
  a MIDI instrument to another program
  (right-click on a MIDI instrument and choose `Change Program')
* Added option to choose between zero-based and one-based
  MIDI bank/program numbering
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to choose whether to include MIDI instrument
  mappings when exporting a sampler configuration to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to set the MIDI instrument loading in background
  when exporting MIDI instrument mappings to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Implemented an option to change the socket read timeout
  (choose Edit/Preferences, then click the `Backend' tab)
* Updated LscpTree
* Fantasia: Added option to hide the active stream/voice count statistic
  in the sampler channel's small view
  (choose Edit/Preferences, then click the `Channels' tab)
* Fantasia: `Turn off animation effects' checkbox moved to the `View' tab

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2006 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.classic;
24
25 import java.awt.BorderLayout;
26 import java.awt.Dimension;
27
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30
31 import javax.swing.AbstractAction;
32 import javax.swing.Action;
33 import javax.swing.BorderFactory;
34 import javax.swing.Box;
35 import javax.swing.BoxLayout;
36 import javax.swing.JComboBox;
37 import javax.swing.JPanel;
38 import javax.swing.JScrollPane;
39 import javax.swing.JToolBar;
40
41 import javax.swing.tree.DefaultTreeCellRenderer;
42
43 import net.sf.juife.LinkButton;
44 import net.sf.juife.NavigationPage;
45
46 import org.jsampler.CC;
47 import org.jsampler.MidiInstrumentMap;
48
49 import org.jsampler.event.ListEvent;
50 import org.jsampler.event.ListListener;
51 import org.jsampler.event.MidiInstrumentMapEvent;
52 import org.jsampler.event.MidiInstrumentMapListener;
53 import org.jsampler.view.std.JSEditMidiInstrumentDlg;
54
55 import org.jsampler.view.std.JSAddMidiInstrumentMapDlg;
56 import org.jsampler.view.std.JSMidiInstrumentTree;
57 import org.jsampler.view.std.JSMidiInstrumentsPane;
58
59 import org.linuxsampler.lscp.MidiInstrumentInfo;
60
61 import static org.jsampler.view.classic.A4n.a4n;
62 import static org.jsampler.view.classic.ClassicI18n.i18n;
63
64
65 /**
66 *
67 * @author Grigor Iliev
68 */
69 public class MidiInstrumentMapsPage extends NavigationPage {
70 private final JToolBar tbMaps = new JToolBar();
71
72 private final EditMap actionEditMap = new EditMap();
73 private final RemoveMap actionRemoveMap = new RemoveMap();
74
75 private final ToolbarButton btnAddMap = new ToolbarButton(A4n.addMidiInstrumentMap);
76 private final ToolbarButton btnEditMap = new ToolbarButton(actionEditMap);
77 private final ToolbarButton btnRemoveMap = new ToolbarButton(actionRemoveMap);
78 private final ToolbarButton btnExportMaps = new ToolbarButton(a4n.exportMidiInstrumentMaps);
79 //private final ToolbarButton btnCloseMapBar = new ToolbarButton();
80
81 //private final ToolbarButton btnCloseInstrumentBar = new ToolbarButton();
82
83 private final JComboBox cbMaps = new JComboBox();
84 private final MidiInstrumentsPane midiInstrumentsPane = new MidiInstrumentsPane();
85
86 /** Creates a new instance of MidiInstrumentMapsPage */
87 public
88 MidiInstrumentMapsPage() {
89 setTitle(i18n.getLabel("MidiInstrumentMapsPage.title"));
90 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
91
92 /*btnCloseMapBar.setIcon(Res.iconClose8);
93 btnCloseMapBar.setMargin(new java.awt.Insets(0, 0, 0, 0));
94 btnCloseMapBar.addActionListener(new ActionListener() {
95 public void
96 actionPerformed(ActionEvent e) {
97 tbMaps.setVisible(false);
98 validate();
99 repaint();
100 }
101 });
102
103
104 btnCloseInstrumentBar.setIcon(Res.iconClose8);
105 btnCloseInstrumentBar.setMargin(new java.awt.Insets(0, 0, 0, 0));
106 btnCloseInstrumentBar.addActionListener(new ActionListener() {
107 public void
108 actionPerformed(ActionEvent e) {
109 tbInstruments.setVisible(false);
110 validate();
111 repaint();
112 }
113 });*/
114
115
116 tbMaps.add(btnAddMap);
117 tbMaps.add(btnEditMap);
118 tbMaps.add(btnRemoveMap);
119 tbMaps.addSeparator();
120 tbMaps.add(btnExportMaps);
121
122 /*tbMaps.add(Box.createHorizontalGlue());
123 tbMaps.add(btnCloseMapBar);*/
124
125 Dimension d = new Dimension(Short.MAX_VALUE, tbMaps.getPreferredSize().height);
126 tbMaps.setMaximumSize(d);
127 tbMaps.setFloatable(false);
128 tbMaps.setAlignmentX(LEFT_ALIGNMENT);
129
130 add(tbMaps);
131
132 JPanel p = new JPanel();
133 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
134 p.setAlignmentX(LEFT_ALIGNMENT);
135 p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
136
137 cbMaps.addActionListener(new ActionListener() {
138 public void
139 actionPerformed(ActionEvent e) { mapChanged(); }
140 });
141
142 for(MidiInstrumentMap m : CC.getSamplerModel().getMidiInstrumentMaps()) {
143 cbMaps.addItem(m);
144 m.addMidiInstrumentMapListener(getHandler());
145 }
146
147 cbMaps.setEnabled(cbMaps.getItemCount() > 0);
148
149 d = new Dimension(Short.MAX_VALUE, cbMaps.getPreferredSize().height);
150 cbMaps.setMaximumSize(d);
151
152 CC.getSamplerModel().addMidiInstrumentMapListListener(getHandler());
153
154 p.add(cbMaps);
155 p.add(Box.createRigidArea(new Dimension(0, 12)));
156 add(p);
157
158 /*tbInstruments.add(Box.createHorizontalGlue());
159 tbInstruments.add(btnCloseInstrumentBar); */
160
161 add(midiInstrumentsPane);
162
163 boolean b = cbMaps.getItemCount() != 0;
164 actionEditMap.setEnabled(b);
165 actionRemoveMap.setEnabled(b);
166 A4n.removeMidiInstrumentMap.setEnabled(b);
167 A4n.addMidiInstrumentWizard.setEnabled(b);
168 }
169
170 private void
171 mapChanged() {
172 MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
173 midiInstrumentsPane.setMidiInstrumentMap(map);
174
175 boolean b = cbMaps.getItemCount() != 0;
176 actionEditMap.setEnabled(b);
177 actionRemoveMap.setEnabled(b);
178 A4n.removeMidiInstrumentMap.setEnabled(b);
179 A4n.addMidiInstrumentWizard.setEnabled(b);
180 }
181
182 class MidiInstrumentsPane extends JSMidiInstrumentsPane {
183 private final JToolBar tbInstruments = new JToolBar();
184
185 private final ToolbarButton btnAddInstrument =
186 new ToolbarButton(A4n.addMidiInstrumentWizard);
187
188 private final ToolbarButton btnEditInstrument
189 = new ToolbarButton(actionEditInstrument);
190
191 private final ToolbarButton btnRemoveInstrument = new ToolbarButton(actionRemove);
192
193 MidiInstrumentsPane() {
194 actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16);
195 actionRemove.putValue(Action.SMALL_ICON, Res.iconDelete16);
196
197 removeAll();
198
199 tbInstruments.add(btnAddInstrument);
200 tbInstruments.add(btnEditInstrument);
201 tbInstruments.add(btnRemoveInstrument);
202
203 Dimension d;
204 d = new Dimension(Short.MAX_VALUE, tbInstruments.getPreferredSize().height);
205 tbInstruments.setMaximumSize(d);
206 tbInstruments.setFloatable(false);
207
208 add(tbInstruments, BorderLayout.NORTH);
209 JScrollPane sp = new JScrollPane(midiInstrumentTree);
210
211 DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
212 renderer.setClosedIcon(Res.iconFolder16);
213 renderer.setOpenIcon(Res.iconFolderOpen16);
214 renderer.setLeafIcon(Res.iconInstrument16);
215
216 midiInstrumentTree.setCellRenderer(renderer);
217
218 JPanel p = new JPanel();
219 p.setLayout(new BorderLayout());
220 p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
221
222 p.add(sp);
223
224 add(p);
225
226 setAlignmentX(LEFT_ALIGNMENT);
227 }
228 }
229
230 private class EditMap extends AbstractAction {
231 EditMap() {
232 super(i18n.getLabel("MidiInstrumentMapsPage.editMap"));
233
234 String s = i18n.getLabel("MidiInstrumentMapsPage.editMap.tt");
235 putValue(SHORT_DESCRIPTION, s);
236 putValue(Action.SMALL_ICON, Res.iconEdit16);
237 }
238
239 public void
240 actionPerformed(ActionEvent e) {
241 MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
242 int id = map.getMapId();
243 JSAddMidiInstrumentMapDlg dlg = new JSAddMidiInstrumentMapDlg();
244 dlg.setTitle(i18n.getLabel("MidiInstrumentMapsPage.editMap"));
245 dlg.setMapName(map.getName());
246 dlg.setVisible(true);
247 if(dlg.isCancelled()) return;
248
249 map.setName(dlg.getMapName());
250 CC.getSamplerModel().setBackendMidiInstrumentMapName(id, dlg.getMapName());
251 }
252 }
253
254 private class RemoveMap extends AbstractAction {
255 RemoveMap() {
256 super(i18n.getMenuLabel("actions.midiInstruments.removeMap"));
257
258 String s = i18n.getMenuLabel("actions.midiInstruments.removeMap.tt");
259 putValue(SHORT_DESCRIPTION, s);
260 putValue(Action.SMALL_ICON, Res.iconDelete16);
261 }
262
263 public void
264 actionPerformed(ActionEvent e) {
265 MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
266 RemoveMidiInstrumentMapDlg dlg = new RemoveMidiInstrumentMapDlg(map);
267 dlg.setVisible(true);
268 if(dlg.isCancelled()) return;
269 int id = dlg.getSelectedMap().getMapId();
270 CC.getSamplerModel().removeBackendMidiInstrumentMap(id);
271 }
272 }
273
274 private final Handler handler = new Handler();
275
276 private Handler
277 getHandler() { return handler; }
278
279 private class Handler implements ListListener<MidiInstrumentMap>,
280 MidiInstrumentMapListener {
281
282 /** Invoked when a new map is added. */
283 public void
284 entryAdded(ListEvent<MidiInstrumentMap> e) {
285 MidiInstrumentMap map = e.getEntry();
286 if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(true);
287 cbMaps.addItem(map);
288 cbMaps.setSelectedItem(map);
289 map.addMidiInstrumentMapListener(getHandler());
290 }
291
292 /** Invoked when a map is removed. */
293 public void
294 entryRemoved(ListEvent<MidiInstrumentMap> e) {
295 cbMaps.removeItem(e.getEntry());
296 if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(false);
297 e.getEntry().removeMidiInstrumentMapListener(getHandler());
298 }
299
300 /** Invoked when the name of MIDI instrument map is changed. */
301 public void
302 nameChanged(MidiInstrumentMapEvent e) {
303 cbMaps.repaint();
304 }
305
306 /** Invoked when an instrument is added to a MIDI instrument map. */
307 public void instrumentAdded(MidiInstrumentMapEvent e) { }
308
309 /** Invoked when an instrument is removed from a MIDI instrument map. */
310 public void instrumentRemoved(MidiInstrumentMapEvent e) { }
311 }
312 }

  ViewVC Help
Powered by ViewVC