pane.add(toolbar, BorderLayout.NORTH);
// Adds main view.
- view = new MooView(seq);
+ view = new MooView(seq.getTracks());
pane.add(view, BorderLayout.CENTER);
// Adds status bar.
statusBar.setBackground(bgColor);
view.setBackground(bgColor);
+ // Sets up global key listener
ActionMap am = getRootPane().getActionMap();
Action playAction = new AbstractAction() {
public void actionPerformed(ActionEvent ae) {
- Moosique.resumepause();
+ if (!Moosique.getSequencer().isRunning()) {
+ Moosique.play();
+ } else {
+ Moosique.stop();
+ }
}};
- am.put("play", playAction);
+ am.put("Play", playAction);
InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
KeyStroke playKey = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0);
- im.put(playKey, "play");
-
+ im.put(playKey, "Play");
// Configures window.
addWindowListener(new MooGUICloser());
*/
public void setSequence(Sequence sequence) {
seq = sequence;
- view.setSequence(seq);
+ view.setTracks(seq.getTracks());
}
/**
}
/**
- * Update the view.
+ * Calls on the main view to update the track views,
+ * and on the toolbar to update the progress indicator.
*/
public void update(){
view.update();
- // Calls on the toolbar to update the progress indicator.
- //toolbar.updateProgInd();
+ toolbar.updateProgInd();
}
class MooGUICloser extends WindowAdapter {
if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
Moosique.saveAs(chooser.getSelectedFile().getAbsolutePath());
}
-
} else if (command == "Exit") {
Moosique.quit();
} else if (command == "Copy") {
} else if (command == "Preferences...") {
} else if (command == "Play") {
- if (Moosique.getSequencer().isRunning()) {
- Moosique.pause();
- } else {
- Moosique.play();
- }
+ if (!Moosique.getSequencer().isRunning()) Moosique.play();
} else if (command == "Pause") {
- if (Moosique.getSequencer().isRunning()) {
- Moosique.resume();
- } else {
- Moosique.pause();
- }
+ if (Moosique.getSequencer().isRunning()) Moosique.pause();
} else if (command == "Stop") {
Moosique.stop();
} else if (command == "Jump...") {
-
+
} else if (command == "Add track...") {
Moosique.getSequence().createTrack();
} else if (command == "Delete track...") {
* @version 1
*/
-public class MooNoteElement extends JPanel{
+public class MooNoteElement extends JPanel {
private MooNote note;
private boolean selected;
public class MooToolbar extends JToolBar {
private JButton rewind, playpause, stop, fastforward;
- private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
+ private JLabel measure, beats, ticks, measureValue, beatsValue, ticksValue;
private ImageIcon playIcon, pauseIcon;
private MooMouseAdapter mouseAdapter;
public static final Color bgColor = new Color(192, 224, 255);
*/
public MooToolbar() {
+ // setAlignmentX(LEFT_ALIGNMENT);
setFloatable(false);
mouseAdapter = new MooMouseAdapter();
// Creates playback buttons
rewind = createButton("images/rewind.gif", "Rewind");
- add(rewind);
playpause = createButton("images/play.gif", "Play");
- add(playpause);
+ stop = createButton("images/stop.gif", "Stop");
+ fastforward = createButton("images/forward.gif", "Fast forward");
playIcon = new ImageIcon("images/play.gif");
pauseIcon = new ImageIcon("images/pause.gif");
- stop = createButton("images/stop.gif", "Stop");
+
+ // Adds playback buttons
+ add(rewind);
+ add(playpause);
add(stop);
- fastforward = createButton("images/forward.gif", "Fast forward");
add(fastforward);
// Creates progress indicator
+ measure = createLabel("Msr", 10);
+ beats = createLabel("Beat", 10);
+ ticks = createLabel("Tick", 10);
+ measureValue = createLabel("1", 16);
+ beatsValue = createLabel("1", 16);
+ ticksValue = createLabel("1", 16);
+ JPanel spacenorth = new JPanel();
+ spacenorth.setBackground(bgColor);
+ JPanel spacesouth = new JPanel();
+ spacesouth.setBackground(bgColor);
+
+ // Creates progress indicator panel and adds components
JPanel progIndPanel = new JPanel();
progIndPanel.setMaximumSize(new Dimension(120,27));
progIndPanel.setLayout(new GridLayout(2,4));
- measure = createLabel("Mrs",10);
- beats = createLabel("Beat",10);
- ticks = createLabel("Tick",10);
- measurevalue = createLabel("1", 16);
- beatsvalue = createLabel("1",16);
- ticksvalue = createLabel("1",16);
-
- JPanel spacenorth = new JPanel();
- spacenorth.setBackground(bgColor);
progIndPanel.add(spacenorth);
-
progIndPanel.add(measure);
progIndPanel.add(beats);
progIndPanel.add(ticks);
-
- JPanel spacesouth = new JPanel();
- spacesouth.setBackground(bgColor);
progIndPanel.add(spacesouth);
-
- progIndPanel.add(measurevalue);
- progIndPanel.add(beatsvalue);
- progIndPanel.add(ticksvalue);
+ progIndPanel.add(measureValue);
+ progIndPanel.add(beatsValue);
+ progIndPanel.add(ticksValue);
add(progIndPanel);
+
}
-
+
+ /**
+ * Updates the progress indicator.
+ */
+ public void updateProgInd() {
+ int pos = Moosique.getSequencer().getTickPosition();
+ int ticksPerBeat = Moosique.getSequencer().getResolution();
+ int beatsPerMeasure = 4;
+ measureValue.setText(pos / (beatsPerMeasure * ticksPerBeat));
+ beatsValue.setText((pos - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat);
+ ticksValue.setText(pos - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat);
+ }
+
/**
* Creates a button with the specified image and tooltip.
* @param imagelocation the imagelacation of the the image displayed in the button
* @param fontsize the fontzise of the text displayed on the label
*/
private JLabel createLabel(String title, int fontSize){
- JLabel value = new JLabel(title,JLabel.CENTER);
- value.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
- value.setBorder(BorderFactory.createLineBorder(Color.black));
- return value;
+ 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;
}
-
- // int pos = Moosique.getSequencer().getTickPosition();
- // int measures = pos / (4 * Moosique.getSequence.get)
- // int beats = (pos - measures * 4 * 96) / 96;
- // int ticks = (pos - measures*4*96 - beats*96);
-
+
class MooMouseAdapter extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
if (((JButton)e.getSource()).getToolTipText() == "Play") {
public void mouseReleased(MouseEvent e) {}
}
-}
+}
\ No newline at end of file
title.setBorder(BorderFactory.createLineBorder(Color.black));
add(title, BorderLayout.NORTH);
- notes = new NoteArea();
+ notes = new NoteArea(track);
notes.setBackground(Color.white);
notes.setBorder(BorderFactory.createLineBorder(Color.black));
}
class NoteArea extends JPanel {
- public void RectanglePanel() {
- setPreferredSize(new Dimension(20, 20));
+
+ public NoteArea(Track track) {
+ MidiEvent note;
+ for (int i = 0; i < track.size(); i++) {
+ note = track.get(i);
+ if (note instanceof MooNote) {
+ add(new MooNoteElement((MooNote)note));
+ }
+ }
+ validate();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
for (int c = 0; c < 1000; c += 20) {
- int r=0;
- for (r = 0; r < 200; r += 20) {
+ for (int r = 0; r < 200; r += 20) {
box = new Rectangle(r, c, 20, 20);
g2.setColor(Color.gray);
g2.draw(box);
}
}
}
-}
+}
\ No newline at end of file
public class MooView extends JScrollPane {
- private Track[] tracks;
- private MooTrackView[] trackViews;
private JPanel trackPanel;
/**
* Creates the main view
*/
- public MooView(Sequence seq) {
+ public MooView(Track[] tracks) {
super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED);
- tracks = seq.getTracks();
-
-
trackPanel = new JPanel(new GridLayout(1,3), true);
- createTrackViews();
+ setTracks(tracks);
setViewportView(trackPanel);
}
/**
* Fills the track panel with track views for all tracks in the current sequence.
+ * @param tracks the tracks for which to add views
*/
- private void createTrackViews() {
+ public void setTracks(Track[] tracks) {
trackPanel.removeAll();
((GridLayout)trackPanel.getLayout()).setColumns(tracks.length);
- trackViews = new MooTrackView[tracks.length];
for (int i = 0; i < tracks.length; i++) {
- trackViews[i] = new MooTrackView(tracks[i]);
trackPanel.add(new MooTrackView(tracks[i]));
}
trackPanel.validate();
+ validate();
}
- public void setSequence(Sequence seq) {
- tracks = seq.getTracks();
- createTrackViews();
- }
-
+ /**
+ * Calls on each track view to update itself.
+ */
public void update() {
- // Calls on each track view to update itself.
- for (int i = 0; i < trackViews.length; i++) {
- //trackViews[i].update();
+ Component[] comps = c.getComponents();
+ for (int i = 0; i < comps.length; i++) {
+ ((MooTrackView)comps[i]).update();
}
}
+
/**
* Creates a view for the given track and adds it to the main view.
* @param track the track for which to add a view
+ * @param index the index at which to insert the view
*/
- public void addTrackView(Track track) {
-
+ public void addTrackView(Track track, int index) {
+ add(new MooTrackView(track), index);
+ validate();
}
/**
* Removes the view for the given track.
- * @param track the track for which to remove the view
+ * @param index the index of the track for which to remove the view
*/
- public void removeTrackView(Track track) {
-
+ public void removeTrackView(int index) {
+ remove(index);
+ validate();
}
-}
+}
\ No newline at end of file
import javax.swing.*;
+import java.awt.*;
/**
*
* @version 1
*/
-public class MooViewCounter {
+public class MooViewCounter extends JPanel {
/**
* Creates
*/
public MooViewCounter () {
+
+ }
+
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ if (!(g instanceof Graphics2D)) return;
+ Graphics2D g2 = (Graphics2D)g;
+
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ // g2.drawLine(0,i*20,
+ }
+ }
}
}
import javax.sound.midi.*;
-import javax.swing.*;
import java.io.*;
+import javax.swing.*;
/**
* Moosique - The MIDI Tracker
private static String filename, fileArg;
private static long position;
private static boolean makeGUI = true;
- private static boolean playing = false;
/**
* Starts the application.
clearSequence();
}
- // If n-flag is set, plays song and then exits. Otherwise builds GUI.
+ // Builds GUI, unless n-flag is set.
if (makeGUI) {
System.out.print("Building GUI...");
+ try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ } catch (Exception e) {}
gui = new MooGUI(seq);
System.out.println("Done");
} else {
* Starts playback of the current sequence.
*/
public static void play() {
- playing = true;
sequencer.setTickPosition(position);
sequencer.start();
}
* Pauses playback of the current sequence.
*/
public static void pause() {
- playing = false;
sequencer.stop();
}
* Resumes playback of the current sequence.
*/
public static void resume() {
- playing = true;
sequencer.start();
}
* Stops playback of the current sequence.
*/
public static void stop() {
- playing = false;
sequencer.stop();
sequencer.setTickPosition(position);
}
- /**
- * Pauses if playing and resumes if stopped.
- */
- public static void resumepause()
- {
- if (playing)
- pause();
- else
- resume();
- }
-
/**
* Rewinds the current sequence the given number of measures.
* @param measures the number of measures to rewind
} catch (InvalidMidiDataException e) {
return false;
} catch (IOException e) {
- JOptionPane.showMessageDialog(null, "Error 404", "File Not Found", JOptionPane.ERROR_MESSAGE);
return false;
}
if (synthesizer.isOpen()) synthesizer.close();
System.exit(0);
}
-}
+}
\ No newline at end of file
\f
MooMenu
- * Inställningar
- - MIDI-enhet Öppna en dialogruta med innehållet i getMidiDeviceInfo() och låt användaren välja.
+x Kom ihåg sökväg vid Open
Musikrelaterade menyer i Midisoft Recording Session:
* getPosition och setPosition - kvar?
+\f
+Skräp
+
+ // Prints the number of notes in each track
+ int count;
+ Track[] tracks = seq.getTracks();
+ for (int k = 0; k < tracks.length; k++) {
+ count = 0;
+ for (int j = 0; j < tracks[k].size(); j++) {
+ if (tracks[k].get(j) instanceof MooNote) count++;
+ }
+ System.out.println("Track " + k + ": " + count + " notes.");
+ }
+
\f
MooNoteProp
* textfält som gör att man bara kan skriva in siffror?