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;
25 private JButton record;
27 private String trackName = "";
28 private int channel = 0;
31 * Creates the title bar for an empty track, and therefore an initial channel is required.
32 * @param aTrack the track that this tracktitle is operating on.
33 * @param chan the initial channel
35 public MooTrackTitle (Track aTrack, int chan) {
41 * Creates the title bar.
42 * @param aTrack the track that this tracktitle is operating on.
44 public MooTrackTitle (Track aTrack) {
45 setDoubleBuffered(true);
48 // Finds track name, program change and channel.
51 for (int i = 0; i < track.size(); i++) {
52 msg = track.get(i).getMessage();
53 status = msg.getStatus();
54 if (status == MetaMessage.META) {
55 if (((MetaMessage)msg).getType() == 3) {
56 trackNameMessage = (MetaMessage)msg;
57 trackName = new String(trackNameMessage.getData());
59 } else if (status >= 192 && status <= 207) {
60 programChangeMessage = (ShortMessage)msg;
61 channel = status - 192;
65 // Creates and places components.
66 setLayout(new GridLayout(4,1));
67 setBorder(BorderFactory.createLineBorder(Color.black));
68 TitleListener tl = new TitleListener();
70 setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
71 title = new JTextField(trackName);
72 title.setFont(Moosique.getGUI().FONT);
73 title.addFocusListener(new TitleFocusListener());
77 if (channel == 9) type = MooInstrumentList.DRUMS;
78 else type = MooInstrumentList.INSTRUMENTS;
79 instruments = new MooInstrumentList(channel, type);
80 // instruments = new MooInstrumentList(channel, type, programChangeMessage);
83 channelBox = new JComboBox();
84 channelBox.setFont(Moosique.getGUI().FONT);
85 for (int i = 1; i <= 16; i++)
86 channelBox.addItem(new Integer(i));
88 channelBox.setSelectedIndex(channel);
90 channelBox.addActionListener(tl);
93 JPanel checkboxes = new JPanel();
94 checkboxes.setLayout(new GridLayout(1,3));
96 mute = new JCheckBox("Mute");
97 mute.setSelected(false);
98 Moosique.setTrackMute(track, false);
99 mute.setFont(Moosique.getGUI().FONT);
100 mute.addActionListener(tl);
101 checkboxes.add(mute);
103 solo = new JCheckBox("Solo");
104 solo.setSelected(false);
105 Moosique.setTrackSolo(track, false);
106 solo.setFont(Moosique.getGUI().FONT);
107 solo.addActionListener(tl);
108 checkboxes.add(solo);
110 record = new JButton("Record");
111 record.setFont(Moosique.getGUI().FONT);
112 record.addActionListener(tl);
113 checkboxes.add(record);
119 * Returns the channel of the track that the view is visualising.
120 * @return the chanel of the visualised track
122 public int getChannel() {
127 * Sets the track view this title should update after recording.
128 * @param the track view
130 public void setTrackView(MooTrackView tv) {
135 * Checks if the focus is lost.
137 class TitleFocusListener extends FocusAdapter {
138 public void focusLost(FocusEvent e) {
139 // Update the MidiEvent containing the title of this track
144 * Takes the appropriate action when a user selects an item on the popup menu.
146 class TitleListener implements ActionListener {
147 public void actionPerformed(ActionEvent e) {
148 Object source = e.getSource();
149 if (source == channelBox) {
150 channel = channelBox.getSelectedIndex();
153 instruments.setChannel(channel);
154 // Query the user before rechannelling???
155 for (int j = 0; j < track.size(); j++) {
157 if (me instanceof MooNote){
159 mn.setChannel(channel);
162 } else if (source == solo) {
163 boolean selected = mute.isSelected();
165 solo.setSelected(false);
166 Moosique.setTrackSolo(track, false);
168 Moosique.setTrackMute(track, selected);
169 } else if (source == mute) {
170 boolean selected = solo.isSelected();
172 mute.setSelected(false);
173 Moosique.setTrackMute(track, false);
175 Moosique.setTrackSolo(track, selected);
176 } else if (source == record) {
177 Sequencer sequencer = Moosique.getSequencer();
178 if (record.getText() == "Record") {
179 record.setText("Stop");
180 mtv.enableKeyboardRecording();
181 sequencer.recordEnable(track, channel);
182 sequencer.startRecording();
183 Moosique.setEdited();
185 record.setText("Record");
186 mtv.disableKeyboardRecording();
187 sequencer.stopRecording();
188 sequencer.recordDisable(track);
189 mtv.placeNoteElements();