]> ruin.nu Git - moosique.git/blob - MooTrackTitle.java
no message
[moosique.git] / MooTrackTitle.java
1 import javax.swing.*;
2 import java.awt.*;
3 import java.awt.event.*;
4 import javax.sound.midi.*;
5
6 /**
7  * The title bar for each track with track name, channelBox, instrument etc.
8  * 
9  * @author  Andersson, Andreen, Lanneskog, Pehrson
10  * @version 1
11  */
12  
13 public class MooTrackTitle extends JPanel {
14
15         private Track track;
16         private MetaMessage trackNameMessage;
17         private ShortMessage programChangeMessage;
18
19         private JTextField title;
20         private MooInstrumentList instruments;
21         private JComboBox channelBox;
22         private JCheckBox mute;
23         private JCheckBox solo;
24
25         private String trackName = "";
26         private int channel = 0;
27
28         /** 
29          * Creates the title bar.
30          * @param aTrack the track that this tracktitle is operating on.
31          */
32         public MooTrackTitle (Track aTrack) {
33                 setDoubleBuffered(true);
34                 track = aTrack;
35
36                 // Finds track name, program change and channel.
37                 MidiMessage msg;
38                 int status;
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());
46                                 }
47                         } else if (status >= 192 && status <= 207) {
48                                 programChangeMessage = (ShortMessage)msg;
49                                 channel = status - 192;
50                         }
51                 }
52
53                 // Creates and places components.
54                 setLayout(new GridLayout(4,1));
55                 setBorder(BorderFactory.createLineBorder(Color.black));
56
57                 setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
58                 title = new JTextField(trackName);
59                 title.setFont(Moosique.getGUI().FONT);
60                 title.addFocusListener(new TitleFocusListener());
61                 add(title);
62
63                 int type;
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);
68                 add(instruments);
69
70                 channelBox = new JComboBox();
71                 channelBox.setFont(Moosique.getGUI().FONT);
72                 for (int i = 1; i <= 16; i++)
73                         channelBox.addItem(new Integer(i));
74
75                 channelBox.setSelectedIndex(channel);
76
77                 channelBox.addActionListener(new ActionListener(){
78                                 public void actionPerformed(ActionEvent e){
79                                         int chan = channelBox.getSelectedIndex();
80                                         MidiEvent me;
81                                         MooNote mn;
82                                         instruments.setChannel(channelBox.getSelectedIndex());
83                                         for (int j = 0; j < track.size(); j++) {
84                                                 me = track.get(j);
85                                             if (me instanceof MooNote){
86                                                         mn = (MooNote)me;
87                                                         mn.setChannel(chan);
88                                                 }
89                                 }}});
90                 add(channelBox);
91
92                 JPanel checkboxes = new JPanel();
93                 checkboxes.setLayout(new GridLayout(1,3));
94
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();
101                                         if (selected){
102                                                 solo.setSelected(false);
103                                                 Moosique.getChannel(channel).setSolo(false);
104                                         }
105                                         Moosique.getChannel(channel).setMute(selected);
106
107                                 }});
108                 checkboxes.add(mute);
109
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){
115                                         //setSolo
116                                         boolean selected = solo.isSelected();
117                                         if (selected){
118                                                 mute.setSelected(false);
119                                                 Moosique.getChannel(channel).setMute(false);
120                                         }
121                                         Moosique.getChannel(channel).setSolo(selected);
122                                 }});
123                 checkboxes.add(solo);
124                 add(checkboxes);
125         }
126         
127         /** 
128          * Returns the channel of the track that the view is visualising.
129          * @return the chanel of the visualised track
130          */
131         public int getChannel() {
132                 return channel;
133         }
134
135         /**
136          * Checks if the focus is lost.
137          */
138         class TitleFocusListener extends FocusAdapter {
139                 public void focusLost(FocusEvent e) {
140                         // Update the MidiEvent containing the title of this track
141                 }
142         }
143 }