X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooTrackTitle.java;h=3ec0b63456a8643b1f7da5eb2173fa9be998ed5e;hb=43e2823caf1642779839312ad71bf5c86d8162ad;hp=e22c3219846e013d6553dbbda8f851c8b65fe250;hpb=ecef41268a927f27f71839d5df1d68a151b37e5e;p=moosique.git diff --git a/MooTrackTitle.java b/MooTrackTitle.java index e22c321..3ec0b63 100644 --- a/MooTrackTitle.java +++ b/MooTrackTitle.java @@ -15,16 +15,28 @@ public class MooTrackTitle extends JPanel { private Track track; private MetaMessage trackNameMessage; private ShortMessage programChangeMessage; + private MooTrackView mtv; private JTextField title; private MooInstrumentList instruments; private JComboBox channelBox; private JCheckBox mute; private JCheckBox solo; + private JButton record; private String trackName = ""; private int channel = 0; + /** + * Creates the title bar for an empty track, and therefore an initial channel is required. + * @param aTrack the track that this tracktitle is operating on. + * @param chan the initial channel + */ + public MooTrackTitle (Track aTrack, int chan) { + this(aTrack); + channel = chan; + } + /** * Creates the title bar. * @param aTrack the track that this tracktitle is operating on. @@ -53,6 +65,7 @@ public class MooTrackTitle extends JPanel { // Creates and places components. setLayout(new GridLayout(4,1)); setBorder(BorderFactory.createLineBorder(Color.black)); + TitleListener tl = new TitleListener(); setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70)); title = new JTextField(trackName); @@ -74,53 +87,31 @@ public class MooTrackTitle extends JPanel { channelBox.setSelectedIndex(channel); - channelBox.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ - channel = channelBox.getSelectedIndex(); - MidiEvent me; - MooNote mn; - instruments.setChannel(channel); - for (int j = 0; j < track.size(); j++) { - me = track.get(j); - if (me instanceof MooNote){ - mn = (MooNote)me; - mn.setChannel(channel); - } - }}}); + channelBox.addActionListener(tl); add(channelBox); JPanel checkboxes = new JPanel(); checkboxes.setLayout(new GridLayout(1,3)); mute = new JCheckBox("Mute"); - mute.setSelected(Moosique.getChannel(channel).getMute()); + mute.setSelected(false); + Moosique.setTrackMute(track, false); mute.setFont(Moosique.getGUI().FONT); - mute.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent event){ - boolean selected = mute.isSelected(); - if (selected){ - solo.setSelected(false); - Moosique.getChannel(channel).setSolo(false); - } - Moosique.getChannel(channel).setMute(selected); - - }}); + mute.addActionListener(tl); checkboxes.add(mute); solo = new JCheckBox("Solo"); - solo.setSelected(Moosique.getChannel(channel).getSolo()); + solo.setSelected(false); + Moosique.setTrackSolo(track, false); solo.setFont(Moosique.getGUI().FONT); - solo.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent event){ - //setSolo - boolean selected = solo.isSelected(); - if (selected){ - mute.setSelected(false); - Moosique.getChannel(channel).setMute(false); - } - Moosique.getChannel(channel).setSolo(selected); - }}); + solo.addActionListener(tl); checkboxes.add(solo); + + record = new JButton("Record"); + record.setFont(Moosique.getGUI().FONT); + record.addActionListener(tl); + checkboxes.add(record); + add(checkboxes); } @@ -132,6 +123,14 @@ public class MooTrackTitle extends JPanel { return channel; } + /** + * Sets the track view this title should update after recording. + * @param the track view + */ + public void setTrackView(MooTrackView tv) { + mtv = tv; + } + /** * Checks if the focus is lost. */ @@ -140,4 +139,63 @@ public class MooTrackTitle extends JPanel { // Update the MidiEvent containing the title of this track } } + + /** + * Takes the appropriate action when a user selects an item on the popup menu. + */ + class TitleListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + if (source == channelBox) { + channel = channelBox.getSelectedIndex(); + MidiEvent me; + MooNote mn; + instruments.setChannel(channel); + // Query the user before rechannelling??? + for (int j = 0; j < track.size(); j++) { + me = track.get(j); + if (me instanceof MooNote){ + mn = (MooNote)me; + mn.setChannel(channel); + } + } + } else if (source == solo) { + boolean selected = mute.isSelected(); + if (selected){ + solo.setSelected(false); + Moosique.setTrackSolo(track, false); + } + Moosique.setTrackMute(track, selected); + } else if (source == mute) { + boolean selected = solo.isSelected(); + if (selected){ + mute.setSelected(false); + Moosique.setTrackMute(track, false); + } + Moosique.setTrackSolo(track, selected); + } else if (source == record) { + Sequencer sequencer = Moosique.getSequencer(); + boolean quantize = false; + if (record.getText() == "Record") { + /* Show a dialog with: + "Track" combo box, + ("Channel" combo box,) + "Quantize" checkbox and + "Start Recording" button. + */ + record.setText("Stop"); + mtv.enableKeyboardRecording(); + sequencer.recordEnable(track, channel); + sequencer.startRecording(); + Moosique.setEdited(); + } else { + record.setText("Record"); + mtv.disableKeyboardRecording(); + sequencer.stopRecording(); + sequencer.recordDisable(track); + mtv.placeNoteElements(quantize); + } + } + } + } }