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 for an empty track, and therefore an initial channel is required.
30 * @param aTrack the track that this tracktitle is operating on.
31 * @param chan the initial channel
33 public MooTrackTitle (Track aTrack, int chan) {
39 * Creates the title bar.
40 * @param aTrack the track that this tracktitle is operating on.
42 public MooTrackTitle (Track aTrack) {
43 setDoubleBuffered(true);
46 // Finds track name, program change and channel.
49 for (int i = 0; i < track.size(); i++) {
50 msg = track.get(i).getMessage();
51 status = msg.getStatus();
52 if (status == MetaMessage.META) {
53 if (((MetaMessage)msg).getType() == 3) {
54 trackNameMessage = (MetaMessage)msg;
55 trackName = new String(trackNameMessage.getData());
57 } else if (status >= 192 && status <= 207) {
58 programChangeMessage = (ShortMessage)msg;
59 channel = status - 192;
63 // Creates and places components.
64 setLayout(new GridLayout(4,1));
65 setBorder(BorderFactory.createLineBorder(Color.black));
67 setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
68 title = new JTextField(trackName);
69 title.setFont(Moosique.getGUI().FONT);
70 title.addFocusListener(new TitleFocusListener());
74 if (channel == 9) type = MooInstrumentList.DRUMS;
75 else type = MooInstrumentList.INSTRUMENTS;
76 instruments = new MooInstrumentList(channel, type);
77 // instruments = new MooInstrumentList(channel, type, programChangeMessage);
80 channelBox = new JComboBox();
81 channelBox.setFont(Moosique.getGUI().FONT);
82 for (int i = 1; i <= 16; i++)
83 channelBox.addItem(new Integer(i));
85 channelBox.setSelectedIndex(channel);
87 channelBox.addActionListener(new ActionListener(){
88 public void actionPerformed(ActionEvent e){
89 channel = channelBox.getSelectedIndex();
92 instruments.setChannel(channel);
93 for (int j = 0; j < track.size(); j++) {
95 if (me instanceof MooNote){
97 mn.setChannel(channel);
102 JPanel checkboxes = new JPanel();
103 checkboxes.setLayout(new GridLayout(1,3));
105 mute = new JCheckBox("Mute");
106 mute.setSelected(false);
107 Moosique.setTrackMute(track, false);
108 mute.setFont(Moosique.getGUI().FONT);
109 mute.addActionListener(new ActionListener(){
110 public void actionPerformed(ActionEvent event){
111 boolean selected = mute.isSelected();
113 solo.setSelected(false);
114 Moosique.setTrackSolo(track, false);
116 Moosique.setTrackMute(track, selected);
119 checkboxes.add(mute);
121 solo = new JCheckBox("Solo");
122 solo.setSelected(false);
123 Moosique.setTrackSolo(track, false);
124 solo.setFont(Moosique.getGUI().FONT);
125 solo.addActionListener(new ActionListener(){
126 public void actionPerformed(ActionEvent event){
128 boolean selected = solo.isSelected();
130 mute.setSelected(false);
131 Moosique.setTrackMute(track, false);
133 Moosique.setTrackSolo(track, selected);
135 checkboxes.add(solo);
140 * Returns the channel of the track that the view is visualising.
141 * @return the chanel of the visualised track
143 public int getChannel() {
148 * Checks if the focus is lost.
150 class TitleFocusListener extends FocusAdapter {
151 public void focusLost(FocusEvent e) {
152 // Update the MidiEvent containing the title of this track