]> ruin.nu Git - moosique.git/blobdiff - MooTrackTitle.java
no message
[moosique.git] / MooTrackTitle.java
index fd9aa967599be3ebc647f9ee8bf792494a90db96..c2f1c0fa20097364e509b16493e548ec7916f250 100644 (file)
@@ -12,60 +12,60 @@ import javax.sound.midi.*;
  
 public class MooTrackTitle extends JPanel {
 
+       private Track track;
        private MetaMessage trackNameMessage;
-       private String trackName = "";
        private ShortMessage programChangeMessage;
-       private int programChange = 0, channel = 0;
+
        private JTextField title;
        private MooInstrumentList instruments;
        private JComboBox channelBox;
        private JCheckBox mute;
        private JCheckBox solo;
-       private Track track;
-       private int trackNum;
+
+       private String trackName = "";
+       private int channel = 0;
 
        /** 
         * Creates the title bar.
+        * @param aTrack the track that this tracktitle is operating on.
         */
-       public MooTrackTitle (Track aTrack, int aTrackNum) {
+       public MooTrackTitle (Track aTrack) {
                setDoubleBuffered(true);
                track = aTrack;
-               this.trackNum = aTrackNum;
 
-               // Finds track name and program change
+               // Finds track name, program change and channel.
                MidiMessage msg;
+               int status;
                for (int i = 0; i < track.size(); i++) {
                        msg = track.get(i).getMessage();
-                       if (msg.getStatus() == 255) {
+                       status = msg.getStatus();
+                       if (status == MetaMessage.META) {
                                if (((MetaMessage)msg).getType() == 3) {
                                        trackNameMessage = (MetaMessage)msg;
                                        trackName = new String(trackNameMessage.getData());
                                }
-                       } else if (msg.getStatus() == 192) {
+                       } else if (status >= 192 && status <= 207) {
                                programChangeMessage = (ShortMessage)msg;
-                               programChange = programChangeMessage.getData1();
+                               channel = status - 192;
                        }
                }
 
-               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(trackName); // JTextField(String text, int columns) 
+               title = new JTextField(trackName);
                title.setFont(Moosique.getGUI().FONT);
                title.addFocusListener(new TitleFocusListener());
                add(title);
 
-
-               JPanel checkboxes = new JPanel();
-               checkboxes.setLayout(new GridLayout(1,3));
+               int type;
+               if (channel == 9) type = MooInstrumentList.DRUMS;
+               else type = MooInstrumentList.INSTRUMENTS;
+               instruments = new MooInstrumentList(channel, type);
+               // instruments = new MooInstrumentList(channel, type, programChangeMessage);
+               add(instruments);
 
                channelBox = new JComboBox();
                channelBox.setFont(Moosique.getGUI().FONT);
@@ -74,10 +74,6 @@ public class MooTrackTitle extends JPanel {
 
                channelBox.setSelectedIndex(channel);
 
-               instruments = new MooInstrumentList(channelBox.getSelectedIndex());
-
-               instruments = new MooInstrumentList(channelBox.getSelectedIndex());
-
                channelBox.addActionListener(new ActionListener(){
                                public void actionPerformed(ActionEvent e){
                                        int chan = channelBox.getSelectedIndex();
@@ -91,28 +87,28 @@ public class MooTrackTitle extends JPanel {
                                                        mn.setChannel(chan);
                                                }
                                }}});
-               channelBox.setSelectedIndex(channel);
-
-               add(instruments);
                add(channelBox);
 
+               JPanel checkboxes = new JPanel();
+               checkboxes.setLayout(new GridLayout(1,3));
+
                mute = new JCheckBox("Mute");
-               mute.setSelected(Moosique.getSequencer().getTrackMute(trackNum));
+               mute.setSelected(Moosique.getChannel(channel).getMute());
                mute.setFont(Moosique.getGUI().FONT);
                mute.addActionListener(new ActionListener(){
                                public void actionPerformed(ActionEvent event){
                                        boolean selected = mute.isSelected();
                                        if (selected){
                                                solo.setSelected(false);
-                                               Moosique.getSequencer().setTrackSolo(trackNum, false);
+                                               Moosique.getChannel(channel).setSolo(false);
                                        }
-                                       Moosique.getSequencer().setTrackMute(trackNum, selected);
+                                       Moosique.getChannel(channel).setMute(selected);
 
                                }});
                checkboxes.add(mute);
 
                solo = new JCheckBox("Solo");
-               solo.setSelected(Moosique.getSequencer().getTrackSolo(trackNum));
+               solo.setSelected(Moosique.getChannel(channel).getSolo());
                solo.setFont(Moosique.getGUI().FONT);
                solo.addActionListener(new ActionListener(){
                                public void actionPerformed(ActionEvent event){
@@ -120,14 +116,25 @@ public class MooTrackTitle extends JPanel {
                                        boolean selected = solo.isSelected();
                                        if (selected){
                                                mute.setSelected(false);
-                                               Moosique.getSequencer().setTrackMute(trackNum, false);
+                                               Moosique.getChannel(channel).setMute(false);
                                        }
-                                       Moosique.getSequencer().setTrackSolo(trackNum, selected);
+                                       Moosique.getChannel(channel).setSolo(selected);
                                }});
                checkboxes.add(solo);
                add(checkboxes);
        }
+       
+       /** 
+        * Returns the channel of the track that the view is visualising.
+        * @return the chanel of the visualised track
+        */
+       public int getChannel() {
+               return channel;
+       }
 
+       /**
+        * Checks if the focus is lost.
+        */
        class TitleFocusListener extends FocusAdapter {
                public void focusLost(FocusEvent e) {
                        // Update the MidiEvent containing the title of this track