1 package camidion.chordhelper.midieditor;
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;
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;
29 import camidion.chordhelper.ButtonIcon;
30 import camidion.chordhelper.ChordHelperApplet;
31 import camidion.chordhelper.mididevice.MidiSequencerModel;
32 import camidion.chordhelper.mididevice.VirtualMidiDevice;
35 * MIDIエディタ(MIDI Editor/Playlist for MIDI Chord Helper)
38 * Copyright (C) 2006-2017 Akiyoshi Kamide
39 * http://www.yk.rim.or.jp/~kamide/music/chordhelper/
41 public class MidiSequenceEditorDialog extends JDialog {
43 * このダイアログを開きます。表示されていなければ表示し、すでに表示されていたら最前面に移動します。
45 public void open() { if( isVisible() ) toFront(); else setVisible(true); }
47 * このダイアログを表示するボタン用アクション
49 public final Action openAction = new AbstractAction("Edit/Playlist/Speed", new ButtonIcon(ButtonIcon.EDIT_ICON)) {
51 String tooltip = "MIDIシーケンスの編集/プレイリスト/再生速度調整";
52 putValue(Action.SHORT_DESCRIPTION, tooltip);
55 public void actionPerformed(ActionEvent e) { open(); }
58 * ドロップされた複数のMIDIファイルを読み込むハンドラー
60 public final TransferHandler transferHandler = new TransferHandler() {
62 public boolean canImport(TransferSupport support) {
63 return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor);
65 @SuppressWarnings("unchecked")
67 public boolean importData(TransferSupport support) {
69 Object data = support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
70 play((List<File>)data);
72 } catch (Exception ex) {
73 JOptionPane.showMessageDialog(
74 MidiSequenceEditorDialog.this, ex,
75 ChordHelperApplet.VersionInfo.NAME,
76 JOptionPane.ERROR_MESSAGE);
82 * このエディタダイアログが表示しているプレイリストモデルを返します。
85 public PlaylistTableModel getPlaylistModel() {
86 return playlistTable.getModel();
89 * 指定されたリストに格納されたMIDIファイルを読み込んで再生します。
90 * すでに再生されていた場合、このエディタダイアログを表示します。
91 * @param fileList 読み込むMIDIファイルのリスト
93 public void play(List<File> fileList) {
94 play(playlistTable.add(fileList));
97 * 指定されたインデックス値(先頭が0)のMIDIシーケンスから再生します。
98 * すでに再生されていた場合、このエディタダイアログを表示します。
99 * @param index プレイリスト内にあるMIDIシーケンスのインデックス値
101 public void play(int index) {
103 PlaylistTableModel playlist = getPlaylistModel();
104 MidiSequencerModel sequencerModel = playlist.getSequencerModel();
105 if( sequencerModel.getSequencer().isRunning() ) { open(); return; }
106 if( index >= 0 ) playlist.play(index);
107 } catch (Exception e) {
108 JOptionPane.showMessageDialog(this, e, ChordHelperApplet.VersionInfo.NAME, JOptionPane.ERROR_MESSAGE);
112 static final Icon deleteIcon = new ButtonIcon(ButtonIcon.X_ICON);
114 * 新しいMIDIシーケンスを生成するダイアログ
116 public NewSequenceDialog newSequenceDialog;
118 * プレイリストビュー(シーケンスリスト)
120 public PlaylistTable playlistTable;
122 * 新しい {@link MidiSequenceEditorDialog} を構築します。
123 * @param playlistTableModel このエディタが参照するプレイリストモデル
124 * @param eventDialog MIDIイベント入力ダイアログ
125 * @param outputMidiDevice イベントテーブルの操作音出力先MIDIデバイス
126 * @param midiDeviceDialogOpenAction MIDIデバイスダイアログを開くアクション
128 public MidiSequenceEditorDialog(PlaylistTableModel playlistTableModel, MidiEventDialog eventDialog, VirtualMidiDevice outputMidiDevice, Action midiDeviceDialogOpenAction) {
129 playlistTable = new PlaylistTable(playlistTableModel, midiDeviceDialogOpenAction);
130 MidiEventTable eventListTable = new MidiEventTable(playlistTableModel.emptyEventListTableModel, eventDialog, outputMidiDevice);
131 SequenceTrackListTable trackListTable = new SequenceTrackListTable(playlistTableModel.emptyTrackListTableModel, eventListTable);
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);
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); }
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); }
152 if(playlistTable.base64EncodeAction != null) {
153 add(Box.createRigidArea(new Dimension(5, 0)));
154 add(new JButton(playlistTable.base64EncodeAction) {
155 { setMargin(ChordHelperApplet.ZERO_INSETS); }
158 add(Box.createRigidArea(new Dimension(5, 0)));
159 add(new JButton(playlistTableModel.getMoveToTopAction()) {
160 { setMargin(ChordHelperApplet.ZERO_INSETS); }
162 add(Box.createRigidArea(new Dimension(5, 0)));
163 add(new JButton(playlistTableModel.getMoveToBottomAction()) {
164 { setMargin(ChordHelperApplet.ZERO_INSETS); }
166 if( playlistTable.midiFileChooser != null ) {
167 add(Box.createRigidArea(new Dimension(5, 0)));
168 add(new JButton(playlistTable.midiFileChooser.saveMidiFileAction) {
169 { setMargin(ChordHelperApplet.ZERO_INSETS); }
172 add( Box.createRigidArea(new Dimension(5, 0)) );
173 add(new JButton(playlistTable.deleteSequenceAction) {
174 { setMargin(ChordHelperApplet.ZERO_INSETS); }
176 add( Box.createRigidArea(new Dimension(5, 0)) );
177 add(new SequencerSpeedSlider(playlistTableModel.getSequencerModel().speedSliderModel));
178 add( Box.createRigidArea(new Dimension(5, 0)) );
180 setBorder(new EtchedBorder());
181 MidiSequencerModel sequencerModel = playlistTableModel.getSequencerModel();
182 add(new JLabel("Sync Master"));
183 add(new JComboBox<Sequencer.SyncMode>(sequencerModel.masterSyncModeModel));
184 add(new JLabel("Slave"));
185 add(new JComboBox<Sequencer.SyncMode>(sequencerModel.slaveSyncModeModel));
188 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
189 add(new JScrollPane(playlistTable));
190 add(Box.createRigidArea(new Dimension(0, 10)));
191 add(playlistOperationPanel);
192 add(Box.createRigidArea(new Dimension(0, 10)));
194 JPanel trackListPanel = new JPanel() {{
195 JPanel trackListOperationPanel = new JPanel() {{
196 add(new JButton(trackListTable.addTrackAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
197 add(new JButton(trackListTable.deleteTrackAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
199 setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
200 add(trackListTable.titleLabel);
201 add(Box.createRigidArea(new Dimension(0, 5)));
202 add(new JScrollPane(trackListTable));
203 add(Box.createRigidArea(new Dimension(0, 5)));
204 add(trackListOperationPanel);
206 JPanel eventListPanel = new JPanel() {{
207 JPanel eventListOperationPanel = new JPanel() {{
208 add(new JCheckBox("Pair NoteON/OFF") {{
209 setModel(eventListTable.pairNoteOnOffModel);
210 setToolTipText("NoteON/OFFをペアで同時選択する");
212 add(new JButton(eventListTable.queryJumpEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
213 add(new JButton(eventListTable.queryAddEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
214 add(new JButton(eventListTable.copyEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
215 add(new JButton(eventListTable.cutEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
216 add(new JButton(eventListTable.queryPasteEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
217 add(new JButton(eventListTable.deleteEventAction) {{ setMargin(ChordHelperApplet.ZERO_INSETS); }});
219 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
220 add(eventListTable.titleLabel);
221 add(eventListTable.scrollPane);
222 add(eventListOperationPanel);
224 Container cp = getContentPane();
225 cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS));
226 cp.add(Box.createVerticalStrut(2));
228 new JSplitPane(JSplitPane.VERTICAL_SPLIT, playlistPanel,
229 new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, trackListPanel, eventListPanel) {{
230 setDividerLocation(300);
233 setDividerLocation(160);