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.getSequencer().getTrackMute(getTrackNum()));
97 mute.setFont(Moosique.getGUI().FONT);
98 mute.addActionListener(new ActionListener(){
99 public void actionPerformed(ActionEvent event){
100 boolean selected = mute.isSelected();
101 int trackNum = getTrackNum();
103 solo.setSelected(false);
104 Moosique.getSequencer().setTrackSolo(trackNum, false);
106 Moosique.getSequencer().setTrackMute(trackNum, selected);
109 checkboxes.add(mute);
111 solo = new JCheckBox("Solo");
112 solo.setSelected(Moosique.getSequencer().getTrackSolo(getTrackNum()));
113 solo.setFont(Moosique.getGUI().FONT);
114 solo.addActionListener(new ActionListener(){
115 public void actionPerformed(ActionEvent event){
117 boolean selected = solo.isSelected();
118 int trackNum = getTrackNum();
120 mute.setSelected(false);
121 Moosique.getSequencer().setTrackMute(trackNum, false);
123 Moosique.getSequencer().setTrackSolo(trackNum, selected);
125 checkboxes.add(solo);
130 * Returns the channel of the track that the view is visualising.
131 * @return the chanel of the visualised track
133 public int getChannel() {
137 protected int getTrackNum() {
138 Track[] tracks = Moosique.getSequence().getTracks();
140 for (int i = 0; i < tracks.length; i++) {
141 if (tracks[i] == track)
144 System.out.println("Couldn't find track");
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