]> ruin.nu Git - moosique.git/commitdiff
*** empty log message ***
authorEinar Pehrson <einarp@itstud.chalmers.se>
Tue, 13 May 2003 16:56:26 +0000 (16:56 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Tue, 13 May 2003 16:56:26 +0000 (16:56 +0000)
MooTrackTitle.java

index 1d9171a84c2083909c24f8acd66ddc5e7e9ec63f..4630a763049d73e0991d73333de7ab240ccb0a6e 100644 (file)
@@ -4,7 +4,7 @@ import java.awt.event.*;
 import javax.sound.midi.*;
 
 /**
- * The title bar for each track with track name, channel, instrument etc.
+ * The title bar for each track with track name, channelBox, instrument etc.
  * 
  * @author  Andersson, Andreen, Lanneskog, Pehrson
  * @version 1
@@ -12,62 +12,91 @@ import javax.sound.midi.*;
  
 public class MooTrackTitle extends JPanel {
 
+       private MetaMessage trackNameMessage;
+       private String trackName = "";
+       private ShortMessage programChangeMessage;
+       private int programChange = 0, channel = 0;
        private JTextField title;
        private MooInstrumentList instruments;
-       private JComboBox channel;
+       private JComboBox channelBox;
        private JCheckBox mute;
        private JCheckBox solo;
        private Track track;
+
        /** 
         * Creates the title bar.
         */
        public MooTrackTitle (Track aTrack) {
                track = aTrack;
+
+               // Finds track name and program change
+               MidiMessage msg;
+               for (int i = 0; i < track.size(); i++) {
+                       msg = track.get(i).getMessage();
+                       if (msg.getStatus() == 255) {
+                               if (((MetaMessage)msg).getType() == 3) {
+                                       trackNameMessage = (MetaMessage)msg;
+                                       trackName = new String(trackNameMessage.getData());
+                               }
+                       } else if (msg.getStatus() == 192) {
+                               programChangeMessage = (ShortMessage)msg;
+                               programChange = programChangeMessage.getData1();
+                       }
+               }
+
+               MidiEvent event;
+               for (int i = 0; i < track.size(); i++) {
+                       event = track.get(i);
+                       if (event instanceof MooNote) channel = ((MooNote)event).getChannel();
+               }
+               
+               // Creates and places components.
                setLayout(new GridLayout(4,1));
                setBorder(BorderFactory.createLineBorder(Color.black));
 
                setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
-               title = new JTextField(); // JTextField(String text, int columns) 
+               title = new JTextField(trackName); // JTextField(String text, int columns) 
                title.setFont(Moosique.getGUI().FONT);
                title.addFocusListener(new TitleFocusListener());
                add(title);
 
+               instruments = new MooInstrumentList(programChange);
+               add(instruments);
 
                JPanel checkboxes = new JPanel();
                checkboxes.setLayout(new GridLayout(1,3));
 
-               channel = new JComboBox();
-               channel.setFont(Moosique.getGUI().FONT);
+               channelBox = new JComboBox();
+               channelBox.setFont(Moosique.getGUI().FONT);
                for (int i = 1; i <= 16; i++)
-                       channel.addItem(new Integer(i));
+                       channelBox.addItem(new Integer(i));
 
                for (int j = 0; j < track.size(); j++) {
                        MidiEvent me = track.get(j);
                if (me instanceof MooNote){
                                MooNote mn = (MooNote)me;
-                               channel.setSelectedIndex(mn.getChannel());
+                               channelBox.setSelectedIndex(mn.getChannel());
                                break;
                        }
         }
 
-               instruments = new MooInstrumentList(channel.getSelectedIndex());
+               instruments = new MooInstrumentList(channelBox.getSelectedIndex());
 
-               channel.addActionListener(new ActionListener(){
+               channelBox.addActionListener(new ActionListener(){
                                public void actionPerformed(ActionEvent e){
-                                       int chan = channel.getSelectedIndex();
+                                       int chan = channelBox.getSelectedIndex();
                                        MidiEvent me;
                                        MooNote mn;
-                                       instruments.setChannel(channel.getSelectedIndex());
+                                       instruments.setChannel(channelBox.getSelectedIndex());
                                        for (int j = 0; j < track.size(); j++) {
                                                me = track.get(j);
                                            if (me instanceof MooNote){
                                                        mn = (MooNote)me;
                                                        mn.setChannel(chan);
                                                }
-                               }
-                               }});
-
-               
+                               }}});
+               channelBox.setSelectedIndex(channel);
+               add(channelBox);
 
                mute = new JCheckBox("Mute");
                mute.setFont(Moosique.getGUI().FONT);
@@ -88,7 +117,6 @@ public class MooTrackTitle extends JPanel {
                checkboxes.add(solo);
 
                add(instruments);
-               add(channel);
                add(checkboxes);
        }