OSDN Git Service

・プレイリストで曲選択クリア時にイベント一覧がクリアされない問題の改善
[midichordhelper/MIDIChordHelper.git] / src / camidion / chordhelper / midieditor / MidiSequenceEditorDialog.java
1 package camidion.chordhelper.midieditor;
2
3 import java.awt.Container;
4 import java.awt.Dimension;
5 import java.awt.FlowLayout;
6 import java.awt.datatransfer.DataFlavor;
7 import java.awt.event.ActionEvent;
8 import java.io.File;
9 import java.util.List;
10
11 import javax.sound.midi.Sequencer;
12 import javax.swing.AbstractAction;
13 import javax.swing.Action;
14 import javax.swing.Box;
15 import javax.swing.BoxLayout;
16 import javax.swing.Icon;
17 import javax.swing.JButton;
18 import javax.swing.JCheckBox;
19 import javax.swing.JComboBox;
20 import javax.swing.JDialog;
21 import javax.swing.JLabel;
22 import javax.swing.JOptionPane;
23 import javax.swing.JPanel;
24 import javax.swing.JScrollPane;
25 import javax.swing.JSplitPane;
26 import javax.swing.TransferHandler;
27 import javax.swing.border.EtchedBorder;
28
29 import camidion.chordhelper.ButtonIcon;
30 import camidion.chordhelper.ChordHelperApplet;
31 import camidion.chordhelper.mididevice.MidiSequencerModel;
32 import camidion.chordhelper.mididevice.VirtualMidiDevice;
33
34 /**
35  * MIDIエディタ(MIDI Editor/Playlist for MIDI Chord Helper)
36  *
37  * @author
38  *      Copyright (C) 2006-2017 Akiyoshi Kamide
39  *      http://www.yk.rim.or.jp/~kamide/music/chordhelper/
40  */
41 public class MidiSequenceEditorDialog extends JDialog {
42         /**
43          * このダイアログを開きます。表示されていなければ表示し、すでに表示されていたら最前面に移動します。
44          */
45         public void open() { if( isVisible() ) toFront(); else setVisible(true); }
46         /**
47          * このダイアログを表示するボタン用アクション
48          */
49         public final Action openAction = new AbstractAction("Edit/Playlist/Speed", new ButtonIcon(ButtonIcon.EDIT_ICON)) {
50                 {
51                         String tooltip = "MIDIシーケンスの編集/プレイリスト/再生速度調整";
52                         putValue(Action.SHORT_DESCRIPTION, tooltip);
53                 }
54                 @Override
55                 public void actionPerformed(ActionEvent e) { open(); }
56         };
57         /**
58          * ドロップされた複数のMIDIファイルを読み込むハンドラー
59          */
60         public final TransferHandler transferHandler = new TransferHandler() {
61                 @Override
62                 public boolean canImport(TransferSupport support) {
63                         return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
64                 }
65                 @SuppressWarnings("unchecked")
66                 @Override
67                 public boolean importData(TransferSupport support) {
68                         try {
69                                 Object data = support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
70                                 play((List<File>)data);
71                                 return true;
72                         } catch (Exception ex) {
73                                 JOptionPane.showMessageDialog(
74                                                 MidiSequenceEditorDialog.this, ex,
75                                                 ChordHelperApplet.VersionInfo.NAME,
76                                                 JOptionPane.ERROR_MESSAGE);
77                                 return false;
78                         }
79                 }
80         };
81         /**
82          * プレイリストビュー(シーケンスリスト)
83          */
84         public PlaylistTable playlistTable;
85         /**
86          * このエディタダイアログが表示しているプレイリストモデルを返します。
87          * @return プレイリストモデル
88          */
89         public PlaylistTableModel getPlaylistModel() {
90                 return playlistTable.getModel();
91         }
92         /**
93          * 指定されたリストに格納されたMIDIファイルを読み込んで再生します。
94          * すでに再生されていた場合、このエディタダイアログを表示します。
95          * @param fileList 読み込むMIDIファイルのリスト
96          */
97         public void play(List<File> fileList) {
98                 play(playlistTable.add(fileList));
99         }
100         /**
101          * 指定されたインデックス値(先頭が0)のMIDIシーケンスから再生します。
102          * すでに再生されていた場合、このエディタダイアログを表示します。
103          * @param index プレイリスト内にあるMIDIシーケンスのインデックス値
104          */
105         public void play(int index) {
106                 try {
107                         PlaylistTableModel playlist = getPlaylistModel();
108                         MidiSequencerModel sequencerModel = playlist.getSequencerModel();
109                         if( sequencerModel.getSequencer().isRunning() ) { open(); return; }
110                         if( index >= 0 ) playlist.play(index);
111                 } catch (Exception e) {
112                         JOptionPane.showMessageDialog(this, e, ChordHelperApplet.VersionInfo.NAME, JOptionPane.ERROR_MESSAGE);
113                 }
114         }
115
116         static final Icon deleteIcon = new ButtonIcon(ButtonIcon.X_ICON);
117         /**
118          * 新しいMIDIシーケンスを生成するダイアログ
119          */
120         public NewSequenceDialog newSequenceDialog;
121         /**
122          * 新しい {@link MidiSequenceEditorDialog} を構築します。
123          * @param playlistTableModel このエディタが参照するプレイリストモデル
124          * @param eventDialog MIDIイベント入力ダイアログ
125          * @param outputMidiDevice イベントテーブルの操作音出力先MIDIデバイス
126          * @param midiDeviceDialogOpenAction MIDIデバイスダイアログを開くアクション
127          */
128         public MidiSequenceEditorDialog(PlaylistTableModel playlistTableModel, MidiEventDialog eventDialog, VirtualMidiDevice outputMidiDevice, Action midiDeviceDialogOpenAction) {
129                 MidiEventTable eventListTable = new MidiEventTable(playlistTableModel.emptyEventListTableModel, eventDialog, outputMidiDevice);
130                 SequenceTrackListTable trackListTable = new SequenceTrackListTable(playlistTableModel.emptyTrackListTableModel, eventListTable);
131                 playlistTable = new PlaylistTable(playlistTableModel, midiDeviceDialogOpenAction, trackListTable);
132                 newSequenceDialog = new NewSequenceDialog(playlistTableModel, outputMidiDevice);
133                 setTitle("MIDI Editor/Playlist - "+ChordHelperApplet.VersionInfo.NAME);
134                 setBounds( 150, 200, 900, 500 );
135                 setLayout(new FlowLayout());
136                 setTransferHandler(transferHandler);
137                 //
138                 // パネルレイアウト
139                 JPanel playlistPanel = new JPanel() {{
140                         JPanel playlistOperationPanel = new JPanel() {{
141                                 setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
142                                 add(Box.createRigidArea(new Dimension(10, 0)));
143                                 add(new JButton(newSequenceDialog.openAction) {
144                                         { setMargin(ChordHelperApplet.ZERO_INSETS); }
145                                 });
146                                 if( playlistTable.midiFileChooser != null ) {
147                                         add( Box.createRigidArea(new Dimension(5, 0)) );
148                                         add(new JButton(playlistTable.midiFileChooser.openMidiFileAction) {
149                                                 { setMargin(ChordHelperApplet.ZERO_INSETS); }
150                                         });
151                                 }
152                                 add(Box.createRigidArea(new Dimension(5, 0)));
153                                 add(new JButton(playlistTable.base64EncodeAction) {
154                                         { setMargin(ChordHelperApplet.ZERO_INSETS); }
155                                 });
156                                 add(Box.createRigidArea(new Dimension(5, 0)));
157                                 add(new JButton(playlistTableModel.getMoveToTopAction()) {
158                                         { setMargin(ChordHelperApplet.ZERO_INSETS); }
159                                 });
160                                 add(Box.createRigidArea(new Dimension(5, 0)));
161                                 add(new JButton(playlistTableModel.getMoveToBottomAction()) {
162                                         { setMargin(ChordHelperApplet.ZERO_INSETS); }
163                                 });
164                                 if( playlistTable.midiFileChooser != null ) {
165                                         add(Box.createRigidArea(new Dimension(5, 0)));
166                                         add(new JButton(playlistTable.midiFileChooser.saveMidiFileAction) {
167                                                 { setMargin(ChordHelperApplet.ZERO_INSETS); }
168                                         });
169                                 }
170                                 add( Box.createRigidArea(new Dimension(5, 0)) );
171                                 add(new JButton(playlistTable.deleteSequenceAction) {
172                                         { setMargin(ChordHelperApplet.ZERO_INSETS); }
173                                 });
174                                 add( Box.createRigidArea(new Dimension(5, 0)) );
175                                 add(new SequencerSpeedSlider(playlistTableModel.getSequencerModel().speedSliderModel));
176                                 add( Box.createRigidArea(new Dimension(5, 0)) );
177                                 add(new JPanel() {{
178                                         setBorder(new EtchedBorder());
179                                         MidiSequencerModel sequencerModel = playlistTableModel.getSequencerModel();
180                                         add(new JLabel("Sync Master"));
181                                         add(new JComboBox<Sequencer.SyncMode>(sequencerModel.masterSyncModeModel));
182                                         add(new JLabel("Slave"));
183                                         add(new JComboBox<Sequencer.SyncMode>(sequencerModel.slaveSyncModeModel));
184                                 }});
185                         }};
186                         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
187                         add(new JScrollPane(playlistTable));
188                         add(Box.createRigidArea(new Dimension(0, 10)));
189                         add(playlistOperationPanel);
190                         add(Box.createRigidArea(new Dimension(0, 10)));
191                 }};
192                 JPanel trackListPanel = new JPanel() {{
193                         JPanel trackListOperationPanel = new JPanel() {{
194                                 add(new JButton(trackListTable.addTrackAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
195                                 add(new JButton(trackListTable.deleteTrackAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
196                         }};
197                         setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
198                         add(trackListTable.titleLabel);
199                         add(Box.createRigidArea(new Dimension(0, 5)));
200                         add(new JScrollPane(trackListTable));
201                         add(Box.createRigidArea(new Dimension(0, 5)));
202                         add(trackListOperationPanel);
203                 }};
204                 JPanel eventListPanel = new JPanel() {{
205                         JPanel eventListOperationPanel = new JPanel() {{
206                                 add(new JCheckBox("Pair NoteON/OFF") {{
207                                         setModel(eventListTable.pairNoteOnOffModel);
208                                         setToolTipText("NoteON/OFFをペアで同時選択する");
209                                 }});
210                                 add(new JButton(eventListTable.queryJumpEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
211                                 add(new JButton(eventListTable.queryAddEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
212                                 add(new JButton(eventListTable.copyEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
213                                 add(new JButton(eventListTable.cutEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
214                                 add(new JButton(eventListTable.queryPasteEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
215                                 add(new JButton(eventListTable.deleteEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
216                         }};
217                         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
218                         add(eventListTable.titleLabel);
219                         add(eventListTable.scrollPane);
220                         add(eventListOperationPanel);
221                 }};
222                 Container cp = getContentPane();
223                 cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
224                 cp.add(Box.createVerticalStrut(2));
225                 cp.add(
226                         new JSplitPane(JSplitPane.VERTICAL_SPLIT, playlistPanel,
227                                 new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, trackListPanel, eventListPanel) {{
228                                         setDividerLocation(300);
229                                 }}
230                         ) {{
231                                 setDividerLocation(160);
232                         }}
233                 );
234         }
235
236 }