Initial
This commit is contained in:
201
proto/source/note.hpp
Normal file
201
proto/source/note.hpp
Normal file
@@ -0,0 +1,201 @@
|
||||
#ifndef _PROTO_NOTE_HPP_
|
||||
#define _PROTO_NOTE_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
|
||||
class Note
|
||||
{
|
||||
public:
|
||||
typedef enum NoteType{A,ASh,B,C,CSh,D,DSh,E,F,FSh,G,GSh};
|
||||
typedef enum Step{HalfStep=1,FullStep=2};
|
||||
Note();
|
||||
Note(const Note &pureNote);
|
||||
Note(NoteType note);
|
||||
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
|
||||
NoteType getNote(void)const;
|
||||
void setNote(NoteType noteType);
|
||||
int getOctave(void)const;
|
||||
void setOctave(int octave);
|
||||
String toString(void)const;
|
||||
String toStringWithOctave(void)const;
|
||||
private:
|
||||
int mNote;
|
||||
int mOctave;
|
||||
};
|
||||
|
||||
inline
|
||||
Note::Note()
|
||||
: mNote(A), mOctave(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Note::Note(NoteType note)
|
||||
: mNote(note), mOctave(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Note::Note(const Note &pureNote)
|
||||
{
|
||||
*this=pureNote;
|
||||
}
|
||||
|
||||
inline
|
||||
Note::~Note()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Note &Note::operator=(const Note ¬e)
|
||||
{
|
||||
setNote(note.getNote());
|
||||
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
|
||||
const Note &Note::operator++() // add half step
|
||||
{
|
||||
mNote++;
|
||||
if(mNote>GSh)
|
||||
{
|
||||
mNote=A;
|
||||
mOctave++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
const Note &Note::operator--() // add half step
|
||||
{
|
||||
mNote--;
|
||||
if(mNote<A)
|
||||
{
|
||||
mNote=GSh;
|
||||
mOctave--;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Note Note::operator++(int postFixDummy)
|
||||
{
|
||||
Note note(*this);
|
||||
++(*this);
|
||||
return note;
|
||||
}
|
||||
|
||||
Note Note::operator--(int postFixDummy)
|
||||
{
|
||||
Note note(*this);
|
||||
++(*this);
|
||||
return note;
|
||||
}
|
||||
|
||||
inline
|
||||
const Note &Note::operator+=(Step step)
|
||||
{
|
||||
int remainder;
|
||||
if(HalfStep==step)return ++(*this);
|
||||
mNote+=step;
|
||||
if(mNote>GSh)
|
||||
{
|
||||
mNote=A+(mNote-GSh)-1;
|
||||
mOctave++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
const Note &Note::operator-=(Step step)
|
||||
{
|
||||
if(HalfStep==step)return --(*this);
|
||||
mNote-=step;
|
||||
if(mNote<A)
|
||||
{
|
||||
mNote=(GSh+mNote)+1;
|
||||
mOctave--;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
Note::NoteType Note::getNote(void)const
|
||||
{
|
||||
return (NoteType)mNote;
|
||||
}
|
||||
|
||||
inline
|
||||
void Note::setNote(NoteType note)
|
||||
{
|
||||
mNote=note;
|
||||
}
|
||||
|
||||
inline
|
||||
String Note::toStringWithOctave(void)const
|
||||
{
|
||||
return toString()+String("(")+String().fromInt(mOctave)+String(")");
|
||||
}
|
||||
|
||||
inline
|
||||
String Note::toString(void)const
|
||||
{
|
||||
switch(mNote)
|
||||
{
|
||||
case Note::A :
|
||||
return "A";
|
||||
case Note::ASh :
|
||||
return "A#";
|
||||
case Note::B :
|
||||
return "B";
|
||||
case Note::C :
|
||||
return "C";
|
||||
case Note::CSh :
|
||||
return "C#";
|
||||
case Note::D :
|
||||
return "D";
|
||||
case Note::DSh :
|
||||
return "D#";
|
||||
case Note::E :
|
||||
return "E";
|
||||
case Note::F :
|
||||
return "F";
|
||||
case Note::FSh :
|
||||
return "F#";
|
||||
case Note::G :
|
||||
return "G";
|
||||
case Note::GSh :
|
||||
return "G#";
|
||||
default :
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user