3 import java.awt.event.*;
4 import javax.sound.midi.*;
7 * The title bar for each track with track name, channelBox, instrument etc.
9 * @author Andersson, Andreen, Lanneskog, Pehrson
13 public class MooTrackTitle extends JPanel {
16 private MetaMessage trackNameMessage;
17 private ShortMessage programChangeMessage;
18 private MooTrackView mtv;
20 private JTextField title;
21 private MooInstrumentList instruments;
22 private JComboBox channelBox;
23 private JCheckBox mute;
24 private JCheckBox solo;
26 private String trackName = "";
27 private int channel = 0;
30 * Creates the title bar for an empty track, and therefore an initial channel is required.
31 * @param aTrack the track that this tracktitle is operating on.
32 * @param chan the initial channel
34 public MooTrackTitle (Track aTrack, int chan) {
40 * Creates the title bar.
41 * @param aTrack the track that this track title is operating on.
43 public MooTrackTitle (Track aTrack) {
44 setDoubleBuffered(true);
47 // Finds track name, program change and channel.
50 for (int i = 0; i < track.size(); i++) {
51 msg = track.get(i).getMessage();
52 status = msg.getStatus();
53 if (status == MetaMessage.META) {
54 if (((MetaMessage)msg).getType() == 3) {
55 trackNameMessage = (MetaMessage)msg;
56 trackName = new String(trackNameMessage.getData());
58 } else if (status >= 192 && status < 208) {
59 programChangeMessage = (ShortMessage)msg;
60 channel = programChangeMessage.getChannel();
64 // Creates and places components.
65 setLayout(new GridLayout(4,1));
66 setBorder(BorderFactory.createLineBorder(Color.black));
67 TitleListener tl = new TitleListener();
69 setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
70 title = new JTextField(trackName);
71 title.setFont(Moosique.getGUI().FONT);
72 title.addFocusListener(new TitleFocusListener());
76 if (channel == 9) type = MooInstrumentList.DRUMS;
77 else type = MooInstrumentList.INSTRUMENTS;
78 instruments = new MooInstrumentList(channel, type, programChangeMessage);
81 channelBox = new JComboBox();
82 channelBox.setFont(Moosique.getGUI().FONT);
83 for (int i = 1; i <= 16; i++)
84 channelBox.addItem(new Integer(i));
86 channelBox.setSelectedIndex(channel);
88 channelBox.addActionListener(tl);
91 JPanel checkboxes = new JPanel();
92 checkboxes.setLayout(new GridLayout(1,3));
94 mute = new JCheckBox("Mute");
95 mute.setSelected(false);
96 Moosique.setTrackMute(track, false);
97 mute.setFont(Moosique.getGUI().FONT);
98 mute.addActionListener(tl);
101 solo = new JCheckBox("Solo");
102 solo.setSelected(false);
103 Moosique.setTrackSolo(track, false);
104 solo.setFont(Moosique.getGUI().FONT);
105 solo.addActionListener(tl);
106 checkboxes.add(solo);
112 * Returns the channel of the track that the view is visualising.
113 * @return the chanel of the visualised track
115 public int getChannel() {
120 * Sets the track view this title should update after recording.
121 * @param the track view
123 public void setTrackView(MooTrackView tv) {
128 * When the title field loses focus, updates the corresponding MidiEvent.
130 class TitleFocusListener extends FocusAdapter {
131 public void focusLost(FocusEvent e) {
133 trackNameMessage.setMessage(3, title.getText().getBytes(), title.getText().length());
134 } catch (InvalidMidiDataException ex) {}
139 * Takes the appropriate action when a user selects an item on the popup menu.
141 class TitleListener implements ActionListener {
142 public void actionPerformed(ActionEvent e) {
143 Object source = e.getSource();
144 if (source == channelBox) {
145 channel = channelBox.getSelectedIndex();
148 instruments.setChannel(channel);
149 // Prompt the user before rechannelling???
150 for (int j = 0; j < track.size(); j++) {
152 if (me instanceof MooNote){
154 mn.setChannel(channel);
157 } else if (source == solo) {
158 boolean selected = mute.isSelected();
160 solo.setSelected(false);
161 Moosique.setTrackSolo(track, false);
163 Moosique.setTrackMute(track, selected);
164 } else if (source == mute) {
165 boolean selected = solo.isSelected();
167 mute.setSelected(false);
168 Moosique.setTrackMute(track, false);
170 Moosique.setTrackSolo(track, selected);