/media/hdb5/canorusNightlyBuildSystem/trunk/src/core/clef.cpp

Go to the documentation of this file.
00001 
00008 #include "core/clef.h"
00009 #include "core/staff.h"
00010 #include "core/mark.h"
00011 
00028 CAClef::CAClef( CAPredefinedClefType type, CAStaff *staff, int time, int offsetInterval ) : CAMusElement( staff, time ) {
00029         _musElementType = CAMusElement::Clef;
00030         
00031         _offset = CAClef::offsetFromReadable( offsetInterval );
00032         setPredefinedType(type);
00033 }
00034 
00041 CAClef::CAClef( CAClefType type, int c1, CAStaff *staff, int time, int offset ) : CAMusElement( staff, time ) {
00042         _musElementType = CAMusElement::Clef;
00043         
00044         _c1 = c1;
00045         _offset = offset;
00046         setClefType(type);
00047 }
00048 
00049 void CAClef::setPredefinedType( CAPredefinedClefType type ) {
00050         switch (type) {
00051                 case Treble:
00052                         setClefType(G);
00053                         _c1 = -2 - offset();                    
00054                         break;
00055                 case Bass:
00056                         setClefType(F);
00057                         _c1 = 10 - offset();
00058                         break;
00059                 case French:
00060                         setClefType(G);
00061                         _c1 = -4 - offset();
00062                         break;
00063                 case Soprano:
00064                         setClefType(C);
00065                         _c1 = 0 - offset();
00066                         break;
00067                 case Mezzosoprano:
00068                         setClefType(C);
00069                         _c1 = 2 - offset();
00070                         break;
00071                 case Alto:
00072                         setClefType(C);
00073                         _c1 = 4 - offset();
00074                         break;
00075                 case Tenor:
00076                         setClefType(C);
00077                         _c1 = 6 - offset();
00078                         break;
00079                 case Baritone:
00080                         setClefType(C);
00081                         _c1 = 8 - offset();
00082                         break;
00083                 case Varbaritone:
00084                         setClefType(F);
00085                         _c1 = 8 - offset();
00086                         break;
00087                 case Subbass:
00088                         setClefType(F);
00089                         _c1 = 12 - offset();
00090                         break;
00091         }
00092 }
00093 
00099 void CAClef::setClefType(CAClefType type) {
00100         _clefType = type;
00101         
00102         switch (type) {
00103         case G: _centerPitch=32; break;
00104         case F: _centerPitch=24; break;
00105         case C: _centerPitch=28; break;
00106         }
00107         
00108         _centerPitch += offset();
00109 }
00110 
00111 CAClef* CAClef::clone() {
00112         CAClef *c = new CAClef( _clefType, _c1, static_cast<CAStaff*>(_context), _timeStart, _offset);
00113         
00114         for (int i=0; i<markList().size(); i++) {
00115                 CAMark *m = static_cast<CAMark*>(markList()[i]->clone());
00116                 m->setAssociatedElement(c);
00117                 c->addMark( m );
00118         }
00119         
00120         return c;
00121 }
00122 
00123 int CAClef::compare(CAMusElement *elt) {
00124         if (elt->musElementType()!=CAMusElement::Clef)
00125                 return -1;
00126         
00127         int diffs=0;
00128         if ( _clefType!=static_cast<CAClef*>(elt)->clefType()) diffs++;
00129         if ( _offset!=static_cast<CAClef*>(elt)->offset()) diffs++;
00130         if ( _c1!=static_cast<CAClef*>(elt)->c1()) diffs++;
00131         
00132         return diffs;
00133 }
00134 
00140 const QString CAClef::clefTypeToString(CAClefType type) {
00141         switch (type) {
00142                 case G: return "G";
00143                 case F: return "F";
00144                 case C: return "C";
00145                 case PercussionHigh: return "percussion-high";
00146                 case PercussionLow: return "percussion-low";
00147                 case Tab: return "tab";
00148                 default: return "";
00149         }
00150 }
00151 
00157 CAClef::CAClefType CAClef::clefTypeFromString(const QString type) {
00158         if (type=="G") return G; else
00159         if (type=="F") return F; else
00160         if (type=="C") return C; else
00161         if (type=="percussion-high") return PercussionHigh; else
00162         if (type=="percussion-low") return PercussionLow; else
00163         if (type=="tab") return Tab;
00164         else return G;
00165 }
00166 
00178 const int CAClef::offsetToReadable( const int offsetInterval ) {
00179         if ( !offsetInterval )
00180                 return 0;
00181         
00182         return offsetInterval + offsetInterval/qAbs(offsetInterval);
00183 }
00184 
00191 const int CAClef::offsetFromReadable( const int offset ) {
00192         if ( qAbs(offset)==1 || !offset )
00193                 return 0;
00194         
00195         return offset - offset/qAbs(offset);
00196 }
00197 

Generated on Sat Feb 9 13:06:25 2008 for Canorus by  doxygen 1.5.3