78 lines
1.6 KiB
C++
78 lines
1.6 KiB
C++
#include <music/notes.hpp>
|
|
#include <midiseq/midiout.hpp>
|
|
#include <midiseq/note.hpp>
|
|
#include <midiseq/pureevnt.hpp>
|
|
#include <common/qsort.hpp>
|
|
|
|
bool Notes::remove(const Note ¬e)
|
|
{
|
|
int count=0;
|
|
for(int index=0;index<size();index++)
|
|
{
|
|
if(note==operator[](index))
|
|
{
|
|
Block<Note>::remove(index);
|
|
index=-1;
|
|
count++;
|
|
continue;
|
|
}
|
|
}
|
|
return count?true:false;
|
|
}
|
|
|
|
void Notes::sort(void)
|
|
{
|
|
QuickSort<Note> sorter;
|
|
sorter.sortItems(*this);
|
|
}
|
|
|
|
void Notes::off(MIDIOutputDevice &device)const
|
|
{
|
|
for(int index=0;index<size();index++)
|
|
{
|
|
((Block<Note>&)*this).operator[](index).noteOff(device);
|
|
}
|
|
}
|
|
|
|
bool Notes::play(MIDIOutputDevice &device,int interNoteDelay,bool noteOffAfterPlay)const
|
|
{
|
|
if(!device.hasDevice())return false;
|
|
for(int index=0;index<size();index++)
|
|
{
|
|
((Block<Note>&)*this).operator[](index).noteOn(device);
|
|
::Sleep(interNoteDelay);
|
|
if(noteOffAfterPlay)((Block<Note>&)*this).operator[](index).noteOff(device);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool Notes::playBack(MIDIOutputDevice &device,bool noteOffAfterPlay)const
|
|
{
|
|
if(!device.hasDevice())return false;
|
|
for(int index=size()-1;index>=0;index--)
|
|
{
|
|
((Block<Note>&)*this).operator[](index).noteOn(device);
|
|
::Sleep(getDelay()/1);
|
|
if(noteOffAfterPlay)((Block<Note>&)*this).operator[](index).noteOff(device);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
String Notes::toString(void)const
|
|
{
|
|
String str;
|
|
for(int index=0;index<size();index++)
|
|
{
|
|
str+=((Notes&)*this).operator[](index).toStringWithOctave();
|
|
if(index<size()-1)str+=",";
|
|
}
|
|
return str;
|
|
}
|
|
|
|
// virtuals
|
|
|
|
int Notes::getDelay()const
|
|
{
|
|
return DefaultDelay;
|
|
}
|