]> ruin.nu Git - moosique.git/blob - MooTrackTitle.java
nu är även den fina scale velocity dialogen färdig
[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 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
32          */
33         public MooTrackTitle (Track aTrack, int chan) {
34                 this(aTrack);
35                 channel = chan;
36         }
37
38         /** 
39          * Creates the title bar.
40          * @param aTrack the track that this tracktitle is operating on.
41          */
42         public MooTrackTitle (Track aTrack) {
43                 setDoubleBuffered(true);
44                 track = aTrack;
45
46                 // Finds track name, program change and channel.
47                 MidiMessage msg;
48                 int status;
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());
56                                 }
57                         } else if (status >= 192 && status <= 207) {
58                                 programChangeMessage = (ShortMessage)msg;
59                                 channel = status - 192;
60                         }
61                 }
62
63                 // Creates and places components.
64                 setLayout(new GridLayout(4,1));
65                 setBorder(BorderFactory.createLineBorder(Color.black));
66
67                 setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
68                 title = new JTextField(trackName);
69                 title.setFont(Moosique.getGUI().FONT);
70                 title.addFocusListener(new TitleFocusListener());
71                 add(title);
72
73                 int type;
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);
78                 add(instruments);
79
80                 channelBox = new JComboBox();
81                 channelBox.setFont(Moosique.getGUI().FONT);
82                 for (int i = 1; i <= 16; i++)
83                         channelBox.addItem(new Integer(i));
84
85                 channelBox.setSelectedIndex(channel);
86
87                 channelBox.addActionListener(new ActionListener(){
88                                 public void actionPerformed(ActionEvent e){
89                                         channel = channelBox.getSelectedIndex();
90                                         MidiEvent me;
91                                         MooNote mn;
92                                         instruments.setChannel(channel);
93                                         for (int j = 0; j < track.size(); j++) {
94                                                 me = track.get(j);
95                                             if (me instanceof MooNote){
96                                                         mn = (MooNote)me;
97                                                         mn.setChannel(channel);
98                                                 }
99                                 }}});
100                 add(channelBox);
101
102                 JPanel checkboxes = new JPanel();
103                 checkboxes.setLayout(new GridLayout(1,3));
104
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();
112                                         if (selected){
113                                                 solo.setSelected(false);
114                                                 Moosique.setTrackSolo(track, false);
115                                         }
116                                         Moosique.setTrackMute(track, selected);
117
118                                 }});
119                 checkboxes.add(mute);
120
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){
127                                         //setSolo
128                                         boolean selected = solo.isSelected();
129                                         if (selected){
130                                                 mute.setSelected(false);
131                                                 Moosique.setTrackMute(track, false);
132                                         }
133                                         Moosique.setTrackSolo(track, selected);
134                                 }});
135                 checkboxes.add(solo);
136                 add(checkboxes);
137         }
138         
139         /** 
140          * Returns the channel of the track that the view is visualising.
141          * @return the chanel of the visualised track
142          */
143         public int getChannel() {
144                 return channel;
145         }
146
147         /**
148          * Checks if the focus is lost.
149          */
150         class TitleFocusListener extends FocusAdapter {
151                 public void focusLost(FocusEvent e) {
152                         // Update the MidiEvent containing the title of this track
153                 }
154         }
155 }