]> ruin.nu Git - moosique.git/blobdiff - MooTrackTitle.java
setting mute and solo on channel instead..
[moosique.git] / MooTrackTitle.java
index e229c6dfbc3da8165bb9e9a4d50b800f6a71ead3..d5876c1485718a34f6ae3ef940152182d5f2974c 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,83 +12,109 @@ import javax.sound.midi.*;
  
 public class MooTrackTitle extends JPanel {
 
+       private Track track;
+       private MetaMessage trackNameMessage;
+       private ShortMessage programChangeMessage;
+
        private JTextField title;
        private MooInstrumentList instruments;
-       private JComboBox channel;
+       private JComboBox channelBox;
        private JCheckBox mute;
        private JCheckBox solo;
-       private Track track;
+
+       private String trackName = "";
+       private int channel = 0;
+
        /** 
         * Creates the title bar.
         */
        public MooTrackTitle (Track aTrack) {
+               setDoubleBuffered(true);
                track = aTrack;
+
+               // Finds track name, program change and channel.
+               MidiMessage msg;
+               int status;
+               for (int i = 0; i < track.size(); i++) {
+                       msg = track.get(i).getMessage();
+                       status = msg.getStatus();
+                       if (status == MetaMessage.META) {
+                               if (((MetaMessage)msg).getType() == 3) {
+                                       trackNameMessage = (MetaMessage)msg;
+                                       trackName = new String(trackNameMessage.getData());
+                               }
+                       } else if (status >= 192 && status <= 207) {
+                               programChangeMessage = (ShortMessage)msg;
+                               channel = status - 192;
+                       }
+               }
+
+               // 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);
                title.setFont(Moosique.getGUI().FONT);
                title.addFocusListener(new TitleFocusListener());
                add(title);
 
-               instruments = new MooInstrumentList();
+               instruments = new MooInstrumentList(channel);
+               // instruments = new MooInstrumentList(channel, programChangeMessage);
                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));
-
-               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());
-                               break;
-                       }
-        }
-
-               channel.addItemListener(new ItemListener(){
-                               public void itemStateChanged(ItemEvent e){
-                                       Object ob = channel.getSelectedItem();
-                                       if (ob instanceof Integer){
-                                               int chan = ((Integer)ob).intValue();
-                                               //set channel
-                                               MidiEvent me;
-                                               MooNote mn;
-                                               for (int j = 0; j < track.size(); j++) {
-                                                       me = track.get(j);
-                                               if (me instanceof MooNote){
-                                                               mn = (MooNote)me;
-                                                               mn.setChannel(chan);
-                                                               System.out.println(ob);
-                                                       }
-                                   }
-                                       }
-                               }});
+                       channelBox.addItem(new Integer(i));
+
+               channelBox.setSelectedIndex(channel);
 
-               add(channel);
-               
+               channelBox.addActionListener(new ActionListener(){
+                               public void actionPerformed(ActionEvent e){
+                                       int chan = channelBox.getSelectedIndex();
+                                       MidiEvent me;
+                                       MooNote mn;
+                                       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);
+                                               }
+                               }}});
+               add(channelBox);
+
+               JPanel checkboxes = new JPanel();
+               checkboxes.setLayout(new GridLayout(1,3));
 
                mute = new JCheckBox("Mute");
+               mute.setSelected(Moosique.getChannel(channel).getMute());
                mute.setFont(Moosique.getGUI().FONT);
                mute.addActionListener(new ActionListener(){
                                public void actionPerformed(ActionEvent event){
-                                       //setMute
-                                       solo.setSelected(false);
+                                       boolean selected = mute.isSelected();
+                                       if (selected){
+                                               solo.setSelected(false);
+                                               Moosique.getChannel(channel).setSolo(false);
+                                       }
+                                       Moosique.getChannel(channel).setMute(selected);
+
                                }});
                checkboxes.add(mute);
 
                solo = new JCheckBox("Solo");
+               solo.setSelected(Moosique.getChannel(channel).getSolo());
                solo.setFont(Moosique.getGUI().FONT);
                solo.addActionListener(new ActionListener(){
                                public void actionPerformed(ActionEvent event){
                                        //setSolo
-                                       mute.setSelected(false);
+                                       boolean selected = solo.isSelected();
+                                       if (selected){
+                                               mute.setSelected(false);
+                                               Moosique.getChannel(channel).setMute(false);
+                                       }
+                                       Moosique.getChannel(channel).setSolo(selected);
                                }});
                checkboxes.add(solo);
                add(checkboxes);