Files
Work/guitar/backup/20030503/Fretboard.cpp
2024-08-07 09:16:27 -04:00

102 lines
2.3 KiB
C++

#include <guitar/Fretboard.hpp>
#include <common/block.hpp>
bool Fretboard::isOnFretboard(const Note &note)
{
for(int frIndex=0;frIndex<mFrets+1;frIndex++)
{
for(int srIndex=0;srIndex<size();srIndex++)
{
Note &srchNote=operator[](srIndex)[frIndex];
if(srchNote.getNote()==note.getNote()&&srchNote.getOctave()==note.getOctave())return true;
}
}
return false;
}
bool Fretboard::getAt(const Note &note,FrettedNote &frettedNote)
{
for(int frIndex=0;frIndex<mFrets+1;frIndex++)
{
for(int srIndex=0;srIndex<size();srIndex++)
{
Note &srchNote=operator[](srIndex)[frIndex];
if(srchNote.getNote()==note.getNote()&&srchNote.getOctave()==note.getOctave())
{
frettedNote.setNote(note);
frettedNote.setString(srIndex);
frettedNote.setFret(frIndex);
return true;
}
}
}
return false;
}
bool Fretboard::getAt(const Note &note,Block<FrettedNote> &frettedNotes)
{
frettedNotes.remove();
for(int frIndex=0;frIndex<mFrets+1;frIndex++)
{
for(int srIndex=0;srIndex<size();srIndex++)
{
Note &srchNote=operator[](srIndex)[frIndex];
if(srchNote.getNote()==note.getNote()&&srchNote.getOctave()==note.getOctave())
{
FrettedNote frettedNote;
frettedNote.setNote(note);
frettedNote.setString(srIndex);
frettedNote.setFret(frIndex);
frettedNotes.insert(&frettedNote);
}
}
}
return frettedNotes.size()?true:false;
}
void Fretboard::createFretboard(const Tuning &tuning,int frets)
{
mTuning=tuning;
mFrets=frets;
createFretboard();
}
bool Fretboard::play(MIDIOutputDevice &device)
{
for(int string=0;string<size();string++)
{
Notes &stringNotes=operator[](string);
stringNotes.play(device);
}
return true;
}
void Fretboard::createFretboard(void)
{
size(mTuning.getStrings());
for(int string=0;string<size();string++)
{
Notes &stringNotes=operator[](string);
stringNotes.size(mFrets+1);
Note fretNote=mTuning[string];
for(int fret=0;fret<mFrets+1;fret++)
{
stringNotes[fret]=fretNote;
fretNote++;
}
}
}
String Fretboard::toString(void)const
{
String strFretboard;
for(int string=0;string<size();string++)
{
Notes &stringNotes=((Array<Notes>&)*this).operator[](string);
strFretboard+=stringNotes.toString();
if(string<size()-1)strFretboard+=String("\n");
}
return strFretboard;
}