Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

tonleiterdatahelper.cpp

Go to the documentation of this file.
00001 #include "tonleiterdatahelper.h"
00002 
00003 #include <math.h>
00004 
00005 using namespace Data;
00006 
00007 int Note::getOctaveOfNote(int note)
00008 {
00009     int remain=note%12;
00010     return (note-remain)/12;
00011 }
00012 //****************************************************************************
00013 QString Note::getNameOfNote(int note)
00014 {
00015     int octave=getOctaveOfNote(note);
00016     return notenames[note-12*octave];
00017 }
00018 //****************************************************************************
00019 int Note::getNoteFromName(QString name,int octave)
00020 {
00021     int notevalue=0;
00022     for(int a=0;a<12;a++)
00023     {
00024         if(name==notenames[a])
00025         {
00026             notevalue=a;
00027             break;
00028         }
00029     }
00030     return notevalue+12*octave;
00031 }
00032 //****************************************************************************
00033 int Note::octaveOfBaseNote(int base,int note)
00034 {
00035     int normnote = (note>=base) ? note-base : (12-base)+note;
00036     int octave=getOctaveOfNote(normnote);
00037     //odebug << "note " << note << " of " << base << " base is norm " << normnote << " -> ocatve " << octave << "" << oendl; 
00038     return octave;
00039 }
00040 //****************************************************************************
00041 //****************************************************************************
00042 Instrument::Instrument()
00043 {
00044     name="UNDEFINED";
00045     frets=0;
00046 }
00047 //****************************************************************************
00048 Instrument::Instrument(QString name,int frets,QValueList<int> strings)
00049 :name(name),frets(frets),strings(strings)
00050 {
00051 }
00052 //****************************************************************************
00053 Instrument::~Instrument()
00054 {
00055 }
00056 //****************************************************************************
00057 int Instrument::noOfStrings()
00058 {
00059     return (int)strings.count();
00060 }
00061 //****************************************************************************
00062 int Instrument::noOfFrets()
00063 {
00064     return frets;
00065 }
00066 //****************************************************************************
00067 QString Instrument::instName()
00068 {
00069     return name;
00070 }
00071 //****************************************************************************
00072 int Instrument::string(int id)
00073 {
00074     return strings[id];
00075 }
00076 //****************************************************************************
00077 int Instrument::noOfOctaves()
00078 {
00079     return (int) ceil((highestNote()-lowestNote())/12.0);
00080 }
00081 //****************************************************************************
00082 int Instrument::lowestNote()
00083 {
00084     return strings[0];
00085 
00086 }
00087 //****************************************************************************
00088 int Instrument::highestNote()
00089 {
00090     return strings[strings.count()-1]+frets;
00091 }
00092 //****************************************************************************
00093 //****************************************************************************
00094 Scale::Scale()
00095 {
00096     name="UNDEFINED";
00097 }
00098 //****************************************************************************
00099 Scale::Scale(QString name,QValueList<int> halftones)
00100 :name(name),halftones(halftones)
00101 {
00102 }
00103 //****************************************************************************
00104 Scale::~Scale()
00105 {
00106 }
00107 //****************************************************************************
00108 int Scale::noOfHaltones()
00109 {
00110     return (int)halftones.count();
00111 }
00112 //****************************************************************************
00113 int Scale::getHalfTone(int id)
00114 {
00115     if(id>=0 && id<noOfHaltones())
00116         return halftones[id];
00117     else
00118         return 0;
00119 }
00120 //****************************************************************************
00121 QString Scale::scaleName()
00122 {
00123     return name;
00124 }
00125 //****************************************************************************
00126 bool Scale::noteInScale(int base,int note)
00127 {
00128     int octave=Note::getOctaveOfNote(note);
00129     note-=12*octave;
00130     int normnote = (note>=base) ? note-base : (12-base)+note;
00131 
00132     if(halftones.contains(normnote)>0)
00133     {
00134         //odebug << "OK : base : " << base << ", note " << note << " -> norm " << normnote << "" << oendl; 
00135         return true;
00136     }
00137     else
00138     {
00139         //odebug << "BAD : base : " << base << ", note " << note << " -> norm " << normnote << "" << oendl; 
00140         return false;
00141     }
00142 }
00143 //****************************************************************************
00144 //****************************************************************************

Generated on Sat Nov 5 16:17:35 2005 for OPIE by  doxygen 1.4.2