]> ruin.nu Git - moosique.git/blob - MooTrackTitle.java
play hangs when changing duration on a note.
[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                                         channel = channelBox.getSelectedIndex();
80                                         MidiEvent me;
81                                         MooNote mn;
82                                         instruments.setChannel(channel);
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(channel);
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(false);
97                 Moosique.setTrackMute(track, false);
98                 mute.setFont(Moosique.getGUI().FONT);
99                 mute.addActionListener(new ActionListener(){
100                                 public void actionPerformed(ActionEvent event){
101                                         boolean selected = mute.isSelected();
102                                         if (selected){
103                                                 solo.setSelected(false);
104                                                 Moosique.setTrackSolo(track, false);
105                                         }
106                                         Moosique.setTrackMute(track, selected);
107
108                                 }});
109                 checkboxes.add(mute);
110
111                 solo = new JCheckBox("Solo");
112                 solo.setSelected(false);
113                 Moosique.setTrackSolo(track, false);
114                 solo.setFont(Moosique.getGUI().FONT);
115                 solo.addActionListener(new ActionListener(){
116                                 public void actionPerformed(ActionEvent event){
117                                         //setSolo
118                                         boolean selected = solo.isSelected();
119                                         if (selected){
120                                                 mute.setSelected(false);
121                                                 Moosique.setTrackMute(track, false);
122                                         }
123                                         Moosique.setTrackSolo(track, selected);
124                                 }});
125                 checkboxes.add(solo);
126                 add(checkboxes);
127         }
128         
129         /** 
130          * Returns the channel of the track that the view is visualising.
131          * @return the chanel of the visualised track
132          */
133         public int getChannel() {
134                 return channel;
135         }
136
137         /**
138          * Checks if the focus is lost.
139          */
140         class TitleFocusListener extends FocusAdapter {
141                 public void focusLost(FocusEvent e) {
142                         // Update the MidiEvent containing the title of this track
143                 }
144         }
145 }