From bff5d38d91f6599653a23c36d3d25803426cafbe Mon Sep 17 00:00:00 2001 From: Akiyoshi Kamide Date: Thu, 12 May 2016 01:47:51 +0900 Subject: [PATCH 1/1] =?utf8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?utf8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/camidion/chordhelper/ChordHelperApplet.java | 52 ++++++++------- src/camidion/chordhelper/MidiChordHelper.java | 4 +- .../chordhelper/mididevice/MidiCablePane.java | 18 +++--- .../chordhelper/mididevice/MidiSequencerModel.java | 22 +++---- .../mididevice/MidiTransceiverListModelList.java | 3 +- .../mididevice/MidiTransceiverListView.java | 2 +- .../mididevice/SequencerMeasureView.java | 73 +++++++++++----------- .../chordhelper/mididevice/SequencerTimeView.java | 64 +++++++++---------- 8 files changed, 117 insertions(+), 121 deletions(-) diff --git a/src/camidion/chordhelper/ChordHelperApplet.java b/src/camidion/chordhelper/ChordHelperApplet.java index 97f8455..e124716 100644 --- a/src/camidion/chordhelper/ChordHelperApplet.java +++ b/src/camidion/chordhelper/ChordHelperApplet.java @@ -62,6 +62,7 @@ import camidion.chordhelper.mididevice.SequencerTimeView; import camidion.chordhelper.mididevice.VirtualMidiDevice; import camidion.chordhelper.midieditor.Base64Dialog; import camidion.chordhelper.midieditor.KeySignatureLabel; +import camidion.chordhelper.midieditor.MidiSequenceEditor; import camidion.chordhelper.midieditor.SequenceTickIndex; import camidion.chordhelper.midieditor.SequenceTrackListTableModel; import camidion.chordhelper.midieditor.TempoSelecter; @@ -91,7 +92,7 @@ public class ChordHelperApplet extends JApplet { * @return 未保存の修正済み MIDI ファイルがあれば true */ public boolean isModified() { - return deviceModelList.editorDialog.sequenceListTable.getModel().isModified(); + return deviceModelList.getEditorDialog().sequenceListTable.getModel().isModified(); } /** * 指定された小節数の曲を、乱数で自動作曲してプレイリストへ追加します。 @@ -99,9 +100,9 @@ public class ChordHelperApplet extends JApplet { * @return 追加先のインデックス値(0から始まる)。追加できなかったときは -1 */ public int addRandomSongToPlaylist(int measureLength) { - deviceModelList.editorDialog.newSequenceDialog.setRandomChordProgression(measureLength); - Sequence sequence = deviceModelList.editorDialog.newSequenceDialog.getMidiSequence(); - return deviceModelList.editorDialog.sequenceListTable.getModel().addSequenceAndPlay(sequence); + deviceModelList.getEditorDialog().newSequenceDialog.setRandomChordProgression(measureLength); + Sequence sequence = deviceModelList.getEditorDialog().newSequenceDialog.getMidiSequence(); + return deviceModelList.getEditorDialog().sequenceListTable.getModel().addSequenceAndPlay(sequence); } /** * URLで指定されたMIDIファイルをプレイリストへ追加します。 @@ -113,13 +114,14 @@ public class ChordHelperApplet extends JApplet { * @return 追加先のインデックス値(0から始まる)。追加できなかったときは -1 */ public int addToPlaylist(String midiFileUrl) { + MidiSequenceEditor editor = deviceModelList.getEditorDialog(); try { - return deviceModelList.editorDialog.sequenceListTable.getModel().addSequenceFromURL(midiFileUrl); + return editor.sequenceListTable.getModel().addSequenceFromURL(midiFileUrl); } catch( URISyntaxException|IOException|InvalidMidiDataException e ) { - deviceModelList.editorDialog.showWarning(e.getMessage()); + editor.showWarning(e.getMessage()); } catch( AccessControlException e ) { e.printStackTrace(); - deviceModelList.editorDialog.showError(e.getMessage()); + editor.showError(e.getMessage()); } return -1; } @@ -141,13 +143,14 @@ public class ChordHelperApplet extends JApplet { * @return 追加先のインデックス値(0から始まる)。追加できなかったときは -1 */ public int addToPlaylistBase64(String base64EncodedText, String filename) { - Base64Dialog d = deviceModelList.editorDialog.base64Dialog; + MidiSequenceEditor editor = deviceModelList.getEditorDialog(); + Base64Dialog d = editor.base64Dialog; d.setBase64Data(base64EncodedText); try { - return deviceModelList.editorDialog.sequenceListTable.getModel().addSequence(d.getMIDIData(), filename); + return editor.sequenceListTable.getModel().addSequence(d.getMIDIData(), filename); } catch (IOException | InvalidMidiDataException e) { e.printStackTrace(); - deviceModelList.editorDialog.showWarning(e.getMessage()); + editor.showWarning(e.getMessage()); return -1; } } @@ -156,7 +159,7 @@ public class ChordHelperApplet extends JApplet { * シーケンサへロードして再生します。 */ public void play() { - play(deviceModelList.editorDialog.sequenceListTable.getModel().sequenceListSelectionModel.getMinSelectionIndex()); + play(deviceModelList.getEditorDialog().sequenceListTable.getModel().sequenceListSelectionModel.getMinSelectionIndex()); } /** * 指定されたインデックス値が示すプレイリスト上のMIDIシーケンスを、 @@ -164,7 +167,7 @@ public class ChordHelperApplet extends JApplet { * @param index インデックス値(0から始まる) */ public void play(int index) { - deviceModelList.editorDialog.sequenceListTable.getModel().loadToSequencer(index); + deviceModelList.getEditorDialog().sequenceListTable.getModel().loadToSequencer(index); deviceModelList.getSequencerModel().start(); } /** @@ -187,10 +190,11 @@ public class ChordHelperApplet extends JApplet { * @return MIDIデータをBase64テキストに変換した結果 */ public String getMidiDataBase64() { + MidiSequenceEditor editor = deviceModelList.getEditorDialog(); SequenceTrackListTableModel sequenceModel = - deviceModelList.editorDialog.sequenceListTable.getModel().sequencerModel.getSequenceTrackListTableModel(); - deviceModelList.editorDialog.base64Dialog.setMIDIData(sequenceModel.getMIDIdata()); - return deviceModelList.editorDialog.base64Dialog.getBase64Data(); + editor.sequenceListTable.getModel().sequencerModel.getSequenceTrackListTableModel(); + editor.base64Dialog.setMIDIData(sequenceModel.getMIDIdata()); + return editor.base64Dialog.getBase64Data(); } /** * 現在シーケンサにロードされているMIDIファイルのファイル名を返します。 @@ -284,7 +288,7 @@ public class ChordHelperApplet extends JApplet { */ public static class VersionInfo { public static final String NAME = "MIDI Chord Helper"; - public static final String VERSION = "Ver.20160510.1"; + public static final String VERSION = "Ver.20160511.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/"; @@ -465,9 +469,9 @@ public class ChordHelperApplet extends JApplet { } } ); - deviceModelList.editorDialog.setIconImage(iconImage); - new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, deviceModelList.editorDialog.dropTargetListener, true); - keyboardPanel.setEventDialog(deviceModelList.editorDialog.eventDialog); + deviceModelList.getEditorDialog().setIconImage(iconImage); + new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, deviceModelList.getEditorDialog().dropTargetListener, true); + keyboardPanel.setEventDialog(deviceModelList.getEditorDialog().eventDialog); midiConnectionDialog = new MidiDeviceDialog(deviceModelList); midiConnectionDialog.setIconImage(iconImage); lyricDisplay = new ChordTextField(deviceModelList.getSequencerModel()) {{ @@ -533,7 +537,7 @@ public class ChordHelperApplet extends JApplet { @Override public void stateChanged(ChangeEvent e) { SequenceTrackListTableModel sequenceTableModel = deviceModelList.getSequencerModel().getSequenceTrackListTableModel(); - int loadedSequenceIndex = deviceModelList.editorDialog.sequenceListTable.getModel().indexOfSequenceOnSequencer(); + int loadedSequenceIndex = deviceModelList.getEditorDialog().sequenceListTable.getModel().indexOfSequenceOnSequencer(); songTitleLabel.setText( ""+( loadedSequenceIndex < 0 ? "[No MIDI file loaded]" : @@ -665,7 +669,7 @@ public class ChordHelperApplet extends JApplet { add( Box.createHorizontalStrut(12) ); add( songTitleLabel ); add( Box.createHorizontalStrut(12) ); - add( new JButton(deviceModelList.editorDialog.openAction) {{ setMargin(ZERO_INSETS); }}); + add( new JButton(deviceModelList.getEditorDialog().openAction) {{ setMargin(ZERO_INSETS); }}); }}); add(new JPanel() {{ setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); @@ -673,7 +677,7 @@ public class ChordHelperApplet extends JApplet { add( new JSlider(deviceModelList.getSequencerModel()) ); add( new SequencerTimeView(deviceModelList.getSequencerModel()) ); add( Box.createHorizontalStrut(5) ); - add( new JButton(deviceModelList.editorDialog.sequenceListTable.getModel().moveToTopAction) {{ + add( new JButton(deviceModelList.getEditorDialog().sequenceListTable.getModel().moveToTopAction) {{ setMargin(ZERO_INSETS); }}); add(new JButton(deviceModelList.getSequencerModel().moveBackwardAction) {{ @@ -683,10 +687,10 @@ public class ChordHelperApplet extends JApplet { add(new JButton(deviceModelList.getSequencerModel().moveForwardAction) {{ setMargin(ZERO_INSETS); }}); - add(new JButton(deviceModelList.editorDialog.sequenceListTable.getModel().moveToBottomAction) {{ + add(new JButton(deviceModelList.getEditorDialog().sequenceListTable.getModel().moveToBottomAction) {{ setMargin(ZERO_INSETS); }}); - add(new JToggleButton(deviceModelList.editorDialog.sequenceListTable.getModel().toggleRepeatAction) {{ + add(new JToggleButton(deviceModelList.getEditorDialog().sequenceListTable.getModel().toggleRepeatAction) {{ setMargin(ZERO_INSETS); }}); add( Box.createHorizontalStrut(10) ); diff --git a/src/camidion/chordhelper/MidiChordHelper.java b/src/camidion/chordhelper/MidiChordHelper.java index e181fb6..c4ce3f1 100644 --- a/src/camidion/chordhelper/MidiChordHelper.java +++ b/src/camidion/chordhelper/MidiChordHelper.java @@ -64,7 +64,7 @@ public class MidiChordHelper { } else { frame = new AppletFrame(applet = new ChordHelperApplet()); } - applet.deviceModelList.editorDialog.loadAndPlay(fileList); + applet.deviceModelList.getEditorDialog().loadAndPlay(fileList); } }); } @@ -108,7 +108,7 @@ public class MidiChordHelper { * @param applet 対象アプレット */ public TitleUpdater(ChordHelperApplet applet) { - applet.deviceModelList.editorDialog.sequenceListTable.getModel().addTableModelListener(this); + applet.deviceModelList.getEditorDialog().sequenceListTable.getModel().addTableModelListener(this); sequencerModel = applet.deviceModelList.getSequencerModel(); sequencerModel.addChangeListener(this); } diff --git a/src/camidion/chordhelper/mididevice/MidiCablePane.java b/src/camidion/chordhelper/mididevice/MidiCablePane.java index 61d3ec1..d9d6536 100644 --- a/src/camidion/chordhelper/mididevice/MidiCablePane.java +++ b/src/camidion/chordhelper/mididevice/MidiCablePane.java @@ -31,21 +31,19 @@ import javax.swing.event.ListDataListener; /** * MIDI ケーブル描画面 */ -public class MidiCablePane extends JComponent { +public class MidiCablePane extends JComponent implements DragSourceMotionListener { private Point draggingPoint; /** * {@link MidiTransceiverListModel} の {@link Transmitter} * をドラッグしている最中に再描画するためのリスナー */ - public final DragSourceMotionListener midiConnecterMotionListener = new DragSourceMotionListener() { - @Override - public void dragMouseMoved(DragSourceDragEvent dsde) { - Point origin = MidiCablePane.this.getLocationOnScreen(); - draggingPoint = dsde.getLocation(); - draggingPoint.translate(-origin.x, -origin.y); - repaint(); - } - }; + @Override + public void dragMouseMoved(DragSourceDragEvent dsde) { + Point origin = getLocationOnScreen(); + draggingPoint = dsde.getLocation(); + draggingPoint.translate(-origin.x, -origin.y); + repaint(); + } /** * ドラッグ&ドロップの終了時に必要な再描画を行います。 */ diff --git a/src/camidion/chordhelper/mididevice/MidiSequencerModel.java b/src/camidion/chordhelper/mididevice/MidiSequencerModel.java index 0c3ecbe..e346a09 100644 --- a/src/camidion/chordhelper/mididevice/MidiSequencerModel.java +++ b/src/camidion/chordhelper/mididevice/MidiSequencerModel.java @@ -28,9 +28,7 @@ import camidion.chordhelper.midieditor.SequenceTrackListTableModel; /** * MIDIシーケンサモデル */ -public class MidiSequencerModel extends MidiTransceiverListModel - implements BoundedRangeModel -{ +public class MidiSequencerModel extends MidiTransceiverListModel implements BoundedRangeModel { /** * MIDIシーケンサモデルを構築します。 * @param sequencer シーケンサーMIDIデバイス @@ -43,17 +41,15 @@ public class MidiSequencerModel extends MidiTransceiverListModel * このシーケンサーの再生スピード調整モデル */ public BoundedRangeModel speedSliderModel = new DefaultBoundedRangeModel(0, 0, -7, 7) {{ - addChangeListener( - new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - int val = getValue(); - getSequencer().setTempoFactor((float)( - val == 0 ? 1.0 : Math.pow( 2.0, ((double)val)/12.0 ) - )); - } + addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + int val = getValue(); + getSequencer().setTempoFactor((float)( + val == 0 ? 1.0 : Math.pow( 2.0, ((double)val)/12.0 ) + )); } - ); + }); }}; /** * MIDIシーケンサを返します。 diff --git a/src/camidion/chordhelper/mididevice/MidiTransceiverListModelList.java b/src/camidion/chordhelper/mididevice/MidiTransceiverListModelList.java index 01df8f0..5fb4efa 100644 --- a/src/camidion/chordhelper/mididevice/MidiTransceiverListModelList.java +++ b/src/camidion/chordhelper/mididevice/MidiTransceiverListModelList.java @@ -20,7 +20,8 @@ public class MidiTransceiverListModelList extends Vector { } }; dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, dgl); - dragSource.addDragSourceMotionListener(cablePane.midiConnecterMotionListener); + dragSource.addDragSourceMotionListener(cablePane); DropTargetListener dtl = new DropTargetAdapter() { @Override public void dragEnter(DropTargetDragEvent event) { diff --git a/src/camidion/chordhelper/mididevice/SequencerMeasureView.java b/src/camidion/chordhelper/mididevice/SequencerMeasureView.java index 87502cb..69f72cc 100644 --- a/src/camidion/chordhelper/mididevice/SequencerMeasureView.java +++ b/src/camidion/chordhelper/mididevice/SequencerMeasureView.java @@ -15,10 +15,9 @@ import camidion.chordhelper.midieditor.SequenceTrackListTableModel; /** * 小節表示ビュー */ -public class SequencerMeasureView extends JPanel implements ChangeListener { - private SequencerMeasureView.MeasurePositionLabel measurePositionLabel; - private SequencerMeasureView.MeasureLengthLabel measureLengthLabel; - private MidiSequencerModel model; +public class SequencerMeasureView extends JPanel { + private MeasurePositionLabel measurePositionLabel; + private MeasureLengthLabel measureLengthLabel; /** * シーケンサの現在の小節位置を表示するビューを構築します。 * @param model スライダー用の時間範囲データモデル @@ -27,35 +26,39 @@ public class SequencerMeasureView extends JPanel implements ChangeListener { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); add(measurePositionLabel = new MeasurePositionLabel()); add(measureLengthLabel = new MeasureLengthLabel()); - (this.model = model).addChangeListener(this); - } - @Override - public void stateChanged(ChangeEvent e) { - Sequencer sequencer = model.getSequencer(); - SequenceTrackListTableModel sequenceTableModel = model.getSequenceTrackListTableModel(); - SequenceTickIndex tickIndex = ( - sequenceTableModel == null ? null : sequenceTableModel.getSequenceTickIndex() - ); - if( ! sequencer.isRunning() || sequencer.isRecording() ) { - // 停止中または録音中の場合、長さが変わることがあるので表示を更新 - if( tickIndex == null ) { - measureLengthLabel.setMeasure(0); - } - else { - long tickLength = sequencer.getTickLength(); - int measureLength = tickIndex.tickToMeasure(tickLength); - measureLengthLabel.setMeasure(measureLength); + model.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + Object source = e.getSource(); + if( ! (source instanceof MidiSequencerModel) ) return; + MidiSequencerModel model = (MidiSequencerModel)source; + Sequencer sequencer = model.getSequencer(); + SequenceTrackListTableModel sequenceTableModel = model.getSequenceTrackListTableModel(); + SequenceTickIndex tickIndex = ( + sequenceTableModel == null ? null : sequenceTableModel.getSequenceTickIndex() + ); + if( ! sequencer.isRunning() || sequencer.isRecording() ) { + // 停止中または録音中の場合、長さが変わることがあるので表示を更新 + if( tickIndex == null ) { + measureLengthLabel.setMeasure(0); + } + else { + long tickLength = sequencer.getTickLength(); + int measureLength = tickIndex.tickToMeasure(tickLength); + measureLengthLabel.setMeasure(measureLength); + } + } + // 小節位置の表示を更新 + if( tickIndex == null ) { + measurePositionLabel.setMeasure(0, 0); + } + else { + long tickPosition = sequencer.getTickPosition(); + int measurePosition = tickIndex.tickToMeasure(tickPosition); + measurePositionLabel.setMeasure(measurePosition, tickIndex.lastBeat); + } } - } - // 小節位置の表示を更新 - if( tickIndex == null ) { - measurePositionLabel.setMeasure(0, 0); - } - else { - long tickPosition = sequencer.getTickPosition(); - int measurePosition = tickIndex.tickToMeasure(tickPosition); - measurePositionLabel.setMeasure(measurePosition, tickIndex.lastBeat); - } + }); } private static abstract class MeasureLabel extends JLabel { protected int measure = -1; @@ -65,7 +68,7 @@ public class SequencerMeasureView extends JPanel implements ChangeListener { return true; } } - private static class MeasurePositionLabel extends SequencerMeasureView.MeasureLabel { + private static class MeasurePositionLabel extends MeasureLabel { protected int beat = 0; public MeasurePositionLabel() { setFont( getFont().deriveFont(getFont().getSize2D() + 4) ); @@ -80,7 +83,7 @@ public class SequencerMeasureView extends JPanel implements ChangeListener { return true; } } - private static class MeasureLengthLabel extends SequencerMeasureView.MeasureLabel { + private static class MeasureLengthLabel extends MeasureLabel { public MeasureLengthLabel() { setText("/0000"); setToolTipText("Measure length - 小節の数"); @@ -92,4 +95,4 @@ public class SequencerMeasureView extends JPanel implements ChangeListener { return true; } } -} \ No newline at end of file +} diff --git a/src/camidion/chordhelper/mididevice/SequencerTimeView.java b/src/camidion/chordhelper/mididevice/SequencerTimeView.java index 6f5dea5..435a7c8 100644 --- a/src/camidion/chordhelper/mididevice/SequencerTimeView.java +++ b/src/camidion/chordhelper/mididevice/SequencerTimeView.java @@ -11,62 +11,56 @@ import javax.swing.event.ChangeListener; /** * シーケンサの現在位置(分:秒)を表示するビュー */ -public class SequencerTimeView extends JPanel implements ChangeListener { +public class SequencerTimeView extends JPanel { + private TimeLabel timePositionLabel = new TimePositionLabel(); + private TimeLabel timeLengthLabel = new TimeLengthLabel(); /** - * シーケンサの現在位置(分:秒)を表示するビューを構築します。 + * シーケンサの現在位置と曲の長さを(分:秒)で表示するビューを構築します。 * @param model MIDIシーケンサモデル */ public SequencerTimeView(MidiSequencerModel model) { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); add(timePositionLabel); add(timeLengthLabel); - (this.model = model).addChangeListener(this); + model.addChangeListener(new ChangeListener() { + @Override + public void stateChanged(ChangeEvent e) { + Object source = e.getSource(); + if( source instanceof MidiSequencerModel ) { + MidiSequencerModel model = (MidiSequencerModel)source; + timeLengthLabel.changeTimeInSecond(model.getMaximum()/1000); + timePositionLabel.changeTimeInSecond(model.getValue()/1000); + } + } + }); } - @Override - public void stateChanged(ChangeEvent e) { - timeLengthLabel.setTimeInSecond(model.getMaximum()/1000); - timePositionLabel.setTimeInSecond(model.getValue()/1000); - } - private MidiSequencerModel model; - private SequencerTimeView.TimeLabel timePositionLabel = new TimePositionLabel(); - private SequencerTimeView.TimeLabel timeLengthLabel = new TimeLengthLabel(); private static abstract class TimeLabel extends JLabel { - /** - * 時間の値(秒) - */ + { setTimeInSecond(0); } + protected String toTimeString(int sec) { + int min = sec/60; + return String.format("%02d:%02d", min, sec - min * 60); + } private int valueInSec; - /** - * 時間の値を秒単位で設定します。 - * @param sec 秒単位の時間 - */ - public void setTimeInSecond(int sec) { - if(valueInSec != sec) setText(toTimeString(valueInSec = sec)); + private void setTimeInSecond(int sec) { + setText(toTimeString(valueInSec = sec)); } - /** - * 時間の値を文字列に変換します。 - * @param sec 秒単位の時間 - * @return 変換結果(分:秒) - */ - protected String toTimeString(int sec) { - return String.format("%02d:%02d", sec/60, sec%60); + private void changeTimeInSecond(int sec) { + if(valueInSec != sec) setTimeInSecond(sec); } } - private static class TimePositionLabel extends SequencerTimeView.TimeLabel { - public TimePositionLabel() { + private static class TimePositionLabel extends TimeLabel { + { setFont( getFont().deriveFont(getFont().getSize2D() + 4) ); setForeground( new Color(0x80,0x00,0x00) ); setToolTipText("Time position - 現在位置(分:秒)"); - setText(toTimeString(0)); } } - private static class TimeLengthLabel extends SequencerTimeView.TimeLabel { - public TimeLengthLabel() { + private static class TimeLengthLabel extends TimeLabel { + { setToolTipText("Time length - 曲の長さ(分:秒)"); - setText(toTimeString(0)); } - @Override protected String toTimeString(int sec) { return "/"+super.toTimeString(sec); } } -} \ No newline at end of file +} -- 2.11.0