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());
63 instruments = new MooInstrumentList(channel);
64 // instruments = new MooInstrumentList(channel, programChangeMessage);
67 channelBox = new JComboBox();
68 channelBox.setFont(Moosique.getGUI().FONT);
69 for (int i = 1; i <= 16; i++)
70 channelBox.addItem(new Integer(i));
72 channelBox.setSelectedIndex(channel);
74 channelBox.addActionListener(new ActionListener(){
75 public void actionPerformed(ActionEvent e){
76 int chan = channelBox.getSelectedIndex();
79 instruments.setChannel(channelBox.getSelectedIndex());
80 for (int j = 0; j < track.size(); j++) {
82 if (me instanceof MooNote){
89 JPanel checkboxes = new JPanel();
90 checkboxes.setLayout(new GridLayout(1,3));
92 mute = new JCheckBox("Mute");
93 mute.setSelected(Moosique.getChannel(channel).getMute());
94 mute.setFont(Moosique.getGUI().FONT);
95 mute.addActionListener(new ActionListener(){
96 public void actionPerformed(ActionEvent event){
97 boolean selected = mute.isSelected();
99 solo.setSelected(false);
100 Moosique.getChannel(channel).setSolo(false);
102 Moosique.getChannel(channel).setMute(selected);
105 checkboxes.add(mute);
107 solo = new JCheckBox("Solo");
108 solo.setSelected(Moosique.getChannel(channel).getSolo());
109 solo.setFont(Moosique.getGUI().FONT);
110 solo.addActionListener(new ActionListener(){
111 public void actionPerformed(ActionEvent event){
113 boolean selected = solo.isSelected();
115 mute.setSelected(false);
116 Moosique.getChannel(channel).setMute(false);
118 Moosique.getChannel(channel).setSolo(selected);
120 checkboxes.add(solo);
125 * Returns the channel of the track that the view is visualising.
126 * @return the chanel of the visualised track
128 public int getChannel() {
133 * Checks if the focus is lost.
135 class TitleFocusListener extends FocusAdapter {
136 public void focusLost(FocusEvent e) {
137 // Update the MidiEvent containing the title of this track