X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooTrackTitle.java;h=8bec94bc2495c2a65d5f730b03b910f986cd999b;hb=f7097bc07b6688d1629e6894c1c42dc06485dc12;hp=d5876c1485718a34f6ae3ef940152182d5f2974c;hpb=ce9a16d679f2058454af367e972888ba8e2c34c0;p=moosique.git diff --git a/MooTrackTitle.java b/MooTrackTitle.java index d5876c1..8bec94b 100644 --- a/MooTrackTitle.java +++ b/MooTrackTitle.java @@ -15,18 +15,31 @@ 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. */ public MooTrackTitle (Track aTrack) { setDoubleBuffered(true); @@ -43,8 +56,9 @@ public class MooTrackTitle extends JPanel { trackNameMessage = (MetaMessage)msg; trackName = new String(trackNameMessage.getData()); } - } else if (status >= 192 && status <= 207) { + } else if (status >= 192 && status < 208) { programChangeMessage = (ShortMessage)msg; + // System.out.println("Program change " + programChangeMessage.getData1()); channel = status - 192; } } @@ -52,6 +66,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); @@ -59,8 +74,11 @@ public class MooTrackTitle extends JPanel { title.addFocusListener(new TitleFocusListener()); add(title); - instruments = new MooInstrumentList(channel); - // instruments = new MooInstrumentList(channel, programChangeMessage); + int type; + if (channel == 9) type = MooInstrumentList.DRUMS; + else type = MooInstrumentList.INSTRUMENTS; + instruments = new MooInstrumentList(channel, type); + // instruments = new MooInstrumentList(channel, type, programChangeMessage); add(instruments); channelBox = new JComboBox(); @@ -70,59 +88,116 @@ public class MooTrackTitle extends JPanel { channelBox.setSelectedIndex(channel); - channelBox.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent e){ - int chan = channelBox.getSelectedIndex(); - MidiEvent me; - MooNote mn; - instruments.setChannel(channelBox.getSelectedIndex()); - for (int j = 0; j < track.size(); j++) { - me = track.get(j); - if (me instanceof MooNote){ - mn = (MooNote)me; - mn.setChannel(chan); - } - }}}); + 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); } + + /** + * Returns the channel of the track that the view is visualising. + * @return the chanel of the visualised track + */ + public int getChannel() { + 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. + */ class TitleFocusListener extends FocusAdapter { public void focusLost(FocusEvent e) { // 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 (disabled?, + "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); + Moosique.convertTrack(track, quantize); + mtv.placeNoteElements(); + } + } + } + } }