public MooNoteElement (MooNote mn) {
note = mn;
columns = mn.getDuration() / 24;
+ setBorder(BorderFactory.createLineBorder(Color.black));
}
/**
private JButton rewind, playpause, stop, fastforward;
private JLabel measure, beats, ticks, measureValue, beatsValue, ticksValue;
+ private JPanel progIndPanel;
private ImageIcon playIcon, pauseIcon;
private MooMouseAdapter mouseAdapter;
public static final Color bgColor = new Color(192, 224, 255);
spacesouth.setBackground(bgColor);
// Creates progress indicator panel and adds components
- JPanel progIndPanel = new JPanel();
+ progIndPanel = new JPanel();
progIndPanel.setMaximumSize(new Dimension(120,27));
progIndPanel.setLayout(new GridLayout(2,4));
progIndPanel.add(spacenorth);
long measures = tickPosition / (beatsPerMeasure * ticksPerBeat);
long beats = (tickPosition - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat;
long ticks = tickPosition - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat;
- measureValue.setText(Long.toString(measures));
- beatsValue.setText(Long.toString(beats));
- ticksValue.setText(Long.toString(ticks));
+ measureValue.setText(Long.toString(1 + measures));
+ beatsValue.setText(Long.toString(1 + beats));
+ ticksValue.setText(Long.toString(1 + ticks));
}
/*
private JPopupMenu notePopup;
private JMenuItem menuItem;
protected static int viewLength = 0;
-
+ public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200;
public MooTrackView (Track track) {
super(true);
this.track = track;
//setPreferredSize(new Dimension(200, 9000));
setLayout(new BorderLayout());
- this.setBorder(BorderFactory.createLineBorder(Color.black));
+ // setBorder(BorderFactory.createLineBorder(Color.black));
//title = new MooTrackTitle(track);
//title.setBorder(BorderFactory.createLineBorder(Color.black));
}
class NoteArea extends JPanel {
- public static final int NOTE_HEIGHT = 10;
- public static final int NOTE_WIDTH = 40;
- private int trackLength;
+ public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200;
private ArrayList rects;
public NoteArea(Track track) {
// Configuring panel
super(true);
setLayout(null);
- trackLength = 140;
- setPreferredSize(new Dimension(200, 140 * NOTE_HEIGHT));
+ setPreferredSize(new Dimension(VIEW_WIDTH, 140 * NOTE_HEIGHT));
// Creating temporary variables
MidiEvent note;
elem.setBounds(r);
rects.add(r);
if (viewLength < (y + height)) viewLength = y + height;
-
- // while(findComponentAt(x, y) instanceof MooNoteElement ||
- // findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_WIDTH;
}
- setPreferredSize(new Dimension(200, viewLength));
+ setPreferredSize(new Dimension(VIEW_WIDTH, viewLength));
}
validate();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
- for (int c = 0; c < viewLength ; c += NOTE_HEIGHT) {
- for (int r = 0; r < (10*NOTE_WIDTH); r += NOTE_WIDTH) {
+ for (int c = 0; c < viewLength || c < getHeight(); 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);
JViewport columnHeader = new JViewport();
columnHeader.setView(titlePanel);
setColumnHeaderView(columnHeader);
- numberOfTracks = tracks.length;
setTracks(tracks);
}
* @param tracks the tracks for which to add views
*/
public void setTracks(Track[] tracks) {
- if (tracks.length == 1) {
+ numberOfTracks = tracks.length;
+ if (numberOfTracks == 1) {
// If MIDI file is of type 0, creates a view for the track.
trackPanel.add(new MooTrackView(tracks[0]));
titlePanel.add(new MooTrackTitle(tracks[0]));
// Starts filling the track panel with track views, while updating the progress bar.
trackPanel.removeAll();
- trackPanel.setLayout(new GridLayout(1,tracks.length));
+ trackPanel.setLayout(new GridLayout(1,numberOfTracks));
for (int i = 1; i < tracks.length; i++) {
trackPanel.add(new MooTrackView(tracks[i]));
titlePanel.add(new MooTrackTitle(tracks[i]));
}
progressDialog.dispose();
}
+/* JPanel filler = new JPanel();
+ int totalViewLength = trackPanel.getComponents().length * MooTrackView.VIEW_WIDTH;
+ if (totalViewLength < getWidth()) {
+ System.out.println("Adding filler since width = " + getWidth() + " and tracks = " + totalViewLength);
+ ((GridLayout)trackPanel.getLayout()).setColumns(numberOfTracks + 1);
+ filler.setPreferredSize(new Dimension(getWidth() - totalViewLength, 140 * MooTrackView.NOTE_HEIGHT));
+ trackPanel.add(filler);
+ setPreferredSize(new Dimension(getWidth(), getHeight()));
+ }
+*/
trackPanel.validate();
setViewportView(trackPanel);
}
private static long position;
private static boolean makeGUI = true, isEdited;
private static Thread player;
+ public static final int RESOLUTION = 96, DEFAULT_TRACKS = 4;
/**
* Starts the application.
public static void clearSequence() {
// Creates a new sequence and sends it to the sequencer.
try {
- seq = new Sequence(Sequence.PPQ, 96, 3);
+ seq = new Sequence(Sequence.PPQ, RESOLUTION, DEFAULT_TRACKS);
sequencer.setSequence(seq);
} catch (InvalidMidiDataException e) {}
// Sends sequence to GUI.
public static void play() {
sequencer.setTickPosition(position);
resume();
-
}
/**
// Creates the visualization thread and starts it.
player = new Thread () {
public void run() {
- gui.update(sequencer.getTickPosition());
+ while(sequencer.isRunning()) gui.update(sequencer.getTickPosition());
+ Moosique.stop();
}
};
player.start();
public static void stop() {
sequencer.stop();
sequencer.setTickPosition(position);
- player.destroy();
+ player.interrupt();
gui.update((long)0);
}