From 99b83588ad553537f891efaf5fbe95e7b9e5442b Mon Sep 17 00:00:00 2001 From: Einar Pehrson Date: Tue, 6 May 2003 23:13:37 +0000 Subject: [PATCH] Updated command-line handling in Moosique, supplied alternate solution to MooMenu, killed MooStatus and added its functionality to MooGUI, and updated To Do.txt --- Methods of Key Classes.txt | 242 +++++++++++++++++++------------------ MooGUI.java | 35 ++++-- MooKeyboard.java | 2 +- MooMenu.java | 43 ++++++- MooStatus.java | 18 --- Moosique.java | 63 ++++++---- To Do.txt | 14 +++ 7 files changed, 249 insertions(+), 168 deletions(-) delete mode 100644 MooStatus.java diff --git a/Methods of Key Classes.txt b/Methods of Key Classes.txt index 97fc6a0..a2dd941 100644 --- a/Methods of Key Classes.txt +++ b/Methods of Key Classes.txt @@ -1,246 +1,254 @@ -Synthesizer + +Synthesizer + Instrument[] getAvailableInstruments() -Obtains a list of instruments that come with the synthesizer. + Obtains a list of instruments that come with the synthesizer. MidiChannel[] getChannels() -Obtains the set of MIDI channels controlled by this synthesizer. + Obtains the set of MIDI channels controlled by this synthesizer. Soundbank getDefaultSoundbank() -Obtains the default soundbank for the synthesizer, if one exists. + Obtains the default soundbank for the synthesizer, if one exists. long getLatency() -Obtains the processing latency incurred by this synthesizer, expressed in microseconds. + Obtains the processing latency incurred by this synthesizer, expressed in microseconds. Instrument[] getLoadedInstruments() -Obtains a list of the instruments that are currently loaded onto this Synthesizer. + Obtains a list of the instruments that are currently loaded onto this Synthesizer. int getMaxPolyphony() -Obtains the maximum number of notes that this synthesizer can sound simultaneously. + Obtains the maximum number of notes that this synthesizer can sound simultaneously. VoiceStatus[] getVoiceStatus() -Obtains the current status of the voices produced by this synthesizer. + Obtains the current status of the voices produced by this synthesizer. boolean isSoundbankSupported(Soundbank soundbank) -Informs the caller whether this synthesizer is capable of loading instruments from the specified soundbank. + Informs the caller whether this synthesizer is capable of loading instruments from the specified soundbank. boolean loadAllInstruments(Soundbank soundbank) -Loads onto the Synthesizer all instruments contained in the specified Soundbank. + Loads onto the Synthesizer all instruments contained in the specified Soundbank. boolean loadInstrument(Instrument instrument) -Makes a particular instrument available for synthesis. + Makes a particular instrument available for synthesis. boolean loadInstruments(Soundbank soundbank, Patch[] patchList) -Loads the instruments referenced by the specified patches, from the specified Soundbank. + Loads the instruments referenced by the specified patches, from the specified Soundbank. boolean remapInstrument(Instrument from, Instrument to) -Remaps an instrument. + Remaps an instrument. void unloadAllInstruments(Soundbank soundbank) -Unloads all instruments contained in the specified Soundbank. + Unloads all instruments contained in the specified Soundbank. void unloadInstrument(Instrument instrument) -Unloads a particular instrument. + Unloads a particular instrument. void unloadInstruments(Soundbank soundbank, Patch[] patchList) -Unloads the instruments referenced by the specified patches, from the MIDI sound bank specified. + Unloads the instruments referenced by the specified patches, from the MIDI sound bank specified. Sequencer - + int[] addControllerEventListener(ControllerEventListener listener, int[] controllers) -Registers a controller event listener to receive notification whenever the sequencer processes a control-change event of the requested type or types. + Registers a controller event listener to receive notification whenever + the sequencer processes a control-change event of the requested type or types. boolean addMetaEventListener(MetaEventListener listener) -Registers a meta-event listener to receive notification whenever a meta-event is encountered in the sequence and processed by the sequencer. + Registers a meta-event listener to receive notification whenever + a meta-event is encountered in the sequence and processed by the sequencer. Sequencer.SyncMode getMasterSyncMode() -Obtains the current master synchronization mode for this sequencer. + Obtains the current master synchronization mode for this sequencer. Sequencer.SyncMode[] getMasterSyncModes() -Obtains the set of master synchronization modes supported by this sequencer. + Obtains the set of master synchronization modes supported by this sequencer. long getMicrosecondLength() -Obtains the length of the current sequence, expressed in microseconds. + Obtains the length of the current sequence, expressed in microseconds. long getMicrosecondPosition() -Obtains the current position in the sequence, expressed in microseconds. + Obtains the current position in the sequence, expressed in microseconds. Sequence getSequence() -Obtains the sequence on which the Sequencer is currently operating. + Obtains the sequence on which the Sequencer is currently operating. Sequencer.SyncMode getSlaveSyncMode() -Obtains the current slave synchronization mode for this sequencer. + Obtains the current slave synchronization mode for this sequencer. Sequencer.SyncMode[] getSlaveSyncModes() -Obtains the set of slave synchronization modes supported by the sequencer. + Obtains the set of slave synchronization modes supported by the sequencer. float getTempoFactor() -Returns the current tempo factor for the sequencer. + Returns the current tempo factor for the sequencer. float getTempoInBPM() -Obtains the current tempo, expressed in beats per minute. + Obtains the current tempo, expressed in beats per minute. float getTempoInMPQ() -Obtains the current tempo, expressed in microseconds per quarter note. + Obtains the current tempo, expressed in microseconds per quarter note. long getTickLength() -Obtains the length of the current sequence, expressed in MIDI ticks. + Obtains the length of the current sequence, expressed in MIDI ticks. long getTickPosition() -Obtains the current position in the sequence, expressed in MIDI ticks. + Obtains the current position in the sequence, expressed in MIDI ticks. boolean getTrackMute(int track) -Obtains the current mute state for a track. + Obtains the current mute state for a track. boolean getTrackSolo(int track) -Obtains the current solo state for a track. + Obtains the current solo state for a track. boolean isRecording() -Indicates whether the Sequencer is currently recording. + Indicates whether the Sequencer is currently recording. boolean isRunning() -Indicates whether the Sequencer is currently running. + Indicates whether the Sequencer is currently running. void recordDisable(Track track) -Disables recording to the specified track. + Disables recording to the specified track. void recordEnable(Track track, int channel) -Prepares the specified track for recording events received on a particular channel. + Prepares the specified track for recording events received on a particular channel. int[] removeControllerEventListener(ControllerEventListener listener, int[] controllers) -Removes a controller event listener's interest in one or more types of controller event. + Removes a controller event listener's interest in one or more types of controller event. void removeMetaEventListener(MetaEventListener listener) -Removes the specified meta-event listener from this sequencer's list of registered listeners, if in fact the listener is registered. + Removes the specified meta-event listener from this sequencer's + list of registered listeners, if in fact the listener is registered. void setMasterSyncMode(Sequencer.SyncMode sync) -Sets the source of timing information used by this sequencer. + Sets the source of timing information used by this sequencer. void setMicrosecondPosition(long microseconds) -Sets the current position in the sequence, expressed in microseconds + Sets the current position in the sequence, expressed in microseconds void setSequence(InputStream stream) -Sets the current sequence on which the sequencer operates. + Sets the current sequence on which the sequencer operates. void setSequence(Sequence sequence) -Sets the current sequence on which the sequencer operates. + Sets the current sequence on which the sequencer operates. void setSlaveSyncMode(Sequencer.SyncMode sync) -Sets the slave synchronization mode for the sequencer. + Sets the slave synchronization mode for the sequencer. void setTempoFactor(float factor) -Scales the sequencer's actual playback tempo by the factor provided. + Scales the sequencer's actual playback tempo by the factor provided. void setTempoInBPM(float bpm) -Sets the tempo in beats per minute. + Sets the tempo in beats per minute. void setTempoInMPQ(float mpq) -Sets the tempo in microseconds per quarter note. + Sets the tempo in microseconds per quarter note. void setTickPosition(long tick) -Sets the current sequencer position in MIDI ticks + Sets the current sequencer position in MIDI ticks void setTrackMute(int track, boolean mute) -Sets the mute state for a track. + Sets the mute state for a track. void setTrackSolo(int track, boolean solo) -Sets the solo state for a track. + Sets the solo state for a track. void start() -Starts playback of the MIDI data in the currently loaded sequence. + Starts playback of the MIDI data in the currently loaded sequence. void startRecording() -Starts recording and playback of MIDI data. + Starts recording and playback of MIDI data. void stop() -Stops recording, if active, and playback of the currently loaded sequence, if any. + Stops recording, if active, and playback of the currently loaded sequence, if any. void stopRecording() -Stops recording, if active. + Stops recording, if active. MidiChannel - + void allNotesOff() -Turns off all notes that are currently sounding on this channel. + Turns off all notes that are currently sounding on this channel. void allSoundOff() -Immediately turns off all sounding notes on this channel, ignoring the state of the Hold Pedal and the internal decay rate of the current Instrument. + Immediately turns off all sounding notes on this channel, + ignoring the state of the Hold Pedal and the internal decay rate of the current Instrument. void controlChange(int controller, int value) -Reacts to a change in the specified controller's value. + Reacts to a change in the specified controller's value. int getChannelPressure() -Obtains the channel's keyboard pressure. + Obtains the channel's keyboard pressure. int getController(int controller) -Obtains the current value of the specified controller. + Obtains the current value of the specified controller. boolean getMono() -Obtains the current mono/poly mode. + Obtains the current mono/poly mode. boolean getMute() -Obtains the current mute state for this channel. + Obtains the current mute state for this channel. boolean getOmni() -Obtains the current omni mode status. + Obtains the current omni mode status. int getPitchBend() -Obtains the upward of downward pitch offset for this channel. + Obtains the upward of downward pitch offset for this channel. int getPolyPressure(int noteNumber) -Obtains the pressure with which the specified key is being depressed. + Obtains the pressure with which the specified key is being depressed. int getProgram() -Obtains the current program number for this channel. + Obtains the current program number for this channel. boolean getSolo() -Obtains the current solo state for this channel. + Obtains the current solo state for this channel. boolean localControl(boolean on) -Turns local control on or off. + Turns local control on or off. void noteOff(int noteNumber) -Turns the specified note off. + Turns the specified note off. void noteOff(int noteNumber, int velocity) -Turns the specified note off. + Turns the specified note off. void noteOn(int noteNumber, int velocity) -Starts the specified note sounding. + Starts the specified note sounding. void programChange(int program) -Changes a program (patch). + Changes a program (patch). void programChange(int bank, int program) -Changes the program using bank and program (patch) numbers. + Changes the program using bank and program (patch) numbers. void resetAllControllers() -Resets all the implemented controllers to their default values. + Resets all the implemented controllers to their default values. void setChannelPressure(int pressure) -Reacts to a change in the keyboard pressure. + Reacts to a change in the keyboard pressure. void setMono(boolean on) -Turns mono mode on or off. + Turns mono mode on or off. void setMute(boolean mute) -Sets the mute state for this channel. + Sets the mute state for this channel. void setOmni(boolean on) -Turns omni mode on or off. + Turns omni mode on or off. void setPitchBend(int bend) -Changes the pitch offset for all notes on this channel. + Changes the pitch offset for all notes on this channel. void setPolyPressure(int noteNumber, int pressure) -Reacts to a change in the specified note's key pressure. + Reacts to a change in the specified note's key pressure. void setSolo(boolean soloState) -Sets the solo state for this channel. + Sets the solo state for this channel. Sequence - + Track createTrack() -Creates a new, initially empty track as part of this sequence. + Creates a new, initially empty track as part of this sequence. boolean deleteTrack(Track track) -Removes the specified track from the sequence. + Removes the specified track from the sequence. float getDivisionType() -Obtains the timing division type for this sequence. + Obtains the timing division type for this sequence. long getMicrosecondLength() -Obtains the duration of this sequence, expressed in microseconds. + Obtains the duration of this sequence, expressed in microseconds. Patch[] getPatchList() -Obtains a list of patches referenced in this sequence. + Obtains a list of patches referenced in this sequence. int getResolution() -Obtains the timing resolution for this sequence. + Obtains the timing resolution for this sequence. long getTickLength() -Obtains the duration of this sequence, expressed in MIDI ticks. + Obtains the duration of this sequence, expressed in MIDI ticks. Track[] getTracks() -Obtains an array containing all the tracks in this sequence. + Obtains an array containing all the tracks in this sequence. Track - + boolean add(MidiEvent event) -Adds a new event to the track. + Adds a new event to the track. MidiEvent get(int index) -Obtains the event at the specified index. + Obtains the event at the specified index. boolean remove(MidiEvent event) -Removes the specified event from the track. + Removes the specified event from the track. int size() -Obtains the number of events in this track. + Obtains the number of events in this track. long ticks() -Obtains the length of the track, expressed in MIDI ticks. + Obtains the length of the track, expressed in MIDI ticks. MidiEvent - + MidiMessage getMessage() -Obtains the MIDI message contained in the event. + Obtains the MIDI message contained in the event. long getTick() -Obtains the time-stamp for the event, in MIDI ticks + Obtains the time-stamp for the event, in MIDI ticks void setTick(long tick) -Sets the time-stamp for the event, in MIDI ticks + Sets the time-stamp for the event, in MIDI ticks MidiMessage - + abstract Object clone() -Creates a new object of the same class and with the same contents as this object. + Creates a new object of the same class and with the same contents as this object. int getLength() -Obtains the total length of the MIDI message in bytes. + Obtains the total length of the MIDI message in bytes. byte[] getMessage() -Obtains the MIDI message data. + Obtains the MIDI message data. int getStatus() -Obtains the status byte for the MIDI message. + Obtains the status byte for the MIDI message. protected void setMessage(byte[] data, int length) -Sets the data for the MIDI message. + Sets the data for the MIDI message. - + ShortMessage - + Object clone() -Creates a new object of the same class and with the same contents as this object. + Creates a new object of the same class and with the same contents as this object. int getChannel() -Obtains the MIDI channel associated with this event. + Obtains the MIDI channel associated with this event. int getCommand() -Obtains the MIDI command associated with this event. + Obtains the MIDI command associated with this event. int getData1() -Obtains the first data byte in the message. + Obtains the first data byte in the message. int getData2() -Obtains the second data byte in the message. + Obtains the second data byte in the message. protected int getDataLength(int status) -Retrieves the number of data bytes associated with a particular status byte value. + Retrieves the number of data bytes associated with a particular status byte value. void setMessage(int status) -Sets the parameters for a MIDI message that takes no data bytes. + Sets the parameters for a MIDI message that takes no data bytes. void setMessage(int status, int data1, int data2) -Sets the parameters for a MIDI message that takes one or two data bytes. + Sets the parameters for a MIDI message that takes one or two data bytes. void setMessage(int command, int channel, int data1, int data2) -Sets the short message parameters for a channel message which takes one or two data bytes. + Sets the short message parameters for a channel message which takes one or two data bytes. + + \ No newline at end of file diff --git a/MooGUI.java b/MooGUI.java index 944ed98..1ab280f 100644 --- a/MooGUI.java +++ b/MooGUI.java @@ -11,26 +11,39 @@ import java.awt.event.*; public class MooGUI extends JFrame implements WindowListener { - Sequence seq; + private Sequence seq; + private JLabel statusBar; + private // MooView view; /** * Creates the GUI. */ public MooGUI(Sequence seq) { super("Moosique"); + + // Adds menu bar. setJMenuBar(new MooMenu()); + + // Adds toolbar. getContentPane().add(new MooToolbar(), BorderLayout.NORTH); addWindowListener(this); + + // Adds main view. + // view = new MooView(); + + // Adds status bar. + statusBar = new JLabel("Welcome to Moosique!", Label.CENTER); + MooInstrumentList m = new MooInstrumentList(); getContentPane().add(m, BorderLayout.CENTER); m.addKeyListener(new MooKeyboard()); pack(); - //Dimension bounds = new Dimension(300,70); - -// setSize(bounds.width,bounds.height); - //setLocation((Toolkit.getDefaultToolkit().getScreenSize().width / 2) - (bounds.width / 2), (Toolkit.getDefaultToolkit().getScreenSize().height / 2) - (bounds.height / 2)); -// setResizable(false); - //setBackground(Color.white); + + // Dimension bounds = new Dimension(300,70); + // setSize(bounds.width,bounds.height); + // setLocation((Toolkit.getDefaultToolkit().getScreenSize().width / 2) - (bounds.width / 2), (Toolkit.getDefaultToolkit().getScreenSize().height / 2) - (bounds.height / 2)); + // setResizable(false); + // setBackground(Color.white); setVisible(true); } @@ -42,6 +55,14 @@ public class MooGUI extends JFrame implements WindowListener { seq = sequence; } + /** + * Shows the given message in the status bar. + * @param text the message to show + */ + public void setStatus(String text) { + statusBar.setText(text); + } + public void windowOpened(WindowEvent e) {} public void windowClosing(WindowEvent e) {Moosique.quit();} public void windowClosed(WindowEvent e) {} diff --git a/MooKeyboard.java b/MooKeyboard.java index 8b4389d..ce110b2 100644 --- a/MooKeyboard.java +++ b/MooKeyboard.java @@ -59,7 +59,7 @@ public class MooKeyboard extends KeyAdapter { * z x c v b n m , . => c d e f g a b c d */ static { - keyToNote[90] = startNote; + keyToNote[KeyEvent.VK_Q] = startNote; keyToNote[83] = startNote + 1; keyToNote[88] = startNote + 2; keyToNote[68] = startNote + 3; diff --git a/MooMenu.java b/MooMenu.java index f206457..86f9500 100644 --- a/MooMenu.java +++ b/MooMenu.java @@ -15,6 +15,47 @@ public class MooMenu extends JMenuBar implements ActionListener add(createHelpMenu()); } +/* + Ett något smidigare sätt, kanske.. / EP + + public MooMenu() { + file = makeMenu("File", KeyEvent.VK_F); + add(file) + // Samma sak med de andra menyerna + + file.add(makeAccItem(file, "New", KeyEvent.VK_N); + // Samma sak med de andra menyalternativen + } + + private JMenu makeMenu(String name, int mnemonic) { + JMenu menu = new JMenu(name); + menu.setMnemonic(mnemonic); + } + + private JMenuItem makeItem(JMenu menu, String name) { + JMenuItem item = new JMenuItem(name); + item.addActionListener(this); + menu.add(item); + } + + private JMenuItem makeAccItem(JMenu menu, String name, int key) { + JMenuItem item = new JMenuItem(name); + item.setAccelerator(KeyStroke.getKeyStroke(key, ActionEvent.CTRL_MASK)); + item.addActionListener(this); + menu.add(item); + } + + public void actionPerformed(ActionEvent e) { + String command = e.getActionCommand(); + ... + if(command == "Play") { + + } else if (command == "Stop") { + + } // Osv. + } +*/ + // creates the filemenu private JMenu createFileMenu() { @@ -102,7 +143,7 @@ public class MooMenu extends JMenuBar implements ActionListener private JMenu createHelpMenu() { help = new JMenu("Help"); - help.setMnemonic(KeyEvent.VK_P); + help.setMnemonic(KeyEvent.VK_H); contents = new JMenuItem("Contents"); help.add(contents); diff --git a/MooStatus.java b/MooStatus.java deleted file mode 100644 index c04325a..0000000 --- a/MooStatus.java +++ /dev/null @@ -1,18 +0,0 @@ -import javax.swing.*; - -/** - * - * - * @author Andersson, Andreen, Lanneskog, Pehrson - * @version 1 - */ - -public class MooStatus { - - /** - * Creates the status bar. - */ - public MooStatus () { - - } -} diff --git a/Moosique.java b/Moosique.java index c411cd6..c2006fa 100644 --- a/Moosique.java +++ b/Moosique.java @@ -12,22 +12,29 @@ import java.io.*; public class Moosique { - protected static MooGUI gui; - protected static Sequence seq; + private static MooGUI gui; + private static Sequence seq; + private static Sequencer sequencer; + private static Synthesizer synthesizer; + private static MidiChannel[] channels; + private static MidiChannel activeChannel; - protected static Sequencer sequencer; - protected static Synthesizer synthesizer; - protected static MidiChannel[] channels; - protected static MidiChannel activeChannel; - - protected static String filename; - protected static long position; + private static String filename, fileArg; + private static long position; + private static boolean makeGUI = true; /** * Starts the application. */ public static void main (String[] args) { System.out.println("\nMoosique version 1.0\n"); + + // Parses command-line arguments. + for (int i = 0; i < args.length; i++) { + if (args[i].equals("-n")) {makeGUI = false;} + else if (fileArg == null) {fileArg = args[i];} + } + // Acquires MIDI devices and connects them. System.out.print("Initializing MIDI devices."); try { @@ -47,19 +54,27 @@ public class Moosique { System.out.println("Done"); //If a filename is given as the command-line argument, attempts to load a sequence from the file. - System.out.print("Loading MIDI sequence..."); - if (args.length == 1) { - if (!load(args[0])) clearSequence(); + if (fileArg != null) { + System.out.print("Loading MIDI sequence from " + fileArg + "..."); + if (!load(fileArg)) clearSequence(); + System.out.println("Done"); } else { // Otherwise creates a new empty one. clearSequence(); } - System.out.println("Done"); - // Sets up channels and GUI. - System.out.print("Creating GUI..."); - gui = new MooGUI(seq); - System.out.println("Done"); + // If n-flag is set, plays song and then exits. Otherwise builds GUI. + if (makeGUI) { + System.out.print("Building GUI..."); + gui = new MooGUI(seq); + System.out.println("Done"); + } else { + System.out.print("Playing..."); + play(); + while (sequencer.isRunning()) {} + System.out.println("Done"); + quit(); + } } /** @@ -98,23 +113,20 @@ public class Moosique { * Replaces the current sequence with a new one, holding three empty tracks. */ public static void clearSequence() { - // Creates sequence. + // Creates a new sequence and sends it to the sequencer. try { seq = new Sequence(Sequence.PPQ, 96, 3); + sequencer.setSequence(seq); } catch (InvalidMidiDataException e) {} // Sends sequence to GUI. if (gui != null) gui.setSequence(seq); - } /** * Starts playback of the current sequence. */ public static void play() { - try { - sequencer.setSequence(seq); - sequencer.setTickPosition(position); - } catch (InvalidMidiDataException e) {} + sequencer.setTickPosition(position); sequencer.start(); } @@ -188,8 +200,11 @@ public class Moosique { return false; } - // Sends sequence to GUI + // Sends sequence to GUI and sequencer if (gui != null) gui.setSequence(seq); + try { + sequencer.setSequence(seq); + } catch (InvalidMidiDataException e) {} // Searches the sequence for NoteOn events Track[] tracks = seq.getTracks(); diff --git a/To Do.txt b/To Do.txt index 4a81abd..960d6aa 100644 --- a/To Do.txt +++ b/To Do.txt @@ -42,3 +42,17 @@ Rolle: MooTrackView(16) Mappa F9-F12 till MooKeyboard.setOctave(n) där n = {2, 4, 6, 8} * Funktioner för att sätta (och läsa?) channel? mute? solo? + För mute och solo gäller följande metoder (ligger utklistrade i Methods of Key Classes.txt): + + boolean getTrackMute(int track) Obtains the current mute state for a track. + boolean getTrackSolo(int track) Obtains the current solo state for a track. + void setTrackMute(int track, boolean mute) Sets the mute state for a track. + void setTrackSolo(int track, boolean solo) Sets the solo state for a track. + + När det gäller kanalerna velar jag lite. Antingen gör jag en mappningsmatris i Moosique som + man får läsa och skriva ifrån (vilket blir FULT!), eller så tar man allt direkt genom + MooNote. Metoden getChannel ska då leta upp den första MooNoten i det aktuella spåret och + ta getChannel på den. setChannel ska loopa igenom alla MooNotes (egentligen alla Events) + och ta setChannel på dem. Kan vara bra att fråga först eftersom det kan ta nån sekund. + +* getPosition och setPosition - kvar? \ No newline at end of file -- 2.39.2