23 |
package org.jsampler.view.std; |
package org.jsampler.view.std; |
24 |
|
|
25 |
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
26 |
|
import java.awt.Dialog; |
27 |
|
import java.awt.Frame; |
28 |
|
import java.awt.Window; |
29 |
|
|
30 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
31 |
|
import java.awt.event.ActionListener; |
32 |
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseAdapter; |
33 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
34 |
|
|
35 |
import javax.swing.AbstractAction; |
import javax.swing.AbstractAction; |
36 |
import javax.swing.Action; |
import javax.swing.Action; |
37 |
|
import javax.swing.JMenu; |
38 |
|
import javax.swing.JMenuItem; |
39 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
40 |
|
import javax.swing.JPopupMenu; |
41 |
import javax.swing.JScrollPane; |
import javax.swing.JScrollPane; |
42 |
|
|
43 |
import javax.swing.event.ListSelectionEvent; |
import javax.swing.event.ListSelectionEvent; |
44 |
import javax.swing.event.ListSelectionListener; |
import javax.swing.event.ListSelectionListener; |
45 |
|
|
46 |
|
import net.sf.juife.JuifeUtils; |
47 |
|
|
48 |
|
import org.jsampler.CC; |
49 |
import org.jsampler.DefaultOrchestraModel; |
import org.jsampler.DefaultOrchestraModel; |
50 |
import org.jsampler.Instrument; |
import org.jsampler.Instrument; |
51 |
|
import org.jsampler.MidiInstrumentMap; |
52 |
import org.jsampler.OrchestraModel; |
import org.jsampler.OrchestraModel; |
53 |
|
import org.jsampler.SamplerChannelModel; |
54 |
|
|
55 |
|
import org.jsampler.event.ListEvent; |
56 |
|
import org.jsampler.event.ListListener; |
57 |
|
import org.jsampler.event.SamplerChannelListEvent; |
58 |
|
import org.jsampler.event.SamplerChannelListListener; |
59 |
|
|
60 |
import org.jsampler.view.InstrumentTable; |
import org.jsampler.view.InstrumentTable; |
61 |
import org.jsampler.view.InstrumentTableModel; |
import org.jsampler.view.InstrumentTableModel; |
62 |
|
|
63 |
|
import org.linuxsampler.lscp.MidiInstrumentInfo; |
64 |
|
|
65 |
import static org.jsampler.view.std.StdI18n.i18n; |
import static org.jsampler.view.std.StdI18n.i18n; |
66 |
|
|
67 |
/** |
/** |
105 |
|
|
106 |
instrumentTable.addMouseListener(new MouseAdapter() { |
instrumentTable.addMouseListener(new MouseAdapter() { |
107 |
public void |
public void |
108 |
|
mousePressed(MouseEvent e) { |
109 |
|
if(e.getButton() != e.BUTTON3) return; |
110 |
|
|
111 |
|
int i = instrumentTable.rowAtPoint(e.getPoint()); |
112 |
|
if(i == -1) return; |
113 |
|
|
114 |
|
instrumentTable.getSelectionModel().setSelectionInterval(i, i); |
115 |
|
|
116 |
|
} |
117 |
|
|
118 |
|
public void |
119 |
mouseClicked(MouseEvent e) { |
mouseClicked(MouseEvent e) { |
120 |
if(e.getClickCount() < 2) return; |
if(e.getClickCount() < 2) return; |
121 |
|
|
123 |
editInstrument(instrumentTable.getSelectedInstrument()); |
editInstrument(instrumentTable.getSelectedInstrument()); |
124 |
} |
} |
125 |
}); |
}); |
126 |
|
|
127 |
|
ContextMenu contextMenu = new ContextMenu(); |
128 |
|
instrumentTable.addMouseListener(contextMenu); |
129 |
} |
} |
130 |
|
|
131 |
public void |
public void |
270 |
instrumentTable.setSelectedInstrument(instr); |
instrumentTable.setSelectedInstrument(instr); |
271 |
} |
} |
272 |
} |
} |
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
private class LoadInstrumentAction extends AbstractAction { |
277 |
|
private final SamplerChannelModel channelModel; |
278 |
|
|
279 |
|
LoadInstrumentAction(SamplerChannelModel model) { |
280 |
|
String s = "instrumentsdb.actions.loadInstrument.onChannel"; |
281 |
|
putValue(Action.NAME, i18n.getMenuLabel(s, model.getChannelId())); |
282 |
|
channelModel = model; |
283 |
|
} |
284 |
|
|
285 |
|
public void |
286 |
|
actionPerformed(ActionEvent e) { |
287 |
|
Instrument instr = instrumentTable.getSelectedInstrument(); |
288 |
|
if(instr == null) return; |
289 |
|
|
290 |
|
int idx = instr.getInstrumentIndex(); |
291 |
|
channelModel.setBackendEngineType(instr.getEngine()); |
292 |
|
channelModel.loadBackendInstrument(instr.getPath(), idx); |
293 |
|
} |
294 |
|
} |
295 |
|
|
296 |
|
class AddToMidiMapAction extends AbstractAction { |
297 |
|
private final MidiInstrumentMap midiMap; |
298 |
|
|
299 |
|
AddToMidiMapAction(MidiInstrumentMap map) { |
300 |
|
super(map.getName()); |
301 |
|
midiMap = map; |
302 |
|
} |
303 |
|
|
304 |
|
public void |
305 |
|
actionPerformed(ActionEvent e) { |
306 |
|
Instrument instr = instrumentTable.getSelectedInstrument(); |
307 |
|
if(instr == null) return; |
308 |
|
|
309 |
|
JSAddMidiInstrumentDlg dlg; |
310 |
|
Window w = JuifeUtils.getWindow(JSOrchestraPane.this); |
311 |
|
if(w instanceof Dialog) { |
312 |
|
dlg = new JSAddMidiInstrumentDlg((Dialog)w); |
313 |
|
} else if(w instanceof Frame) { |
314 |
|
dlg = new JSAddMidiInstrumentDlg((Frame)w); |
315 |
|
} else { |
316 |
|
dlg = new JSAddMidiInstrumentDlg((Frame)null); |
317 |
|
} |
318 |
|
|
319 |
|
dlg.setInstrumentName(instr.getName()); |
320 |
|
dlg.setVisible(true); |
321 |
|
if(dlg.isCancelled()) return; |
322 |
|
|
323 |
|
MidiInstrumentInfo instrInfo = new MidiInstrumentInfo(); |
324 |
|
instrInfo.setName(dlg.getInstrumentName()); |
325 |
|
instrInfo.setFilePath(instr.getPath()); |
326 |
|
instrInfo.setInstrumentIndex(instr.getInstrumentIndex()); |
327 |
|
instrInfo.setEngine(instr.getEngine()); |
328 |
|
instrInfo.setVolume(dlg.getVolume()); |
329 |
|
instrInfo.setLoadMode(dlg.getLoadMode()); |
330 |
|
|
331 |
|
int id = midiMap.getMapId(); |
332 |
|
int b = dlg.getMidiBank(); |
333 |
|
int p = dlg.getMidiProgram(); |
334 |
|
CC.getSamplerModel().mapBackendMidiInstrument(id, b, p, instrInfo); |
335 |
|
} |
336 |
|
} |
337 |
|
|
338 |
|
|
339 |
|
class ContextMenu extends MouseAdapter |
340 |
|
implements SamplerChannelListListener, ListSelectionListener { |
341 |
|
|
342 |
|
private final JPopupMenu cmenu = new JPopupMenu(); |
343 |
|
JMenuItem miEdit = new JMenuItem(i18n.getMenuLabel("ContextMenu.edit")); |
344 |
|
|
345 |
|
JMenu mLoadInstrument = |
346 |
|
new JMenu(i18n.getMenuLabel("JSOrchestraPane.loadInstrument")); |
347 |
|
|
348 |
|
JMenu mMapInstrument = |
349 |
|
new JMenu(i18n.getMenuLabel("JSOrchestraPane.mapInstrument")); |
350 |
|
|
351 |
|
ContextMenu() { |
352 |
|
cmenu.add(miEdit); |
353 |
|
miEdit.addActionListener(new ActionListener() { |
354 |
|
public void |
355 |
|
actionPerformed(ActionEvent e) { |
356 |
|
actionEditInstrument.actionPerformed(null); |
357 |
|
} |
358 |
|
}); |
359 |
|
|
360 |
|
JMenuItem mi = new JMenuItem(i18n.getMenuLabel("ContextMenu.delete")); |
361 |
|
cmenu.add(mi); |
362 |
|
mi.addActionListener(new ActionListener() { |
363 |
|
public void |
364 |
|
actionPerformed(ActionEvent e) { |
365 |
|
actionDeleteInstrument.actionPerformed(null); |
366 |
|
} |
367 |
|
}); |
368 |
|
|
369 |
|
cmenu.addSeparator(); |
370 |
|
|
371 |
|
cmenu.add(mLoadInstrument); |
372 |
|
cmenu.add(mMapInstrument); |
373 |
|
|
374 |
|
CC.getSamplerModel().addSamplerChannelListListener(this); |
375 |
|
instrumentTable.getSelectionModel().addListSelectionListener(this); |
376 |
|
|
377 |
|
ListListener<MidiInstrumentMap> l = new ListListener<MidiInstrumentMap>() { |
378 |
|
public void |
379 |
|
entryAdded(ListEvent<MidiInstrumentMap> e) { |
380 |
|
updateAddToMidiMapMenu(mMapInstrument); |
381 |
|
} |
382 |
|
|
383 |
|
public void |
384 |
|
entryRemoved(ListEvent<MidiInstrumentMap> e) { |
385 |
|
updateAddToMidiMapMenu(mMapInstrument); |
386 |
|
} |
387 |
|
}; |
388 |
|
|
389 |
|
CC.getSamplerModel().addMidiInstrumentMapListListener(l); |
390 |
|
} |
391 |
|
|
392 |
|
private void |
393 |
|
updateLoadInstrumentMenu(JMenu menu) { |
394 |
|
menu.removeAll(); |
395 |
|
for(SamplerChannelModel m : CC.getSamplerModel().getChannels()) { |
396 |
|
menu.add(new JMenuItem(new LoadInstrumentAction(m))); |
397 |
|
} |
398 |
|
|
399 |
|
updateLoadInstrumentMenuState(menu); |
400 |
|
} |
401 |
|
|
402 |
|
private void |
403 |
|
updateLoadInstrumentMenuState(JMenu menu) { |
404 |
|
Instrument instr = instrumentTable.getSelectedInstrument(); |
405 |
|
boolean b = instr == null; |
406 |
|
b = b || CC.getSamplerModel().getChannelCount() == 0; |
407 |
|
menu.setEnabled(!b); |
408 |
|
} |
409 |
|
|
410 |
|
private void |
411 |
|
updateAddToMidiMapMenu(JMenu menu) { |
412 |
|
menu.removeAll(); |
413 |
|
for(int i = 0; i < CC.getSamplerModel().getMidiInstrumentMapCount(); i++) { |
414 |
|
MidiInstrumentMap m = CC.getSamplerModel().getMidiInstrumentMap(i); |
415 |
|
menu.add(new JMenuItem(new AddToMidiMapAction(m))); |
416 |
|
} |
417 |
|
|
418 |
|
updateAddToMidiMapMenuState(menu); |
419 |
|
} |
420 |
|
|
421 |
|
private void |
422 |
|
updateAddToMidiMapMenuState(JMenu menu) { |
423 |
|
Instrument instr = instrumentTable.getSelectedInstrument(); |
424 |
|
boolean b = instr == null; |
425 |
|
b = b || CC.getSamplerModel().getMidiInstrumentMapCount() == 0; |
426 |
|
menu.setEnabled(!b); |
427 |
|
} |
428 |
|
|
429 |
|
public void |
430 |
|
valueChanged(ListSelectionEvent e) { |
431 |
|
updateLoadInstrumentMenuState(mLoadInstrument); |
432 |
|
updateAddToMidiMapMenuState(mMapInstrument); |
433 |
|
} |
434 |
|
|
435 |
|
public void |
436 |
|
channelAdded(SamplerChannelListEvent e) { |
437 |
|
updateLoadInstrumentMenu(mLoadInstrument); |
438 |
|
} |
439 |
|
|
440 |
|
public void |
441 |
|
channelRemoved(SamplerChannelListEvent e) { |
442 |
|
updateLoadInstrumentMenu(mLoadInstrument); |
443 |
|
} |
444 |
|
|
445 |
|
public void |
446 |
|
mousePressed(MouseEvent e) { |
447 |
|
if(e.isPopupTrigger()) show(e); |
448 |
|
} |
449 |
|
|
450 |
|
public void |
451 |
|
mouseReleased(MouseEvent e) { |
452 |
|
if(e.isPopupTrigger()) show(e); |
453 |
|
} |
454 |
|
|
455 |
|
void |
456 |
|
show(MouseEvent e) { |
457 |
|
cmenu.show(e.getComponent(), e.getX(), e.getY()); |
458 |
|
} |
459 |
|
} |
460 |
} |
} |