beats = createLabel("Beat", 10);
ticks = createLabel("Tick", 10);
measureValue = createLabel("1", 16);
+ measureValue.setBorder(BorderFactory.createLineBorder(Color.black));
beatsValue = createLabel("1", 16);
+ beatsValue.setBorder(BorderFactory.createLineBorder(Color.black));
ticksValue = createLabel("1", 16);
+ ticksValue.setBorder(BorderFactory.createLineBorder(Color.black));
JPanel spacenorth = new JPanel();
spacenorth.setBackground(bgColor);
JPanel spacesouth = new JPanel();
private JLabel createLabel(String title, int fontSize){
JLabel label = new JLabel(title,JLabel.CENTER);
label.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
- label.setBorder(BorderFactory.createLineBorder(Color.black));
return label;
}
Moosique.play();
playpause.setIcon(pauseIcon);
playpause.setToolTipText("Pause");
+ while(Moosique.getSequencer().isRunning()) {
+ Moosique.getGUI().update();
+ }
} else if (((JButton)e.getSource()).getToolTipText() == "Pause") {
Moosique.pause();
playpause.setIcon(playIcon);
Moosique.resume();
playpause.setIcon(pauseIcon);
playpause.setToolTipText("Pause");
+ while(Moosique.getSequencer().isRunning()) {
+ Moosique.getGUI().update();
+ }
} else if (((JButton)e.getSource()).getToolTipText() == "Stop") {
Moosique.stop();
playpause.setIcon(playIcon);
* Updates the track view.
*/
public void update() {
-
+ repaint();
}
class NoteArea extends JPanel {
- public static final int NOTE_SIZE = 25;
+ public static final int NOTE_HEIGHT = 10;
+ public static final int NOTE_WIDTH = 40;
private int trackLength;
public NoteArea(Track track) {
+ System.out.println("Creating track view...");
setLayout(null);
- trackLength = 60;
+ trackLength = 140;
MidiEvent note;
MooNoteElement elem;
boolean isOccupied;
// Places the note element in the appropriate place.
x = insets.left;
- y = insets.top + (int)(mn.getTick() / 24) * NOTE_SIZE;
- height = NOTE_SIZE;
- // height = (mn.getDuration() / 24) * NOTE_SIZE;
- System.out.println("Comp at: " + x + ", " + y + " is: " + findComponentAt(x + 10, y + 10));
+ y = insets.top + (int)(mn.getTick() / 24) * NOTE_HEIGHT;
+ height = NOTE_HEIGHT;
+ // height = (mn.getDuration() / 24) * NOTE_HEIGHT;
+ // System.out.println("Comp at: " + x + ", " + y + " is: " + findComponentAt(x + 10, y + 10));
while(findComponentAt(x, y) instanceof MooNoteElement ||
- findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_SIZE;
- elem.setBounds(x, y, NOTE_SIZE, height);
+ findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_WIDTH;
+ elem.setBounds(x, y, NOTE_WIDTH, height);
}
}
+ validate();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
- for (int c = 0; c < (trackLength*NOTE_SIZE); c += NOTE_SIZE) {
- for (int r = 0; r < (10*NOTE_SIZE); r += NOTE_SIZE) {
- box = new Rectangle(r, c, NOTE_SIZE, NOTE_SIZE);
+ for (int c = 0; c < (trackLength*NOTE_HEIGHT); c += NOTE_HEIGHT) {
+ for (int r = 0; r < (10*NOTE_WIDTH); r += NOTE_WIDTH) {
+ box = new Rectangle(r, c, NOTE_WIDTH, NOTE_HEIGHT);
g2.setColor(Color.gray);
g2.draw(box);
}
public class MooView extends JScrollPane {
private JPanel trackPanel;
+ private int numberOfTracks;
/**
* Creates the main view
*/
public MooView(Track[] tracks) {
super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ numberOfTracks = tracks.length;
trackPanel = new JPanel(new GridLayout(1,3), true);
setTracks(tracks);
setViewportView(trackPanel);
*/
public void setTracks(Track[] tracks) {
trackPanel.removeAll();
- ((GridLayout)trackPanel.getLayout()).setColumns(tracks.length);
+ trackPanel.setLayout(new GridLayout(1,tracks.length));
for (int i = 0; i < tracks.length; i++) {
trackPanel.add(new MooTrackView(tracks[i]));
}
trackPanel.validate();
- validate();
}
/**
public void update() {
Component[] comps = getComponents();
for (int i = 0; i < comps.length; i++) {
- ((MooTrackView)comps[i]).update();
+ if(comps[i] instanceof MooTrackView) ((MooTrackView)comps[i]).update();
}
}
* @param index the index at which to insert the view
*/
public void addTrackView(Track track, int index) {
- add(new MooTrackView(track), index);
+ ((GridLayout)trackPanel.getLayout()).setColumns(++numberOfTracks);
+ trackPanel.add(new MooTrackView(track), index);
validate();
}
*/
public void removeTrackView(int index) {
remove(index);
+ ((GridLayout)trackPanel.getLayout()).setColumns(--numberOfTracks);
validate();
}
}
\ No newline at end of file