OSDN Git Service

[BUGFIX] 起動時、開くのに失敗したMIDIデバイスが一つでもあると、画面が一切表示されなくなる問題を修正
authorAkiyoshi Kamide <kamide@yk.rim.or.jp>
Sat, 4 Mar 2017 16:20:49 +0000 (01:20 +0900)
committerAkiyoshi Kamide <kamide@yk.rim.or.jp>
Sat, 4 Mar 2017 16:20:49 +0000 (01:20 +0900)
src/camidion/chordhelper/ChordHelperApplet.java
src/camidion/chordhelper/mididevice/MidiDeviceDesktopPane.java
src/camidion/chordhelper/mididevice/MidiDeviceTreeModel.java

index 150ec63..8dca4d0 100644 (file)
@@ -283,7 +283,7 @@ public class ChordHelperApplet extends JApplet {
         */
        public static class VersionInfo {
                public static final String NAME = "MIDI Chord Helper";
-               public static final String VERSION = "Ver.20170112.1";
+               public static final String VERSION = "Ver.20170304.1";
                public static final String COPYRIGHT = "Copyright (C) 2004-2017";
                public static final String AUTHER = "@きよし - Akiyoshi Kamide";
                public static final String URL = "http://www.yk.rim.or.jp/~kamide/music/chordhelper/";
index afc9c2c..045b772 100644 (file)
@@ -21,6 +21,8 @@ import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
 import javax.swing.tree.TreePath;
 
+import camidion.chordhelper.ChordHelperApplet;
+
 /**
  * 開いているMIDIデバイスを置くためのデスクトップビュー
  */
@@ -201,9 +203,10 @@ public class MidiDeviceDesktopPane extends JDesktopPane implements TreeSelection
                                        //   例えば、「Microsort MIDI マッパー」と「Microsoft GS Wavetable SW Synth」は
                                        //   連動して開かれるため、同時に開こうとすると、ここにたどり着く。
                                        //
-                                       String title = "Cannot open MIDI device";
-                                       String message = "MIDIデバイス "+deviceModel+" はすでに使用中です。\n"
-                                               +"他のデバイスが連動して開いている可能性があります。\n\n"
+                                       String title = ChordHelperApplet.VersionInfo.NAME;
+                                       String message = "Cannot open MIDI device '"+deviceModel+"'"
+                                                       + "\nMIDIデバイス "+deviceModel+" を開くことができません。\n"
+                                               +"すでに他のデバイスが連動して開いている可能性があります。\n\n"
                                                + e.getMessage();
                                        JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
                                } catch (Exception ex) {
index 97f8dbb..2411c8e 100644 (file)
@@ -18,6 +18,7 @@ import javax.sound.midi.Receiver;
 import javax.sound.midi.Sequencer;
 import javax.sound.midi.Synthesizer;
 import javax.sound.midi.Transmitter;
+import javax.swing.JOptionPane;
 import javax.swing.event.EventListenerList;
 import javax.swing.event.TreeModelEvent;
 import javax.swing.event.TreeModelListener;
@@ -132,22 +133,6 @@ public class MidiDeviceTreeModel extends AbstractList<MidiDeviceModel> implement
        }
 
        /**
-        * 指定されたMIDIデバイスモデルをまとめて開きます。
-        *
-        * @param toOpenList 開きたいMIDIデバイスモデルのコレクション
-        */
-       public void openDevices(Collection<MidiDeviceModel> toOpenList) {
-               for( MidiDeviceModel toOpen : toOpenList ) {
-                       try {
-                               toOpen.open();
-                       } catch( MidiUnavailableException ex ) {
-                               System.out.println("Cannot open MIDI device " + toOpen);
-                               ex.printStackTrace();
-                       }
-               }
-       }
-
-       /**
         * このMIDIデバイスツリーモデルに登録されているMIDIシーケンサーモデルを返します。
         * @return MIDIシーケンサーモデル
         */
@@ -201,7 +186,7 @@ public class MidiDeviceTreeModel extends AbstractList<MidiDeviceModel> implement
                        //
                        addInternally(m);
                }
-               // 開くMIDIデバイスモデルの一覧を作成
+               // MIDIデバイスモデルを開く
                //
                //   NOTE: 必ず MIDI OUT Rx デバイスを先に開くこと。
                //
@@ -211,21 +196,29 @@ public class MidiDeviceTreeModel extends AbstractList<MidiDeviceModel> implement
                //
                //   開く順序が逆になると「進みすぎるから遅らせよう」として無用なレイテンシーが発生する原因になる。
                //
-               List<MidiDeviceModel> toOpenList = new ArrayList<>();
+               List<MidiDeviceModel> openedMidiDeviceModelList = new ArrayList<>();
                for( MidiDeviceModel toOpen : Arrays.asList(
                                synthModel, firstMidiOutModel, sequencerModel, guiModel, firstMidiInModel) ) {
-                       if( toOpen != null ) toOpenList.add(toOpen);
+                       if( toOpen == null ) continue;
+                       try {
+                               toOpen.open();
+                       } catch( MidiUnavailableException ex ) {
+                               String title = ChordHelperApplet.VersionInfo.NAME;
+                               String message = "Cannot open MIDI device '"+toOpen+"'\n"
+                                               + "MIDIデバイス "+toOpen+" を開くことができません。\n\n"
+                                               + ex.getMessage();
+                               JOptionPane.showMessageDialog(null, message, title, JOptionPane.ERROR_MESSAGE);
+                               continue;
+                       }
+                       openedMidiDeviceModelList.add(toOpen);
                }
-               // MIDIデバイスモデルを開く
-               openDevices(toOpenList);
-               //
                // 初期接続マップを作成(開いたデバイスを相互に接続する)
                Map<MidiDeviceModel, Collection<MidiDeviceModel>> initialConnection = new LinkedHashMap<>();
-               for( MidiDeviceModel rxm : toOpenList ) {
+               for( MidiDeviceModel rxm : openedMidiDeviceModelList ) {
                        if( rxm.getReceiverListModel() == null ) continue;
                        List<MidiDeviceModel> txmList;
                        initialConnection.put(rxm, txmList = new ArrayList<>());
-                       for( MidiDeviceModel txm : toOpenList ) {
+                       for( MidiDeviceModel txm : openedMidiDeviceModelList ) {
                                if( txm.getTransmitterListModel() == null ) continue;
                                //
                                // Tx/Rx両方を持つデバイスでは