139 lines
3.1 KiB
C++
139 lines
3.1 KiB
C++
#ifndef _MUSIC_NOTE_HPP_
|
|
#define _MUSIC_NOTE_HPP_
|
|
#ifndef _COMMON_STRING_HPP_
|
|
#include <common/string.hpp>
|
|
#endif
|
|
#ifndef _COMMON_ARRAY_HPP_
|
|
#include <common/array.hpp>
|
|
#endif
|
|
|
|
class PureNote;
|
|
class MIDIOutputDevice;
|
|
|
|
class Note
|
|
{
|
|
public:
|
|
enum {Octave=4,Octaves=11,NotesPerOctave=12};
|
|
typedef enum NoteType{C,CSh,D,DSh,E,F,FSh,G,GSh,A,ASh,B,None};
|
|
typedef enum Step{HalfStep=1,WholeStep=2};
|
|
Note();
|
|
Note(const Note &pureNote);
|
|
Note(const PureNote &pureNote);
|
|
Note(const String &strNote,int octave=Octave);
|
|
Note(NoteType note,int octave=Octave);
|
|
virtual ~Note();
|
|
Note &operator=(const Note ¬e);
|
|
bool operator==(const Note ¬e)const;
|
|
bool operator<(const Note ¬e)const;
|
|
bool operator>(const Note ¬e)const;
|
|
const Note &operator++(); // increment by half step
|
|
const Note &operator--(); // decrement by half step
|
|
Note operator++(int postFixDummy); // postfix increment by half step
|
|
Note operator--(int postFixDummy); // postfix decrement by half step
|
|
const Note &operator+=(Step step); // increment by step
|
|
const Note &operator-=(Step step); // decrement by step
|
|
Note getSecond(void)const;
|
|
Note getThird(void)const;
|
|
Note getMinorThird(void)const;
|
|
Note getFourth(void)const;
|
|
Note getFifth(void)const;
|
|
Note getDiminishedFifth(void)const;
|
|
Note getAugmentedFifth(void)const;
|
|
Note getSixth(void)const;
|
|
Note getSeventh(void)const;
|
|
Note getNinth(void)const;
|
|
Note getEleventh(void)const;
|
|
Note getThirteenth(void)const;
|
|
Note getMinorSeventh(void)const;
|
|
Note getParentSecond(void)const; // get's the parent who's second is this note
|
|
Note getParentFifth(void)const; // get's the parent who's fifth is this note
|
|
NoteType getNote(void)const;
|
|
void setNote(NoteType noteType);
|
|
void setNote(const Note ¬e);
|
|
int getOctave(void)const;
|
|
void setOctave(int octave);
|
|
String toString(void)const;
|
|
String toStringWithOctave(void)const;
|
|
PureNote toMIDINote(void)const;
|
|
bool fromMIDINote(const PureNote &pureNote);
|
|
bool noteOn(MIDIOutputDevice &midiDevice);
|
|
bool noteOff(MIDIOutputDevice &midiDevice);
|
|
static NoteType getNoteType(String note);
|
|
private:
|
|
BYTE lookupPitch(void)const;
|
|
bool lookupNote(int pitch,Note &refNote)const;
|
|
|
|
int mNote;
|
|
int mOctave;
|
|
static unsigned char pitchArray[11][12];
|
|
};
|
|
|
|
inline
|
|
Note::Note()
|
|
: mNote(A), mOctave(Octave)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Note::Note(const PureNote &pureNote)
|
|
{
|
|
fromMIDINote(pureNote);
|
|
}
|
|
|
|
inline
|
|
Note::Note(const String ¬e,int octave)
|
|
: mNote(getNoteType(note)), mOctave(octave)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Note::Note(NoteType note,int octave)
|
|
: mNote(note), mOctave(octave)
|
|
{
|
|
}
|
|
|
|
inline
|
|
Note::Note(const Note &pureNote)
|
|
{
|
|
*this=pureNote;
|
|
}
|
|
|
|
inline
|
|
Note::~Note()
|
|
{
|
|
}
|
|
|
|
inline
|
|
Note &Note::operator=(const Note ¬e)
|
|
{
|
|
setNote(note.getNote());
|
|
setOctave(note.getOctave());
|
|
return *this;
|
|
}
|
|
|
|
inline
|
|
bool Note::operator==(const Note ¬e)const
|
|
{
|
|
return mNote==note.mNote;
|
|
}
|
|
|
|
inline
|
|
bool Note::operator<(const Note ¬e)const
|
|
{
|
|
return mNote<note.mNote;
|
|
}
|
|
|
|
inline
|
|
bool Note::operator>(const Note ¬e)const
|
|
{
|
|
return mNote>note.mNote;
|
|
}
|
|
|
|
inline
|
|
void Note::setNote(const Note ¬e)
|
|
{
|
|
mNote=note.mNote;
|
|
mOctave=note.mOctave;
|
|
}
|
|
#endif
|