From c042cd1b86ce2f107f9e102bada7e999b13a960d Mon Sep 17 00:00:00 2001 From: Einar Pehrson Date: Tue, 13 May 2003 16:56:26 +0000 Subject: [PATCH] *** empty log message *** --- MooTrackTitle.java | 60 +++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/MooTrackTitle.java b/MooTrackTitle.java index 1d9171a..4630a76 100644 --- a/MooTrackTitle.java +++ b/MooTrackTitle.java @@ -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); } -- 2.39.2