Class Note
Represents a musical note.
Inherited Members
Namespace: Melanchall.DryWetMidi.Interaction
Assembly: Melanchall.DryWetMidi.dll
Syntax
public class Note : ILengthedObject, ITimedObject, IMusicalObject, INotifyTimeChanged, INotifyLengthChanged
Constructors
Note(SevenBitNumber)
Initializes a new instance of the Note with the specified note number.
Declaration
public Note(SevenBitNumber noteNumber)
Parameters
| Type | Name | Description |
|---|---|---|
| SevenBitNumber | noteNumber | Number of the note (60 is middle C). |
Note(SevenBitNumber, long)
Initializes a new instance of the Note with the specified
note number and length.
Declaration
public Note(SevenBitNumber noteNumber, long length)
Parameters
| Type | Name | Description |
|---|---|---|
| SevenBitNumber | noteNumber | Number of the note (60 is middle C). |
| long | length | Length of the note in units defined by time division of a MIDI file. |
Note(SevenBitNumber, long, long)
Initializes a new instance of the Note with the specified
note number, length and absolute time.
Declaration
public Note(SevenBitNumber noteNumber, long length, long time)
Parameters
| Type | Name | Description |
|---|---|---|
| SevenBitNumber | noteNumber | Number of the note (60 is middle C). |
| long | length | Length of the note in units defined by time division of a MIDI file. |
| long | time | Absolute time of the note in units defined by the time division of a MIDI file. |
Note(TimedEvent, TimedEvent)
Initializes a new instance of the Note with the specified pair of
timed events holding corresponding NoteOnEvent and NoteOffEvent events.
Declaration
public Note(TimedEvent timedNoteOnEvent, TimedEvent timedNoteOffEvent)
Parameters
| Type | Name | Description |
|---|---|---|
| TimedEvent | timedNoteOnEvent | TimedEvent holding NoteOnEvent event of a note. |
| TimedEvent | timedNoteOffEvent | TimedEvent holding NoteOffEvent event of a note. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | One of the following errors occurred:
|
Note(NoteName, int)
Initializes a new instance of the Note with the specified
note name and octave.
Declaration
public Note(NoteName noteName, int octave)
Parameters
| Type | Name | Description |
|---|---|---|
| NoteName | noteName | Name of the note. |
| int | octave | Number of the octave in scientific pitch notation. |
Remarks
Octave number is specified in scientific pitch notation which means that 4 must be
passed to
octave to get the middle C.Exceptions
| Type | Condition |
|---|---|
| InvalidEnumArgumentException | noteName specified an
invalid value. |
| ArgumentException | Note number is out of range for the specified note name and octave. |
Note(NoteName, int, long)
Initializes a new instance of the Note with the specified
note name, octave and length.
Declaration
public Note(NoteName noteName, int octave, long length)
Parameters
| Type | Name | Description |
|---|---|---|
| NoteName | noteName | Name of the note. |
| int | octave | Number of the octave in scientific pitch notation. |
| long | length | Length of the note in units defined by time division of a MIDI file. |
Remarks
Octave number is specified in scientific pitch notation which means that 4 must be
passed to
octave to get the middle C.Exceptions
| Type | Condition |
|---|---|
| InvalidEnumArgumentException | noteName specified an
invalid value. |
| ArgumentException | Note number is out of range for the specified note name and octave. |
Note(NoteName, int, long, long)
Initializes a new instance of the Note with the specified
note name, octave, length and absolute time.
Declaration
public Note(NoteName noteName, int octave, long length, long time)
Parameters
| Type | Name | Description |
|---|---|---|
| NoteName | noteName | Name of the note. |
| int | octave | Number of the octave in scientific pitch notation. |
| long | length | Length of the note in units defined by time division of a MIDI file. |
| long | time | Absolute time of the note in units defined by the time division of a MIDI file. |
Remarks
Octave number is specified in scientific pitch notation which means that 4 must be
passed to
octave to get the middle C.Exceptions
| Type | Condition |
|---|---|
| InvalidEnumArgumentException | noteName specified an
invalid value. |
| ArgumentException | Note number is out of range for the specified note name and octave. |
Fields
DefaultOffVelocity
Default off velocity (velocity of underlying NoteOffEvent event).
Declaration
public static readonly SevenBitNumber DefaultOffVelocity
Field Value
| Type | Description |
|---|---|
| SevenBitNumber |
DefaultVelocity
Default velocity (velocity of underlying NoteOnEvent event).
Declaration
public static readonly SevenBitNumber DefaultVelocity
Field Value
| Type | Description |
|---|---|
| SevenBitNumber |
Properties
Channel
Gets or sets channel to play the note on.
Declaration
public FourBitNumber Channel { get; set; }
Property Value
| Type | Description |
|---|---|
| FourBitNumber |
EndTime
Gets the end time of an object.
Declaration
public long EndTime { get; }
Property Value
| Type | Description |
|---|---|
| long |
Length
Gets or sets the length of the note in units defined by the time division of a MIDI file.
Declaration
public long Length { get; set; }
Property Value
| Type | Description |
|---|---|
| long |
Remarks
Note that the returned value will be in ticks (not seconds, not milliseconds and so on).
Please read Time and length article to learn how you can
get the length in different representations.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | value is negative. |
NoteName
Gets name of the note.
Declaration
public NoteName NoteName { get; }
Property Value
| Type | Description |
|---|---|
| NoteName |
NoteNumber
Gets or sets number of the note (60 is middle C).
Declaration
public SevenBitNumber NoteNumber { get; set; }
Property Value
| Type | Description |
|---|---|
| SevenBitNumber |
Octave
Gets octave of the note.
Declaration
public int Octave { get; }
Property Value
| Type | Description |
|---|---|
| int |
OffVelocity
Gets or sets velocity of the underlying NoteOffEvent.
Declaration
public SevenBitNumber OffVelocity { get; set; }
Property Value
| Type | Description |
|---|---|
| SevenBitNumber |
Time
Gets or sets absolute time of the note in units defined by the time division of a MIDI file.
Declaration
public long Time { get; set; }
Property Value
| Type | Description |
|---|---|
| long |
Remarks
Note that the returned value will be in ticks (not seconds, not milliseconds and so on).
Please read Time and length article to learn how you can
get the time in different representations.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | value is negative. |
Velocity
Gets or sets velocity of the underlying NoteOnEvent.
Declaration
public SevenBitNumber Velocity { get; set; }
Property Value
| Type | Description |
|---|---|
| SevenBitNumber |
Methods
Clone()
Clones object by creating a copy of it.
Declaration
public virtual ITimedObject Clone()
Returns
| Type | Description |
|---|---|
| ITimedObject | Copy of the object. |
GetTimedNoteOffEvent()
Gets the 'Note Off' timed event of the current note.
Declaration
public TimedEvent GetTimedNoteOffEvent()
Returns
| Type | Description |
|---|---|
| TimedEvent | The 'Note Off' timed event of the current note. |
GetTimedNoteOnEvent()
Gets the 'Note On' timed event of the current note.
Declaration
public TimedEvent GetTimedNoteOnEvent()
Returns
| Type | Description |
|---|---|
| TimedEvent | The 'Note On' timed event of the current note. |
SetNoteNameAndOctave(NoteName, int)
Sets note name and octave for current Note.
Declaration
public void SetNoteNameAndOctave(NoteName noteName, int octave)
Parameters
| Type | Name | Description |
|---|---|---|
| NoteName | noteName | Name of the note. |
| int | octave | Number of the octave in scientific pitch notation. |
Remarks
Octave number is specified in scientific pitch notation which means that 4 must be
passed to
octave to get the number of the middle C.Exceptions
| Type | Condition |
|---|---|
| InvalidEnumArgumentException | noteName specified an
invalid value. |
| ArgumentException | Note number is out of range for the specified note name and octave. |
Split(long)
Splits the current object by the specified time.
Declaration
public SplitLengthedObject Split(long time)
Parameters
| Type | Name | Description |
|---|---|---|
| long | time | Time to split the object at. |
Returns
| Type | Description |
|---|---|
| SplitLengthedObject | An object containing left and right parts of the split object. Both parts have the same type as the original object. |
Remarks
If time is less than or equal to time of the object, the left part will
be null. If time is greater than or equal to end time of the object,
the right part will be null.
Let's see a simple example. Suppose we have an object with time of 10 and length of 50.
The table below shows what left and right parts will be in case of different values of
time:
| Time to split at | Left part | Right part |
|---|---|---|
5
|
null
| Copy of the object |
10
|
null
| Copy of the object |
30
| Copy of the object with time of 10 and length of 20 | Copy of the object with time of 30 and length of 30 |
60
| Copy of the object |
null
|
70
| Copy of the object |
null
|
To learn about other ways to split an object please read Objects splitting article.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | time is negative. |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string that represents the current object. |
Overrides
Events
LengthChanged
Occurs when the length of an object has been changed.
Declaration
public event EventHandler<LengthChangedEventArgs> LengthChanged
Event Type
| Type | Description |
|---|---|
| EventHandler<LengthChangedEventArgs> |
TimeChanged
Occurs when the time of an object has been changed.
Declaration
public event EventHandler<TimeChangedEventArgs> TimeChanged
Event Type
| Type | Description |
|---|---|
| EventHandler<TimeChangedEventArgs> |