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

109 lines
2.3 KiB
C++

#ifndef _GUITAR_FRETBOARD_HPP_
#define _GUITAR_FRETBOARD_HPP_
#ifndef _GUITAR_TUNING_HPP_
#include <guitar/tuning.hpp>
#endif
#ifndef _COMMON_ARRAY_HPP_
#include <common/array.hpp>
#endif
#ifndef _MUSIC_NOTES_HPP_
#include <music/notes.hpp>
#endif
#ifndef _MUSIC_CHORD_HPP_
#include <music/chord.hpp>
#endif
#ifndef _GUITAR_FRETTEDNOTE_HPP_
#include <guitar/frettednote.hpp>
#endif
// |-5-
// |-4-
// |-3-
// |-2-
// |-1-
// |-0-
class MIDIOutputDevice;
class Fretboard : public Array<Notes>
{
public:
enum{Frets=24,Strings=6};
Fretboard(const Tuning &tuning=Tuning(),int frets=Frets);
virtual ~Fretboard();
void createFretboard(const Tuning &tuning,int frets=Frets);
const Tuning &getTuning();
void setTuning(const Tuning &tuning);
const Note &getAt(int string,int fret);
bool getAt(const Music::Chord &chord,Block<FrettedNote> &frettedNotes);
bool getAt(const Note &note,FrettedNote &frettedNote);
bool getAt(const Note &note,Block<FrettedNote> &frettedNotes);
int getFrets(void)const;
void setFrets(int frets);
bool isOnFretboard(const Note &note);
bool play(MIDIOutputDevice &device);
String toString(void)const;
static bool isValidFret(int fret);
private:
void createFretboard();
bool getAt(const Note &note,FrettedNote &frettedNote,Block<FrettedNote> &containedNotes);
bool contains(const FrettedNote &frettedNote,Block<FrettedNote> &frettedNotes);
bool getFillerNotes(int fret,const Music::Chord &chord,Block<FrettedNote> &frettedNotes);
int distance(const FrettedNote &frettedNote,Block<FrettedNote> &frettedNotes);
bool isIn(const FrettedNote &frettedNote,const Music::Chord &chord);
Tuning mTuning;
int mFrets;
};
inline
Fretboard::Fretboard(const Tuning &tuning,int frets)
: mTuning(tuning),mFrets(frets)
{
createFretboard();
}
inline
Fretboard::~Fretboard()
{
}
inline
const Tuning &Fretboard::getTuning()
{
return mTuning;
}
inline
void Fretboard::setTuning(const Tuning &tuning)
{
mTuning=tuning;
createFretboard();
}
inline
int Fretboard::getFrets(void)const
{
return mFrets;
}
inline
void Fretboard::setFrets(int frets)
{
mFrets=frets;
createFretboard();
}
inline
const Note &Fretboard::getAt(int string,int fret)
{
return (operator[](string)).operator[](fret);
}
inline
bool Fretboard::isValidFret(int fret)
{
if(fret<=Fretboard::Frets)return true;
return false;
}
#endif