• R/O
  • HTTP
  • SSH
  • HTTPS

MIDIChordHelper: Commit

Javaアプリ MIDI Chord Helper のソースコード


Commit MetaInfo

Revision4a963257052c080288b7acae148d02515c200087 (tree)
Time2018-04-14 23:03:12
AuthorAkiyoshi Kamide <kamide@yk.r...>
CommiterAkiyoshi Kamide

Log Message

New MIDI Sequence画面のTrack切替をコンボボックスから横長リストに変更して使いやすくした

Change Summary

Incremental Difference

--- a/src/camidion/chordhelper/ChordHelperApplet.java
+++ b/src/camidion/chordhelper/ChordHelperApplet.java
@@ -266,7 +266,7 @@ public class ChordHelperApplet extends JApplet {
266266 */
267267 public static class VersionInfo {
268268 public static final String NAME = "MIDI Chord Helper";
269- public static final String VERSION = "Ver.20180108.1";
269+ public static final String VERSION = "Ver.20180414.1";
270270 public static final String COPYRIGHT = "Copyright (C) 2004-2018";
271271 public static final String AUTHER = "@きよし - Akiyoshi Kamide";
272272 public static final String URL = "http://www.yk.rim.or.jp/~kamide/music/chordhelper/";
--- a/src/camidion/chordhelper/midieditor/NewSequenceDialog.java
+++ b/src/camidion/chordhelper/midieditor/NewSequenceDialog.java
@@ -15,6 +15,7 @@ import java.awt.event.MouseEvent;
1515 import java.awt.event.MouseListener;
1616 import java.nio.charset.Charset;
1717 import java.util.ArrayList;
18+import java.util.List;
1819 import java.util.Vector;
1920
2021 import javax.sound.midi.MidiChannel;
@@ -22,12 +23,15 @@ import javax.sound.midi.Sequence;
2223 import javax.swing.AbstractAction;
2324 import javax.swing.Action;
2425 import javax.swing.BoxLayout;
26+import javax.swing.DefaultListCellRenderer;
27+import javax.swing.DefaultListModel;
2528 import javax.swing.JButton;
2629 import javax.swing.JCheckBox;
2730 import javax.swing.JComboBox;
2831 import javax.swing.JComponent;
2932 import javax.swing.JDialog;
3033 import javax.swing.JLabel;
34+import javax.swing.JList;
3135 import javax.swing.JOptionPane;
3236 import javax.swing.JPanel;
3337 import javax.swing.JScrollPane;
@@ -36,7 +40,10 @@ import javax.swing.JSpinner;
3640 import javax.swing.JTabbedPane;
3741 import javax.swing.JTextArea;
3842 import javax.swing.JTextField;
43+import javax.swing.ListModel;
44+import javax.swing.ListSelectionModel;
3945 import javax.swing.SpinnerNumberModel;
46+import javax.swing.SwingConstants;
4047 import javax.swing.event.ChangeEvent;
4148 import javax.swing.event.ChangeListener;
4249
@@ -68,23 +75,7 @@ public class NewSequenceDialog extends JDialog {
6875 private TimeSignatureSelecter timesigSelecter = new TimeSignatureSelecter();
6976 private TempoSelecter tempoSelecter = new TempoSelecter();
7077 private MeasureSelecter measureSelecter = new MeasureSelecter();
71- private TrackSpecPanel trackSpecPanel = new TrackSpecPanel() {{
72- DrumTrackSpec dts = new DrumTrackSpec(9, "Percussion track");
73- dts.velocity = 127;
74- addTrackSpec(dts);
75- MelodyTrackSpec mts;
76- mts = new MelodyTrackSpec(2, "Bass track", new Range(36,48));
77- mts.isBass = true;
78- mts.velocity = 96;
79- addTrackSpec(mts);
80- mts = new MelodyTrackSpec(1, "Chord track", new Range(60,72));
81- addTrackSpec(mts);
82- mts = new MelodyTrackSpec(0, "Melody track", new Range(60,84));
83- mts.randomMelody = true;
84- mts.beatPattern = 0xFFFF;
85- mts.continuousBeatPattern = 0x820A;
86- addTrackSpec(mts);
87- }};
78+ private TrackSpecPanel trackSpecPanel = new TrackSpecPanel();
8879 /**
8980 * ダイアログを開くアクション
9081 */
@@ -254,14 +245,23 @@ public class NewSequenceDialog extends JDialog {
254245 timesigSelecter.setValue((byte)timesig_upper, (byte)timesig_lower_index);
255246 setChordProgression(new ChordProgression(measureLength, timesig_upper));
256247 }
248+ private static class TrackSelecter extends JList<AbstractNoteTrackSpec> {
249+ public TrackSelecter() {
250+ setLayoutOrientation(HORIZONTAL_WRAP);
251+ setVisibleRowCount(1);
252+ setFixedCellWidth(130);
253+ DefaultListCellRenderer renderer = (DefaultListCellRenderer) getCellRenderer();
254+ renderer.setHorizontalAlignment(SwingConstants.CENTER);
255+ setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
256+ }
257+ }
257258 /**
258- * トラック設定画面
259+ * トラック仕様設定パネル
259260 */
260261 private static class TrackSpecPanel extends JPanel
261- implements PianoKeyboardListener, ActionListener, ChangeListener
262+ implements PianoKeyboardListener, ChangeListener
262263 {
263- JComboBox<AbstractNoteTrackSpec> trackSelecter = new JComboBox<>();
264- JLabel trackTypeLabel = new JLabel();
264+ TrackSelecter trackSelecter = new TrackSelecter();
265265 JTextField nameTextField = new JTextField(20);
266266 MidiChannelComboSelecter chSelecter =
267267 new MidiChannelComboSelecter("MIDI Channel:");
@@ -287,13 +287,11 @@ public class NewSequenceDialog extends JDialog {
287287 private MidiChannel[] midiChannels;
288288
289289 public TrackSpecPanel() {
290- nameTextField.addActionListener(this);
290+ nameTextField.addActionListener(
291+ e -> getTrackSpec().name = nameTextField.getText()
292+ );
291293 keyboardPanel.keyboard.addPianoKeyboardListener(this);
292- add(new JPanel() {{
293- add(new JLabel("Track select:"));
294- add(trackSelecter);
295- }});
296- add(trackTypeLabel);
294+ add(trackSelecter);
297295 add(new JPanel() {{
298296 add(new JLabel("Track name (Press [Enter] key to change):"));
299297 add(nameTextField);
@@ -314,12 +312,64 @@ public class NewSequenceDialog extends JDialog {
314312 nsx39Checkbox.addChangeListener(this);
315313 add(nsx39Checkbox);
316314 add(beatPadPanel);
317- trackSelecter.addActionListener(this);
318- chSelecter.comboBox.addActionListener(this);
315+ trackSelecter.addListSelectionListener(e -> {
316+ AbstractNoteTrackSpec ants = trackSelecter.getSelectedValue();
317+ nameTextField.setText(ants.name);
318+ chSelecter.setSelectedChannel(ants.midiChannel);
319+ keyboardPanel.keyboard.velocityModel.setValue(ants.velocity);
320+ pgSelecter.setProgram(ants.programNumber);
321+ keyboardPanel.keyboard.clear();
322+ if( ants instanceof DrumTrackSpec ) {
323+ rangePanel.setVisible(false);
324+ randomMelodyCheckbox.setVisible(false);
325+ randomLyricCheckbox.setVisible(false);
326+ nsx39Checkbox.setVisible(false);
327+ bassCheckbox.setVisible(false);
328+ }
329+ else if( ants instanceof MelodyTrackSpec ) {
330+ MelodyTrackSpec ts = (MelodyTrackSpec)ants;
331+ rangePanel.setVisible(true);
332+ keyboardPanel.keyboard.setSelectedNote(ts.range.minNote);
333+ keyboardPanel.keyboard.setSelectedNote(ts.range.maxNote);
334+ keyboardPanel.keyboard.autoScroll(ts.range.minNote);
335+ randomMelodyCheckbox.setSelected(ts.randomMelody);
336+ randomLyricCheckbox.setSelected(ts.randomLyric);
337+ bassCheckbox.setSelected(ts.isBass);
338+ randomMelodyCheckbox.setVisible(true);
339+ randomLyricCheckbox.setVisible(true);
340+ nsx39Checkbox.setVisible(true);
341+ bassCheckbox.setVisible(true);
342+ }
343+ beatPadPanel.setTrackSpec(ants);
344+ });
345+ chSelecter.comboBox.addActionListener(
346+ e -> getTrackSpec().midiChannel = chSelecter.getSelectedChannel()
347+ );
319348 keyboardPanel.keyboard.velocityModel.addChangeListener(
320349 e -> getTrackSpec().velocity = keyboardPanel.keyboard.velocityModel.getValue()
321350 );
322- pgSelecter.addActionListener(this);
351+ pgSelecter.addActionListener(
352+ e -> getTrackSpec().programNumber = pgSelecter.getProgram()
353+ );
354+ // Add track specs
355+ DefaultListModel<AbstractNoteTrackSpec> tracksModel = new DefaultListModel<>();
356+ DrumTrackSpec dts = new DrumTrackSpec(9, "Percussion track");
357+ dts.velocity = 127;
358+ tracksModel.addElement(dts);
359+ MelodyTrackSpec mts;
360+ mts = new MelodyTrackSpec(2, "Bass track", new Range(36,48));
361+ mts.isBass = true;
362+ mts.velocity = 96;
363+ tracksModel.addElement(mts);
364+ mts = new MelodyTrackSpec(1, "Chord track", new Range(60,72));
365+ tracksModel.addElement(mts);
366+ mts = new MelodyTrackSpec(0, "Melody track", new Range(60,84));
367+ mts.randomMelody = true;
368+ mts.beatPattern = 0xFFFF;
369+ mts.continuousBeatPattern = 0x820A;
370+ tracksModel.addElement(mts);
371+ trackSelecter.setModel(tracksModel);
372+ trackSelecter.setSelectedIndex(0);
323373 }
324374 @Override
325375 public void stateChanged(ChangeEvent e) {
@@ -354,55 +404,6 @@ public class NewSequenceDialog extends JDialog {
354404 }
355405 }
356406 @Override
357- public void actionPerformed(ActionEvent e) {
358- Object src = e.getSource();
359- AbstractNoteTrackSpec ants;
360- if( src == nameTextField ) {
361- getTrackSpec().name = nameTextField.getText();
362- }
363- else if( src == trackSelecter ) {
364- ants = (AbstractNoteTrackSpec)(trackSelecter.getSelectedItem());
365- String trackTypeString = "Track type: " + (
366- ants instanceof DrumTrackSpec ? "Percussion" :
367- ants instanceof MelodyTrackSpec ? "Melody" : "(Unknown)"
368- );
369- trackTypeLabel.setText(trackTypeString);
370- nameTextField.setText(ants.name);
371- chSelecter.setSelectedChannel(ants.midiChannel);
372- keyboardPanel.keyboard.velocityModel.setValue(ants.velocity);
373- pgSelecter.setProgram(ants.programNumber);
374- keyboardPanel.keyboard.clear();
375- if( ants instanceof DrumTrackSpec ) {
376- rangePanel.setVisible(false);
377- randomMelodyCheckbox.setVisible(false);
378- randomLyricCheckbox.setVisible(false);
379- nsx39Checkbox.setVisible(false);
380- bassCheckbox.setVisible(false);
381- }
382- else if( ants instanceof MelodyTrackSpec ) {
383- MelodyTrackSpec ts = (MelodyTrackSpec)ants;
384- rangePanel.setVisible(true);
385- keyboardPanel.keyboard.setSelectedNote(ts.range.minNote);
386- keyboardPanel.keyboard.setSelectedNote(ts.range.maxNote);
387- keyboardPanel.keyboard.autoScroll(ts.range.minNote);
388- randomMelodyCheckbox.setSelected(ts.randomMelody);
389- randomLyricCheckbox.setSelected(ts.randomLyric);
390- bassCheckbox.setSelected(ts.isBass);
391- randomMelodyCheckbox.setVisible(true);
392- randomLyricCheckbox.setVisible(true);
393- nsx39Checkbox.setVisible(true);
394- bassCheckbox.setVisible(true);
395- }
396- beatPadPanel.setTrackSpec(ants);
397- }
398- else if( src == chSelecter.comboBox ) {
399- getTrackSpec().midiChannel = chSelecter.getSelectedChannel();
400- }
401- else if( src == pgSelecter ) {
402- getTrackSpec().programNumber = pgSelecter.getProgram();
403- }
404- }
405- @Override
406407 public void pianoKeyPressed(int n, InputEvent e) {
407408 noteOn(n);
408409 AbstractNoteTrackSpec ants = getTrackSpec();
@@ -429,22 +430,19 @@ public class NewSequenceDialog extends JDialog {
429430 this.midiChannels = midiChannels;
430431 }
431432 public AbstractNoteTrackSpec getTrackSpec() {
432- Object trackSpecObj = trackSelecter.getSelectedItem();
433- AbstractNoteTrackSpec ants = (AbstractNoteTrackSpec)trackSpecObj;
433+ AbstractNoteTrackSpec ants = trackSelecter.getSelectedValue();
434434 ants.name = nameTextField.getText();
435435 return ants;
436436 }
437- public Vector<AbstractNoteTrackSpec> getTrackSpecs() {
438- Vector<AbstractNoteTrackSpec> trackSpecs = new Vector<>();
439- int i=0, n_items = trackSelecter.getItemCount();
440- while( i < n_items ) {
441- trackSpecs.add((AbstractNoteTrackSpec)trackSelecter.getItemAt(i++));
437+ public List<AbstractNoteTrackSpec> getTrackSpecs() {
438+ List<AbstractNoteTrackSpec> trackSpecs = new Vector<>();
439+ ListModel<AbstractNoteTrackSpec> m = trackSelecter.getModel();
440+ int i=0, n = m.getSize();
441+ while( i < n ) {
442+ trackSpecs.add(m.getElementAt(i++));
442443 }
443444 return trackSpecs;
444445 }
445- public void addTrackSpec(AbstractNoteTrackSpec trackSpec) {
446- trackSelecter.addItem(trackSpec);
447- }
448446 }
449447 private static class MeasureSelecter extends JPanel {
450448 public MeasureSelecter() {
--- a/src/camidion/chordhelper/music/ChordProgression.java
+++ b/src/camidion/chordhelper/music/ChordProgression.java
@@ -494,7 +494,7 @@ public class ChordProgression {
494494 public Sequence toMidiSequence(
495495 int ppq, int startMeasure, int endMeasure,
496496 FirstTrackSpec firstTrack,
497- Vector<AbstractNoteTrackSpec> trackSpecs,
497+ List<AbstractNoteTrackSpec> trackSpecs,
498498 Charset charset
499499 ) {
500500 Sequence seq;
Show on old repository browser