X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=MooTrackTitle.java;h=9cffb14570bbd48633e380441963e0865188b78b;hp=e22c3219846e013d6553dbbda8f851c8b65fe250;hb=HEAD;hpb=ecef41268a927f27f71839d5df1d68a151b37e5e diff --git a/MooTrackTitle.java b/MooTrackTitle.java index e22c321..9cffb14 100644 --- a/MooTrackTitle.java +++ b/MooTrackTitle.java @@ -15,6 +15,7 @@ public class MooTrackTitle extends JPanel { private Track track; private MetaMessage trackNameMessage; private ShortMessage programChangeMessage; + private MooTrackView mtv; private JTextField title; private MooInstrumentList instruments; @@ -26,8 +27,18 @@ public class MooTrackTitle extends JPanel { private int channel = 0; /** - * Creates the title bar. + * Creates the title bar for an empty track, and therefore an initial channel is required. * @param aTrack the track that this tracktitle is operating on. + * @param chan the initial channel + */ + public MooTrackTitle (Track aTrack, int chan) { + this(aTrack); + channel = chan; + } + + /** + * Creates the title bar. + * @param aTrack the track that this track title is operating on. */ public MooTrackTitle (Track aTrack) { setDoubleBuffered(true); @@ -44,15 +55,16 @@ public class MooTrackTitle extends JPanel { trackNameMessage = (MetaMessage)msg; trackName = new String(trackNameMessage.getData()); } - } else if (status >= 192 && status <= 207) { + } else if (status >= 192 && status < 208) { programChangeMessage = (ShortMessage)msg; - channel = status - 192; + channel = programChangeMessage.getChannel(); } } // Creates and places components. setLayout(new GridLayout(4,1)); setBorder(BorderFactory.createLineBorder(Color.black)); + TitleListener tl = new TitleListener(); setPreferredSize(new Dimension(MooTrackView.VIEW_WIDTH,70)); title = new JTextField(trackName); @@ -63,8 +75,7 @@ public class MooTrackTitle extends JPanel { int type; if (channel == 9) type = MooInstrumentList.DRUMS; else type = MooInstrumentList.INSTRUMENTS; - instruments = new MooInstrumentList(channel, type); - // instruments = new MooInstrumentList(channel, type, programChangeMessage); + instruments = new MooInstrumentList(channel, type, programChangeMessage); add(instruments); channelBox = new JComboBox(); @@ -74,53 +85,26 @@ public class MooTrackTitle extends JPanel { 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); - } - }}}); + channelBox.addActionListener(tl); add(channelBox); JPanel checkboxes = new JPanel(); checkboxes.setLayout(new GridLayout(1,3)); mute = new JCheckBox("Mute"); - mute.setSelected(Moosique.getChannel(channel).getMute()); + mute.setSelected(false); + Moosique.setTrackMute(track, false); mute.setFont(Moosique.getGUI().FONT); - mute.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent event){ - boolean selected = mute.isSelected(); - if (selected){ - solo.setSelected(false); - Moosique.getChannel(channel).setSolo(false); - } - Moosique.getChannel(channel).setMute(selected); - - }}); + mute.addActionListener(tl); checkboxes.add(mute); solo = new JCheckBox("Solo"); - solo.setSelected(Moosique.getChannel(channel).getSolo()); + solo.setSelected(false); + Moosique.setTrackSolo(track, false); solo.setFont(Moosique.getGUI().FONT); - solo.addActionListener(new ActionListener(){ - public void actionPerformed(ActionEvent event){ - //setSolo - boolean selected = solo.isSelected(); - if (selected){ - mute.setSelected(false); - Moosique.getChannel(channel).setMute(false); - } - Moosique.getChannel(channel).setSolo(selected); - }}); + solo.addActionListener(tl); checkboxes.add(solo); + add(checkboxes); } @@ -132,12 +116,59 @@ public class MooTrackTitle extends JPanel { return channel; } + /** + * Sets the track view this title should update after recording. + * @param the track view + */ + public void setTrackView(MooTrackView tv) { + mtv = tv; + } + /** - * Checks if the focus is lost. + * When the title field loses focus, updates the corresponding MidiEvent. */ class TitleFocusListener extends FocusAdapter { public void focusLost(FocusEvent e) { - // Update the MidiEvent containing the title of this track + try { + trackNameMessage.setMessage(3, title.getText().getBytes(), title.getText().length()); + } catch (InvalidMidiDataException ex) {} + } + } + + /** + * Takes the appropriate action when a user selects an item on the popup menu. + */ + class TitleListener implements ActionListener { + public void actionPerformed(ActionEvent e) { + Object source = e.getSource(); + if (source == channelBox) { + channel = channelBox.getSelectedIndex(); + MidiEvent me; + MooNote mn; + instruments.setChannel(channel); + // Prompt the user before rechannelling??? + for (int j = 0; j < track.size(); j++) { + me = track.get(j); + if (me instanceof MooNote){ + mn = (MooNote)me; + mn.setChannel(channel); + } + } + } else if (source == solo) { + boolean selected = mute.isSelected(); + if (selected){ + solo.setSelected(false); + Moosique.setTrackSolo(track, false); + } + Moosique.setTrackMute(track, selected); + } else if (source == mute) { + boolean selected = solo.isSelected(); + if (selected){ + mute.setSelected(false); + Moosique.setTrackMute(track, false); + } + Moosique.setTrackSolo(track, selected); + } } } }