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;
* @return 未保存の修正済み MIDI ファイルがあれば true
*/
public boolean isModified() {
- return deviceModelList.editorDialog.sequenceListTable.getModel().isModified();
+ return deviceModelList.getEditorDialog().sequenceListTable.getModel().isModified();
}
/**
* 指定された小節数の曲を、乱数で自動作曲してプレイリストへ追加します。
* @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ファイルをプレイリストへ追加します。
* @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;
}
* @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;
}
}
* シーケンサへロードして再生します。
*/
public void play() {
- play(deviceModelList.editorDialog.sequenceListTable.getModel().sequenceListSelectionModel.getMinSelectionIndex());
+ play(deviceModelList.getEditorDialog().sequenceListTable.getModel().sequenceListSelectionModel.getMinSelectionIndex());
}
/**
* 指定されたインデックス値が示すプレイリスト上のMIDIシーケンスを、
* @param index インデックス値(0から始まる)
*/
public void play(int index) {
- deviceModelList.editorDialog.sequenceListTable.getModel().loadToSequencer(index);
+ deviceModelList.getEditorDialog().sequenceListTable.getModel().loadToSequencer(index);
deviceModelList.getSequencerModel().start();
}
/**
* @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ファイルのファイル名を返します。
*/
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/";
}
}
);
- 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()) {{
@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(
"<html>"+(
loadedSequenceIndex < 0 ? "[No MIDI file loaded]" :
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));
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) {{
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) );
} else {
frame = new AppletFrame(applet = new ChordHelperApplet());
}
- applet.deviceModelList.editorDialog.loadAndPlay(fileList);
+ applet.deviceModelList.getEditorDialog().loadAndPlay(fileList);
}
});
}
* @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);
}
/**
* 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();
+ }
/**
* ドラッグ&ドロップの終了時に必要な再描画を行います。
*/
/**
* MIDIシーケンサモデル
*/
-public class MidiSequencerModel extends MidiTransceiverListModel
- implements BoundedRangeModel
-{
+public class MidiSequencerModel extends MidiTransceiverListModel implements BoundedRangeModel {
/**
* MIDIシーケンサモデルを構築します。
* @param sequencer シーケンサーMIDIデバイス
* このシーケンサーの再生スピード調整モデル
*/
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シーケンサを返します。
public String toString() { return "MIDI devices"; }
- public MidiSequenceEditor editorDialog;
+ private MidiSequenceEditor editorDialog;
+ public MidiSequenceEditor getEditorDialog() { return editorDialog; }
private MidiSequencerModel sequencerModel;
public MidiSequencerModel getSequencerModel() { return sequencerModel; }
}
};
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) {
/**
* 小節表示ビュー
*/
-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 スライダー用の時間範囲データモデル
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;
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) );
return true;
}
}
- private static class MeasureLengthLabel extends SequencerMeasureView.MeasureLabel {
+ private static class MeasureLengthLabel extends MeasureLabel {
public MeasureLengthLabel() {
setText("/0000");
setToolTipText("Measure length - 小節の数");
return true;
}
}
-}
\ No newline at end of file
+}
/**
* シーケンサの現在位置(分:秒)を表示するビュー
*/
-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
+}