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

Annotation of /jsampler/trunk/src/org/jsampler/view/fantasia/MidiInstrumentsPane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1778 - (hide annotations) (download)
Sun Sep 28 20:38:36 2008 UTC (15 years, 7 months ago) by iliev
File size: 8263 byte(s)
* Fantasia: Improved look and feel
* Fantasia: Added buttons for increasing/decreasing the key number
  of the MIDI keyboard (Ctrl+Up Arrow/Ctrl+Down Arrow)
* Fantasia: Added buttons for scrolling left/right on the MIDI keyboard
  (Ctrl+Left Arrow/Ctrl+Right Arrow)
* Added key bindings for triggering MIDI notes using the computer keyboard
  (from a to ' for the white keys and from 0 to 7 for changing the octaves)
* Notes are now triggered when dragging the mouse over the MIDI keyboard

1 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1778 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1286 *
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.BorderLayout;
26     import java.awt.Color;
27     import java.awt.Dimension;
28     import java.awt.Graphics;
29 iliev 1778 import java.awt.Graphics2D;
30 iliev 1286 import java.awt.Insets;
31    
32     import java.awt.event.ActionEvent;
33     import java.awt.event.ActionListener;
34    
35     import java.beans.PropertyChangeEvent;
36     import java.beans.PropertyChangeListener;
37    
38     import javax.swing.Action;
39     import javax.swing.BorderFactory;
40     import javax.swing.Box;
41     import javax.swing.BoxLayout;
42     import javax.swing.JComboBox;
43     import javax.swing.JPanel;
44     import javax.swing.JScrollPane;
45     import javax.swing.JToolBar;
46    
47     import net.sf.juife.Wizard;
48    
49     import org.jsampler.CC;
50     import org.jsampler.MidiInstrumentMap;
51    
52     import org.jsampler.event.ListEvent;
53     import org.jsampler.event.ListListener;
54    
55     import org.jsampler.view.std.JSManageMidiMapsPane;
56     import org.jsampler.view.std.JSMidiInstrumentsPane;
57     import org.jsampler.view.std.JSNewMidiInstrumentWizard;
58    
59     import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
60     import static org.jsampler.view.fantasia.FantasiaPrefs.*;
61    
62     /**
63     *
64     * @author Grigor Iliev
65     */
66     public class MidiInstrumentsPane extends JPanel {
67     private final JPanel taskPaneContainer = new JPanel();
68 iliev 1778 private final FantasiaTaskPane mapsTaskPane = new FantasiaTaskPane();
69 iliev 1286
70     private ManageMapsPane manageMapsPane = new ManageMapsPane();
71     private final InstrumentsPane instrumentsPane = new InstrumentsPane();
72    
73     private final JComboBox cbMaps = new JComboBox();
74     //private final InstrumentsPane instrumentsPane = new InstrumentsPane();
75    
76     /** Creates a new instance of <code>MidiInstrumentsPane</code> */
77     public
78     MidiInstrumentsPane() {
79     setLayout(new BorderLayout());
80     setOpaque(false);
81    
82     mapsTaskPane.setTitle(i18n.getLabel("MidiInstrumentsPane.mapsTaskPane"));
83 iliev 1778
84     FantasiaSubPanel fsp = new FantasiaSubPanel(false, true, false);
85     fsp.add(manageMapsPane);
86     mapsTaskPane.add(fsp);
87 iliev 1286 boolean b;
88     mapsTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED));
89     b = preferences().getBoolProperty("MidiInstrumentsPane.mapsTaskPane.expanded");
90     mapsTaskPane.setExpanded(b);
91    
92     preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
93     public void
94     propertyChange(PropertyChangeEvent e) {
95     mapsTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED));
96     }
97     });
98    
99     taskPaneContainer.setOpaque(false);
100     taskPaneContainer.setLayout(new BorderLayout());
101     taskPaneContainer.add(mapsTaskPane);
102     taskPaneContainer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
103    
104     add(taskPaneContainer, BorderLayout.NORTH);
105     add(new MapsPane());
106    
107     cbMaps.addActionListener(new ActionListener() {
108     public void
109     actionPerformed(ActionEvent e) { mapChanged(); }
110     });
111    
112     for(Object o : CC.getSamplerModel().getMidiInstrumentMaps()) {
113     cbMaps.addItem(o);
114     }
115    
116     CC.getSamplerModel().addMidiInstrumentMapListListener(getHandler());
117     cbMaps.setEnabled(cbMaps.getItemCount() != 0);
118     }
119    
120     private void
121     mapChanged() {
122     MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
123     instrumentsPane.setMidiInstrumentMap(map);
124     }
125    
126     public void
127     savePreferences() {
128     boolean b = mapsTaskPane.isExpanded();
129     preferences().setBoolProperty("MidiInstrumentsPane.mapsTaskPane.expanded", b);
130     }
131    
132     class ManageMapsPane extends JSManageMidiMapsPane {
133     ManageMapsPane() {
134     actionAddMap.putValue(Action.SMALL_ICON, Res.iconNew16);
135     actionEditMap.putValue(Action.SMALL_ICON, Res.iconEdit16);
136     actionRemoveMap.putValue(Action.SMALL_ICON, Res.iconDelete16);
137    
138     removeAll();
139    
140 iliev 1778 JToolBar toolBar = FantasiaUtils.createSubToolBar();
141 iliev 1286 toolBar.add(new ToolbarButton(actionAddMap));
142     toolBar.add(new ToolbarButton(actionEditMap));
143     toolBar.add(new ToolbarButton(actionRemoveMap));
144     add(toolBar, BorderLayout.NORTH);
145    
146     JScrollPane sp = new JScrollPane(midiMapTable);
147     sp.setPreferredSize(new Dimension(120, 130));
148    
149 iliev 1778 JPanel p = FantasiaUtils.createBottomSubPane();
150     p.add(sp);
151     add(p);
152     }
153    
154     @Override
155     protected void
156     paintComponent(Graphics g) {
157     super.paintComponent(g);
158 iliev 1286
159 iliev 1778 double h = getSize().getHeight();
160     double w = getSize().getWidth();
161 iliev 1286
162 iliev 1778 FantasiaPainter.paintGradient((Graphics2D)g, 0, 0, w - 1, h - 1);
163    
164     FantasiaPainter.RoundCorners rc =
165     new FantasiaPainter.RoundCorners(true, false, false, true);
166    
167     FantasiaPainter.paintOuterBorder((Graphics2D)g, 0, 0, w - 1, h - 1, rc);
168 iliev 1286 }
169     }
170    
171     class MapsPane extends JPanel {
172     MapsPane() {
173     setOpaque(false);
174     setLayout(new BorderLayout());
175 iliev 1778 setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
176 iliev 1286
177 iliev 1778 FantasiaSubPanel p2 = new FantasiaSubPanel(true, false);
178     p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
179 iliev 1286 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
180    
181 iliev 1778 JPanel p = new FantasiaPanel();
182     p.setOpaque(false);
183     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
184     p.add(cbMaps);
185     p.setBorder(BorderFactory.createEmptyBorder(3, 1, 5, 1));
186     p2.add(p);
187    
188     FantasiaSubPanel fsp = new FantasiaSubPanel(false, true, false);
189     fsp.add(instrumentsPane);
190    
191     p2.add(fsp);
192    
193 iliev 1286 add(p2);
194     }
195     }
196    
197     class InstrumentsPane extends JSMidiInstrumentsPane {
198     InstrumentsPane() {
199     actionAddInstrument.putValue(Action.SMALL_ICON, Res.iconNew16);
200     actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16);
201     actionRemove.putValue(Action.SMALL_ICON, Res.iconDelete16);
202    
203     removeAll();
204    
205 iliev 1778 JToolBar toolBar = FantasiaUtils.createSubToolBar();
206 iliev 1286 toolBar.add(new ToolbarButton(actionAddInstrument));
207     toolBar.add(new ToolbarButton(actionEditInstrument));
208     toolBar.add(new ToolbarButton(actionRemove));
209    
210     add(toolBar, java.awt.BorderLayout.NORTH);
211    
212     JScrollPane sp = new JScrollPane(midiInstrumentTree);
213     Dimension d;
214     d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height);
215     sp.setPreferredSize(d);
216    
217 iliev 1778 JPanel p = FantasiaUtils.createBottomSubPane();
218     p.add(sp);
219 iliev 1286
220     add(p);
221     }
222    
223 iliev 1778 @Override
224 iliev 1286 public void
225     addInstrument() {
226 iliev 1329 MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
227    
228 iliev 1286 JSNewMidiInstrumentWizard wizard =
229 iliev 1329 new JSNewMidiInstrumentWizard(Res.iconBrowse16, map);
230 iliev 1286 wizard.getWizardDialog().setResizable(false);
231     wizard.putClientProperty(Wizard.BACK_BUTTON_ICON, Res.iconBack16);
232     wizard.putClientProperty(Wizard.NEXT_BUTTON_ICON, Res.iconNext16);
233     Color c = new Color(0x626262);
234     wizard.putClientProperty(Wizard.LEFT_PANE_BACKGROUND_COLOR, c);
235     //c = new Color(0x4b4b4b);
236     //wizard.putClientProperty(Wizard.LEFT_PANE_FOREGROUND_COLOR, c);
237    
238     if(preferences().getBoolProperty("NewMidiInstrumentWizard.skip1")) {
239     if(wizard.getModel().getCurrentPage() == null) {
240     wizard.getModel().next();
241     }
242     wizard.getModel().next();
243     }
244    
245     wizard.showWizard();
246     }
247     }
248    
249     private final Handler eventHandler = new Handler();
250    
251     private Handler
252     getHandler() { return eventHandler; }
253    
254     private class Handler implements ListListener<MidiInstrumentMap> {
255     /** Invoked when an orchestra is added to the orchestra list. */
256 iliev 1778 @Override
257 iliev 1286 public void
258     entryAdded(ListEvent<MidiInstrumentMap> e) {
259     if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(true);
260     cbMaps.addItem(e.getEntry());
261     }
262    
263     /** Invoked when an orchestra is removed from the orchestra list. */
264 iliev 1778 @Override
265 iliev 1286 public void
266     entryRemoved(ListEvent<MidiInstrumentMap> e) {
267     cbMaps.removeItem(e.getEntry());
268     if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(false);
269     }
270     }
271     }

  ViewVC Help
Powered by ViewVC