X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=MooTrackTitle.java;h=9cffb14570bbd48633e380441963e0865188b78b;hp=2dfd67f63e2266c015cb7fd86be1902803ed6bea;hb=HEAD;hpb=ae45edfc5dff1e0a098df4afe747a2dec6c90362 diff --git a/MooTrackTitle.java b/MooTrackTitle.java index 2dfd67f..9cffb14 100644 --- a/MooTrackTitle.java +++ b/MooTrackTitle.java @@ -12,115 +12,163 @@ import javax.sound.midi.*; public class MooTrackTitle extends JPanel { + private Track track; private MetaMessage trackNameMessage; - private String trackName = ""; private ShortMessage programChangeMessage; - private int programChange = 0, channel = 0; + private MooTrackView mtv; + private JTextField title; private MooInstrumentList instruments; private JComboBox channelBox; private JCheckBox mute; private JCheckBox solo; - private Track track; + + 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 track title is operating on. */ public MooTrackTitle (Track aTrack) { + setDoubleBuffered(true); track = aTrack; - // Finds track name and program change + // Finds track name, program change and channel. MidiMessage msg; + int status; for (int i = 0; i < track.size(); i++) { msg = track.get(i).getMessage(); - if (msg.getStatus() == 255) { + status = msg.getStatus(); + if (status == MetaMessage.META) { if (((MetaMessage)msg).getType() == 3) { trackNameMessage = (MetaMessage)msg; trackName = new String(trackNameMessage.getData()); } - } else if (msg.getStatus() == 192) { + } else if (status >= 192 && status < 208) { programChangeMessage = (ShortMessage)msg; - programChange = programChangeMessage.getData1(); + channel = programChangeMessage.getChannel(); } } - MidiEvent event; - for (int i = 0; i < track.size(); i++) { - event = track.get(i); - if (event instanceof MooNote) channel = ((MooNote)event).getChannel(); - } - // 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); // JTextField(String text, int columns) + title = new JTextField(trackName); title.setFont(Moosique.getGUI().FONT); title.addFocusListener(new TitleFocusListener()); add(title); - instruments = new MooInstrumentList(programChange); + int type; + if (channel == 9) type = MooInstrumentList.DRUMS; + else type = MooInstrumentList.INSTRUMENTS; + instruments = new MooInstrumentList(channel, type, programChangeMessage); add(instruments); - JPanel checkboxes = new JPanel(); - checkboxes.setLayout(new GridLayout(1,3)); - channelBox = new JComboBox(); channelBox.setFont(Moosique.getGUI().FONT); for (int i = 1; i <= 16; i++) channelBox.addItem(new Integer(i)); - for (int j = 0; j < track.size(); j++) { - MidiEvent me = track.get(j); - if (me instanceof MooNote){ - MooNote mn = (MooNote)me; - channelBox.setSelectedIndex(mn.getChannel()); - break; - } - } - - instruments = new MooInstrumentList(channelBox.getSelectedIndex()); - - 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.setSelectedIndex(channel); + + channelBox.addActionListener(tl); add(channelBox); + JPanel checkboxes = new JPanel(); + checkboxes.setLayout(new GridLayout(1,3)); + mute = new JCheckBox("Mute"); + mute.setSelected(false); + Moosique.setTrackMute(track, false); mute.setFont(Moosique.getGUI().FONT); - mute.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent event){ - //setMute - solo.setSelected(false); - }}); + mute.addActionListener(tl); checkboxes.add(mute); solo = new JCheckBox("Solo"); + solo.setSelected(false); + Moosique.setTrackSolo(track, false); solo.setFont(Moosique.getGUI().FONT); - solo.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent event){ - //setSolo - mute.setSelected(false); - }}); + solo.addActionListener(tl); checkboxes.add(solo); + 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; + } + + /** + * When the title field loses focus, updates the corresponding MidiEvent. + */ class TitleFocusListener extends FocusAdapter { public void focusLost(FocusEvent e) { - // Update the MidiEvent containing the title of this track + try { + trackNameMessage.setMessage(3, title.getText().getBytes(), title.getText().length()); + } catch (InvalidMidiDataException ex) {} + } + } + + /** + * 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); + // Prompt 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); + } } } }