]> ruin.nu Git - moosique.git/blob - MooNote.java
removed exportMIDI method; added quit, getPosition, setPosition and resume
[moosique.git] / MooNote.java
1 import javax.sound.midi.*;
2
3 /*
4  * Functional representation of a MIDI note, which contains two MIDI events, note on and note off.
5  * 
6  * @author  Andersson, Andreen, Lanneskog, Pehrson
7  * @version 1
8  */
9  
10 public class MooNote {
11
12         private MidiEvent noteOnEvent, noteOffEvent;
13         private ShortMessage noteOnMsg, noteOffMsg;
14         private long noteOnTime, noteOffTime;
15
16         /* 
17          * Creates a MooNote of the given pitch, velocity and length in the current track.
18          */
19         public MooNote (int pitch, int velocity, int length) {
20                 noteOnMsg = new ShortMessage();
21                 noteOffMsg = new ShortMessage();
22                 noteOnMsg.setMessage(ShortMessage.NOTE_ON, pitch, velocity);
23                 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, pitch, velocity);
24 //              noteOnTime = ???;
25                 noteOffTime = noteOnTime + length;
26                 noteOnEvent = new MidiEvent(noteOnMsg, noteOnTime);
27                 noteOffEvent = new MidiEvent(noteOffMsg, noteOffTime);
28         }
29
30         /* 
31          * Sets the pitch of the current note.
32          * @param pitch         the pitch of the note (0-127)
33          */
34         public void setPitch(int pitch) {
35                 noteOnMsg.setMessage(ShortMessage.NOTE_ON, pitch, noteOnMsg.getData2());
36                 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, pitch, noteOffMsg.getData2());
37         }
38
39         /* 
40          * Sets the velocity of the current note.
41          + @param vel   the velocity of the note (0-127)
42          */
43         public void setVelocity(int vel) {
44                 noteOnMsg.setMessage(ShortMessage.NOTE_ON, noteOnMsg.getData1(), vel);
45                 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, noteOffMsg.getData1(), vel);
46         }
47
48         /* 
49          * Sets the length of the current note (or rather moves the note off event).
50          + @param n     the length of the note in ticks (100 per beat)
51          */
52         public void setLength(int ticks) {
53                 
54         }
55
56         /* 
57          * Returns the note on event of the current note.
58          * @return      the note on MidiEvent
59          */
60         public MidiEvent getNoteOnEvent() {
61                 return noteOnEvent;
62         }
63
64         /* 
65          * Returns the note off event of the current note.
66          * @return      the note off MidiEvent
67          */
68         public MidiEvent getNoteOffEvent() {
69                 return noteOffEvent;
70         }
71
72         /* 
73          * Returns the pitch of the current note.
74          * @return the pitch of the note
75          */
76         public int getPitch() {
77                 return noteOnMsg.getData1();
78         }
79
80         /* 
81          * Returns the velocity of the current note.
82          * @return the velocity of the note
83          */
84         public int getVelocity() {
85                 return noteOnMsg.getData2();
86         }
87
88         /* 
89          * Returns the length of the current note.
90          * @return the length of the note
91          */
92         public int getLength() {
93         
94         }
95 }