OSDN Git Service

MIDIイベントテーブル、MIDIシーケンス自動生成時の
authorAkiyoshi Kamide <kamide@yk.rim.or.jp>
Tue, 24 May 2016 17:48:07 +0000 (02:48 +0900)
committerAkiyoshi Kamide <kamide@yk.rim.or.jp>
Tue, 24 May 2016 17:48:07 +0000 (02:48 +0900)
操作音出力デバイス名を変更

src/camidion/chordhelper/ChordHelperApplet.java
src/camidion/chordhelper/mididevice/MidiTransceiverListModelList.java
src/camidion/chordhelper/midieditor/MidiSequenceEditor.java
src/camidion/chordhelper/midieditor/NewSequenceDialog.java
src/camidion/chordhelper/midieditor/TempoSelecter.java
src/camidion/chordhelper/midieditor/TimeSignatureSelecter.java

index bc2bdbe..6984077 100644 (file)
@@ -289,7 +289,7 @@ public class ChordHelperApplet extends JApplet {
         */
        public static class VersionInfo {
                public static final String      NAME = "MIDI Chord Helper";
-               public static final String      VERSION = "Ver.20160520.1";
+               public static final String      VERSION = "Ver.20160524.1";
                public static final String      COPYRIGHT = "Copyright (C) 2004-2016";
                public static final String      AUTHER = "@きよし - Akiyoshi Kamide";
                public static final String      URL = "http://www.yk.rim.or.jp/~kamide/music/chordhelper/";
@@ -381,6 +381,8 @@ public class ChordHelperApplet extends JApplet {
         */
        public static final Insets ZERO_INSETS = new Insets(0,0,0,0);
        //
+       private static final String IMAGE_ICON_PATH = "midichordhelper.png";
+       //
        public ChordMatrix chordMatrix;
        MidiTransceiverListModelList    deviceModelList;
        //
@@ -406,16 +408,19 @@ public class ChordHelperApplet extends JApplet {
        private JToggleButton anoGakkiToggleButton;
 
        public void init() {
-               String imageIconPath = "midichordhelper.png";
-               URL imageIconUrl = getClass().getResource(imageIconPath);
+               //
+               // アイコンイメージの取得
+               URL imageIconUrl = getClass().getResource(IMAGE_ICON_PATH);
                if( imageIconUrl == null ) {
-                       System.out.println("Icon image "+imageIconPath+" not found");
+                       System.out.println("Icon image "+IMAGE_ICON_PATH+" not found");
                }
                else {
-                       imageIcon = new ImageIcon(imageIconUrl);
-                       iconImage = imageIcon.getImage();
+                       iconImage = (imageIcon = new ImageIcon(imageIconUrl)).getImage();
                }
+               // 背景色の取得
                rootPaneDefaultBgcolor = getContentPane().getBackground();
+               //
+               // コードボタンとピアノ鍵盤のセットアップ
                chordMatrix = new ChordMatrix() {{
                        addChordMatrixListener(new ChordMatrixListener(){
                                public void keySignatureChanged() {
@@ -463,12 +468,14 @@ public class ChordHelperApplet extends JApplet {
                        );
                        keyboardCenterPanel.keyboard.setPreferredSize(new Dimension(571, 80));
                }};
+               // MIDIデバイスのセットアップ
                deviceModelList = new MidiTransceiverListModelList(
                        Arrays.asList(keyboardPanel.keyboardCenterPanel.keyboard.midiDevice)
                );
-               deviceModelList.getEditorDialog().setIconImage(iconImage);
-               new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, deviceModelList.getEditorDialog().dropTargetListener, true);
-               keyboardPanel.setEventDialog(deviceModelList.getEditorDialog().eventDialog);
+               MidiSequenceEditor midiEditor = deviceModelList.getEditorDialog();
+               midiEditor.setIconImage(iconImage);
+               new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, midiEditor.dropTargetListener, true);
+               keyboardPanel.setEventDialog(midiEditor.eventDialog);
                (midiDeviceDialog = new MidiDeviceDialog(deviceModelList)).setIconImage(iconImage);
                lyricDisplay = new ChordTextField(deviceModelList.getSequencerModel()) {{
                        addActionListener(new ActionListener() {
@@ -482,43 +489,39 @@ public class ChordHelperApplet extends JApplet {
                lyricDisplayDefaultBorder = lyricDisplay.getBorder();
                lyricDisplayDefaultBgcolor = lyricDisplay.getBackground();
                chordDiagram = new ChordDiagram(this);
-               tempoSelecter = new TempoSelecter() {{
-                       setEditable(false);
-                       deviceModelList.getSequencerModel().getSequencer().addMetaEventListener(this);
-               }};
-               timesigSelecter = new TimeSignatureSelecter() {{
-                       setEditable(false);
-                       deviceModelList.getSequencerModel().getSequencer().addMetaEventListener(this);
-               }};
+               Sequencer sequencer = deviceModelList.getSequencerModel().getSequencer();
+               sequencer.addMetaEventListener(tempoSelecter = new TempoSelecter() {{ setEditable(false); }});
+               sequencer.addMetaEventListener(timesigSelecter = new TimeSignatureSelecter() {{ setEditable(false); }});
                keysigLabel = new KeySignatureLabel() {{
                        addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent e) { chordMatrix.setKeySignature(getKey()); }
                        });
                }};
-               deviceModelList.getSequencerModel().getSequencer().addMetaEventListener(
+               sequencer.addMetaEventListener(
                        new MetaEventListener() {
-                               class SetKeySignatureRunnable implements Runnable {
-                                       Key key;
-                                       public SetKeySignatureRunnable(Key key) { this.key = key; }
-                                       @Override
-                                       public void run() { setKeySignature(key); }
-                               }
+                               private Key key;
                                @Override
                                public void meta(MetaMessage msg) {
                                        switch(msg.getType()) {
                                        case 0x59: // Key signature (2 bytes) : 調号
-                                               Key key = new Key(msg.getData());
-                                               if( ! SwingUtilities.isEventDispatchThread() ) {
-                                                       SwingUtilities.invokeLater(new SetKeySignatureRunnable(key));
+                                               key = new Key(msg.getData());
+                                               if( SwingUtilities.isEventDispatchThread() ) {
+                                                       keysigLabel.setKeySignature(key);
+                                                       chordMatrix.setKeySignature(key);
+                                               } else {
+                                                       // MIDIシーケンサのスレッドから呼ばれた場合、GUI更新は自分で行わず、
+                                                       // AWTイベントディスパッチスレッドに依頼する。
+                                                       SwingUtilities.invokeLater(new Runnable() {
+                                                               @Override
+                                                               public void run() {
+                                                                       keysigLabel.setKeySignature(key);
+                                                                       chordMatrix.setKeySignature(key);
+                                                               }
+                                                       });
                                                }
-                                               setKeySignature(key);
                                                break;
                                        }
                                }
-                               private void setKeySignature(Key key) {
-                                       keysigLabel.setKeySignature(key);
-                                       chordMatrix.setKeySignature(key);
-                               }
                        }
                );
                songTitleLabel = new JLabel();
index 8c12cc9..35a83fa 100644 (file)
@@ -11,6 +11,7 @@ import javax.sound.midi.Synthesizer;
 
 import camidion.chordhelper.ChordHelperApplet;
 import camidion.chordhelper.midieditor.MidiSequenceEditor;
+import camidion.chordhelper.midieditor.PlaylistTableModel;
 
 /**
  * 仮想MIDIデバイスを含めたすべてのMIDIデバイスモデル {@link MidiTransceiverListModel} を収容するリスト
@@ -42,9 +43,9 @@ public class MidiTransceiverListModelList extends Vector<MidiTransceiverListMode
                        e.printStackTrace();
                }
                // MIDIエディタの生成
-               editorDialog = new MidiSequenceEditor(sequencerModel);
-               MidiTransceiverListModel editorDialogModel;
-               addElement(editorDialogModel = new MidiTransceiverListModel(editorDialog.getVirtualMidiDevice(), this));
+               editorDialog = new MidiSequenceEditor(new PlaylistTableModel(sequencerModel));
+               MidiTransceiverListModel eventTableDeviceModel;
+               addElement(eventTableDeviceModel = new MidiTransceiverListModel(editorDialog.getEventTableMidiDevice(), this));
                MidiTransceiverListModel synthModel = null;
                MidiTransceiverListModel firstMidiInModel = null;
                MidiTransceiverListModel firstMidiOutModel = null;
@@ -94,7 +95,7 @@ public class MidiTransceiverListModelList extends Vector<MidiTransceiverListMode
                                firstMidiOutModel,
                                sequencerModel,
                                firstMidiInModel,
-                               editorDialogModel,
+                               eventTableDeviceModel,
                        };
                        for( MidiTransceiverListModel m : openModels ) if( m != null ) {
                                m.getMidiDevice().open();
@@ -126,9 +127,9 @@ public class MidiTransceiverListModelList extends Vector<MidiTransceiverListMode
                        sequencerModel.connectToReceiverOf(synthModel);
                        sequencerModel.connectToReceiverOf(firstMidiOutModel);
                }
-               if( editorDialogModel != null ) {
-                       editorDialogModel.connectToReceiverOf(synthModel);
-                       editorDialogModel.connectToReceiverOf(firstMidiOutModel);
+               if( eventTableDeviceModel != null ) {
+                       eventTableDeviceModel.connectToReceiverOf(synthModel);
+                       eventTableDeviceModel.connectToReceiverOf(firstMidiOutModel);
                }
        }
 }
\ No newline at end of file
index 3b5aa6a..c127a87 100644 (file)
@@ -98,24 +98,9 @@ public class MidiSequenceEditor extends JDialog {
        };
 
        /**
-        * ã\81\93ã\81®MIDIã\82¨ã\83\87ã\82£ã\82¿ã\81«ã\81\8aã\81\91ã\82\8bæ\93\8dä½\9cé\9f³ã\81®å\87ºå\8a\9bå\85\88ã\81¨ã\81ªã\82\8bä»®æ\83³MIDIデバイスを返します。
+        * ã\82¤ã\83\99ã\83³ã\83\88ã\83ªã\82¹ã\83\88æ\93\8dä½\9cé\9f³å\87ºå\8a\9bå\85\88MIDIデバイスを返します。
         */
-       public VirtualMidiDevice getVirtualMidiDevice() { return virtualMidiDevice; }
-       private static VirtualMidiDevice virtualMidiDevice = new AbstractVirtualMidiDevice() {
-               {
-                       info = new MyInfo();
-                       setMaxReceivers(0); // 送信専用とする(MIDI IN はサポートしない)
-               }
-               /**
-                * MIDIデバイス情報
-                */
-               protected MyInfo info;
-               @Override
-               public Info getDeviceInfo() { return info; }
-               class MyInfo extends Info {
-                       protected MyInfo() { super("MIDI Editor","Unknown vendor","MIDI sequence editor",""); }
-               }
-       };
+       public VirtualMidiDevice getEventTableMidiDevice() { return eventListTable.outputMidiDevice; }
 
        /**
         * エラーメッセージダイアログを表示します。
@@ -215,7 +200,7 @@ public class MidiSequenceEditor extends JDialog {
        /**
         * 新しいMIDIシーケンスを生成するダイアログ
         */
-       public NewSequenceDialog newSequenceDialog = new NewSequenceDialog(this);
+       public NewSequenceDialog newSequenceDialog;
        /**
         * BASE64テキスト入力ダイアログ
         */
@@ -663,6 +648,21 @@ public class MidiSequenceEditor extends JDialog {
         * MIDIイベントリストテーブルビュー(選択中のトラックの中身)
         */
        public class EventListTable extends JTable {
+               private VirtualMidiDevice outputMidiDevice = new AbstractVirtualMidiDevice() {
+                       {
+                               info = new MyInfo();
+                               setMaxReceivers(0); // 送信専用とする(MIDI IN はサポートしない)
+                       }
+                       /**
+                        * MIDIデバイス情報
+                        */
+                       protected MyInfo info;
+                       @Override
+                       public Info getDeviceInfo() { return info; }
+                       class MyInfo extends Info {
+                               protected MyInfo() { super("MIDI Event Table Editor","Unknown vendor","MIDI event table editor",""); }
+                       }
+               };
                /**
                 * 新しいイベントリストテーブルを構築します。
                 * <p>データモデルとして一つのトラックのイベントリストを指定できます。
@@ -772,7 +772,7 @@ public class MidiSequenceEditor extends JDialog {
                                                        int cmd = sm.getCommand();
                                                        if( cmd == 0x80 || cmd == 0x90 || cmd == 0xA0 ) {
                                                                // ノート番号を持つ場合、音を鳴らす。
-                                                               MidiChannel outMidiChannels[] = virtualMidiDevice.getChannels();
+                                                               MidiChannel outMidiChannels[] = outputMidiDevice.getChannels();
                                                                int ch = sm.getChannel();
                                                                int note = sm.getData1();
                                                                int vel = sm.getData2();
@@ -1051,7 +1051,7 @@ public class MidiSequenceEditor extends JDialog {
                         * MIDIイベントセルエディタを構築します。
                         */
                        public MidiEventCellEditor() {
-                               eventDialog.midiMessageForm.setOutputMidiChannels(virtualMidiDevice.getChannels());
+                               eventDialog.midiMessageForm.setOutputMidiChannels(outputMidiDevice.getChannels());
                                eventDialog.tickPositionInputForm.setModel(editContext.tickPositionModel);
                                int index = TrackEventListTableModel.Column.MESSAGE.ordinal();
                                getColumnModel().getColumn(index).setCellEditor(this);
@@ -1135,14 +1135,15 @@ public class MidiSequenceEditor extends JDialog {
 
        /**
         * 新しい {@link MidiSequenceEditor} を構築します。
-        * @param sequencerModel シーケンサーモデル
+        * @param playlistTableModel このエディタが参照するプレイリストモデル
         */
-       public MidiSequenceEditor(MidiSequencerModel sequencerModel) {
-               sequenceListTable = new SequenceListTable(new PlaylistTableModel(sequencerModel));
+       public MidiSequenceEditor(PlaylistTableModel playlistTableModel) {
+               sequenceListTable = new SequenceListTable(playlistTableModel);
                trackListTable = new TrackListTable(
                        new SequenceTrackListTableModel(sequenceListTable.getModel(), null, null)
                );
                eventListTable = new EventListTable(new TrackEventListTableModel(trackListTable.getModel(), null));
+               newSequenceDialog = new NewSequenceDialog(playlistTableModel, eventListTable.outputMidiDevice);
                setTitle("MIDI Editor/Playlist - MIDI Chord Helper");
                setBounds( 150, 200, 900, 500 );
                setLayout(new FlowLayout());
index 6e0a187..73f4253 100644 (file)
@@ -40,6 +40,7 @@ import javax.swing.event.ChangeListener;
 
 import camidion.chordhelper.ButtonIcon;
 import camidion.chordhelper.ChordHelperApplet;
+import camidion.chordhelper.mididevice.VirtualMidiDevice;
 import camidion.chordhelper.music.AbstractNoteTrackSpec;
 import camidion.chordhelper.music.ChordProgression;
 import camidion.chordhelper.music.DrumTrackSpec;
@@ -93,7 +94,7 @@ public class NewSequenceDialog extends JDialog {
                @Override
                public void actionPerformed(ActionEvent e) { setVisible(true); }
        };
-       private MidiSequenceEditor midiEditor;
+       private PlaylistTableModel playlist;
        /**
         * MIDIシーケンス生成アクション
         */
@@ -103,17 +104,18 @@ public class NewSequenceDialog extends JDialog {
        ) {
                @Override
                public void actionPerformed(ActionEvent e) {
-                       midiEditor.sequenceListTable.getModel().addSequenceAndPlay(getMidiSequence());
+                       playlist.addSequenceAndPlay(getMidiSequence());
                        NewSequenceDialog.this.setVisible(false);
                }
        };
        /**
         * 新しいMIDIシーケンスを生成するダイアログを構築します。
-        * @param midiEditor シーケンス追加先エディタ
+        * @param playlist シーケンス追加先プレイリスト
+        * @param midiOutDevice 操作音を出力するMIDI出力デバイス
         */
-       public NewSequenceDialog(MidiSequenceEditor midiEditor) {
-               this.midiEditor = midiEditor;
-               trackSpecPanel.setChannels(midiEditor.getVirtualMidiDevice().getChannels());
+       public NewSequenceDialog(PlaylistTableModel playlist, VirtualMidiDevice midiOutDevice) {
+               this.playlist = playlist;
+               trackSpecPanel.setChannels(midiOutDevice.getChannels());
                setTitle("Generate new sequence - " + ChordHelperApplet.VersionInfo.NAME);
                add(new JTabbedPane() {{
                        add("Sequence", new JPanel() {{
index 2af643b..aee1957 100644 (file)
@@ -54,11 +54,11 @@ public class TempoSelecter extends JPanel implements MouseListener, MetaEventLis
        public void meta(MetaMessage msg) {
                switch(msg.getType()) {
                case 0x51: // Tempo (3 bytes) - テンポ
-                       if( ! SwingUtilities.isEventDispatchThread() ) {
+                       if( SwingUtilities.isEventDispatchThread() ) {
+                               setTempo(msg.getData());
+                       } else {
                                SwingUtilities.invokeLater(new SetTempoRunnable(msg.getData()));
-                               break;
                        }
-                       setTempo(msg.getData());
                        break;
                }
        }
index c1d14ac..57f96be 100644 (file)
@@ -29,20 +29,20 @@ public class TimeSignatureSelecter extends JPanel implements MetaEventListener {
                }
        };
        private class SetValueRunnable implements Runnable {
-               byte[] qpm;
-               public SetValueRunnable(byte[] qpm) { this.qpm = qpm; }
+               byte[] timesig;
+               public SetValueRunnable(byte[] timesig) { this.timesig = timesig; }
                @Override
-               public void run() { setValue(qpm);}
+               public void run() { setValue(timesig);}
        }
        @Override
        public void meta(MetaMessage msg) {
                switch(msg.getType()) {
                case 0x58: // Time signature (4 bytes) - 拍子
-                       if( ! SwingUtilities.isEventDispatchThread() ) {
+                       if( SwingUtilities.isEventDispatchThread() ) {
+                               setValue(msg.getData());
+                       } else {
                                SwingUtilities.invokeLater(new SetValueRunnable(msg.getData()));
-                               break;
                        }
-                       setValue(msg.getData());
                        break;
                }
        }