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 {
+ 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 track) {
+ 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(200,70));
- title = new JTextField(); // JTextField(String text, int columns)
+ setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70));
+ title = new JTextField(trackName); // JTextField(String text, int columns)
title.setFont(Moosique.getGUI().FONT);
title.addFocusListener(new TitleFocusListener());
add(title);
- instruments = new MooInstrumentList();
+ 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));
- channel.addItemListener(new ItemListener(){
- public void itemStateChanged(ItemEvent e){
- Object ob = channel.getSelectedItem();
- if (ob instanceof Integer){
- //set channel
- }
- }});
- add(channel);
-
+ 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;
+ channelBox.setSelectedIndex(mn.getChannel());
+ break;
+ }
+ }
+
+ instruments = new MooInstrumentList(channelBox.getSelectedIndex());
+
+ 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);
+ }
+ }}});
+ channelBox.setSelectedIndex(channel);
+ add(channelBox);
mute = new JCheckBox("Mute");
mute.setFont(Moosique.getGUI().FONT);