X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=MooDialog.java;fp=MooDialog.java;h=25e544adc383ea0cc67392bf33aa105a7d6319d3;hp=fc9c2c0b19bd39ad7c23a4560e06cac0513dcd0a;hb=8a34847eda594b03ab65ae74ee17c556846d8694;hpb=e49cbedbb512d2cbadb19f9b4b84c1b0ef39ff9c diff --git a/MooDialog.java b/MooDialog.java index fc9c2c0..25e544a 100644 --- a/MooDialog.java +++ b/MooDialog.java @@ -13,6 +13,9 @@ import java.beans.*; public class MooDialog extends JDialog { + private Container pane; + private Track[] tracks; + private JLabel labelA, labelB, labelC, labelD, labelE, labelF, labelG, labelH; private JTextField textFieldA, textFieldB, textFieldC, textFieldD, textFieldE, textFieldF, textFieldG, textFieldH, textFieldI, textFieldJ, @@ -32,6 +35,7 @@ public class MooDialog extends JDialog { TRANSPOSE = 11, SCALE_VELOCITY = 12, RECORD = 13; + public static final String[] noteSizes = {"Whole", "Half", "Quarter", "Eighth", "Sixteenth"}; /** * Constructor of the dialogs. @@ -39,24 +43,25 @@ public class MooDialog extends JDialog { public MooDialog(int type) { super(Moosique.getGUI(), false); - Container pane = getContentPane(); + pane = getContentPane(); pane.setLayout(null); - Track[] tracks = Moosique.getSequence().getTracks(); + tracks = Moosique.getSequence().getTracks(); switch (type) { - case ADD_TRACK: makeAddDialog(pane, tracks); break; - case DELETE_TRACK: makeDelDialog(pane, tracks); break; - case COPY_TRACK: makeCopyDialog(pane, tracks); break; - case MOVE_TRACK: makeMoveDialog(pane, tracks); break; - case SET_POSITION: makeSetPositionDialog(pane); break; - case MANUAL: makeTextDialog(pane, "Manual.txt"); break; - case INSERT_MEASURE: makeInsertMeasureDialog(pane); break; - case DELETE_MEASURE: makeDeleteMeasureDialog(pane); break; - case SET_TEMPO: makeSetTempoDialog(pane); break; - case PREFERENCES: makePrefsDialog(pane); break; - case TRANSPOSE: makeTransposeDialog(pane, tracks); break; - case SCALE_VELOCITY: makeScaleVelocityDialog(pane, tracks); break; + case ADD_TRACK: makeAddDialog(); break; + case DELETE_TRACK: makeDelDialog(); break; + case COPY_TRACK: makeCopyDialog(); break; + case MOVE_TRACK: makeMoveDialog(); break; + case SET_POSITION: makeSetPositionDialog(); break; + case MANUAL: makeTextDialog("User Manual", "Manual.txt", 30, 95); break; + case INSERT_MEASURE: makeInsertMeasureDialog(); break; + case DELETE_MEASURE: makeDeleteMeasureDialog(); break; + case SET_TEMPO: makeSetTempoDialog(); break; + case PREFERENCES: makePrefsDialog(); break; + case TRANSPOSE: makeTransposeDialog(); break; + case SCALE_VELOCITY: makeScaleVelocityDialog(); break; + case RECORD: makeRecordDialog(); break; } } @@ -65,7 +70,7 @@ public class MooDialog extends JDialog { * @param pane The container to put the dialog in. * @param tracks A array containing miditracks. */ - private void makeAddDialog(Container pane, Track[] tracks) { + private void makeAddDialog() { setTitle("Add track"); // create the contents of the dialog and add to container labelA = new JLabel("Name of track", JLabel.CENTER); @@ -77,7 +82,7 @@ public class MooDialog extends JDialog { pane.add(labelB); // list of where to add track trackListA = new JComboBox(); - for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i); + for (int i = 1; i < tracks.length; i++) trackListA.addItem("Track " + i); pane.add(trackListA); // ok and cancel button cancelButton = new JButton("Cancel"); @@ -103,7 +108,7 @@ public class MooDialog extends JDialog { * @param pane The container to put the dialog in. * @param tracks A array containing miditracks. */ - private void makeDelDialog(Container pane, Track[] tracks) { + private void makeDelDialog() { setTitle("Delete track"); // create the contents of the dialog and add to container labelB = new JLabel("Delete track", JLabel.CENTER); @@ -134,7 +139,7 @@ public class MooDialog extends JDialog { * @param pane The container to put the dialog in. * @param tracks A array containing miditracks. */ - private void makeCopyDialog(Container pane, Track[] tracks) { + private void makeCopyDialog() { setTitle("Copy Track"); // create the contents of the dialog and add to container labelA = new JLabel("Track to copy", JLabel.CENTER); @@ -172,7 +177,7 @@ public class MooDialog extends JDialog { * @param pane The container to put the dialog in. * @param tracks A array containing miditracks. */ - private void makeMoveDialog(Container pane, Track[] tracks) { + private void makeMoveDialog() { setTitle("Move track"); // create the contents of the dialog and add to container labelA = new JLabel("Track to move", JLabel.CENTER); @@ -211,7 +216,7 @@ public class MooDialog extends JDialog { * @param pane The container to put the dialog in. * @param tracks A array containing miditracks. */ - private void makeSetPositionDialog(Container pane) { + private void makeSetPositionDialog() { setTitle("Set edit position"); // create the contents of the dialog and add to container @@ -252,7 +257,7 @@ public class MooDialog extends JDialog { * Builds the insert measure popupdialog. * @param pane The container to put the dialog in. */ - private void makeInsertMeasureDialog(Container pane){ + private void makeInsertMeasureDialog(){ setTitle("Insert Measure"); // create the contents of the dialog and add to container labelA = new JLabel("Insert at:", JLabel.RIGHT); @@ -286,7 +291,7 @@ public class MooDialog extends JDialog { * Builds the delete measure popupdialog. * @param pane The container to put the dialog in. */ - private void makeDeleteMeasureDialog(Container pane) { + private void makeDeleteMeasureDialog() { setTitle("Delete Measure"); // create the contents of the dialog and add to container labelA = new JLabel("Delete at:", JLabel.RIGHT); @@ -320,7 +325,7 @@ public class MooDialog extends JDialog { * Builds the set tempo dialog. * @param pane The container to put the dialog in. */ - private void makeSetTempoDialog(Container pane) { + private void makeSetTempoDialog() { setTitle("Set tempo"); // create contents of dialog and add to container // track edit-intervall labels @@ -429,7 +434,7 @@ public class MooDialog extends JDialog { * @param pane The container to put the dialog in. * @param tracks A array containing miditracks. */ - private void makeTransposeDialog(Container pane, Track[] tracks) { + private void makeTransposeDialog() { setTitle("Transpose"); // create contents of dialog and add to container // track edit-intervall labels @@ -535,7 +540,7 @@ public class MooDialog extends JDialog { * @param pane The container to put the dialog in. * @param tracks A array containing miditracks. */ - private void makeScaleVelocityDialog(Container pane, Track[] tracks) { + private void makeScaleVelocityDialog() { setTitle("Scale velocity"); // create contents of dialog and add to container // track edit-intervall labels @@ -651,8 +656,8 @@ public class MooDialog extends JDialog { } /** creates the "User manual dialog" that displays a textfile */ - private void makeTextDialog(Container pane, String filename) { - setTitle("User Manual"); + private void makeTextDialog(String title, String filename, int rows, int columns) { + setTitle(title); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); File manual = new File(filename); String s; @@ -662,9 +667,9 @@ public class MooDialog extends JDialog { br.read(chars, 0, (int)manual.length()); s = new String(chars); } catch (Exception ex) { - s = "Manual not found"; + s = "File not found"; } - JTextArea text = new JTextArea(s, 30, 95); + JTextArea text = new JTextArea(s, rows, columns); text.setLineWrap(true); text.setWrapStyleWord(true); text.setEnabled(false); @@ -683,7 +688,7 @@ public class MooDialog extends JDialog { setVisible(true); } - private void makePrefsDialog(Container pane) { + private void makePrefsDialog() { /* MidiDevice.Info[] devInfo = MidiSystem.getMidiDeviceInfo(); for (int i = 0; i < devInfo.length; i++) { @@ -702,19 +707,88 @@ public class MooDialog extends JDialog { */ } - private void makeRecordDialog(Container pane) { - /* Show a dialog with: - "Track" combo box, - "Channel" field? (disabled?, - "Quantize" pane with - "Quantize" checkbox, - "Resolution" combo box, - "Location" checkboxes and - "Duration" checkboxes - "Start Recording" button. - - Moosique.record(track); - */ + private void makeRecordDialog() { + setTitle("Record"); + + JPanel panel = new JPanel(); + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + + // Creating track combo box, + panel.add(new Label("Track: ")); + trackListA = new JComboBox(); + for (int i = 1; i < tracks.length; i++) trackListA.addItem("Track " + i); + trackListA.setFont(Moosique.getGUI().FONT); + panel.add(trackListA); + + // Creating channel combo box + panel.add(new Label("Channel: ")); + JComboBox channelList = new JComboBox(); + for (int i = 1; i <= 16; i++) channelList.addItem("Channel " + i); + channelList.setFont(Moosique.getGUI().FONT); + panel.add(channelList); + + // Creating quantize pane + JLayeredPane quantizePane = new JLayeredPane(); + quantizePane.setBorder(BorderFactory.createTitledBorder("Quantize")); + JCheckBox quantizeBox = new JCheckBox("Quantize"); + quantizePane.add(quantizeBox); + JLabel quantizeSizeLabel = new JLabel("Resolution"); + JComboBox quantizeSize = new JComboBox(noteSizes); + quantizeSize.setSelectedIndex(4); + quantizeSize.setEnabled(false); + quantizeSize.setFont(Moosique.getGUI().FONT); + quantizeSizeLabel.setLabelFor(quantizeSize); + quantizePane.add(quantizeSizeLabel); + quantizePane.add(quantizeSize); + JCheckBox quantizeLocationBox = new JCheckBox("Affect location", true); + quantizeLocationBox.setEnabled(false); + quantizePane.add(quantizeLocationBox); + JCheckBox quantizeDurationBox = new JCheckBox("Affect duration", true); + quantizeDurationBox.setEnabled(false); + quantizePane.add(quantizeDurationBox); + panel.add(quantizePane); + + // Creating buttons + final String btnString1 = "Record!"; + final String btnString2 = "Cancel"; + Object[] options = {btnString1, btnString2}; + + // Creating option pane + optionPane = new JOptionPane(panel, + JOptionPane.QUESTION_MESSAGE, + JOptionPane.YES_NO_OPTION, + null, + options, + options[0]); + optionPane.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent e) { + String prop = e.getPropertyName(); + + if (isVisible() && (e.getSource() == optionPane) && + (prop.equals(JOptionPane.VALUE_PROPERTY) || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) { + Object value = optionPane.getValue(); + if (value == JOptionPane.UNINITIALIZED_VALUE) return; + optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE); + + if (value.equals(btnString1)) { + // boolean[] quantizers = {quantize, location, duration}; + Track track = tracks[trackListA.getSelectedIndex() + 1]; + int channel = Moosique.getGUI().getView().getTrackView(track).getTitle().getChannel(); + boolean[] quantizers = {false, false, false}; + int resolution = Moosique.SIXTEENTH_NOTE; + Moosique.record(track, channel, quantizers, resolution); + } + setVisible(false); + } + } + }); + setContentPane(optionPane); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + + setResizable(false); + pack(); + setLocationRelativeTo(Moosique.getGUI()); + setVisible(true); } private MooNote note; @@ -729,9 +803,12 @@ public class MooDialog extends JDialog { */ public MooDialog(MooNote mn) { super(Moosique.getGUI(), "Note properties", true); + + note = mn; + JPanel panel = new JPanel(); panel.setLayout(new GridLayout(3,2)); - note = mn; + pitch = new JTextField(new Integer(note.getPitch()).toString(),3); panel.add(new Label("Pitch: ")); panel.add(pitch); @@ -812,6 +889,7 @@ public class MooDialog extends JDialog { } }); pack(); + setLocationRelativeTo(Moosique.getGUI()); setVisible(true); } }