Initial
This commit is contained in:
181
music/Chord.cpp
Normal file
181
music/Chord.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
#include <music/chord.hpp>
|
||||
#include <midiseq/noteon.hpp>
|
||||
#include <midiseq/noteoff.hpp>
|
||||
|
||||
using namespace Music;
|
||||
|
||||
bool Chord::play(MIDIOutputDevice &device,bool noteOffAfterPlay)
|
||||
{
|
||||
if(!device.hasDevice())return false;
|
||||
for(int index=0;index<size();index++)
|
||||
{
|
||||
NoteOn ¬eOn=(NoteOn&)operator[](index);
|
||||
PureEvent midiEvent=((NoteOn&)operator[](index).toMIDINote()).getEvent();
|
||||
device.midiEvent(midiEvent);
|
||||
}
|
||||
if(!noteOffAfterPlay)return true;
|
||||
::Sleep(getDelay());
|
||||
for(index=0;index<size();index++)
|
||||
{
|
||||
NoteOff ¬eOff=(NoteOff&)operator[](index);
|
||||
PureEvent midiEvent=((NoteOff&)operator[](index).toMIDINote()).getEvent();
|
||||
device.midiEvent(midiEvent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Chord::create(const Note &root,ChordType chordType)
|
||||
{
|
||||
switch(chordType)
|
||||
{
|
||||
case MajorTriad :
|
||||
handleMajorTriad(root);
|
||||
break;
|
||||
case MajorSeventh :
|
||||
handleMajorSeventh(root);
|
||||
break;
|
||||
case MinorTriad :
|
||||
handleMinorTriad(root);
|
||||
break;
|
||||
case DiminishedTriad :
|
||||
handleDiminishedTriad(root);
|
||||
break;
|
||||
case AugmentedTriad :
|
||||
handleAugmentedTriad(root);
|
||||
break;
|
||||
case DiminishedSeventh :
|
||||
handleDiminishedSeventh(root);
|
||||
break;
|
||||
case HalfDiminishedSeventh :
|
||||
handleHalfDiminishedSeventh(root);
|
||||
break;
|
||||
case MinorSixth :
|
||||
handleMinorSixth(root);
|
||||
break;
|
||||
case MinorSeventh :
|
||||
handleMinorSeventh(root);
|
||||
break;
|
||||
case MinorMajorSeventh :
|
||||
handleMinorMajorSeventh(root);
|
||||
break;
|
||||
case DominantSixth :
|
||||
handleDominantSixth(root);
|
||||
break;
|
||||
case DominantSeventh :
|
||||
handleDominantSeventh(root);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Chord::handleMajorTriad(Note root)
|
||||
{
|
||||
size(3);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getThird();
|
||||
operator[](2)=root.getFifth();
|
||||
}
|
||||
|
||||
void Chord::handleMinorTriad(Note root)
|
||||
{
|
||||
size(3);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getMinorThird();
|
||||
operator[](2)=root.getFifth();
|
||||
}
|
||||
|
||||
void Chord::handleDiminishedTriad(Note root)
|
||||
{
|
||||
size(3);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getMinorThird();
|
||||
operator[](2)=root.getDiminishedFifth();
|
||||
}
|
||||
|
||||
void Chord::handleAugmentedTriad(Note root)
|
||||
{
|
||||
size(3);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getThird();
|
||||
operator[](2)=root.getAugmentedFifth();
|
||||
}
|
||||
|
||||
void Chord::handleMajorSeventh(Note root)
|
||||
{
|
||||
size(4);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getThird();
|
||||
operator[](2)=root.getFifth();
|
||||
operator[](3)=root.getSeventh();
|
||||
}
|
||||
|
||||
void Chord::handleDiminishedSeventh(Note root)
|
||||
{
|
||||
size(4);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getMinorThird();
|
||||
operator[](2)=operator[](1).getMinorThird();
|
||||
operator[](3)=operator[](2).getMinorThird();
|
||||
}
|
||||
|
||||
void Chord::handleHalfDiminishedSeventh(Note root)
|
||||
{
|
||||
size(4);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getMinorThird();
|
||||
operator[](2)=operator[](1).getMinorThird();
|
||||
operator[](3)=root.getMinorSeventh();
|
||||
}
|
||||
|
||||
void Chord::handleMinorSixth(Note root)
|
||||
{
|
||||
size(4);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getMinorThird();
|
||||
operator[](2)=root.getFifth();
|
||||
operator[](3)=root.getSixth();
|
||||
}
|
||||
|
||||
void Chord::handleMinorSeventh(Note root)
|
||||
{
|
||||
size(4);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getMinorThird();
|
||||
operator[](2)=root.getFifth();
|
||||
operator[](3)=root.getMinorSeventh();
|
||||
}
|
||||
|
||||
void Chord::handleMinorMajorSeventh(Note root)
|
||||
{
|
||||
size(4);
|
||||
operator[](0)=root;
|
||||
operator[](1)=root.getMinorThird();
|
||||
operator[](2)=root.getFifth();
|
||||
operator[](3)=root.getSeventh();
|
||||
}
|
||||
|
||||
void Chord::handleDominantSixth(Note root)
|
||||
{
|
||||
Chord majorTriad;
|
||||
|
||||
size(4);
|
||||
majorTriad.handleMajorTriad(root);
|
||||
operator[](0)=majorTriad[0];
|
||||
operator[](1)=majorTriad[1];
|
||||
operator[](2)=majorTriad[2];
|
||||
operator[](3)=root.getSixth();
|
||||
}
|
||||
|
||||
void Chord::handleDominantSeventh(Note root)
|
||||
{
|
||||
Chord majorTriad;
|
||||
|
||||
size(4);
|
||||
majorTriad.handleMajorTriad(root);
|
||||
operator[](0)=majorTriad[0];
|
||||
operator[](1)=majorTriad[1];
|
||||
operator[](2)=majorTriad[2];
|
||||
operator[](3)=root.getMinorSeventh();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user