]> ruin.nu Git - moosique.git/blob - MooTrackTitle.java
*** empty log 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 MetaMessage trackNameMessage;
16         private String trackName = "";
17         private ShortMessage programChangeMessage;
18         private int programChange = 0, channel = 0;
19         private JTextField title;
20         private MooInstrumentList instruments;
21         private JComboBox channelBox;
22         private JCheckBox mute;
23         private JCheckBox solo;
24         private Track track;
25
26         /** 
27          * Creates the title bar.
28          */
29         public MooTrackTitle (Track aTrack) {
30                 track = aTrack;
31
32                 // Finds track name and program change
33                 MidiMessage msg;
34                 for (int i = 0; i < track.size(); i++) {
35                         msg = track.get(i).getMessage();
36                         if (msg.getStatus() == 255) {
37                                 if (((MetaMessage)msg).getType() == 3) {
38                                         trackNameMessage = (MetaMessage)msg;
39                                         trackName = new String(trackNameMessage.getData());
40                                 }
41                         } else if (msg.getStatus() == 192) {
42                                 programChangeMessage = (ShortMessage)msg;
43                                 programChange = programChangeMessage.getData1();
44                         }
45                 }
46
47                 MidiEvent event;
48                 for (int i = 0; i < track.size(); i++) {
49                         event = track.get(i);
50                         if (event instanceof MooNote) channel = ((MooNote)event).getChannel();
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); // JTextField(String text, int columns) 
59                 title.setFont(Moosique.getGUI().FONT);
60                 title.addFocusListener(new TitleFocusListener());
61                 add(title);
62
63                 instruments = new MooInstrumentList(programChange);
64                 add(instruments);
65
66                 JPanel checkboxes = new JPanel();
67                 checkboxes.setLayout(new GridLayout(1,3));
68
69                 channelBox = new JComboBox();
70                 channelBox.setFont(Moosique.getGUI().FONT);
71                 for (int i = 1; i <= 16; i++)
72                         channelBox.addItem(new Integer(i));
73
74                 for (int j = 0; j < track.size(); j++) {
75                         MidiEvent me = track.get(j);
76                 if (me instanceof MooNote){
77                                 MooNote mn = (MooNote)me;
78                                 channelBox.setSelectedIndex(mn.getChannel());
79                                 break;
80                         }
81         }
82
83                 instruments = new MooInstrumentList(channelBox.getSelectedIndex());
84
85                 channelBox.addActionListener(new ActionListener(){
86                                 public void actionPerformed(ActionEvent e){
87                                         int chan = channelBox.getSelectedIndex();
88                                         MidiEvent me;
89                                         MooNote mn;
90                                         instruments.setChannel(channelBox.getSelectedIndex());
91                                         for (int j = 0; j < track.size(); j++) {
92                                                 me = track.get(j);
93                                             if (me instanceof MooNote){
94                                                         mn = (MooNote)me;
95                                                         mn.setChannel(chan);
96                                                 }
97                                 }}});
98                 channelBox.setSelectedIndex(channel);
99                 add(channelBox);
100
101                 mute = new JCheckBox("Mute");
102                 mute.setFont(Moosique.getGUI().FONT);
103                 mute.addActionListener(new ActionListener(){
104                                 public void actionPerformed(ActionEvent event){
105                                         //setMute
106                                         solo.setSelected(false);
107                                 }});
108                 checkboxes.add(mute);
109
110                 solo = new JCheckBox("Solo");
111                 solo.setFont(Moosique.getGUI().FONT);
112                 solo.addActionListener(new ActionListener(){
113                                 public void actionPerformed(ActionEvent event){
114                                         //setSolo
115                                         mute.setSelected(false);
116                                 }});
117                 checkboxes.add(solo);
118
119                 add(instruments);
120                 add(checkboxes);
121         }
122
123         class TitleFocusListener extends FocusAdapter {
124                 public void focusLost(FocusEvent e) {
125                         // Update the MidiEvent containing the title of this track
126                 }
127         }
128 }