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;
19 private JTextField title;
20 private MooInstrumentList instruments;
21 private JComboBox channelBox;
22 private JCheckBox mute;
23 private JCheckBox solo;
25 private String trackName = "";
26 private int channel = 0;
29 * Creates the title bar.
30 * @param aTrack the track that this tracktitle is operating on.
32 public MooTrackTitle (Track aTrack) {
33 setDoubleBuffered(true);
36 // Finds track name, program change and channel.
39 for (int i = 0; i < track.size(); i++) {
40 msg = track.get(i).getMessage();
41 status = msg.getStatus();
42 if (status == MetaMessage.META) {
43 if (((MetaMessage)msg).getType() == 3) {
44 trackNameMessage = (MetaMessage)msg;
45 trackName = new String(trackNameMessage.getData());
47 } else if (status >= 192 && status <= 207) {
48 programChangeMessage = (ShortMessage)msg;
49 channel = status - 192;
53 // Creates and places components.
54 setLayout(new GridLayout(4,1));
55 setBorder(BorderFactory.createLineBorder(Color.black));
57 setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
58 title = new JTextField(trackName);
59 title.setFont(Moosique.getGUI().FONT);
60 title.addFocusListener(new TitleFocusListener());
64 if (channel == 9) type = MooInstrumentList.DRUMS;
65 else type = MooInstrumentList.INSTRUMENTS;
66 instruments = new MooInstrumentList(channel, type);
67 // instruments = new MooInstrumentList(channel, type, programChangeMessage);
70 channelBox = new JComboBox();
71 channelBox.setFont(Moosique.getGUI().FONT);
72 for (int i = 1; i <= 16; i++)
73 channelBox.addItem(new Integer(i));
75 channelBox.setSelectedIndex(channel);
77 channelBox.addActionListener(new ActionListener(){
78 public void actionPerformed(ActionEvent e){
79 channel = channelBox.getSelectedIndex();
82 instruments.setChannel(channel);
83 for (int j = 0; j < track.size(); j++) {
85 if (me instanceof MooNote){
87 mn.setChannel(channel);
92 JPanel checkboxes = new JPanel();
93 checkboxes.setLayout(new GridLayout(1,3));
95 mute = new JCheckBox("Mute");
96 mute.setSelected(Moosique.getChannel(channel).getMute());
97 mute.setFont(Moosique.getGUI().FONT);
98 mute.addActionListener(new ActionListener(){
99 public void actionPerformed(ActionEvent event){
100 boolean selected = mute.isSelected();
102 solo.setSelected(false);
103 Moosique.getChannel(channel).setSolo(false);
105 Moosique.getChannel(channel).setMute(selected);
108 checkboxes.add(mute);
110 solo = new JCheckBox("Solo");
111 solo.setSelected(Moosique.getChannel(channel).getSolo());
112 solo.setFont(Moosique.getGUI().FONT);
113 solo.addActionListener(new ActionListener(){
114 public void actionPerformed(ActionEvent event){
116 boolean selected = solo.isSelected();
118 mute.setSelected(false);
119 Moosique.getChannel(channel).setMute(false);
121 Moosique.getChannel(channel).setSolo(selected);
123 checkboxes.add(solo);
128 * Returns the channel of the track that the view is visualising.
129 * @return the chanel of the visualised track
131 public int getChannel() {
136 * Checks if the focus is lost.
138 class TitleFocusListener extends FocusAdapter {
139 public void focusLost(FocusEvent e) {
140 // Update the MidiEvent containing the title of this track