]> ruin.nu Git - moosique.git/blobdiff - MooTrackTitle.java
play hangs when changing duration on a note.
[moosique.git] / MooTrackTitle.java
index 0eb3128db8ccd4f5980cd198afe20840d87ccf3f..f2bed14e37b919130e2c6abda153bdc113aed64c 100644 (file)
 import javax.swing.*;
 import java.awt.*;
 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
  */
  
-public class MooTrackTitle extends JPanel{
+public class MooTrackTitle extends JPanel {
 
+       private Track track;
+       private MetaMessage trackNameMessage;
+       private ShortMessage programChangeMessage;
+
+       private JTextField title;
        private MooInstrumentList instruments;
-       //private JSpinner channel;
+       private JComboBox channelBox;
        private JCheckBox mute;
        private JCheckBox solo;
+
+       private String trackName = "";
+       private int channel = 0;
+
        /** 
         * Creates the title bar.
+        * @param aTrack the track that this tracktitle is operating on.
         */
-       public MooTrackTitle () {
-               setLayout(new GridLayout(1,3));
-               instruments = new MooInstrumentList();
+       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(trackName);
+               title.setFont(Moosique.getGUI().FONT);
+               title.addFocusListener(new TitleFocusListener());
+               add(title);
+
+               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);
+               for (int i = 1; i <= 16; i++)
+                       channelBox.addItem(new Integer(i));
+
+               channelBox.setSelectedIndex(channel);
+
+               channelBox.addActionListener(new ActionListener(){
+                               public void actionPerformed(ActionEvent e){
+                                       channel = channelBox.getSelectedIndex();
+                                       MidiEvent me;
+                                       MooNote mn;
+                                       instruments.setChannel(channel);
+                                       for (int j = 0; j < track.size(); j++) {
+                                               me = track.get(j);
+                                           if (me instanceof MooNote){
+                                                       mn = (MooNote)me;
+                                                       mn.setChannel(channel);
+                                               }
+                               }}});
+               add(channelBox);
+
+               JPanel checkboxes = new JPanel();
+               checkboxes.setLayout(new GridLayout(1,3));
+
                mute = new JCheckBox("Mute");
+               mute.setSelected(false);
+               Moosique.setTrackMute(track, false);
+               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.setTrackSolo(track, false);
+                                       }
+                                       Moosique.setTrackMute(track, selected);
+
                                }});
-               add(mute);
+               checkboxes.add(mute);
+
                solo = new JCheckBox("Solo");
+               solo.setSelected(false);
+               Moosique.setTrackSolo(track, false);
+               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.setTrackMute(track, false);
+                                       }
+                                       Moosique.setTrackSolo(track, selected);
                                }});
-               add(solo);
+               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
+               }
        }
 }