1 /* 2 GUIDO Library 3 Copyright (C) 2006 Grame 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 Grame Research Laboratory, 9 rue du Garet, 69001 Lyon - France 20 research@grame.fr 21 22 */ 23 24 #ifndef __ARNote__ 25 #define __ARNote__ 26 27 #include <map> 28 #include <string> 29 30 #include "guidoelement.h" 31 #include "guidorational.h" 32 #include "arexport.h" 33 34 namespace guido 35 { 36 37 /*! 38 \addtogroup abstract 39 @{ 40 */ 41 42 class basevisitor; 43 //______________________________________________________________________________ 44 /*! 45 \brief A Guido note description 46 */ 47 class gar_export ARNote : public guidoelement 48 { 49 protected: 50 ARNote(); ~ARNote()51 virtual ~ARNote() {} 52 53 int fOctave, fAccidental, fDots; 54 rational fDuration; 55 56 static std::map<std::string, std::pair<char, int> > fNormalizeMap; 57 58 public: 59 enum { kUndefinedOctave = -999, kUndefinedDuration = -999999, kDefaultOctave=1 }; 60 enum pitch { kNoPitch = -1, C, D, E, F, G, A, B }; 61 62 static SMARTP<ARNote> create(); 63 virtual void acceptIn (basevisitor& v); 64 virtual void acceptOut (basevisitor& v); 65 SetOctave(int oct)66 void SetOctave (int oct) { fOctave = oct; } SetAccidental(int acc)67 void SetAccidental (int acc) { fAccidental= acc; } SetDots(int dots)68 void SetDots (int dots) { fDots = dots; } 69 70 //! normalizes pitch names to 'a b c d...' notation, alter is to catch 'cis, dis...' notation 71 char NormalizedPitchName (int* alter = 0) const; 72 GetOctave()73 int GetOctave () const { return fOctave; } GetAccidental()74 int GetAccidental () const { return fAccidental; } GetDots()75 int GetDots () const { return fDots; } isRest()76 bool isRest () const { return getName() == "_"; } isEmpty()77 bool isEmpty () const { return getName() == "empty"; } isPitched()78 bool isPitched () const { return !isRest() && !isEmpty(); } 79 80 pitch GetPitch (int& alter) const; 81 int midiPitch (int& currentOctave) const; 82 83 // duration operations duration()84 const rational& duration() const { return fDuration; } 85 rational totalduration(rational& current, int& currentdots) const; 86 ARNote& operator = (const rational&); 87 ARNote& operator += (const rational&); 88 ARNote& operator -= (const rational&); 89 ARNote& operator *= (const rational&); 90 ARNote& operator /= (const rational&); implicitDuration()91 bool implicitDuration() const { return fDuration == getImplicitDuration(); } implicitOctave()92 bool implicitOctave() const { return fOctave == getImplicitOctave(); } setImplicitDuration()93 void setImplicitDuration() { fDuration.set(kUndefinedDuration,4); } 94 getImplicitDuration()95 static rational getImplicitDuration() { return rational(kUndefinedDuration,4); } implicitDuration(const rational & d)96 static bool implicitDuration(const rational& d) { return d.getNumerator() == kUndefinedDuration; } getDefaultDuration()97 static rational getDefaultDuration() { return rational(1,4); } getDefaultOctave()98 static int getDefaultOctave() { return 1; } getImplicitOctave()99 static int getImplicitOctave() { return kUndefinedOctave; } implicitOctave(int o)100 static bool implicitOctave(int o) { return o == kUndefinedOctave; } 101 102 /// offsets a pitch according diatonic steps and a chromatic target interval 103 static pitch OffsetPitch (pitch p, int offset, int& octave, int& alter, int targetinterval); 104 /// converts a note name to a pitch 105 static pitch NormalizedName2Pitch (char note); 106 /// converts a pitch to a normalized note name 107 static char NormalizedPitch2Name (pitch p); 108 /// converts a note name to a normalized note name i.e. 'a b c d...' notation, outalter is to catch 'cis, dis...' notation 109 static char NormalizedPitchName (const std::string& name, int* outalter=0); 110 static pitch chromaticOffsetPitch (pitch p, int interval, int& octave, int& alter, bool preferSharp); 111 112 /// converts a pitch to the enharmonic pitch 113 static pitch enharmonic (pitch p, int& octave, int& alter); 114 /// a semi tone pitch increment (updates octave and alter) 115 static pitch incPitch (pitch p, int& octave, int& alter); 116 /// a semi tone pitch decrement (updates octave and alter) 117 static pitch decPitch (pitch p, int& octave, int& alter); 118 119 operator std::string () const; 120 }; 121 122 } 123 124 /*! @} */ 125 126 #endif 127