]> ruin.nu Git - moosique.git/blob - MooNote.java
Implemented some obvious methods.
[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                 // MidiEvent(MidiMessage message, long tick)
21                 noteOnMsg = new ShortMessage();
22                 noteOffMsg = new ShortMessage();
23                 noteOnMsg.setMessage(ShortMessage.NOTE_ON, pitch, velocity);
24                 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, pitch, velocity);
25 //              noteOnTime = ???;
26                 noteOffTime = noteOnTime + length;
27                 noteOnEvent = new MidiEvent(noteOnMsg, noteOnTime)
28                 noteOffEvent = new MidiEvent(noteOffMsg, noteOffTime)
29         }
30
31         /* 
32          * Sets the pitch of the current note.
33          + @param pitch         the pitch of the note (0-127)
34          */
35         public void setPitch(int pitch) {
36                 noteOnMsg.setMessage(ShortMessage.NOTE_ON, pitch, noteOnMsg.getData2());
37                 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, pitch, noteOffMsg.getData2());
38         }
39
40         /* 
41          * Sets the velocity of the current note.
42          + @param vel   the velocity of the note (0-127)
43          */
44         public void setVelocity(int vel) {
45                 noteOnMsg.setMessage(ShortMessage.NOTE_ON, noteOnMsg.getData1(), vel);
46                 noteOffMsg.setMessage(ShortMessage.NOTE_OFF, noteOffMsg.getData1(), vel);
47         }
48
49         /* 
50          * Sets the length of the current note (or rather moves the note off event).
51          + @param n     the length of the note in ticks (100 per beat)
52          */
53         public void setLength(int ticks) {
54                 
55         }
56
57         /* 
58          * Returns the note on event of the current note.
59          * @return      the note on MidiEvent
60          */
61         public MidiEvent getNoteOnEvent() {
62                 return noteOnEvent;
63         }
64
65         /* 
66          * Returns the note off event of the current note.
67          * @return      the note off MidiEvent
68          */
69         public MidiEvent getNoteOffEvent() {
70                 return noteOffEvent;
71         }
72
73         /* 
74          * Returns the pitch of the current note.
75          * @return the pitch of the note
76          */
77         public int getPitch() {
78                 return noteOnMsg.getData1();
79         }
80
81         /* 
82          * Returns the velocity of the current note.
83          * @return the velocity of the note
84          */
85         public int getVelocity() {
86                 return noteOnMsg.getData2();
87         }
88
89         /* 
90          * Returns the length of the current note.
91          * @return the length of the note
92          */
93         public int getLength() {
94         
95         }
96 }