1 //========================================================= 2 // MusE 3 // Linux Music Editor 4 // $Id: tempo.h,v 1.2.2.1 2006/09/19 19:07:09 spamatica Exp $ 5 // 6 // (C) Copyright 1999/2000 Werner Schweer (ws@seh.de) 7 // 8 // This program is free software; you can redistribute it and/or 9 // modify it under the terms of the GNU General Public License 10 // as published by the Free Software Foundation; version 2 of 11 // the License, or (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU General Public License for more details. 17 // 18 // You should have received a copy of the GNU General Public License 19 // along with this program; if not, write to the Free Software 20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 // 22 //========================================================= 23 #ifndef KEYEVENT_H 24 #define KEYEVENT_H 25 26 #include <map> 27 28 #include <QString> 29 #include <QStringList> 30 31 #ifndef MAX_TICK 32 #define MAX_TICK (0x7fffffff/100) 33 #endif 34 35 namespace MusECore { 36 37 class Xml; 38 39 //don't change this enum! changing the numeric values will affect 40 //all files using key_enum, and even worse: 41 //PREVIOUSLY SAVED FILES WILL BE CORRUPT because the keys are 42 //stored as integers. when the integer -> key mapping changes 43 //(by inserting or removing elements, for example), this will 44 //break stuff! (flo) 45 enum key_enum 46 { 47 KEY_SHARP_BEGIN, 48 KEY_C, // C or am, uses # for "black keys" 49 KEY_G, 50 KEY_D, 51 KEY_A, 52 KEY_E, 53 KEY_B, // or H in german. 54 KEY_FIS, //replaces F with E# 55 KEY_SHARP_END, 56 KEY_B_BEGIN, 57 KEY_C_B, // the same as C, but uses b for "black keys" 58 KEY_F, 59 KEY_BES, // or B in german 60 KEY_ES, 61 KEY_AS, 62 KEY_DES, 63 KEY_GES, //sounds like FIS, but uses b instead of # 64 KEY_B_END 65 }; 66 67 68 69 70 //--------------------------------------------------------- 71 // Key Event 72 //--------------------------------------------------------- 73 74 struct KeyEvent { 75 key_enum key; 76 unsigned tick; 77 bool minor; 78 79 80 int read(Xml&); 81 void write(int, Xml&, int) const; 82 83 KeyEvent(); 84 KeyEvent(key_enum k, unsigned tk, bool isMinor); 85 86 static const QStringList keyStrs; 87 static KeyEvent stringToKey(QString input); 88 static int keyToIndex(key_enum key, bool isMinor); 89 static QString keyToString(key_enum key, bool isMinor); 90 91 int keyIndex() const; 92 QString keyString() const; 93 }; 94 95 //--------------------------------------------------------- 96 // KeyList 97 //--------------------------------------------------------- 98 99 typedef std::map<unsigned, KeyEvent, std::less<unsigned> > KEYLIST; 100 typedef KEYLIST::iterator iKeyEvent; 101 typedef KEYLIST::const_iterator ciKeyEvent; 102 typedef KEYLIST::reverse_iterator riKeyEvent; 103 typedef KEYLIST::const_reverse_iterator criKeyEvent; 104 105 106 107 class KeyList : public KEYLIST { 108 void add(unsigned tick, key_enum tempo, bool isMinor); 109 void add(KeyEvent e); 110 void del(iKeyEvent); 111 void del(unsigned tick); 112 113 public: 114 115 KeyList(); 116 // Makes a copy of the source list including all items. 117 // This clears existing items in the destination list. 118 void copy(const KeyList& src); 119 120 void clear(); 121 122 void read(Xml&); 123 void write(int, Xml&) const; 124 void dump() const; 125 126 KeyEvent keyAtTick(unsigned tick) const; 127 128 void addKey(unsigned t, key_enum newKey, bool isMinor); 129 void delKey(unsigned tick); 130 }; 131 } // namespace MusECore 132 133 namespace MusEGlobal { 134 extern MusECore::KeyList keymap; 135 } 136 137 #endif // KEYEVENT_H 138