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 {
15 private MetaMessage trackNameMessage;
16 private String trackName = "";
17 private ShortMessage programChangeMessage;
18 private int programChange = 0, channel = 0;
19 private JTextField title;
20 private MooInstrumentList instruments;
21 private JComboBox channelBox;
22 private JCheckBox mute;
23 private JCheckBox solo;
27 * Creates the title bar.
29 public MooTrackTitle (Track aTrack) {
32 // Finds track name and program change
34 for (int i = 0; i < track.size(); i++) {
35 msg = track.get(i).getMessage();
36 if (msg.getStatus() == 255) {
37 if (((MetaMessage)msg).getType() == 3) {
38 trackNameMessage = (MetaMessage)msg;
39 trackName = new String(trackNameMessage.getData());
41 } else if (msg.getStatus() == 192) {
42 programChangeMessage = (ShortMessage)msg;
43 programChange = programChangeMessage.getData1();
48 for (int i = 0; i < track.size(); i++) {
50 if (event instanceof MooNote) channel = ((MooNote)event).getChannel();
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); // JTextField(String text, int columns)
59 title.setFont(Moosique.getGUI().FONT);
60 title.addFocusListener(new TitleFocusListener());
63 instruments = new MooInstrumentList(programChange);
66 JPanel checkboxes = new JPanel();
67 checkboxes.setLayout(new GridLayout(1,3));
69 channelBox = new JComboBox();
70 channelBox.setFont(Moosique.getGUI().FONT);
71 for (int i = 1; i <= 16; i++)
72 channelBox.addItem(new Integer(i));
74 for (int j = 0; j < track.size(); j++) {
75 MidiEvent me = track.get(j);
76 if (me instanceof MooNote){
77 MooNote mn = (MooNote)me;
78 channelBox.setSelectedIndex(mn.getChannel());
83 instruments = new MooInstrumentList(channelBox.getSelectedIndex());
85 channelBox.addActionListener(new ActionListener(){
86 public void actionPerformed(ActionEvent e){
87 int chan = channelBox.getSelectedIndex();
90 instruments.setChannel(channelBox.getSelectedIndex());
91 for (int j = 0; j < track.size(); j++) {
93 if (me instanceof MooNote){
98 channelBox.setSelectedIndex(channel);
101 mute = new JCheckBox("Mute");
102 mute.setFont(Moosique.getGUI().FONT);
103 mute.addActionListener(new ActionListener(){
104 public void actionPerformed(ActionEvent event){
106 solo.setSelected(false);
108 checkboxes.add(mute);
110 solo = new JCheckBox("Solo");
111 solo.setFont(Moosique.getGUI().FONT);
112 solo.addActionListener(new ActionListener(){
113 public void actionPerformed(ActionEvent event){
115 mute.setSelected(false);
117 checkboxes.add(solo);
123 class TitleFocusListener extends FocusAdapter {
124 public void focusLost(FocusEvent e) {
125 // Update the MidiEvent containing the title of this track